Skip to content

Commit

Permalink
make singletons, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 20, 2024
1 parent 856ddce commit ea1c35c
Show file tree
Hide file tree
Showing 26 changed files with 199 additions and 180 deletions.
2 changes: 1 addition & 1 deletion source/Gui/AlienWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AlienWindow : public ShutdownInterface
void setOn(bool value);

protected:
virtual void shutdownIntern() {};
virtual void shutdownIntern() {}
virtual void processIntern() = 0;
virtual void processBackground() {}
virtual void processActivated() {}
Expand Down
29 changes: 16 additions & 13 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ namespace
auto constexpr AutosaveSenderId = "Autosave";
}

_AutosaveWindow::_AutosaveWindow(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade)
: AlienWindow("Autosave (work in progress)", "windows.autosave", false)
, _simulationFacade(simulationFacade)
, _persisterFacade(persisterFacade)
void AutosaveWindow::init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade)
{
_simulationFacade = simulationFacade;
_persisterFacade = persisterFacade;
_settingsOpen = GlobalSettings::get().getBool("windows.autosave.settings.open", _settingsOpen);
_settingsHeight = GlobalSettings::get().getFloat("windows.autosave.settings.height", _settingsHeight);
_autosaveEnabled = GlobalSettings::get().getBool("windows.autosave.enabled", _autosaveEnabled);
Expand All @@ -31,7 +30,11 @@ _AutosaveWindow::_AutosaveWindow(SimulationFacade const& simulationFacade, Persi
_numberOfFiles = GlobalSettings::get().getInt("windows.autosave.number of files", _origNumberOfFiles);
}

_AutosaveWindow::~_AutosaveWindow()
AutosaveWindow::AutosaveWindow()
: AlienWindow("Autosave (work in progress)", "windows.autosave", false)
{}

void AutosaveWindow::shutdownIntern()
{
GlobalSettings::get().setBool("windows.autosave.settings.open", _settingsOpen);
GlobalSettings::get().setFloat("windows.autosave.settings.height", _settingsHeight);
Expand All @@ -41,7 +44,7 @@ _AutosaveWindow::~_AutosaveWindow()
GlobalSettings::get().setInt("windows.autosave.number of files", _numberOfFiles);
}

void _AutosaveWindow::processIntern()
void AutosaveWindow::processIntern()
{
processToolbar();

Expand All @@ -58,7 +61,7 @@ void _AutosaveWindow::processIntern()
validationAndCorrection();
}

void _AutosaveWindow::processToolbar()
void AutosaveWindow::processToolbar()
{
ImGui::SameLine();
if (AlienImGui::ToolbarButton(ICON_FA_SAVE)) {
Expand All @@ -83,15 +86,15 @@ void _AutosaveWindow::processToolbar()
AlienImGui::Separator();
}

void _AutosaveWindow::processHeader()
void AutosaveWindow::processHeader()
{
AlienImGui::InputInt(
AlienImGui::InputIntParameters().name("Autosave interval (min)").textWidth(RightColumnWidth).defaultValue(_origAutosaveInterval),
_autosaveInterval,
&_autosaveEnabled);
}

void _AutosaveWindow::processTable()
void AutosaveWindow::processTable()
{
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_RowBg
| ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_ScrollY | ImGuiTableFlags_ScrollX;
Expand Down Expand Up @@ -148,7 +151,7 @@ void _AutosaveWindow::processTable()
}
}

void _AutosaveWindow::processSettings()
void AutosaveWindow::processSettings()
{
if (_settingsOpen) {
ImGui::Spacing();
Expand Down Expand Up @@ -179,7 +182,7 @@ void _AutosaveWindow::processSettings()
}
}

void _AutosaveWindow::createSavepoint()
void AutosaveWindow::createSavepoint()
{
printOverlayMessage("Creating save point ...");
static int i = 0;
Expand All @@ -190,7 +193,7 @@ void _AutosaveWindow::createSavepoint()
_savePoints.emplace_front(SavepointState::InQueue, jobId.value, "", "", 0);
}

void _AutosaveWindow::updateSavepoint(SavepointEntry& savepoint)
void AutosaveWindow::updateSavepoint(SavepointEntry& savepoint)
{
if (savepoint.state != SavepointState::Persisted) {
auto requestState = _persisterFacade->getRequestState(PersisterRequestId(savepoint.id));
Expand All @@ -210,7 +213,7 @@ void _AutosaveWindow::updateSavepoint(SavepointEntry& savepoint)
}
}

void _AutosaveWindow::validationAndCorrection()
void AutosaveWindow::validationAndCorrection()
{
_numberOfFiles = std::max(1, _numberOfFiles);
}
11 changes: 8 additions & 3 deletions source/Gui/AutosaveWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ struct SavepointEntry
uint64_t timestep;
};

