Skip to content

Commit

Permalink
make FpsController and StartupController singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 19, 2024
1 parent 419cbb4 commit 0a17ec2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 32 deletions.
6 changes: 2 additions & 4 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ using GpuSettingsDialog = std::shared_ptr<_GpuSettingsDialog>;
class _NewSimulationDialog;
using NewSimulationDialog = std::shared_ptr<_NewSimulationDialog>;

class _StartupController;
using StartupController = std::shared_ptr<_StartupController>;
class StartupController;

class _ExitDialog;
using ExitDialog = std::shared_ptr<_ExitDialog>;
Expand Down Expand Up @@ -94,8 +93,7 @@ using MultiplierWindow = std::shared_ptr<_MultiplierWindow>;
class _PatternAnalysisDialog;
using PatternAnalysisDialog = std::shared_ptr<_PatternAnalysisDialog>;

class _FpsController;
using FpsController = std::shared_ptr<_FpsController>;
class FpsController;

class BrowserWindow;

Expand Down
2 changes: 1 addition & 1 deletion source/Gui/FpsController.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "FpsController.h"

void _FpsController::processForceFps(int fps)
void FpsController::processForceFps(int fps)
{
auto callTimepoint = std::chrono::steady_clock::now();
if (_lastCallTimepoint) {
Expand Down
6 changes: 5 additions & 1 deletion source/Gui/FpsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

#include <chrono>

#include "Base/Singleton.h"

#include "Definitions.h"

class _FpsController
class FpsController
{
MAKE_SINGLETON(FpsController);

public:
void processForceFps(int fps);

Expand Down
25 changes: 12 additions & 13 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca
RadiationSourcesWindow::get().init(_simulationFacade);
SimulationParametersWindow::get().init(_simulationFacade);
_gpuSettingsDialog = std::make_shared<_GpuSettingsDialog>(_simulationFacade);
_startupController = std::make_shared<_StartupController>(_simulationFacade, _persisterFacade);
StartupController::get().init(_simulationFacade, _persisterFacade);
_exitDialog = std::make_shared<_ExitDialog>(_onExit);
_aboutDialog = std::make_shared<_AboutDialog>();
_massOperationsDialog = std::make_shared<_MassOperationsDialog>(_simulationFacade);
Expand All @@ -135,7 +135,6 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca
_newSimulationDialog = std::make_shared<_NewSimulationDialog>(_simulationFacade);
_displaySettingsDialog = std::make_shared<_DisplaySettingsDialog>();
_patternAnalysisDialog = std::make_shared<_PatternAnalysisDialog>(_simulationFacade);
_fpsController = std::make_shared<_FpsController>();
BrowserWindow::get().init(_simulationFacade, _persisterFacade);
ActivateUserDialog::get().init(_simulationFacade);
_newPasswordDialog = std::make_shared<_NewPasswordDialog>(_simulationFacade);
Expand Down Expand Up @@ -188,20 +187,20 @@ void _MainWindow::mainLoop()

// ImGui::ShowDemoWindow(NULL);

switch (_startupController->getState()) {
case _StartupController::State::StartLoadSimulation:
switch (StartupController::get().getState()) {
case StartupController::State::StartLoadSimulation:
processLoadingScreen();
break;
case _StartupController::State::LoadingSimulation:
case StartupController::State::LoadingSimulation:
processLoadingScreen();
break;
case _StartupController::State::FadeOutLoadingScreen:
case StartupController::State::FadeOutLoadingScreen:
processFadeoutLoadingScreen();
break;
case _StartupController::State::FadeInUI:
case StartupController::State::FadeInUI:
processFadeInUI();
break;
case _StartupController::State::Ready:
case StartupController::State::Ready:
processReady();
break;
default:
Expand Down Expand Up @@ -294,7 +293,7 @@ char const* _MainWindow::initGlfwAndReturnGlslVersion()

void _MainWindow::processLoadingScreen()
{
_startupController->process();
StartupController::get().process();
OverlayMessageController::get().process();

// render mainData
Expand All @@ -313,7 +312,7 @@ void _MainWindow::processLoadingScreen()

void _MainWindow::processFadeoutLoadingScreen()
{
_startupController->process();
StartupController::get().process();
renderSimulation();

finishFrame();
Expand All @@ -331,11 +330,11 @@ void _MainWindow::processFadeInUI()
processControllers();

SimulationView::get().processControls(_renderSimulation);
_startupController->process();
StartupController::get().process();

popGlobalStyle();

_fpsController->processForceFps(WindowController::get().getFps());
FpsController::get().processForceFps(WindowController::get().getFps());

finishFrame();
}
Expand All @@ -355,7 +354,7 @@ void _MainWindow::processReady()

popGlobalStyle();

_fpsController->processForceFps(WindowController::get().getFps());
FpsController::get().processForceFps(WindowController::get().getFps());

finishFrame();
}
Expand Down
2 changes: 0 additions & 2 deletions source/Gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class _MainWindow

PersisterFacade _persisterFacade;
SimulationFacade _simulationFacade;
StartupController _startupController;
FpsController _fpsController;

bool _onExit = false;
bool _simulationMenuToggled = false;
Expand Down
15 changes: 8 additions & 7 deletions source/Gui/StartupController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ namespace
auto const StartupSenderId = "Startup";
}

_StartupController::_StartupController(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade)
: _simulationFacade(simulationFacade)
, _persisterFacade(persisterFacade)
void StartupController::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade)
{
_simulationFacade = simulationFacade;
_persisterFacade =persisterFacade;

log(Priority::Important, "starting ALIEN v" + Const::ProgramVersion);
_logo = OpenGLHelper::loadTexture(Const::LogoFilename);
}

void _StartupController::process()
void StartupController::process()
{
if (_state == State::StartLoadSimulation) {
auto senderInfo = SenderInfo{.senderId = SenderId{StartupSenderId}, .wishResultData = true, .wishErrorInfo = true};
Expand Down Expand Up @@ -129,17 +130,17 @@ void _StartupController::process()
}
}

auto _StartupController::getState() -> State
auto StartupController::getState() -> State
{
return _state;
}

void _StartupController::activate()
void StartupController::activate()
{
_state = State::StartLoadSimulation;
}

void _StartupController::processLoadingScreen()
void StartupController::processLoadingScreen()
{
auto& styleRep = StyleRepository::get();
auto center = ImGui::GetMainViewport()->GetCenter();
Expand Down
10 changes: 6 additions & 4 deletions source/Gui/StartupController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

#include <chrono>

#include "Base/Singleton.h"
#include "EngineInterface/Definitions.h"
#include "PersisterInterface/Definitions.h"
#include "PersisterInterface/PersisterRequestId.h"

#include "Definitions.h"

class _StartupController
class StartupController
{
MAKE_SINGLETON(StartupController);

public:
_StartupController(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade);
void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade);

void process();
enum class State
Expand All @@ -28,8 +32,6 @@ class _StartupController
private:
void processLoadingScreen();

void drawGrid(float yPos, float alpha);

SimulationFacade _simulationFacade;
PersisterFacade _persisterFacade;

Expand Down

0 comments on commit 0a17ec2

Please sign in to comment.