Skip to content

Commit 30430a0

Browse files
committed
Removed async savedata on scene, it's no longer necessary
Added helper function to return whether we're currently saving
1 parent db92b04 commit 30430a0

File tree

10 files changed

+28
-33
lines changed

10 files changed

+28
-33
lines changed

Source/Entities/SLTerrain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ int SLTerrain::LoadData() {
298298
return 0;
299299
}
300300

301-
int SLTerrain::SaveData(const std::string& pathBase, bool doAsyncSaves) {
301+
int SLTerrain::SaveData(const std::string& pathBase) {
302302
if (pathBase.empty()) {
303303
return -1;
304304
}
305-
SceneLayer::SaveData(pathBase + " Mat.png", doAsyncSaves);
306-
m_FGColorLayer->SaveData(pathBase + " FG.png", doAsyncSaves);
307-
m_BGColorLayer->SaveData(pathBase + " BG.png", doAsyncSaves);
305+
SceneLayer::SaveData(pathBase + " Mat.png");
306+
m_FGColorLayer->SaveData(pathBase + " FG.png");
307+
m_BGColorLayer->SaveData(pathBase + " BG.png");
308308
return 0;
309309
}
310310

Source/Entities/SLTerrain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace RTE {
6666
/// @param pathBase The filepath base to the where to save the Bitmap data. This means everything up to the extension. "FG" and "Mat" etc will be added.
6767
/// @param doAsyncSaves Whether or not to save asynchronously.
6868
/// @return An error return value signaling success or any particular failure. Anything below 0 is an error signal.
69-
int SaveData(const std::string& pathBase, bool doAsyncSaves = true) override;
69+
int SaveData(const std::string& pathBase) override;
7070

7171
/// Copies bitmap data into layerInfos.
7272
/// @param layerInfos List of SceneLayerInfo to emplace our copied data into.

Source/Entities/Scene.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ int Scene::ExpandAIPlanAssemblySchemes() {
815815
return 0;
816816
}
817817

818-
int Scene::SaveData(std::string pathBase, bool doAsyncSaves) {
818+
int Scene::SaveData(std::string pathBase) {
819819
const std::string fullPathBase = g_PresetMan.GetFullModulePath(pathBase);
820820
if (fullPathBase.empty())
821821
return -1;
@@ -824,7 +824,7 @@ int Scene::SaveData(std::string pathBase, bool doAsyncSaves) {
824824
return 0;
825825

826826
// Save Terrain's data
827-
if (m_pTerrain->SaveData(fullPathBase, doAsyncSaves) < 0) {
827+
if (m_pTerrain->SaveData(fullPathBase) < 0) {
828828
RTEAbort("Saving Terrain " + m_pTerrain->GetPresetName() + "\'s data failed!");
829829
return -1;
830830
}
@@ -837,7 +837,7 @@ int Scene::SaveData(std::string pathBase, bool doAsyncSaves) {
837837
if (m_apUnseenLayer[team]) {
838838
std::snprintf(str, sizeof(str), "T%d", team);
839839
// Save unseen layer data to disk
840-
if (m_apUnseenLayer[team]->SaveData(fullPathBase + " US" + str + ".png", doAsyncSaves) < 0) {
840+
if (m_apUnseenLayer[team]->SaveData(fullPathBase + " US" + str + ".png") < 0) {
841841
g_ConsoleMan.PrintString("ERROR: Saving unseen layer " + m_apUnseenLayer[team]->GetPresetName() + "\'s data failed!");
842842
return -1;
843843
}

Source/Entities/Scene.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ namespace RTE {
242242
/// Saves data currently in memory to disk.
243243
/// @param pathBase The filepath base to the where to save the Bitmap data. This means
244244
/// everything up to the extension. "FG" and "Mat" etc will be added.
245-
/// @param doAsyncSaves Whether or not to save asynchronously. (default: true)
246245
/// @return An error return value signaling success or any particular failure.
247246
/// Anything below 0 is an error signal.
248-
int SaveData(std::string pathBase, bool doAsyncSaves = true);
247+
int SaveData(std::string pathBase);
249248

250249
// Gets copied bitmaps of our scene layers, for saving.
251250
// @return A list of SceneLayerInfo including our name and a copied bitmap.

Source/Entities/SceneLayer.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::LoadData() {
221221
}
222222

223223
template <bool TRACK_DRAWINGS, bool STATIC_TEXTURE>
224-
int SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::SaveData(const std::string& bitmapPath, bool doAsyncSaves) {
224+
int SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::SaveData(const std::string& bitmapPath) {
225225
if (bitmapPath.empty()) {
226226
return -1;
227227
}
@@ -231,21 +231,14 @@ int SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::SaveData(const std::string&
231231
BITMAP* outputBitmap = create_bitmap_ex(bitmap_color_depth(m_MainBitmap), m_MainBitmap->w, m_MainBitmap->h);
232232
blit(m_MainBitmap, outputBitmap, 0, 0, 0, 0, m_MainBitmap->w, m_MainBitmap->h);
233233

234-
auto saveLayerBitmap = [bitmapPath, doAsyncSaves](BITMAP* bitmapToSave) {
235-
PALETTE palette;
236-
get_palette(palette);
237-
if (save_png(bitmapPath.c_str(), bitmapToSave, palette) != 0) {
238-
RTEAbort(std::string("Failed to save SceneLayerImpl bitmap to path and name: " + bitmapPath));
239-
}
240-
destroy_bitmap(bitmapToSave);
241-
};
242-
243234
m_BitmapFile.SetDataPath(bitmapPath);
244-
if (doAsyncSaves) {
245-
g_ActivityMan.GetSaveGameTask().push_back(g_ThreadMan.GetBackgroundThreadPool().submit(saveLayerBitmap, outputBitmap));
246-
} else {
247-
saveLayerBitmap(outputBitmap);
235+
236+
PALETTE palette;
237+
get_palette(palette);
238+
if (save_png(bitmapPath.c_str(), outputBitmap, palette) != 0) {
239+
RTEAbort(std::string("Failed to save SceneLayerImpl bitmap to path and name: " + bitmapPath));
248240
}
241+
destroy_bitmap(outputBitmap);
249242
}
250243
return 0;
251244
}

Source/Entities/SceneLayer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ namespace RTE {
9191

9292
/// Saves data currently in memory to disk.
9393
/// @param bitmapPath The filepath to the where to save the bitmap data.
94-
/// @param doAsyncSaves Whether or not to save asynchronously.
9594
/// @return An error return value signaling success or any particular failure. Anything below 0 is an error signal.
96-
virtual int SaveData(const std::string& bitmapPath, bool doAsyncSaves = true);
95+
virtual int SaveData(const std::string& bitmapPath);
9796

9897
/// Clears out any previously loaded bitmap data from memory.
9998
/// @return An error return value signaling success or any particular failure. Anything below 0 is an error signal.

Source/Managers/ActivityMan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ActivityMan::Clear() {
4848
m_DefaultActivityName = "Tutorial Mission";
4949
m_Activity = nullptr;
5050
m_StartActivity = nullptr;
51-
m_SaveGameTask = BS::multi_future<void>();
51+
m_SaveGameTask = std::future<void>();
5252
m_InActivity = false;
5353
m_ActivityNeedsRestart = false;
5454
m_ActivityNeedsResume = false;
@@ -82,7 +82,7 @@ bool ActivityMan::ForceAbortSave() {
8282

8383
bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
8484
m_SaveGameTask.wait();
85-
m_SaveGameTask = BS::multi_future<void>();
85+
m_SaveGameTask = std::future<void>();
8686

8787
Scene* scene = g_SceneMan.GetScene();
8888
GAScripted* activity = dynamic_cast<GAScripted*>(GetActivity());
@@ -241,7 +241,7 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
241241
};
242242

243243
// For some reason I can't std::move a unique ptr in, so just releasing and deleting manually...
244-
m_SaveGameTask.push_back(g_ThreadMan.GetBackgroundThreadPool().submit(saveWriterData, writer.release()));
244+
m_SaveGameTask = g_ThreadMan.GetBackgroundThreadPool().submit(saveWriterData, writer.release());
245245

246246
// We didn't transfer ownership, so we must be very careful that sceneAltered's deletion doesn't touch the stuff we got from MovableMan.
247247
modifiableScene->ClearPlacedObjectSet(Scene::PlacedObjectSets::PLACEONLOAD, false);

Source/Managers/ActivityMan.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace RTE {
3838

3939
/// Gets the async save game task.
4040
/// @return The savegame task.
41-
BS::multi_future<void>& GetSaveGameTask() { return m_SaveGameTask; }
41+
std::future<void>& GetSaveGameTask() { return m_SaveGameTask; }
4242

4343
/// Indicates whether the game is currently running or not (not editing, over or paused).
4444
/// @return Whether the game is running or not.
@@ -132,6 +132,10 @@ namespace RTE {
132132

133133
/// Waits for the task that saves the game to complete.
134134
void WaitForSaveGameTask() const { m_SaveGameTask.wait(); }
135+
136+
/// Returns whether a save is currently in progress.
137+
/// @return Whether or not a save is currently in progress.
138+
bool IsCurrentlySaving() const { return m_SaveGameTask.wait_for(std::chrono::seconds(0)) == std::future_status::ready; }
135139
#pragma endregion
136140

137141
#pragma region Activity Start Handling
@@ -198,7 +202,7 @@ namespace RTE {
198202
std::unique_ptr<Activity> m_Activity; //!< The currently active Activity.
199203
std::unique_ptr<Activity> m_StartActivity; //!< The starting condition of the next Activity to be (re)started.
200204

201-
BS::multi_future<void> m_SaveGameTask; //!< The current save game task.
205+
std::future<void> m_SaveGameTask; //!< The current save game task.
202206

203207
bool m_InActivity; //!< Whether we are currently in game (as in, not in the main menu or any other out-of-game menus), regardless of its state.
204208
bool m_ActivityNeedsRestart; //!< Whether the current Activity needs to be restarted.

Source/Managers/MetaMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int MetaMan::SaveSceneData(std::string pathBase) {
319319
// Only save the data of revealed scenes that have already had their layers built and saved into files
320320
if ((*sItr)->IsRevealed() && (*sItr)->GetTerrain() && (*sItr)->GetTerrain()->IsLoadedFromDisk()) {
321321
// Save the scene data to a good unique prefix for the Scene's layers' bitmap files as they are saved
322-
if ((*sItr)->SaveData(pathBase + " - " + (*sItr)->GetPresetName(), false) < 0)
322+
if ((*sItr)->SaveData(pathBase + " - " + (*sItr)->GetPresetName()) < 0)
323323
return -1;
324324
}
325325
}

Source/Menus/MetagameGUI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ void MetagameGUI::CompletedActivity() {
25922592
// However, don't suck up actors of any non-winning team, and don't save the brains if we autoresolved, because that took care of placing the resident brains already
25932593
pAlteredScene->RetrieveSceneObjects(true, winningTeam, autoResolved);
25942594
// Save out the altered scene before clearing out its data from memory
2595-
pAlteredScene->SaveData(METASAVEPATH + std::string(AUTOSAVENAME) + " - " + pAlteredScene->GetPresetName(), false);
2595+
pAlteredScene->SaveData(METASAVEPATH + std::string(AUTOSAVENAME) + " - " + pAlteredScene->GetPresetName());
25962596
// Clear the bitmap data etc of the altered scene, we don't need to copy that over
25972597
pAlteredScene->ClearData();
25982598

0 commit comments

Comments
 (0)