Skip to content

Commit

Permalink
make TemporalControlWindow a singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 19, 2024
1 parent 9e26f2a commit 5fc204c
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 91 deletions.
9 changes: 1 addition & 8 deletions source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include "StyleRepository.h"
#include "StatisticsWindow.h"
#include "Viewport.h"
#include "SerializationHelperService.h"
#include "TemporalControlWindow.h"
#include "MessageDialog.h"
#include "LoginDialog.h"
#include "UploadSimulationDialog.h"
Expand Down Expand Up @@ -75,16 +73,11 @@ namespace
{WorkspaceType_Private, std::string("private")}};
}

void BrowserWindow::init(
SimulationFacade const& simulationFacade,
PersisterFacade const& persisterFacade,
StatisticsWindow const& statisticsWindow,
TemporalControlWindow const& temporalControlWindow)
void BrowserWindow::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade, StatisticsWindow const& statisticsWindow)
{
_simulationFacade = simulationFacade;
_persisterFacade = persisterFacade;
_statisticsWindow = statisticsWindow;
_temporalControlWindow = temporalControlWindow;
_downloadCache = std::make_shared<_DownloadCache>();

_refreshProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
Expand Down
7 changes: 1 addition & 6 deletions source/Gui/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ class BrowserWindow : public AlienWindow
MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(BrowserWindow);

public:
void init(
SimulationFacade const& simulationFacade,
PersisterFacade const& persisterFacade,
StatisticsWindow const& statisticsWindow,
TemporalControlWindow const& temporalControlWindow);
void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade, StatisticsWindow const& statisticsWindow);
void shutdown();

void onRefresh();
Expand Down Expand Up @@ -142,5 +138,4 @@ class BrowserWindow : public AlienWindow
SimulationFacade _simulationFacade;
PersisterFacade _persisterFacade;
StatisticsWindow _statisticsWindow;
TemporalControlWindow _temporalControlWindow;
};
3 changes: 1 addition & 2 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class Viewport;

class StyleRepository;

class _TemporalControlWindow;
using TemporalControlWindow = std::shared_ptr<_TemporalControlWindow>;
class TemporalControlWindow;

class _SpatialControlWindow;
using SpatialControlWindow = std::shared_ptr<_SpatialControlWindow>;
Expand Down
8 changes: 2 additions & 6 deletions source/Gui/FileTransferController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ namespace
auto constexpr FileTransferSenderId = "FileTransfer";
}

void FileTransferController::init(
PersisterFacade const& persisterFacade,
SimulationFacade const& simulationFacade,
TemporalControlWindow const& temporalControlWindow)
void FileTransferController::init(PersisterFacade const& persisterFacade, SimulationFacade const& simulationFacade)
{
_persisterFacade = persisterFacade;
_simulationFacade = simulationFacade;
_temporalControlWindow = temporalControlWindow;
_openSimulationProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
}

Expand Down Expand Up @@ -77,7 +73,7 @@ void FileTransferController::onOpenSimulation()

Viewport::get().setCenterInWorldPos(data.deserializedSimulation.auxiliaryData.center);
Viewport::get().setZoomFactor(data.deserializedSimulation.auxiliaryData.zoom);
_temporalControlWindow->onSnapshot();
TemporalControlWindow::get().onSnapshot();
printOverlayMessage(data.simulationName + ".sim");
},
[](auto const& criticalErrors) { MessageDialog::get().information("Error", criticalErrors); });
Expand Down
3 changes: 1 addition & 2 deletions source/Gui/FileTransferController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FileTransferController
MAKE_SINGLETON(FileTransferController);

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

void onOpenSimulation();
void onSaveSimulation();
Expand All @@ -22,7 +22,6 @@ class FileTransferController
private:
PersisterFacade _persisterFacade;
SimulationFacade _simulationFacade;
TemporalControlWindow _temporalControlWindow;

TaskProcessor _openSimulationProcessor;

