From df60b84f65fd5bfd80af2287463714fd0fa4a1a3 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 16 Aug 2025 22:00:16 +0200 Subject: feat: preferences and saving --- src/states/config_state.cpp | 54 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'src/states/config_state.cpp') diff --git a/src/states/config_state.cpp b/src/states/config_state.cpp index 8cf24ef..1f1ef16 100644 --- a/src/states/config_state.cpp +++ b/src/states/config_state.cpp @@ -2,6 +2,7 @@ #include "rendering/renderer.h" #include "core/application.h" #include "core/theme_manager.h" +#include "core/settings_manager.h" #include #include @@ -13,8 +14,22 @@ namespace Donut { DONUT_INFO("Entering Config State"); - m_selected_api = Renderer::get_api(); - m_selected_theme = static_cast(ThemeManager::get_current_theme()); + const auto& settings = SettingsManager::get_settings_const(); + + m_selected_api = (settings.graphics.render_api == "Vulkan") ? RendererAPI::API::Vulkan : RendererAPI::API::OpenGL; + m_selected_theme = (settings.graphics.selected_theme == "Light") ? 1 : + (settings.graphics.selected_theme == "Blue") ? 2 : 0; + m_target_fps = settings.simulation.target_fps; + m_compute_height = settings.simulation.compute_height; + m_max_steps_moving = settings.simulation.max_steps_moving; + m_max_steps_static = settings.simulation.max_steps_static; + m_early_exit_distance = settings.simulation.early_exit_distance; + m_gravity_enabled = settings.simulation.gravity_enabled; + m_v_sync_enabled = settings.graphics.v_sync_enabled; + m_show_fps = settings.graphics.show_fps; + m_show_performance_metrics = settings.graphics.show_performance_metrics; + m_show_debug_info = settings.graphics.show_debug_info; + m_enable_anti_aliasing = settings.graphics.enable_anti_aliasing; } void ConfigState::on_exit() @@ -200,7 +215,7 @@ namespace Donut ImGui::Separator(); ImGui::Spacing(); - float button_width = (ImGui::GetWindowWidth() - 80) / 4.0f; + float button_width = (ImGui::GetWindowWidth() - 100) / 5.0f; if (ImGui::Button("Start Simulation", ImVec2(button_width, 35))) { @@ -216,6 +231,13 @@ namespace Donut if (ImGui::Button("Apply Settings", ImVec2(button_width, 35))) apply_settings(); + ImGui::SameLine(); + if (ImGui::Button("Save Settings", ImVec2(button_width, 35))) + { + apply_settings(); + DONUT_INFO("Settings saved manually"); + } + ImGui::SameLine(); if (ImGui::Button("Exit", ImVec2(button_width, 35))) Application::get().close(); @@ -237,8 +259,29 @@ namespace Donut void ConfigState::apply_settings() { + SimulationSettings sim_settings; + sim_settings.target_fps = m_target_fps; + sim_settings.compute_height = m_compute_height; + sim_settings.max_steps_moving = m_max_steps_moving; + sim_settings.max_steps_static = m_max_steps_static; + sim_settings.early_exit_distance = m_early_exit_distance; + sim_settings.gravity_enabled = m_gravity_enabled; + + GraphicsSettings gfx_settings; + gfx_settings.render_api = (m_selected_api == RendererAPI::API::Vulkan) ? "Vulkan" : "OpenGL"; + gfx_settings.v_sync_enabled = m_v_sync_enabled; + gfx_settings.show_fps = m_show_fps; + gfx_settings.show_performance_metrics = m_show_performance_metrics; + gfx_settings.show_debug_info = m_show_debug_info; + gfx_settings.enable_anti_aliasing = m_enable_anti_aliasing; + gfx_settings.selected_theme = (m_selected_theme == 1) ? "Light" : + (m_selected_theme == 2) ? "Blue" : "Dark"; + + SettingsManager::set_simulation_settings(sim_settings); + SettingsManager::set_graphics_settings(gfx_settings); + RendererAPI::set_api(m_selected_api); - DONUT_INFO("Settings applied"); + DONUT_INFO("Settings applied and saved"); } void ConfigState::reset_to_defaults() @@ -257,6 +300,7 @@ namespace Donut m_enable_anti_aliasing = true; m_selected_theme = 0; - DONUT_INFO("Settings reset to defaults"); + apply_settings(); + DONUT_INFO("Settings reset to defaults and saved"); } }; -- cgit v1.3