Skip to content

Commit

Permalink
make StatisticsWindow a singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 19, 2024
1 parent 5fc204c commit c13482f
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 92 deletions.
3 changes: 1 addition & 2 deletions source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ namespace
{WorkspaceType_Private, std::string("private")}};
}

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

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

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

void onRefresh();
Expand Down Expand Up @@ -137,5 +137,4 @@ class BrowserWindow : public AlienWindow

SimulationFacade _simulationFacade;
PersisterFacade _persisterFacade;
StatisticsWindow _statisticsWindow;
};
6 changes: 2 additions & 4 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ using MainWindow = std::shared_ptr<_MainWindow>;

class AlienWindow;

class _SimulationView;
using SimulationView= std::shared_ptr<_SimulationView>;
class SimulationView;

class _Shader;
using Shader = std::shared_ptr<_Shader>;
Expand All @@ -28,8 +27,7 @@ using SpatialControlWindow = std::shared_ptr<_SpatialControlWindow>;
class _SimulationParametersWindow;
using SimulationParametersWindow = std::shared_ptr<_SimulationParametersWindow>;

class _StatisticsWindow;
using StatisticsWindow = std::shared_ptr<_StatisticsWindow>;
class StatisticsWindow;

class SimulationInteractionController;

Expand Down
35 changes: 18 additions & 17 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
if (width > 0 && height > 0) {
_SimulationView::get().resize({width, height});
SimulationView::get().resize({width, height});
glViewport(0, 0, width, height);
}
}
Expand Down Expand Up @@ -128,10 +128,10 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca
Viewport::get().init(_simulationFacade);
AutosaveController::get().init(_simulationFacade);
EditorController::get().init(_simulationFacade);
_SimulationView::get().init(_simulationFacade);
SimulationView::get().init(_simulationFacade);
SimulationInteractionController::get().init(_simulationFacade);
_statisticsWindow = std::make_shared<_StatisticsWindow>(_simulationFacade);
TemporalControlWindow::get().init(_simulationFacade, _statisticsWindow);
StatisticsWindow::get().init(_simulationFacade);
TemporalControlWindow::get().init(_simulationFacade);
_spatialControlWindow = std::make_shared<_SpatialControlWindow>(_simulationFacade);
_radiationSourcesWindow = std::make_shared<_RadiationSourcesWindow>(_simulationFacade);
_simulationParametersWindow = std::make_shared<_SimulationParametersWindow>(_simulationFacade, _radiationSourcesWindow);
Expand All @@ -142,11 +142,11 @@ _MainWindow::_MainWindow(SimulationFacade const& simulationFacade, PersisterFaca
_massOperationsDialog = std::make_shared<_MassOperationsDialog>(_simulationFacade);
_logWindow = std::make_shared<_LogWindow>(_logger);
_gettingStartedWindow = std::make_shared<_GettingStartedWindow>();
_newSimulationDialog = std::make_shared<_NewSimulationDialog>(_simulationFacade, _statisticsWindow);
_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, _statisticsWindow);
BrowserWindow::get().init(_simulationFacade, _persisterFacade);
ActivateUserDialog::get().init(_simulationFacade);
_newPasswordDialog = std::make_shared<_NewPasswordDialog>(_simulationFacade);
_resetPasswordDialog = std::make_shared<_ResetPasswordDialog>(_newPasswordDialog);
Expand Down Expand Up @@ -224,6 +224,7 @@ void _MainWindow::mainLoop()
void _MainWindow::shutdown()
{
BrowserWindow::get().shutdown();
StatisticsWindow::get().shutdown();

EditorController::get().shutdown();
LoginController::get().shutdown();
Expand All @@ -239,7 +240,7 @@ void _MainWindow::shutdown()
glfwDestroyWindow(_window);
glfwTerminate();

_SimulationView::get().shutdown();
SimulationView::get().shutdown();

_persisterFacade->shutdown();
_simulationFacade->closeSimulation();
Expand Down Expand Up @@ -317,7 +318,7 @@ void _MainWindow::processFadeInUI()
processWindows();
processControllers();

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

popGlobalStyle();
Expand All @@ -338,7 +339,7 @@ void _MainWindow::processReady()
processWindows();
processControllers();

_SimulationView::get().processControls(_renderSimulation);
SimulationView::get().processControls(_renderSimulation);

popGlobalStyle();

Expand All @@ -352,7 +353,7 @@ void _MainWindow::renderSimulation()
int display_w, display_h;
glfwGetFramebufferSize(_window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
_SimulationView::get().draw(_renderSimulation);
SimulationView::get().draw(_renderSimulation);
}

void _MainWindow::processMenubar()
Expand Down Expand Up @@ -438,8 +439,8 @@ void _MainWindow::processMenubar()
if (ImGui::MenuItem("Spatial control", "ALT+2", _spatialControlWindow->isOn())) {
_spatialControlWindow->setOn(!_spatialControlWindow->isOn());
}
if (ImGui::MenuItem("Statistics", "ALT+3", _statisticsWindow->isOn())) {
_statisticsWindow->setOn(!_statisticsWindow->isOn());
if (ImGui::MenuItem("Statistics", "ALT+3", StatisticsWindow::get().isOn())) {
StatisticsWindow::get().setOn(!StatisticsWindow::get().isOn());
}
if (ImGui::MenuItem("Simulation parameters", "ALT+4", _simulationParametersWindow->isOn())) {
_simulationParametersWindow->setOn(!_simulationParametersWindow->isOn());
Expand Down Expand Up @@ -512,8 +513,8 @@ void _MainWindow::processMenubar()
}

if (AlienImGui::BeginMenuButton(" " ICON_FA_EYE " View ", _viewMenuToggled, "View")) {
if (ImGui::MenuItem("Information overlay", "ALT+O", _SimulationView::get().isOverlayActive())) {
_SimulationView::get().setOverlayActive(!_SimulationView::get().isOverlayActive());
if (ImGui::MenuItem("Information overlay", "ALT+O", SimulationView::get().isOverlayActive())) {
SimulationView::get().setOverlayActive(!SimulationView::get().isOverlayActive());
}
if (ImGui::MenuItem("Render UI", "ALT+U", UiController::get().isOn())) {
UiController::get().setOn(!UiController::get().isOn());
Expand Down Expand Up @@ -617,7 +618,7 @@ void _MainWindow::processMenubar()
_spatialControlWindow->setOn(!_spatialControlWindow->isOn());
}
if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_3)) {
_statisticsWindow->setOn(!_statisticsWindow->isOn());
StatisticsWindow::get().setOn(!StatisticsWindow::get().isOn());
}
if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_4)) {
_simulationParametersWindow->setOn(!_simulationParametersWindow->isOn());
Expand Down Expand Up @@ -690,7 +691,7 @@ void _MainWindow::processMenubar()
}