Expand Down
22 changes: 11 additions & 11 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca
_SimulationView::get().init(_simulationFacade);
SimulationInteractionController::get().init(_simulationFacade);
_statisticsWindow = std::make_shared<_StatisticsWindow>(_simulationFacade);
_temporalControlWindow = std::make_shared<_TemporalControlWindow>(_simulationFacade, _statisticsWindow);
_spatialControlWindow = std::make_shared<_SpatialControlWindow>(_simulationFacade, _temporalControlWindow);
TemporalControlWindow::get().init(_simulationFacade, _statisticsWindow);
_spatialControlWindow = std::make_shared<_SpatialControlWindow>(_simulationFacade);
_radiationSourcesWindow = std::make_shared<_RadiationSourcesWindow>(_simulationFacade);
_simulationParametersWindow = std::make_shared<_SimulationParametersWindow>(_simulationFacade, _radiationSourcesWindow);
_gpuSettingsDialog = std::make_shared<_GpuSettingsDialog>(_simulationFacade);
_startupController = std::make_shared<_StartupController>(_simulationFacade, _persisterFacade, _temporalControlWindow);
_startupController = std::make_shared<_StartupController>(_simulationFacade, _persisterFacade);
_exitDialog = std::make_shared<_ExitDialog>(_onExit);
_aboutDialog = std::make_shared<_AboutDialog>();
_massOperationsDialog = std::make_shared<_MassOperationsDialog>(_simulationFacade);
_logWindow = std::make_shared<_LogWindow>(_logger);
_gettingStartedWindow = std::make_shared<_GettingStartedWindow>();
_newSimulationDialog = std::make_shared<_NewSimulationDialog>(_simulationFacade, _temporalControlWindow, _statisticsWindow);
_newSimulationDialog = std::make_shared<_NewSimulationDialog>(_simulationFacade, _statisticsWindow);
_displaySettingsDialog = std::make_shared<_DisplaySettingsDialog>();
_patternAnalysisDialog = std::make_shared<_PatternAnalysisDialog>(_simulationFacade);
_fpsController = std::make_shared<_FpsController>();
BrowserWindow::get().init(_simulationFacade, _persisterFacade, _statisticsWindow, _temporalControlWindow);
BrowserWindow::get().init(_simulationFacade, _persisterFacade, _statisticsWindow);
ActivateUserDialog::get().init(_simulationFacade);
_newPasswordDialog = std::make_shared<_NewPasswordDialog>(_simulationFacade);
_resetPasswordDialog = std::make_shared<_ResetPasswordDialog>(_newPasswordDialog);
Expand All @@ -158,8 +158,8 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca
_shaderWindow = std::make_shared<_ShaderWindow>();
_autosaveWindow = std::make_shared<_AutosaveWindow>(_simulationFacade, _persisterFacade);
OverlayMessageController::get().init(_persisterFacade);
FileTransferController::get().init(_persisterFacade, _simulationFacade, _temporalControlWindow);
NetworkTransferController::get().init(_simulationFacade, _persisterFacade, _temporalControlWindow);
FileTransferController::get().init(_persisterFacade, _simulationFacade);
NetworkTransferController::get().init(_simulationFacade, _persisterFacade);
LoginController::get().init(_simulationFacade, _persisterFacade);

ifd::FileDialog::Instance().CreateTexture = [](uint8_t* data, int w, int h, char fmt) -> void* {
Expand Down Expand Up @@ -432,8 +432,8 @@ void _MainWindow::processMenubar()
}

