From 4c848990840d7c339656579d731b0d5658d95c35 Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com> Date: Sat, 22 Mar 2025 17:08:37 +0100 Subject: [PATCH] add settings menu remove time_offset --- src/main.cpp | 104 ++++++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 16294e2..0e97c87 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,7 +55,10 @@ static M4x4 inverse_view_matrix = inverse_view(V3_(0.0f, 0.0f, 0.0f), radians(45 static M4x4 projection_matrix = projection (radians(45.0f), 16.0f / 9.0f, NEAR_PLANE); static M4x4 inverse_projection_matrix = inverse_projection(radians(45.0f), 16.0f / 9.0f, NEAR_PLANE); -static SDL_DateTime time_offset = {}; +static SDL_Time time; + +static bool use_actual_time = true; +static SDL_DateTime calendar_time; static int time_tints_times[4][3] = { { 4, 0, 0 }, @@ -1212,7 +1215,7 @@ int main(int argc, char **argv) { bool first_frame = true; bool show_demo_window = false; bool show_tile_picker = false; - + bool show_settings = false; SDL_GetWindowSizeInPixels(window, &window_width, &window_height); @@ -1223,18 +1226,13 @@ int main(int argc, char **argv) { ImGui_ImplSDL3_NewFrame(); ImGui::NewFrame(); - SDL_Time time; SDL_GetCurrentTime(&time); - SDL_DateTime calendar_time; - SDL_TimeToDateTime(time, &calendar_time, true); + if (use_actual_time) + SDL_TimeToDateTime(time, &calendar_time, true); - calendar_time.second += time_offset.second; - calendar_time.minute += time_offset.minute; - calendar_time.hour += time_offset.hour; - - calendar_time.minute += calendar_time.second / 60; - calendar_time.hour += calendar_time.minute / 60; + calendar_time.minute += calendar_time.second >= 0 ? calendar_time.second / 60 : calendar_time.second / 60 - 1; + calendar_time.hour += calendar_time.minute >= 0 ? calendar_time.minute / 60 : calendar_time.minute / 60 - 1; calendar_time.second = real_mod(calendar_time.second, 60); calendar_time.minute = real_mod(calendar_time.minute, 60); @@ -1242,7 +1240,12 @@ int main(int argc, char **argv) { if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu("File")) { + ImGui::MenuItem("Settings", NULL, &show_settings); ImGui::MenuItem("Demo Window", NULL, &show_demo_window); + ImGui::Separator(); + if (ImGui::MenuItem("Exit")) { + Running = false; + } ImGui::EndMenu(); } @@ -1267,6 +1270,50 @@ int main(int argc, char **argv) { } ImGui::DockSpaceOverViewport(main_viewport_dock, ImGui::GetMainViewport(), ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingOverCentralNode); + if (show_settings) { + ImGui::SetNextWindowSize(ImVec2(400, 0), ImGuiCond_FirstUseEver); + if (ImGui::Begin("Settings", &show_settings)) { + ImGui::DragFloat("fovy", &per_frame.fovy_degrees); + ImGui::DragFloat("camera_distance", &per_frame.camera_distance, 0.25f, 1.0f, INFINITY); + ImGui::DragFloat("camera_tilt", &per_frame.camera_tilt, 0.25f, 0.0f, 89.0f); + + if (ImGui::Checkbox("MSAA", &enable_msaa)) { + recreate_graphics_pipelines(); + if (msaa_texture) { + SDL_ReleaseGPUTexture(device, msaa_texture); + msaa_texture = NULL; + } + } + + ImGui::NewLine(); + ImGui::BeginDisabled(use_actual_time); + ImGui::DragScalarN("Time", ImGuiDataType_S32, &calendar_time.hour, 3); + ImGui::EndDisabled(); + ImGui::Checkbox("use actual time", &use_actual_time); + + ImGui::NewLine(); + imgui_time_picker("time0", time_tints_times[0]); + imgui_time_picker("time1", time_tints_times[1]); + imgui_time_picker("time2", time_tints_times[2]); + imgui_time_picker("time3", time_tints_times[3]); + + ImGui::NewLine(); + ImGui::ColorEdit3("time0_color", time_tints[0].E); + ImGui::ColorEdit3("time1_color", time_tints[1].E); + ImGui::ColorEdit3("time2_color", time_tints[2].E); + ImGui::ColorEdit3("time3_color", time_tints[3].E); + + if (selected_tile != -1 && ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_R, false)) { + if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) { + selected_rotation = (selected_rotation - 1) & 3; + } else { + selected_rotation = (selected_rotation + 1) & 3; + } + } + } + ImGui::End(); + } + if (show_tile_picker) { if (ImGui::Begin("Tile Picker", &show_tile_picker, ImGuiWindowFlags_NoFocusOnAppearing)) { if (SelectableTile("##tile", selected_tile == -1, NULL, 0, ImVec2(32, 32))) { @@ -1319,41 +1366,6 @@ int main(int argc, char **argv) { if (ImGui::Selectable("Random", selected_rotation == -1)) selected_rotation = -1; } - - ImGui::DragFloat("fovy", &per_frame.fovy_degrees); - ImGui::DragFloat("camera_distance", &per_frame.camera_distance, 0.25f, 1.0f, INFINITY); - ImGui::DragFloat("camera_tilt", &per_frame.camera_tilt, 0.25f, 0.0f, 89.0f); - - if (ImGui::Checkbox("MSAA", &enable_msaa)) { - recreate_graphics_pipelines(); - if (msaa_texture) { - SDL_ReleaseGPUTexture(device, msaa_texture); - msaa_texture = NULL; - } - } - - ImGui::DragScalarN("calendar_time", ImGuiDataType_S32, &calendar_time.hour, 3); - imgui_time_picker("time_offset", &time_offset.hour); - - ImGui::NewLine(); - imgui_time_picker("time0", time_tints_times[0]); - imgui_time_picker("time1", time_tints_times[1]); - imgui_time_picker("time2", time_tints_times[2]); - imgui_time_picker("time3", time_tints_times[3]); - - ImGui::NewLine(); - ImGui::ColorEdit3("time0_color", time_tints[0].E); - ImGui::ColorEdit3("time1_color", time_tints[1].E); - ImGui::ColorEdit3("time2_color", time_tints[2].E); - ImGui::ColorEdit3("time3_color", time_tints[3].E); - - if (selected_tile != -1 && ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_R, false)) { - if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) { - selected_rotation = (selected_rotation - 1) & 3; - } else { - selected_rotation = (selected_rotation + 1) & 3; - } - } } ImGui::End(); }