if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_O)) {
_SimulationView::get().setOverlayActive(!_SimulationView::get().isOverlayActive());
SimulationView::get().setOverlayActive(!SimulationView::get().isOverlayActive());
}
if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_U)) {
UiController::get().setOn(!UiController::get().isOn());
Expand Down Expand Up @@ -738,7 +739,7 @@ void _MainWindow::processWindows()
{
TemporalControlWindow::get().process();
_spatialControlWindow->process();
_statisticsWindow->process();
StatisticsWindow::get().process();
_simulationParametersWindow->process();
_logWindow->process();
BrowserWindow::get().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 @@ -42,7 +42,6 @@ class _MainWindow

SpatialControlWindow _spatialControlWindow;
SimulationParametersWindow _simulationParametersWindow;
StatisticsWindow _statisticsWindow;
LogWindow _logWindow;
GettingStartedWindow _gettingStartedWindow;
ShaderWindow _shaderWindow;
Expand Down
5 changes: 1 addition & 4 deletions source/Gui/NewSimulationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ namespace
auto const ContentTextInputWidth = 60.0f;
}

_NewSimulationDialog::_NewSimulationDialog(
SimulationFacade const& simulationFacade,
StatisticsWindow const& statisticsWindow)
_NewSimulationDialog::_NewSimulationDialog(SimulationFacade const& simulationFacade)
: AlienDialog("New simulation")
, _simulationFacade(simulationFacade)
, _statisticsWindow(statisticsWindow)
{
_adoptSimulationParameters = GlobalSettings::get().getBool("dialogs.new simulation.adopt simulation parameters", true);
}
Expand Down
3 changes: 1 addition & 2 deletions source/Gui/NewSimulationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class _NewSimulationDialog : public AlienDialog
{
public:
_NewSimulationDialog(SimulationFacade const& simulationFacade, StatisticsWindow const& statisticsWindow);
_NewSimulationDialog(SimulationFacade const& simulationFacade);
~_NewSimulationDialog() override;

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

SimulationFacade _simulationFacade;
StatisticsWindow _statisticsWindow;

bool _adoptSimulationParameters = true;
int _width = 0;
Expand Down
18 changes: 9 additions & 9 deletions source/Gui/ShaderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ _ShaderWindow::~_ShaderWindow()

void _ShaderWindow::processIntern()
{
auto const defaultBrightness = _SimulationView::DefaultBrightness;
auto const defaultContrast = _SimulationView::DefaultContrast;
auto const defaultMotionBlur = _SimulationView::DefaultMotionBlur;
auto const defaultBrightness = SimulationView::DefaultBrightness;
auto const defaultContrast = SimulationView::DefaultContrast;
auto const defaultMotionBlur = SimulationView::DefaultMotionBlur;

auto brightness = _SimulationView::get().getBrightness();
auto contrast = _SimulationView::get().getContrast();
auto motionBlur = _SimulationView::get().getMotionBlur();
auto brightness = SimulationView::get().getBrightness();
auto contrast = SimulationView::get().getContrast();
auto motionBlur = SimulationView::get().getMotionBlur();
if (AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters().name("Brightness").min(0).max(3.0f).textWidth(RightColumnWidth).defaultValue(&defaultBrightness), &brightness)) {
_SimulationView::get().setBrightness(brightness);
SimulationView::get().setBrightness(brightness);
}
if (AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters().name("Contrast").min(0).max(2.0f).textWidth(RightColumnWidth).defaultValue(&defaultContrast), &contrast)) {
_SimulationView::get().setContrast(contrast);
SimulationView::get().setContrast(contrast);
}
if (AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
Expand All @@ -45,6 +45,6 @@ void _ShaderWindow::processIntern()
.logarithmic(true)
.defaultValue(&defaultMotionBlur),
&motionBlur)) {
_SimulationView::get().setMotionBlur(motionBlur);
SimulationView::get().setMotionBlur(motionBlur);
}
}
8 changes: 4 additions & 4 deletions source/Gui/SimulationInteractionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void SimulationInteractionController::leftMouseButtonPressed(IntVector2D const&

if (!_modes.editMode) {
_lastZoomTimepoint.reset();
_SimulationView::get().setMotionBlur(_SimulationView::get().getMotionBlur() * 2);
SimulationView::get().setMotionBlur(SimulationView::get().getMotionBlur() * 2);
} else {
if (!ImGui::GetIO().KeyAlt) {
if (!_modes.drawMode) {
Expand Down Expand Up @@ -220,7 +220,7 @@ void SimulationInteractionController::leftMouseButtonReleased(IntVector2D const&
}

if (!_modesAtClick.editMode) {
_SimulationView::get().setMotionBlur(_SimulationView::get().getMotionBlur() / 2);
SimulationView::get().setMotionBlur(SimulationView::get().getMotionBlur() / 2);
} else {
if (_modesAtClick.drawMode) {
EditorController::get().getCreatorWindow()->finishDrawing();
Expand All @@ -245,7 +245,7 @@ void SimulationInteractionController::rightMouseButtonPressed(IntVector2D const&

if (!_modes.editMode) {
_lastZoomTimepoint.reset();
_SimulationView::get().setMotionBlur(_SimulationView::get().getMotionBlur() * 2);
SimulationView::get().setMotionBlur(SimulationView::get().getMotionBlur() * 2);
} else {
if (!ImGui::GetIO().KeyAlt) {
if (!_simulationFacade->isSimulationRunning() && !_modes.drawMode) {
Expand Down Expand Up @@ -293,7 +293,7 @@ void SimulationInteractionController::rightMouseButtonReleased()
}

if (!_modesAtClick.editMode) {
_SimulationView::get().setMotionBlur(_SimulationView::get().getMotionBlur() / 2);
SimulationView::get().setMotionBlur(SimulationView::get().getMotionBlur() / 2);
} else {
if (!_simulationFacade->isSimulationRunning()) {
_selectionRect.reset();
Expand Down
Loading

0 comments on commit c13482f

Please sign in to comment.