if (AlienImGui::BeginMenuButton(" " ICON_FA_WINDOW_RESTORE " Windows ", _windowMenuToggled, "Windows")) {
if (ImGui::MenuItem("Temporal control", "ALT+1", _temporalControlWindow->isOn())) {
_temporalControlWindow->setOn(!_temporalControlWindow->isOn());
if (ImGui::MenuItem("Temporal control", "ALT+1", TemporalControlWindow::get().isOn())) {
TemporalControlWindow::get().setOn(!TemporalControlWindow::get().isOn());
}
if (ImGui::MenuItem("Spatial control", "ALT+2", _spatialControlWindow->isOn())) {
_spatialControlWindow->setOn(!_spatialControlWindow->isOn());
Expand Down Expand Up @@ -611,7 +611,7 @@ void _MainWindow::processMenubar()
}

if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_1)) {
_temporalControlWindow->setOn(!_temporalControlWindow->isOn());
TemporalControlWindow::get().setOn(!TemporalControlWindow::get().isOn());
}
if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_2)) {
_spatialControlWindow->setOn(!_spatialControlWindow->isOn());
Expand Down Expand Up @@ -736,7 +736,7 @@ void _MainWindow::processDialogs()

void _MainWindow::processWindows()
{
_temporalControlWindow->process();
TemporalControlWindow::get().process();
_spatialControlWindow->process();
_statisticsWindow->process();
_simulationParametersWindow->process();
Expand Down
1 change: 0 additions & 1 deletion source/Gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class _MainWindow
GLFWwindow* _window;
GuiLogger _logger;

TemporalControlWindow _temporalControlWindow;
SpatialControlWindow _spatialControlWindow;
SimulationParametersWindow _simulationParametersWindow;
StatisticsWindow _statisticsWindow;
Expand Down
5 changes: 2 additions & 3 deletions source/Gui/NetworkTransferController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
#include "BrowserWindow.h"
#include "OverlayMessageController.h"

void NetworkTransferController::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade, TemporalControlWindow const& temporalControlWindow)
void NetworkTransferController::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade)
{
_simulationFacade = simulationFacade;
_persisterFacade = persisterFacade;
_temporalControlWindow = temporalControlWindow;
_downloadProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
_uploadProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
_replaceProcessor = _TaskProcessor::createTaskProcessor(_persisterFacade);
Expand Down Expand Up @@ -67,7 +66,7 @@ void NetworkTransferController::onDownload(DownloadNetworkResourceRequestData co

Viewport::get().setCenterInWorldPos(deserializedSimulation.auxiliaryData.center);
Viewport::get().setZoomFactor(deserializedSimulation.auxiliaryData.zoom);
_temporalControlWindow->onSnapshot();
TemporalControlWindow::get().onSnapshot();
} else {
EditorController::get().setOn(true);
EditorController::get().getGenomeEditorWindow()->openTab(std::get<GenomeDescription>(data.resourceData));
Expand Down
3 changes: 1 addition & 2 deletions source/Gui/NetworkTransferController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NetworkTransferController
MAKE_SINGLETON(NetworkTransferController);

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

void onDownload(DownloadNetworkResourceRequestData const& requestData);
void onUpload(UploadNetworkResourceRequestData const& requestData);
Expand All @@ -29,7 +29,6 @@ class NetworkTransferController
private:
SimulationFacade _simulationFacade;
PersisterFacade _persisterFacade;
TemporalControlWindow _temporalControlWindow;

TaskProcessor _downloadProcessor;
TaskProcessor _uploadProcessor;
Expand Down
4 changes: 1 addition & 3 deletions source/Gui/NewSimulationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ namespace

_NewSimulationDialog::_NewSimulationDialog(
SimulationFacade const& simulationFacade,
TemporalControlWindow const& temporalControlWindow,
StatisticsWindow const& statisticsWindow)
: AlienDialog("New simulation")
, _simulationFacade(simulationFacade)
, _temporalControlWindow(temporalControlWindow)
, _statisticsWindow(statisticsWindow)
{
_adoptSimulationParameters = GlobalSettings::get().getBool("dialogs.new simulation.adopt simulation parameters", true);
Expand Down Expand Up @@ -80,5 +78,5 @@ void _NewSimulationDialog::onNewSimulation()
_simulationFacade->newSimulation(std::nullopt, 0, generalSettings, parameters);
Viewport::get().setCenterInWorldPos({toFloat(_width) / 2, toFloat(_height) / 2});
Viewport::get().setZoomFactor(4.0f);
_temporalControlWindow->onSnapshot();
TemporalControlWindow::get().onSnapshot();
}
6 changes: 1 addition & 5 deletions source/Gui/NewSimulationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
class _NewSimulationDialog : public AlienDialog
{
public:
_NewSimulationDialog(
SimulationFacade const& simulationFacade,
TemporalControlWindow const& temporalControlWindow,
StatisticsWindow const& statisticsWindow);
_NewSimulationDialog(SimulationFacade const& simulationFacade, StatisticsWindow const& statisticsWindow);
~_NewSimulationDialog() override;

private:
Expand All @@ -21,7 +18,6 @@ class _NewSimulationDialog : public AlienDialog
void onNewSimulation();

SimulationFacade _simulationFacade;
TemporalControlWindow _temporalControlWindow;
StatisticsWindow _statisticsWindow;

bool _adoptSimulationParameters = true;
Expand Down
5 changes: 2 additions & 3 deletions source/Gui/ResizeWorldDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#include "AlienImGui.h"
#include "TemporalControlWindow.h"

_ResizeWorldDialog::_ResizeWorldDialog(SimulationFacade const& simulationFacade, TemporalControlWindow const& temporalControlWindow)
_ResizeWorldDialog::_ResizeWorldDialog(SimulationFacade const& simulationFacade)
: AlienDialog("Resize world")
, _simulationFacade(simulationFacade)
, _temporalControlWindow(temporalControlWindow)
{}

void _ResizeWorldDialog::open()
Expand Down Expand Up @@ -94,5 +93,5 @@ void _ResizeWorldDialog::onResizing()
_simulationFacade->setClusteredSimulationData(content);
_simulationFacade->setStatisticsHistory(statistics);
_simulationFacade->setRealTime(realtime);
_temporalControlWindow->onSnapshot();
TemporalControlWindow::get().onSnapshot();
}
3 changes: 1 addition & 2 deletions source/Gui/ResizeWorldDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class _ResizeWorldDialog : public AlienDialog
{
public:
_ResizeWorldDialog(SimulationFacade const& simulationFacade, TemporalControlWindow const& temporalControlWindow);
_ResizeWorldDialog(SimulationFacade const& simulationFacade);

void open();

Expand All @@ -16,7 +16,6 @@ class _ResizeWorldDialog : public AlienDialog
void onResizing();

SimulationFacade _simulationFacade;
TemporalControlWindow _temporalControlWindow;

bool _scaleContent = false;
int _width = 0;
Expand Down
4 changes: 2 additions & 2 deletions source/Gui/SpatialControlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include "AlienImGui.h"
#include "ResizeWorldDialog.h"

_SpatialControlWindow::_SpatialControlWindow(SimulationFacade const& simulationFacade, TemporalControlWindow const& temporalControlWindow)
_SpatialControlWindow::_SpatialControlWindow(SimulationFacade const& simulationFacade)
: AlienWindow("Spatial control", "windows.spatial control", true)
, _simulationFacade(simulationFacade)
{
_resizeWorldDialog = std::make_shared<_ResizeWorldDialog>(simulationFacade, temporalControlWindow);
_resizeWorldDialog = std::make_shared<_ResizeWorldDialog>(simulationFacade);

auto& settings = GlobalSettings::get();
Viewport::get().setZoomSensitivity(settings.getFloat("windows.spatial control.zoom sensitivity factor", Viewport::get().getZoomSensitivity()));
Expand Down
2 changes: 1 addition & 1 deletion source/Gui/SpatialControlWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class _SpatialControlWindow : public AlienWindow
{
public:
_SpatialControlWindow(SimulationFacade const& simulationFacade, TemporalControlWindow const& temporalControlWindow);
_SpatialControlWindow(SimulationFacade const& simulationFacade);
~_SpatialControlWindow() override;

private:
Expand Down
10 changes: 3 additions & 7 deletions source/Gui/StartupController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ namespace
auto const StartupSenderId = "Startup";
}

_StartupController::_StartupController(
SimulationFacade const& simulationFacade,
PersisterFacade const& persisterFacade,
TemporalControlWindow const& temporalControlWindow)
_StartupController::_StartupController(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade)
: _simulationFacade(simulationFacade)
, _temporalControlWindow(temporalControlWindow)
, _persisterFacade(persisterFacade)
{
log(Priority::Important, "starting ALIEN v" + Const::ProgramVersion);
Expand Down Expand Up @@ -65,7 +61,7 @@ void _StartupController::process()
_simulationFacade->setRealTime(deserializedSim.auxiliaryData.realTime);
Viewport::get().setCenterInWorldPos(deserializedSim.auxiliaryData.center);
Viewport::get().setZoomFactor(deserializedSim.auxiliaryData.zoom);
_temporalControlWindow->onSnapshot();
TemporalControlWindow::get().onSnapshot();

_lastActivationTimepoint = std::chrono::steady_clock::now();
_state = State::FadeOutLoadingScreen;
Expand All @@ -91,7 +87,7 @@ void _StartupController::process()
_simulationFacade->setRealTime(deserializedSim.auxiliaryData.realTime);
Viewport::get().setCenterInWorldPos(deserializedSim.auxiliaryData.center);
Viewport::get().setZoomFactor(deserializedSim.auxiliaryData.zoom);
_temporalControlWindow->onSnapshot();
TemporalControlWindow::get().onSnapshot();

_lastActivationTimepoint = std::chrono::steady_clock::now();
_state = State::FadeOutLoadingScreen;
Expand Down
6 changes: 1 addition & 5 deletions source/Gui/StartupController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
class _StartupController
{
public:
_StartupController(
SimulationFacade const& simulationFacade,
PersisterFacade const& persisterFacade,
TemporalControlWindow const& temporalControlWindow);
_StartupController(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade);

void process();
enum class State
Expand All @@ -34,7 +31,6 @@ class _StartupController
void drawGrid(float yPos, float alpha);

SimulationFacade _simulationFacade;
TemporalControlWindow _temporalControlWindow;
PersisterFacade _persisterFacade;

PersisterRequestId _startupSimRequestId;
Expand Down
Loading

0 comments on commit 5fc204c

Please sign in to comment.