Skip to content

Commit

Permalink
automatic execution of main loop entities
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 20, 2024
1 parent a2de5bf commit 3d63721
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 129 deletions.
11 changes: 5 additions & 6 deletions source/Gui/AlienWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename ...Dependencies>
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);

Expand All @@ -38,6 +36,7 @@ class AlienWindow : public ShutdownInterface
std::string _settingsNode;

private:
void process() override;
void shutdown() override;
};

Expand All @@ -56,7 +55,7 @@ template <typename ... Dependencies>
void AlienWindow<Dependencies...>::init(Dependencies... dependencies)
{
_on = GlobalSettings::get().getBool(_settingsNode + ".active", _defaultOn);
ShutdownController::get().registerObject(this);
MainLoopEntityController::get().registerObject(this);
initIntern(dependencies...);
}

Expand Down
4 changes: 2 additions & 2 deletions source/Gui/AutosaveController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "DelayedExecutionController.h"
#include "OverlayMessageController.h"
#include "SerializationHelperService.h"
#include "ShutdownController.h"
#include "MainLoopEntityController.h"

namespace
{
Expand All @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions source/Gui/AutosaveController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions source/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 1 addition & 23 deletions source/Gui/EditorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "GenomeEditorWindow.h"
#include "MessageDialog.h"
#include "OverlayMessageController.h"
#include "ShutdownController.h"
#include "MainLoopEntityController.h"

namespace
{
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions source/Gui/EditorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<CellOrParticleDescription> const& entities, bool selectGenomeTab);
Expand All @@ -43,7 +41,6 @@ class EditorController : public ShutdownInterface
void onAccelerateSelectedObjects(RealVector2D const& viewPos, RealVector2D const& prevWorldPos);

private:
void shutdown() override;
void processInspectorWindows();

SimulationFacade _simulationFacade;
Expand Down
5 changes: 3 additions & 2 deletions source/Gui/ImageToPatternDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -18,6 +18,7 @@ class ImageToPatternDialog : public ShutdownInterface

private:
void shutdown() override;
void process() override {}

SimulationFacade _simulationFacade;

Expand Down
4 changes: 2 additions & 2 deletions source/Gui/LoginController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -28,7 +28,7 @@ void LoginController::init(SimulationFacade const& simulationFacade, PersisterFa
onLogin();
}

ShutdownController::get().registerObject(this);
MainLoopEntityController::get().registerObject(this);
}

void LoginController::shutdown()
Expand Down
7 changes: 3 additions & 4 deletions source/Gui/LoginController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -15,8 +15,6 @@ class LoginController : public ShutdownInterface

void onLogin();

void process();

void saveSettings();

bool shareGpuInfo() const;
Expand All @@ -34,6 +32,7 @@ class LoginController : public ShutdownInterface
UserInfo getUserInfo();

private:
void process() override;
void shutdown() override;

SimulationFacade _simulationFacade;
Expand Down
10 changes: 10 additions & 0 deletions source/Gui/MainLoopEntity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

class MainLoopEntity
{
public:
virtual ~MainLoopEntity() = default;

virtual void shutdown() = 0;
virtual void process() = 0;
};
22 changes: 22 additions & 0 deletions source/Gui/MainLoopEntityController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "MainLoopEntityController.h"

#include <ranges>

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();
}
}
21 changes: 21 additions & 0 deletions source/Gui/MainLoopEntityController.h
Original file line number Diff line number Diff line change
@@ -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<MainLoopEntity*> _objects;
};
Loading

0 comments on commit 3d63721

Please sign in to comment.