Skip to content

Commit e9907d7

Browse files
committed
made saving faster by copying bitmaps async
1 parent 1d5bccf commit e9907d7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Source/Managers/ActivityMan.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "zip.h"
2929
#include "unzip.h"
3030

31+
#include "tracy/Tracy.hpp"
32+
3133
#include "SDL3/SDL_surface.h"
3234
#include <SDL3_image/SDL_image.h>
3335

@@ -85,6 +87,8 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
8587
m_SaveGameTask.wait();
8688
}
8789

90+
ZoneScopedN("Save Game");
91+
8892
Scene* scene = g_SceneMan.GetScene();
8993
GAScripted* activity = dynamic_cast<GAScripted*>(GetActivity());
9094

@@ -93,6 +97,12 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
9397
return false;
9498
}
9599

100+
// Get BITMAPS so save into our zip, do this async so we can copy the scene info at the same time
101+
std::vector<SceneLayerInfo>* sceneLayerInfos = new std::vector<SceneLayerInfo>();
102+
std::future<void> copyBitmaps = g_ThreadMan.GetBackgroundThreadPool().submit([&]() {
103+
*sceneLayerInfos = std::move(scene->GetCopiedSceneLayerBitmaps());
104+
});
105+
96106
// We need a copy of our scene, because we have to do some fixup to remove PLACEONLOAD items and only keep the current MovableMan state.
97107
std::unique_ptr<Scene> modifiableScene(dynamic_cast<Scene*>(scene->Clone()));
98108

@@ -153,11 +163,6 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
153163
indexWriter->NewPropertyWithValue("ActivityName", activity->GetPresetName());
154164
indexWriter->NewPropertyWithValue("OriginalScenePresetName", scene->GetPresetName());
155165

156-
// Get BITMAPS so save into our zip
157-
// I tried std::moving this into the function directly but threadpool really doesn't like that
158-
std::vector<SceneLayerInfo>* sceneLayerInfos = new std::vector<SceneLayerInfo>();
159-
*sceneLayerInfos = std::move(scene->GetCopiedSceneLayerBitmaps());
160-
161166
auto saveWriterData = [fileName, sceneLayerInfos, indexWriter](Writer* mainWriter) {
162167
// Create zip sav file
163168
zipFile zippedSaveFile = zipOpen((g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ccsave").c_str(), APPEND_STATUS_CREATE);
@@ -242,6 +247,8 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
242247
delete sceneLayerInfos;
243248
};
244249

250+
copyBitmaps.wait();
251+
245252
// For some reason I can't std::move a unique ptr in, so just releasing and deleting manually...
246253
m_SaveGameTask = g_ThreadMan.GetBackgroundThreadPool().submit(saveWriterData, writer.release());
247254

0 commit comments

Comments
 (0)