Skip to content

Commit

Permalink
show savepoint progress
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 30, 2024
1 parent 23a1857 commit 9fa0cc4
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 27 deletions.
47 changes: 38 additions & 9 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void _AutosaveWindow::processToolbar()
{
ImGui::SameLine();
if (AlienImGui::ToolbarButton(ICON_FA_SAVE)) {
onCreateSave();
createSavepoint();
}
AlienImGui::Tooltip("Create save point");

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()
Expand Down
31 changes: 20 additions & 11 deletions source/Gui/AutosaveWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,7 +37,8 @@ class _AutosaveWindow : public _AlienWindow
void processTable();
void processSettings();

void onCreateSave();
void createSavepoint();
void updateSavepoint(SavepointEntry& savepoint);

void validationAndCorrection();

Expand All @@ -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<SavePointEntry> _savePoints;
std::deque<SavepointEntry> _savePoints;
};
4 changes: 2 additions & 2 deletions source/Gui/TemporalControlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });

Expand All @@ -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); });
Expand Down
2 changes: 1 addition & 1 deletion source/PersisterImpl/PersisterControllerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ PersisterJobId _PersisterControllerImpl::saveSimulationToDisc(std::string const&
PersisterJobId _PersisterControllerImpl::generateNewJobId()
{
++_latestJobId;
return _latestJobId;
return std::to_string(_latestJobId);
}
2 changes: 1 addition & 1 deletion source/PersisterImpl/PersisterControllerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ class _PersisterControllerImpl : public _PersisterController

std::shared_ptr<_PersisterWorker> _worker;
std::thread* _thread = nullptr;
PersisterJobId _latestJobId = PersisterJobId(0);
int _latestJobId = 0;
};
2 changes: 1 addition & 1 deletion source/PersisterImpl/PersisterJob.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "PersisterJob.h"

int _PersisterJob::getId() const
PersisterJobId _PersisterJob::getId() const
{
return _id;
}
Expand Down
2 changes: 1 addition & 1 deletion source/PersisterImpl/PersisterWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {

Check failure on line 39 in source/PersisterImpl/PersisterWorker.cpp

View workflow job for this annotation

GitHub Actions / build

‘find_if’ is not a member of ‘std::ranges’; did you mean ‘std::find_if’?
return PersisterJobState::InProgress;
return PersisterJobState::Finished;
}
THROW_NOT_IMPLEMENTED();
}
Expand Down
2 changes: 1 addition & 1 deletion source/PersisterInterface/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
class _PersisterController;
using PersisterController = std::shared_ptr<_PersisterController>;

using PersisterJobId = int;
using PersisterJobId = std::string;

0 comments on commit 9fa0cc4

Please sign in to comment.