diff --git a/source/Gui/AlienWindow.h b/source/Gui/AlienWindow.h index afd473c7a..ad46fb255 100644 --- a/source/Gui/AlienWindow.h +++ b/source/Gui/AlienWindow.h @@ -6,20 +6,18 @@ #include "Definitions.h" #include "StyleRepository.h" -#include "ShutdownInterface.h" -#include "ShutdownController.h" +#include "MainLoopEntity.h" +#include "MainLoopEntityController.h" #include "WindowController.h" template -class AlienWindow : public ShutdownInterface +class AlienWindow : public MainLoopEntity { public: AlienWindow(std::string const& title, std::string const& settingsNode, bool defaultOn); void init(Dependencies... dependencies); - void process(); - bool isOn() const; void setOn(bool value); @@ -38,6 +36,7 @@ class AlienWindow : public ShutdownInterface std::string _settingsNode; private: + void process() override; void shutdown() override; }; @@ -56,7 +55,7 @@ template void AlienWindow::init(Dependencies... dependencies) { _on = GlobalSettings::get().getBool(_settingsNode + ".active", _defaultOn); - ShutdownController::get().registerObject(this); + MainLoopEntityController::get().registerObject(this); initIntern(dependencies...); } diff --git a/source/Gui/AutosaveController.cpp b/source/Gui/AutosaveController.cpp index 21b9d7894..751d05834 100644 --- a/source/Gui/AutosaveController.cpp +++ b/source/Gui/AutosaveController.cpp @@ -11,7 +11,7 @@ #include "DelayedExecutionController.h" #include "OverlayMessageController.h" #include "SerializationHelperService.h" -#include "ShutdownController.h" +#include "MainLoopEntityController.h" namespace { @@ -24,7 +24,7 @@ void AutosaveController::init(SimulationFacade const& simulationFacade) _startTimePoint = std::chrono::steady_clock::now(); _on = GlobalSettings::get().getBool("controllers.auto save.active", true); - ShutdownController::get().registerObject(this); + MainLoopEntityController::get().registerObject(this); } void AutosaveController::shutdown() diff --git a/source/Gui/AutosaveController.h b/source/Gui/AutosaveController.h index bca7346f3..186b9d26f 100644 --- a/source/Gui/AutosaveController.h +++ b/source/Gui/AutosaveController.h @@ -6,9 +6,9 @@ #include "EngineInterface/Definitions.h" #include "Definitions.h" -#include "ShutdownInterface.h" +#include "MainLoopEntity.h" -class AutosaveController : public ShutdownInterface +class AutosaveController : public MainLoopEntity { MAKE_SINGLETON(AutosaveController); @@ -18,9 +18,8 @@ class AutosaveController : public ShutdownInterface bool isOn() const; void setOn(bool value); - void process(); - private: + void process() override; void shutdown() override; void onSave(); diff --git a/source/Gui/CMakeLists.txt b/source/Gui/CMakeLists.txt index 2d58bdec0..4b708f9c5 100644 --- a/source/Gui/CMakeLists.txt +++ b/source/Gui/CMakeLists.txt @@ -106,9 +106,9 @@ PUBLIC Shader.h ShaderWindow.cpp ShaderWindow.h - ShutdownController.cpp - ShutdownController.h - ShutdownInterface.h + MainLoopEntityController.cpp + MainLoopEntityController.h + MainLoopEntity.h SimulationInteractionController.cpp SimulationInteractionController.h SimulationParametersWindow.cpp diff --git a/source/Gui/EditorController.cpp b/source/Gui/EditorController.cpp index 2d6c83aaa..481b500b4 100644 --- a/source/Gui/EditorController.cpp +++ b/source/Gui/EditorController.cpp @@ -18,7 +18,7 @@ #include "GenomeEditorWindow.h" #include "MessageDialog.h" #include "OverlayMessageController.h" -#include "ShutdownController.h" +#include "MainLoopEntityController.h" namespace { @@ -35,12 +35,6 @@ void EditorController::init(SimulationFacade const& simulationFacade) PatternEditorWindow::get().init(_simulationFacade); CreatorWindow::get().init(_simulationFacade); MultiplierWindow::get().init(_simulationFacade); - - ShutdownController::get().registerObject(this); -} - -void EditorController::shutdown() -{ } bool EditorController::isOn() const @@ -59,12 +53,6 @@ void EditorController::process() return; } - SelectionWindow::get().process(); - PatternEditorWindow::get().process(); - CreatorWindow::get().process(); - MultiplierWindow::get().process(); - GenomeEditorWindow::get().process(); - processInspectorWindows(); EditorModel::get().setForceNoRollout(ImGui::GetIO().KeyShift); @@ -85,16 +73,6 @@ void EditorController::onCloseAllInspectorWindows() _inspectorWindows.clear(); } -bool EditorController::isObjectInspectionPossible() const -{ - return PatternEditorWindow::get().isObjectInspectionPossible(); -} - -bool EditorController::isGenomeInspectionPossible() const -{ - return PatternEditorWindow::get().isGenomeInspectionPossible(); -} - void EditorController::onInspectSelectedObjects() { auto selection = EditorModel::get().getSelectionShallowData(); diff --git a/source/Gui/EditorController.h b/source/Gui/EditorController.h index e7945cc39..7a176a12f 100644 --- a/source/Gui/EditorController.h +++ b/source/Gui/EditorController.h @@ -5,9 +5,9 @@ #include "EngineInterface/Descriptions.h" #include "Definitions.h" -#include "ShutdownInterface.h" +#include "MainLoopEntity.h" -class EditorController : public ShutdownInterface +class EditorController { MAKE_SINGLETON(EditorController); @@ -22,8 +22,6 @@ class EditorController : public ShutdownInterface bool areInspectionWindowsActive() const; void onCloseAllInspectorWindows(); - bool isObjectInspectionPossible() const; - bool isGenomeInspectionPossible() const; void onInspectSelectedObjects(); void onInspectSelectedGenomes(); void onInspectObjects(std::vector const& entities, bool selectGenomeTab); @@ -43,7 +41,6 @@ class EditorController : public ShutdownInterface void onAccelerateSelectedObjects(RealVector2D const& viewPos, RealVector2D const& prevWorldPos); private: - void shutdown() override; void processInspectorWindows(); SimulationFacade _simulationFacade; diff --git a/source/Gui/ImageToPatternDialog.h b/source/Gui/ImageToPatternDialog.h index a29560ab2..0e29727df 100644 --- a/source/Gui/ImageToPatternDialog.h +++ b/source/Gui/ImageToPatternDialog.h @@ -4,9 +4,9 @@ #include "EngineInterface/Definitions.h" #include "Definitions.h" -#include "ShutdownInterface.h" +#include "MainLoopEntity.h" -class ImageToPatternDialog : public ShutdownInterface +class ImageToPatternDialog : public MainLoopEntity { MAKE_SINGLETON(ImageToPatternDialog); @@ -18,6 +18,7 @@ class ImageToPatternDialog : public ShutdownInterface private: void shutdown() override; + void process() override {} SimulationFacade _simulationFacade; diff --git a/source/Gui/LoginController.cpp b/source/Gui/LoginController.cpp index 32673ae0e..5e9e957a0 100644 --- a/source/Gui/LoginController.cpp +++ b/source/Gui/LoginController.cpp @@ -10,7 +10,7 @@ #include "MessageDialog.h" #include "ActivateUserDialog.h" #include "BrowserWindow.h" -#include "ShutdownController.h" +#include "MainLoopEntityController.h" void LoginController::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade) { @@ -28,7 +28,7 @@ void LoginController::init(SimulationFacade const& simulationFacade, PersisterFa onLogin(); } - ShutdownController::get().registerObject(this); + MainLoopEntityController::get().registerObject(this); } void LoginController::shutdown() diff --git a/source/Gui/LoginController.h b/source/Gui/LoginController.h index 20bf36d2d..812ba0174 100644 --- a/source/Gui/LoginController.h +++ b/source/Gui/LoginController.h @@ -4,9 +4,9 @@ #include "PersisterInterface/PersisterFacade.h" #include "Definitions.h" -#include "ShutdownInterface.h" +#include "MainLoopEntity.h" -class LoginController : public ShutdownInterface +class LoginController : public MainLoopEntity { MAKE_SINGLETON(LoginController); public: @@ -15,8 +15,6 @@ class LoginController : public ShutdownInterface void onLogin(); - void process(); - void saveSettings(); bool shareGpuInfo() const; @@ -34,6 +32,7 @@ class LoginController : public ShutdownInterface UserInfo getUserInfo(); private: + void process() override; void shutdown() override; SimulationFacade _simulationFacade; diff --git a/source/Gui/MainLoopEntity.h b/source/Gui/MainLoopEntity.h new file mode 100644 index 000000000..e4b2aa05c --- /dev/null +++ b/source/Gui/MainLoopEntity.h @@ -0,0 +1,10 @@ +#pragma once + +class MainLoopEntity +{ +public: + virtual ~MainLoopEntity() = default; + + virtual void shutdown() = 0; + virtual void process() = 0; +}; diff --git a/source/Gui/MainLoopEntityController.cpp b/source/Gui/MainLoopEntityController.cpp new file mode 100644 index 000000000..8e1ea72b2 --- /dev/null +++ b/source/Gui/MainLoopEntityController.cpp @@ -0,0 +1,22 @@ +#include "MainLoopEntityController.h" + +#include + +void MainLoopEntityController::registerObject(MainLoopEntity* object) +{ + _objects.emplace_back(object); +} + +void MainLoopEntityController::shutdown() +{ + for (auto const& object : _objects | std::views::reverse) { + object->shutdown(); + } +} + +void MainLoopEntityController::process() +{ + for (auto const& object : _objects | std::views::reverse) { + object->process(); + } +} \ No newline at end of file diff --git a/source/Gui/MainLoopEntityController.h b/source/Gui/MainLoopEntityController.h new file mode 100644 index 000000000..5a97a3f9a --- /dev/null +++ b/source/Gui/MainLoopEntityController.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Base/Singleton.h" + +#include "Definitions.h" +#include "MainLoopEntity.h" + + +class MainLoopEntityController +{ + MAKE_SINGLETON(MainLoopEntityController); + +public: + void registerObject(MainLoopEntity* object); + + void shutdown(); + void process(); + +private: + std::vector _objects; +}; diff --git a/source/Gui/MainWindow.cpp b/source/Gui/MainWindow.cpp index e43395716..cda9cc519 100644 --- a/source/Gui/MainWindow.cpp +++ b/source/Gui/MainWindow.cpp @@ -77,7 +77,7 @@ #include "FileTransferController.h" #include "LoginController.h" #include "NetworkTransferController.h" -#include "ShutdownController.h" +#include "MainLoopEntityController.h" namespace { @@ -209,7 +209,7 @@ void _MainWindow::mainLoop() void _MainWindow::shutdown() { - ShutdownController::get().shutdown(); + MainLoopEntityController::get().shutdown(); GpuSettingsDialog::get().shutdown(); NewSimulationDialog::get().shutdown(); @@ -319,8 +319,8 @@ void _MainWindow::processFadeInUI() processMenubar(); processDialogs(); - processWindows(); processControllers(); + MainLoopEntityController::get().process(); SimulationView::get().processControls(_renderSimulation); StartupController::get().process(); @@ -340,8 +340,8 @@ void _MainWindow::processReady() processMenubar(); processDialogs(); - processWindows(); processControllers(); + MainLoopEntityController::get().process(); SimulationView::get().processControls(_renderSimulation); @@ -481,12 +481,12 @@ void _MainWindow::processMenubar() } ImGui::EndDisabled(); ImGui::Separator(); - ImGui::BeginDisabled(!SimulationInteractionController::get().isEditMode() || !EditorController::get().isObjectInspectionPossible()); + ImGui::BeginDisabled(!SimulationInteractionController::get().isEditMode() || !PatternEditorWindow::get().isObjectInspectionPossible()); if (ImGui::MenuItem("Inspect objects", "ALT+N")) { EditorController::get().onInspectSelectedObjects(); } ImGui::EndDisabled(); - ImGui::BeginDisabled(!SimulationInteractionController::get().isEditMode() || !EditorController::get().isGenomeInspectionPossible()); + ImGui::BeginDisabled(!SimulationInteractionController::get().isEditMode() || !PatternEditorWindow::get().isGenomeInspectionPossible()); if (ImGui::MenuItem("Inspect principal genome", "ALT+F")) { EditorController::get().onInspectSelectedGenomes(); } @@ -652,10 +652,10 @@ void _MainWindow::processMenubar() if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_A)) { MultiplierWindow::get().setOn(!MultiplierWindow::get().isOn()); } - if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_N) && EditorController::get().isObjectInspectionPossible()) { + if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_N) && PatternEditorWindow::get().isObjectInspectionPossible()) { EditorController::get().onInspectSelectedObjects(); } - if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_F) && EditorController::get().isGenomeInspectionPossible()) { + if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_F) && PatternEditorWindow::get().isGenomeInspectionPossible()) { EditorController::get().onInspectSelectedGenomes(); } if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { @@ -717,7 +717,6 @@ void _MainWindow::processDialogs() MassOperationsDialog::get().process(); GpuSettingsDialog::get().process(); DisplaySettingsDialog::get().process(); - PatternAnalysisDialog::get().process(); LoginDialog::get().process(); CreateUserDialog::get().process(); ActivateUserDialog::get().process(); @@ -733,30 +732,14 @@ void _MainWindow::processDialogs() GenericFileDialogs::get().process(); } -void _MainWindow::processWindows() -{ - TemporalControlWindow::get().process(); - SpatialControlWindow::get().process(); - StatisticsWindow::get().process(); - SimulationParametersWindow::get().process(); - LogWindow::get().process(); - BrowserWindow::get().process(); - GettingStartedWindow::get().process(); - ShaderWindow::get().process(); - RadiationSourcesWindow::get().process(); - AutosaveWindow::get().process(); -} - void _MainWindow::processControllers() { - AutosaveController::get().process(); EditorController::get().process(); OverlayMessageController::get().process(); SimulationInteractionController::get().process(); DelayedExecutionController::get().process(); FileTransferController::get().process(); NetworkTransferController::get().process(); - LoginController::get().process(); UiController::get().process(); } diff --git a/source/Gui/MainWindow.h b/source/Gui/MainWindow.h index 6881827fd..d4c909695 100644 --- a/source/Gui/MainWindow.h +++ b/source/Gui/MainWindow.h @@ -27,7 +27,6 @@ class _MainWindow void processMenubar(); void processDialogs(); - void processWindows(); void processControllers(); void onRunSimulation(); diff --git a/source/Gui/PatternAnalysisDialog.cpp b/source/Gui/PatternAnalysisDialog.cpp index c4a960413..f2ae778cc 100644 --- a/source/Gui/PatternAnalysisDialog.cpp +++ b/source/Gui/PatternAnalysisDialog.cpp @@ -13,7 +13,7 @@ #include "EngineInterface/SimulationFacade.h" #include "MessageDialog.h" -#include "ShutdownController.h" +#include "MainLoopEntityController.h" void PatternAnalysisDialog::init(SimulationFacade const& simulationFacade) @@ -26,7 +26,7 @@ void PatternAnalysisDialog::init(SimulationFacade const& simulationFacade) } _startingPath = GlobalSettings::get().getString("dialogs.pattern analysis.starting path", path.string()); - ShutdownController::get().registerObject(this); + MainLoopEntityController::get().registerObject(this); } void PatternAnalysisDialog::shutdown() diff --git a/source/Gui/PatternAnalysisDialog.h b/source/Gui/PatternAnalysisDialog.h index 16d97a5a7..27b82fc7e 100644 --- a/source/Gui/PatternAnalysisDialog.h +++ b/source/Gui/PatternAnalysisDialog.h @@ -4,19 +4,19 @@ #include "EngineInterface/Descriptions.h" #include "Definitions.h" -#include "ShutdownInterface.h" +#include "MainLoopEntity.h" -class PatternAnalysisDialog : public ShutdownInterface +class PatternAnalysisDialog : public MainLoopEntity { MAKE_SINGLETON(PatternAnalysisDialog); public: void init(SimulationFacade const& simulationFacade); - void process(); void show(); private: + void process() override; void shutdown() override; void saveRepetitiveActiveClustersToFiles(std::string const& filename); diff --git a/source/Gui/ShutdownController.cpp b/source/Gui/ShutdownController.cpp deleted file mode 100644 index 0e08867ec..000000000 --- a/source/Gui/ShutdownController.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "ShutdownController.h" - -#include -void ShutdownController::registerObject(ShutdownInterface* object) -{ - _objects.emplace_back(object); -} - -void ShutdownController::shutdown() -{ - for (auto const& object : _objects | std::views::reverse) { - object->shutdown(); - } -} \ No newline at end of file diff --git a/source/Gui/ShutdownController.h b/source/Gui/ShutdownController.h deleted file mode 100644 index ddf0368cd..000000000 --- a/source/Gui/ShutdownController.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "Base/Singleton.h" - -#include "Definitions.h" -#include "ShutdownInterface.h" - - -class ShutdownController -{ - MAKE_SINGLETON(ShutdownController); - -public: - void registerObject(ShutdownInterface* object); - - void shutdown(); - -private: - std::vector _objects; -}; diff --git a/source/Gui/ShutdownInterface.h b/source/Gui/ShutdownInterface.h deleted file mode 100644 index 520d583d6..000000000 --- a/source/Gui/ShutdownInterface.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -class ShutdownInterface -{ -public: - virtual ~ShutdownInterface() = default; - - virtual void shutdown() = 0; -}; diff --git a/source/Gui/WindowController.cpp b/source/Gui/WindowController.cpp index a2e4d7fc9..c43a21ac4 100644 --- a/source/Gui/WindowController.cpp +++ b/source/Gui/WindowController.cpp @@ -8,7 +8,7 @@ #include "Base/GlobalSettings.h" #include "Base/LoggingService.h" -#include "ShutdownController.h" +#include "MainLoopEntityController.h" namespace { @@ -88,7 +88,7 @@ void WindowController::init() float temp; glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &_contentScaleFactor, &temp); //consider only horizontal content scale - ShutdownController::get().registerObject(this); + MainLoopEntityController::get().registerObject(this); } void WindowController::shutdown() diff --git a/source/Gui/WindowController.h b/source/Gui/WindowController.h index 9bfcfc3d7..c3fcefbd4 100644 --- a/source/Gui/WindowController.h +++ b/source/Gui/WindowController.h @@ -4,9 +4,9 @@ #include "Base/Singleton.h" #include "Definitions.h" -#include "ShutdownInterface.h" +#include "MainLoopEntity.h" -class WindowController : public ShutdownInterface +class WindowController : public MainLoopEntity { MAKE_SINGLETON(WindowController); @@ -41,6 +41,7 @@ class WindowController : public ShutdownInterface float getLastContentScaleFactor(); private: + void process() override {} void shutdown() override; void updateWindowSize();