class _AutosaveWindow : public AlienWindow
class AutosaveWindow : public AlienWindow
{
MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(AutosaveWindow);

public:
_AutosaveWindow(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade);
~_AutosaveWindow() override;
void init(SimulationFacade const& simulationFacade, PersisterFacade const& persisterFacade);

private:
AutosaveWindow();

void shutdownIntern() override;

void processIntern() override;

void processToolbar();
Expand Down
30 changes: 10 additions & 20 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class SimulationInteractionController;

class GpuSettingsDialog;

class _NewSimulationDialog;
using NewSimulationDialog = std::shared_ptr<_NewSimulationDialog>;
class NewSimulationDialog;

class StartupController;

Expand All @@ -53,8 +52,7 @@ class AutosaveController;

class GettingStartedWindow;

class _DisplaySettingsDialog;
using DisplaySettingsDialog = std::shared_ptr<_DisplaySettingsDialog>;
class DisplaySettingsDialog;

class _EditorModel;
using EditorModel = std::shared_ptr<_EditorModel>;
Expand Down Expand Up @@ -84,15 +82,13 @@ using CreatorWindow = std::shared_ptr<_CreatorWindow>;
class _MultiplierWindow;
using MultiplierWindow = std::shared_ptr<_MultiplierWindow>;

class _PatternAnalysisDialog;
using PatternAnalysisDialog = std::shared_ptr<_PatternAnalysisDialog>;
class PatternAnalysisDialog;

class FpsController;

class BrowserWindow;

class _ShaderWindow;
using ShaderWindow = std::shared_ptr<_ShaderWindow>;
class ShaderWindow;

class LoginDialog;

Expand All @@ -104,20 +100,15 @@ class CreateUserDialog;

class ActivateUserDialog;

class _DeleteUserDialog;
using DeleteUserDialog = std::shared_ptr<_DeleteUserDialog>;
class DeleteUserDialog;

class _NetworkSettingsDialog;
using NetworkSettingsDialog = std::shared_ptr<_NetworkSettingsDialog>;
class NetworkSettingsDialog;

class _ResetPasswordDialog;
using ResetPasswordDialog = std::shared_ptr<_ResetPasswordDialog>;
class ResetPasswordDialog;

class _NewPasswordDialog;
using NewPasswordDialog = std::shared_ptr<_NewPasswordDialog>;
class NewPasswordDialog;

class _ImageToPatternDialog;
using ImageToPatternDialog = std::shared_ptr<_ImageToPatternDialog>;
class ImageToPatternDialog;

class _GenomeEditorWindow;
using GenomeEditorWindow = std::shared_ptr<_GenomeEditorWindow>;
Expand All @@ -127,8 +118,7 @@ class RadiationSourcesWindow;
class _ChangeColorDialog;
using ChangeColorDialog = std::shared_ptr<_ChangeColorDialog>;

class _AutosaveWindow;
using AutosaveWindow = std::shared_ptr<_AutosaveWindow>;
class AutosaveWindow;

class FileTransferController;

Expand Down
6 changes: 3 additions & 3 deletions source/Gui/DeleteUserDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "CreateUserDialog.h"
#include "MessageDialog.h"

_DeleteUserDialog::_DeleteUserDialog()
DeleteUserDialog::DeleteUserDialog()
: AlienDialog("Delete user")
{}

void _DeleteUserDialog::processIntern()
void DeleteUserDialog::processIntern()
{
AlienImGui::Text(
"Warning: All the data of the user '" + *NetworkService::get().getLoggedInUserName()
Expand Down Expand Up @@ -43,7 +43,7 @@ void _DeleteUserDialog::processIntern()
}
}

void _DeleteUserDialog::onDelete()
void DeleteUserDialog::onDelete()
{
auto userName = *NetworkService::get().getLoggedInUserName();
if (NetworkService::get().deleteUser()) {
Expand Down
8 changes: 5 additions & 3 deletions source/Gui/DeleteUserDialog.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#pragma once

#include "Base/Singleton.h"
#include "Network/Definitions.h"

#include "AlienDialog.h"
#include "Definitions.h"

class _DeleteUserDialog : public AlienDialog
class DeleteUserDialog : public AlienDialog
{
public:
_DeleteUserDialog();
MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(DeleteUserDialog);

private:
DeleteUserDialog();

void processIntern();
void onDelete();

Expand Down
17 changes: 10 additions & 7 deletions source/Gui/DisplaySettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ namespace
auto const RightColumnWidth = 185.0f;
}

_DisplaySettingsDialog::_DisplaySettingsDialog()
: AlienDialog("Display settings")
void DisplaySettingsDialog::init()
{
auto primaryMonitor = glfwGetPrimaryMonitor();
_videoModes = glfwGetVideoModes(primaryMonitor, &_videoModesCount);
_videoModeStrings = createVideoModeStrings();
}

void _DisplaySettingsDialog::processIntern()
DisplaySettingsDialog::DisplaySettingsDialog()
: AlienDialog("Display settings")
{}

void DisplaySettingsDialog::processIntern()
{
auto isFullscreen = !WindowController::get().isWindowedMode();

Expand Down Expand Up @@ -77,15 +80,15 @@ void _DisplaySettingsDialog::processIntern()
}
}

void _DisplaySettingsDialog::openIntern()
void DisplaySettingsDialog::openIntern()
{
_selectionIndex = getSelectionIndex();
_origSelectionIndex = _selectionIndex;
_origMode = WindowController::get().getMode();
_origFps = WindowController::get().getFps();
}

void _DisplaySettingsDialog::setFullscreen(int selectionIndex)
void DisplaySettingsDialog::setFullscreen(int selectionIndex)
{
if (0 == selectionIndex) {
WindowController::get().setDesktopMode();
Expand All @@ -103,7 +106,7 @@ namespace
}
}

int _DisplaySettingsDialog::getSelectionIndex() const
int DisplaySettingsDialog::getSelectionIndex() const
{
auto result = 0;
if (!WindowController::get().isWindowedMode() && !WindowController::get().isDesktopMode()) {
Expand All @@ -127,7 +130,7 @@ namespace
}
}

std::vector<std::string> _DisplaySettingsDialog::createVideoModeStrings() const
std::vector<std::string> DisplaySettingsDialog::createVideoModeStrings() const
{
std::vector<std::string> result;
result.emplace_back("Desktop");
Expand Down
18 changes: 12 additions & 6 deletions source/Gui/DisplaySettingsDialog.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#pragma once

#include "AlienDialog.h"
#include "Base/Singleton.h"
#include "EngineInterface/Definitions.h"

#include "Definitions.h"
#include "AlienDialog.h"

class _DisplaySettingsDialog : public AlienDialog
class DisplaySettingsDialog : public AlienDialog
{
MAKE_SINGLETON_NO_DEFAULT_CONSTRUCTION(DisplaySettingsDialog);

public:
_DisplaySettingsDialog();
void init();

private:
DisplaySettingsDialog();

void processIntern();
void openIntern();

Expand All @@ -18,9 +24,9 @@ class _DisplaySettingsDialog : public AlienDialog
std::vector<std::string> createVideoModeStrings() const;

std::string _origMode;
int _origSelectionIndex;
int _selectionIndex;
int _origFps;
int _origSelectionIndex = 0;
int _selectionIndex = 0;
int _origFps = 33;

int _videoModesCount = 0;
GLFWvidmode const* _videoModes;
Expand Down
9 changes: 5 additions & 4 deletions source/Gui/ImageToPatternDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
#include "GenericFileDialogs.h"


_ImageToPatternDialog::_ImageToPatternDialog(SimulationFacade const& simulationFacade)
: _simulationFacade(simulationFacade)
void ImageToPatternDialog::init(SimulationFacade const& simulationFacade)
{
_simulationFacade = simulationFacade;

auto path = std::filesystem::current_path();
if (path.has_parent_path()) {
path = path.parent_path();
}
_startingPath = GlobalSettings::get().getString("dialogs.open image.starting path", path.string());
}

_ImageToPatternDialog::~_ImageToPatternDialog()
void ImageToPatternDialog::shutdown()
{
GlobalSettings::get().setString("dialogs.open image.starting path", _startingPath);
}
Expand Down Expand Up @@ -76,7 +77,7 @@ namespace
}
}

void _ImageToPatternDialog::show()
void ImageToPatternDialog::show()
{
GenericFileDialogs::get().showOpenFileDialog(
"Open image", "Image (*.png){.png},.*", _startingPath, [&](std::filesystem::path const& path) {
Expand Down
Loading

0 comments on commit ea1c35c

Please sign in to comment.