Skip to content

Commit

Permalink
allow to save peak simulation in autosave
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Nov 3, 2024
1 parent 00b27f7 commit 04e604a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
48 changes: 32 additions & 16 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void AutosaveWindow::processToolbar()
ImGui::SameLine();
ImGui::BeginDisabled(!_savepointTable.has_value());
if (AlienImGui::ToolbarButton(ICON_FA_PLUS)) {
onCreateSavepoint();
onCreateSavepoint(false);
}
ImGui::EndDisabled();
AlienImGui::Tooltip("Create save point");
Expand Down Expand Up @@ -275,21 +275,27 @@ void AutosaveWindow::processStatusBar()
AlienImGui::StatusBar(statusText);
}

void AutosaveWindow::onCreateSavepoint()
void AutosaveWindow::onCreateSavepoint(bool usePeakSimulation)
{
printOverlayMessage("Creating save point ...");

if (_saveMode == SaveMode_Circular) {
auto nonPersistentEntries = SavepointTableService::get().truncate(_savepointTable.value(), _numberOfFiles - 1);
scheduleDeleteNonPersistentSavepoint(nonPersistentEntries);
}
auto senderInfo = SenderInfo{.senderId = SenderId{AutosaveSenderId}, .wishResultData = true, .wishErrorInfo = true};
auto saveData = SaveSimulationRequestData{
.filename = _directory,
.zoom = Viewport::get().getZoomFactor(),
.center = Viewport::get().getCenterInWorldPos(),
.generateNameFromTimestep = true};
auto requestId = _persisterFacade->scheduleSaveSimulation(senderInfo, saveData);

PersisterRequestId requestId;
if (usePeakSimulation) {
auto senderInfo = SenderInfo{.senderId = SenderId{AutosaveSenderId}, .wishResultData = true, .wishErrorInfo = true};
auto saveData = SaveDeserializedSimulationRequestData{
.filename = _directory, .sharedDeserializedSimulation = _peakDeserializedSimulation, .generateNameFromTimestep = true};
requestId = _persisterFacade->scheduleSaveDeserializedSimulation(senderInfo, saveData);
} else {
auto senderInfo = SenderInfo{.senderId = SenderId{AutosaveSenderId}, .wishResultData = true, .wishErrorInfo = true};
auto saveData = SaveSimulationRequestData{
.filename = _directory, .zoom = Viewport::get().getZoomFactor(), .center = Viewport::get().getCenterInWorldPos(), .generateNameFromTimestep = true};
requestId = _persisterFacade->scheduleSaveSimulation(senderInfo, saveData);
}

auto entry = std::make_shared<_SavepointEntry>(
_SavepointEntry{.filename = "", .state = SavepointState_InQueue, .timestamp = "", .name = "", .timestep = 0, .requestId = requestId.value});
Expand Down Expand Up @@ -327,12 +333,12 @@ void AutosaveWindow::processAutomaticSavepoints()

auto minSinceLastAutosave = std::chrono::duration_cast<std::chrono::minutes>(std::chrono::steady_clock::now() - _lastAutosaveTimepoint).count();
if (minSinceLastAutosave >= _autosaveInterval) {
onCreateSavepoint();
onCreateSavepoint(_catchPeak != CatchPeak_None);
_lastAutosaveTimepoint = std::chrono::steady_clock::now();
}

auto minSinceLastCatchPeak = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _lastPeakTimepoint).count();
if (minSinceLastCatchPeak >= 10) {
if (minSinceLastCatchPeak >= 60) {
_peakProcessor->executeTask(
[&](auto const& senderId) {
return _persisterFacade->scheduleGetPeakSimulation(
Expand Down Expand Up @@ -394,11 +400,21 @@ void AutosaveWindow::updateSavepoint(int row)
}
if (requestState.value() == PersisterRequestState::Finished) {
newEntry->state = SavepointState_Persisted;
auto requestResult = _persisterFacade->fetchSaveSimulationData(PersisterRequestId{newEntry->requestId});
newEntry->timestep = requestResult.timestep;
newEntry->timestamp = StringHelper::format(requestResult.timestamp);
newEntry->name = requestResult.projectName;
newEntry->filename = requestResult.filename;
auto requestResult = _persisterFacade->fetchPersisterRequestResult(PersisterRequestId{newEntry->requestId});

if (auto saveResult = std::dynamic_pointer_cast<_SaveSimulationRequestResult>(requestResult)) {
auto const& data = saveResult->getData();
newEntry->timestep = data.timestep;
newEntry->timestamp = StringHelper::format(data.timestamp);
newEntry->name = data.projectName;
newEntry->filename = data.filename;
} else if (auto saveResult = std::dynamic_pointer_cast<_SaveDeserializedSimulationRequestResult>(requestResult)) {
auto const& data = saveResult->getData();
newEntry->timestep = data.timestep;
newEntry->timestamp = StringHelper::format(data.timestamp);
newEntry->name = data.projectName;
newEntry->filename = data.filename;
}
}
if (requestState.value() == PersisterRequestState::Error) {
newEntry->state = SavepointState_Error;
Expand Down
2 changes: 1 addition & 1 deletion source/Gui/AutosaveWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AutosaveWindow : public AlienWindow<SimulationFacade, PersisterFacade>
void processSettings();
void processStatusBar();

void onCreateSavepoint();
void onCreateSavepoint(bool usePeakSimulation);
void onDeleteSavepoint(SavepointEntry const& entry);

void scheduleDeleteNonPersistentSavepoint(std::vector<SavepointEntry> const& entries);
Expand Down

0 comments on commit 04e604a

Please sign in to comment.