@@ -120,7 +120,7 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
120
120
writer->NewPropertyWithValue (" Scene" , modifiableScene.get ());
121
121
122
122
// Get BITMAPS so save into our zip
123
- // I tired std::moving this into the function directly but threadpool really doesn't like that
123
+ // I tried std::moving this into the function directly but threadpool really doesn't like that
124
124
std::vector<SceneLayerInfo>* sceneLayerInfos = new std::vector<SceneLayerInfo>();
125
125
*sceneLayerInfos = std::move (scene->GetCopiedSceneLayerBitmaps ());
126
126
@@ -141,7 +141,7 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
141
141
}
142
142
143
143
const int defaultCompression = 6 ;
144
- zipOpenNewFileInZip (zippedSaveFile, (fileName + " .ini" ). c_str () , &zfi, nullptr , 0 , nullptr , 0 , nullptr , Z_DEFLATED, defaultCompression);
144
+ zipOpenNewFileInZip (zippedSaveFile, " Save .ini" , &zfi, nullptr , 0 , nullptr , 0 , nullptr , Z_DEFLATED, defaultCompression);
145
145
zipWriteInFileInZip (zippedSaveFile, streamAsString.data (), streamAsString.size ());
146
146
zipCloseFileInZip (zippedSaveFile);
147
147
@@ -164,7 +164,7 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
164
164
size_t size;
165
165
fmem_mem (&memStructure, &buffer, &size);
166
166
167
- zipOpenNewFileInZip (zippedSaveFile, (fileName + " " + layerInfo.name + " .png" ).c_str (), &zfi, nullptr , 0 , nullptr , 0 , nullptr , Z_DEFLATED, defaultCompression);
167
+ zipOpenNewFileInZip (zippedSaveFile, (" Save " + layerInfo.name + " .png" ).c_str (), &zfi, nullptr , 0 , nullptr , 0 , nullptr , Z_DEFLATED, defaultCompression);
168
168
zipWriteInFileInZip (zippedSaveFile, static_cast <const char *>(buffer), size);
169
169
zipCloseFileInZip (zippedSaveFile);
170
170
@@ -191,9 +191,10 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
191
191
bool ActivityMan::LoadAndLaunchGame (const std::string& fileName) {
192
192
m_SaveGameTask.wait ();
193
193
194
- std::string saveFilePath = g_PresetMan.GetFullModulePath (c_UserScriptedSavesModuleName) + " /" + fileName + " .ccsave " ;
194
+ std::string filePath = g_PresetMan.GetFullModulePath (c_UserScriptedSavesModuleName) + " /" + fileName;
195
195
196
196
// load zip sav file
197
+ std::string saveFilePath = filePath + " .ccsave" ;
197
198
unzFile zippedSaveFile = unzOpen (saveFilePath.c_str ());
198
199
if (!zippedSaveFile) {
199
200
RTEError::ShowMessageBox (" Game loading failed! Make sure you have a saved game called \" " + fileName + " \" " );
@@ -218,9 +219,9 @@ bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
218
219
unzCloseCurrentFile (zippedSaveFile);
219
220
};
220
221
221
- unzipFileIntoBuffer (fileName + " .ini" );
222
+ unzipFileIntoBuffer (" Save .ini" );
222
223
223
- Reader reader (std::make_unique<std::istringstream>(buffer), saveFilePath , true , nullptr , false );
224
+ Reader reader (std::make_unique<std::istringstream>(buffer), filePath + " /Save.ini " , true , nullptr , false );
224
225
225
226
std::unique_ptr<Scene> scene (std::make_unique<Scene>());
226
227
std::unique_ptr<GAScripted> activity (std::make_unique<GAScripted>());
@@ -247,41 +248,47 @@ bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
247
248
248
249
int numberOfTeams = activity->m_TeamCount ;
249
250
250
- // SetSceneToLoad() doesn't Clone(), but when the Activity starts, it will eventually call LoadScene(), which does a Clone() of scene internally.
251
- g_SceneMan.SetSceneToLoad (scene.get (), true , true );
252
- // Saved Scenes get their presetname set to their filename to ensure they're separate from the preset Scene they're based off of.
253
- // However, saving a game you've already saved will end up with its OriginalScenePresetName set to the filename, which will screw up restarting the Activity, so we set its PresetName here.
254
- scene->SetPresetName (originalScenePresetName);
255
- // For starting Activity, we need to directly clone the Activity we want to start.
256
- StartActivity (dynamic_cast <GAScripted*>(activity->Clone ()));
257
- // When this method exits, our Scene object will be destroyed, which will cause problems if you try to restart it. To avoid this, set the Scene to load to the preset object with the same name.
258
- g_SceneMan.SetSceneToLoad (originalScenePresetName, placeObjectsIfSceneIsRestarted, placeUnitsIfSceneIsRestarted);
259
-
260
- // Replace our scene images with the ones from the zip
261
- std::vector<SceneLayerInfo> layerInfos;
262
-
251
+ // Manually load all our bitmaps into our cache so the activity skips looking for the file and just gets it directly from us
263
252
PALETTE palette;
264
253
get_palette (palette);
265
254
266
- unzipFileIntoBuffer (fileName + " Mat.png" );
267
- layerInfos. emplace_back ( " Mat" , std::unique_ptr<BITMAP>( load_memory_png (buffer, info.uncompressed_size , palette) ));
255
+ unzipFileIntoBuffer (" Save Mat.png" );
256
+ ContentFile::ManuallyLoadDataBitmap (filePath + " /Save Mat.png " , load_memory_png (buffer, info.uncompressed_size , palette));
268
257
free (buffer);
269
258
270
- unzipFileIntoBuffer (fileName + " FG.png" );
271
- layerInfos. emplace_back ( " FG " , std::unique_ptr<BITMAP>( load_memory_png (buffer, info.uncompressed_size , palette) ));
259
+ unzipFileIntoBuffer (" Save FG.png" );
260
+ ContentFile::ManuallyLoadDataBitmap (filePath + " /Save FG.png " , load_memory_png (buffer, info.uncompressed_size , palette));
272
261
free (buffer);
273
262
274
- unzipFileIntoBuffer (fileName + " BG.png" );
275
- layerInfos. emplace_back ( " BG " , std::unique_ptr<BITMAP>( load_memory_png (buffer, info.uncompressed_size , palette) ));
263
+ unzipFileIntoBuffer (" Save BG.png" );
264
+ ContentFile::ManuallyLoadDataBitmap (filePath + " /Save BG.png " , load_memory_png (buffer, info.uncompressed_size , palette));
276
265
free (buffer);
277
266
278
267
for (int i = 0 ; i < numberOfTeams; ++i) {
279
- unzipFileIntoBuffer (fileName + std::format (" T %i.png" , i));
280
- layerInfos. emplace_back ( std::format (" T %i" , i), std::unique_ptr<BITMAP>( load_memory_png (buffer, info.uncompressed_size , palette) ));
268
+ unzipFileIntoBuffer (std::format (" Save UST %i.png" , i));
269
+ ContentFile::ManuallyLoadDataBitmap (filePath + std::format (" /Save UST %i" , i), load_memory_png (buffer, info.uncompressed_size , palette));
281
270
free (buffer);
282
271
}
283
272
284
- g_SceneMan.GetScene ()->ConstructSceneLayersFromBitmaps (std::move (layerInfos));
273
+ unzClose (zippedSaveFile);
274
+
275
+ // SetSceneToLoad() doesn't Clone(), but when the Activity starts, it will eventually call LoadScene(), which does a Clone() of scene internally.
276
+ g_SceneMan.SetSceneToLoad (scene.get (), true , true );
277
+ // Saved Scenes get their presetname set to their filename to ensure they're separate from the preset Scene they're based off of.
278
+ // However, saving a game you've already saved will end up with its OriginalScenePresetName set to the filename, which will screw up restarting the Activity, so we set its PresetName here.
279
+ scene->SetPresetName (originalScenePresetName);
280
+ // For starting Activity, we need to directly clone the Activity we want to start.
281
+ StartActivity (dynamic_cast <GAScripted*>(activity->Clone ()));
282
+ // When this method exits, our Scene object will be destroyed, which will cause problems if you try to restart it. To avoid this, set the Scene to load to the preset object with the same name.
283
+ g_SceneMan.SetSceneToLoad (originalScenePresetName, placeObjectsIfSceneIsRestarted, placeUnitsIfSceneIsRestarted);
284
+
285
+ // Clear out the cache, we don't need it anymore (and don't want a cache reload to look for this file thinking it really exists)
286
+ ContentFile::ManuallyClearDataBitmap (filePath + " /Save Mat.png" );
287
+ ContentFile::ManuallyClearDataBitmap (filePath + " /Save FG.png" );
288
+ ContentFile::ManuallyClearDataBitmap (filePath + " /Save BG.png" );
289
+ for (int i = 0 ; i < numberOfTeams; ++i) {
290
+ ContentFile::ManuallyClearDataBitmap (filePath + std::format (" /Save UST%i.png" , i));
291
+ }
285
292
286
293
g_ConsoleMan.PrintString (" SYSTEM: Game \" " + fileName + " \" loaded!" );
287
294
0 commit comments