From 9fa0cc4444ea7d3ac22f7ac8199c910c9fd5c199 Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Mon, 30 Sep 2024 21:53:49 +0200 Subject: [PATCH] show savepoint progress --- source/Gui/AutosaveWindow.cpp | 47 +++++++++++++++---- source/Gui/AutosaveWindow.h | 31 +++++++----- source/Gui/TemporalControlWindow.cpp | 4 +- .../PersisterImpl/PersisterControllerImpl.cpp | 2 +- .../PersisterImpl/PersisterControllerImpl.h | 2 +- source/PersisterImpl/PersisterJob.cpp | 2 +- source/PersisterImpl/PersisterWorker.cpp | 2 +- source/PersisterInterface/Definitions.h | 2 +- 8 files changed, 65 insertions(+), 27 deletions(-) diff --git a/source/Gui/AutosaveWindow.cpp b/source/Gui/AutosaveWindow.cpp index 90860a456..0df377923 100644 --- a/source/Gui/AutosaveWindow.cpp +++ b/source/Gui/AutosaveWindow.cpp @@ -60,7 +60,7 @@ void _AutosaveWindow::processToolbar() { ImGui::SameLine(); if (AlienImGui::ToolbarButton(ICON_FA_SAVE)) { - onCreateSave(); + createSavepoint(); } AlienImGui::Tooltip("Create save point"); @@ -106,22 +106,35 @@ void _AutosaveWindow::processTable() clipper.Begin(_savePoints.size()); while (clipper.Step()) { for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { - auto item = &_savePoints[row]; + auto& entry = _savePoints[row]; + updateSavepoint(entry); ImGui::PushID(row); ImGui::TableNextRow(0, scale(15.0f)); ImGui::TableNextColumn(); - AlienImGui::Text(std::to_string(item->sequenceNumber)); + AlienImGui::Text(std::to_string(entry.sequenceNumber)); ImGui::TableNextColumn(); - AlienImGui::Text(item->timestamp); + if (entry.state == SavepointState::InQueue) { + AlienImGui::Text("In queue"); + } + if (entry.state == SavepointState::InProgress) { + AlienImGui::Text("In progress"); + } + if (entry.state == SavepointState::Persisted) { + AlienImGui::Text(entry.timestamp); + } ImGui::TableNextColumn(); - AlienImGui::Text(item->name); + if (entry.state == SavepointState::Persisted) { + AlienImGui::Text(entry.name); + } ImGui::TableNextColumn(); - AlienImGui::Text(std::to_string(item->timestep)); + if (entry.state == SavepointState::Persisted) { + AlienImGui::Text(std::to_string(entry.timestep)); + } ImGui::PopID(); } @@ -161,12 +174,28 @@ void _AutosaveWindow::processSettings() } } -void _AutosaveWindow::onCreateSave() +void _AutosaveWindow::createSavepoint() { - printOverlayMessage("Saving ..."); + printOverlayMessage("Creating save point ...", true); auto jobId = _persisterController->saveSimulationToDisc("d:\\test2.sim", Viewport::getZoomFactor(), Viewport::getCenterInWorldPos()); - _savePoints.emplace_front(true, 1, std::to_string(jobId), "", "", 0); + for (auto& savePoint : _savePoints) { + ++savePoint.sequenceNumber; + } + _savePoints.emplace_front(SavepointState::InQueue, 1, jobId, "", "", 0); +} + +void _AutosaveWindow::updateSavepoint(SavepointEntry& savepoint) +{ + if (savepoint.state != SavepointState::Persisted) { + auto jobState = _persisterController->getJobState(PersisterJobId(savepoint.id)); + if (jobState == PersisterJobState::InProgress) { + savepoint.state = SavepointState::InProgress; + } + if (jobState == PersisterJobState::Finished) { + savepoint.state = SavepointState::Persisted; + } + } } void _AutosaveWindow::validationAndCorrection() diff --git a/source/Gui/AutosaveWindow.h b/source/Gui/AutosaveWindow.h index b5ad76756..cf8c93b0d 100644 --- a/source/Gui/AutosaveWindow.h +++ b/source/Gui/AutosaveWindow.h @@ -6,6 +6,23 @@ #include "AlienWindow.h" #include "PersisterInterface/PersisterController.h" +enum class SavepointState +{ + InQueue, + InProgress, + Persisted, +}; + +struct SavepointEntry +{ + SavepointState state = SavepointState::InQueue; + int sequenceNumber = 0; + std::string id; + std::string timestamp; + std::string name; + uint64_t timestep; +}; + class _AutosaveWindow : public _AlienWindow { public: @@ -20,7 +37,8 @@ class _AutosaveWindow : public _AlienWindow void processTable(); void processSettings(); - void onCreateSave(); + void createSavepoint(); + void updateSavepoint(SavepointEntry& savepoint); void validationAndCorrection(); @@ -47,14 +65,5 @@ class _AutosaveWindow : public _AlienWindow int _origNumberOfFiles = 20; int _numberOfFiles = 20; - struct SavePointEntry - { - bool transient = true; - int sequenceNumber = 0; - std::string id; - std::string timestamp; - std::string name; - uint64_t timestep; - }; - std::deque _savePoints; + std::deque _savePoints; }; diff --git a/source/Gui/TemporalControlWindow.cpp b/source/Gui/TemporalControlWindow.cpp index 5afda65c7..342bc9da8 100644 --- a/source/Gui/TemporalControlWindow.cpp +++ b/source/Gui/TemporalControlWindow.cpp @@ -181,7 +181,7 @@ void _TemporalControlWindow::processStepForwardButton() void _TemporalControlWindow::processCreateFlashbackButton() { auto result = AlienImGui::ToolbarButton(ICON_FA_CAMERA); - AlienImGui::Tooltip("Creating flashback: It saves the content of the current world to the memory."); + AlienImGui::Tooltip("Creating in-memory flashback: It saves the content of the current world to the memory."); if (result) { delayedExecution([this] { onSnapshot(); }); @@ -193,7 +193,7 @@ void _TemporalControlWindow::processLoadFlashbackButton() { ImGui::BeginDisabled(!_snapshot); auto result = AlienImGui::ToolbarButton(ICON_FA_UNDO); - AlienImGui::Tooltip("Loading flashback: It loads the saved world from the memory. Static simulation parameters will not be changed. Non-static parameters " + AlienImGui::Tooltip("Loading in-memory flashback: It loads the saved world from the memory. Static simulation parameters will not be changed. Non-static parameters " "(such as the position of moving zones) will be restored as well."); if (result) { delayedExecution([this] { applySnapshot(*_snapshot); }); diff --git a/source/PersisterImpl/PersisterControllerImpl.cpp b/source/PersisterImpl/PersisterControllerImpl.cpp index ffd0a34b6..17d82b8dc 100644 --- a/source/PersisterImpl/PersisterControllerImpl.cpp +++ b/source/PersisterImpl/PersisterControllerImpl.cpp @@ -44,5 +44,5 @@ PersisterJobId _PersisterControllerImpl::saveSimulationToDisc(std::string const& PersisterJobId _PersisterControllerImpl::generateNewJobId() { ++_latestJobId; - return _latestJobId; + return std::to_string(_latestJobId); } diff --git a/source/PersisterImpl/PersisterControllerImpl.h b/source/PersisterImpl/PersisterControllerImpl.h index 12bb6b5b4..ad82e23f6 100644 --- a/source/PersisterImpl/PersisterControllerImpl.h +++ b/source/PersisterImpl/PersisterControllerImpl.h @@ -24,5 +24,5 @@ class _PersisterControllerImpl : public _PersisterController std::shared_ptr<_PersisterWorker> _worker; std::thread* _thread = nullptr; - PersisterJobId _latestJobId = PersisterJobId(0); + int _latestJobId = 0; }; diff --git a/source/PersisterImpl/PersisterJob.cpp b/source/PersisterImpl/PersisterJob.cpp index 605181e17..f8122c6e8 100644 --- a/source/PersisterImpl/PersisterJob.cpp +++ b/source/PersisterImpl/PersisterJob.cpp @@ -1,6 +1,6 @@ #include "PersisterJob.h" -int _PersisterJob::getId() const +PersisterJobId _PersisterJob::getId() const { return _id; } diff --git a/source/PersisterImpl/PersisterWorker.cpp b/source/PersisterImpl/PersisterWorker.cpp index 4fc863c8f..ed11e1401 100644 --- a/source/PersisterImpl/PersisterWorker.cpp +++ b/source/PersisterImpl/PersisterWorker.cpp @@ -37,7 +37,7 @@ PersisterJobState _PersisterWorker::getJobState(PersisterJobId const& id) const return PersisterJobState::InProgress; } if (std::ranges::find_if(_finishedJobs, [&](PersisterJobResult const& job) { return job->getId() == id; }) != _finishedJobs.end()) { - return PersisterJobState::InProgress; + return PersisterJobState::Finished; } THROW_NOT_IMPLEMENTED(); } diff --git a/source/PersisterInterface/Definitions.h b/source/PersisterInterface/Definitions.h index bd00d13ca..46f062786 100644 --- a/source/PersisterInterface/Definitions.h +++ b/source/PersisterInterface/Definitions.h @@ -5,4 +5,4 @@ class _PersisterController; using PersisterController = std::shared_ptr<_PersisterController>; -using PersisterJobId = int; +using PersisterJobId = std::string;