Skip to content

Commit bfbb06a

Browse files
committed
Merge remote-tracking branch 'source/zip-save-files' into zip-save-files
2 parents c5d0d69 + 43f664e commit bfbb06a

File tree

9 files changed

+103
-8
lines changed

9 files changed

+103
-8
lines changed

Entities/Scene.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,29 @@ int Scene::SaveData(std::string pathBase, bool doAsyncSaves)
10681068
return 0;
10691069
}
10701070

1071+
std::vector<SceneLayerInfo> Scene::GetCopiedSceneLayerBitmaps() {
1072+
std::vector<SceneLayerInfo> layerInfos;
1073+
1074+
/*
1075+
// Save Terrain's data
1076+
m_pTerrain
1077+
1078+
// Don't bother saving background layers to disk, as they are never altered
1079+
1080+
// Save unseen layers' data
1081+
char str[64];
1082+
for (int team = Activity::TeamOne; team < Activity::MaxTeamCount; ++team)
1083+
{
1084+
if (m_apUnseenLayer[team])
1085+
{
1086+
m_apUnseenLayer[team]
1087+
}
1088+
}
1089+
*/
1090+
1091+
return layerInfos;
1092+
}
1093+
10711094

10721095
//////////////////////////////////////////////////////////////////////////////////////////
10731096
// Virtual method: SavePreview

Entities/Scene.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class BunkerAssembly;
3232
class SceneObject;
3333
class Deployment;
3434

35+
struct SceneLayerInfo {
36+
std::string name;
37+
std::unique_ptr<BITMAP> bitmap;
38+
};
39+
3540

3641
//////////////////////////////////////////////////////////////////////////////////////////
3742
// Class: Scene
@@ -403,6 +408,8 @@ EntityAllocation(Scene)
403408

404409
int SaveData(std::string pathBase, bool doAsyncSaves = true);
405410

411+
std::vector<SceneLayerInfo> GetCopiedSceneLayerBitmaps();
412+
406413

407414
//////////////////////////////////////////////////////////////////////////////////////////
408415
// Virtual method: SavePreview

Entities/SceneLayer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ namespace RTE {
230230
return 0;
231231
}
232232

233+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
234+
235+
template <bool TRACK_DRAWINGS>
236+
std::unique_ptr<BITMAP> SceneLayerImpl<TRACK_DRAWINGS>::CopyBitmap() {
237+
BITMAP* outputBitmap = create_bitmap_ex(bitmap_color_depth(m_MainBitmap), m_MainBitmap->w, m_MainBitmap->h);
238+
if (m_MainBitmap) {
239+
outputBitmap = create_bitmap_ex(bitmap_color_depth(m_MainBitmap), m_MainBitmap->w, m_MainBitmap->h);
240+
blit(m_MainBitmap, outputBitmap, 0, 0, 0, 0, m_MainBitmap->w, m_MainBitmap->h);
241+
}
242+
return std::unique_ptr<BITMAP>(outputBitmap);
243+
}
244+
233245
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
234246

235247
template <bool TRACK_DRAWINGS>

Entities/SceneLayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ namespace RTE {
112112
/// </summary>
113113
/// <returns>An error return value signaling success or any particular failure. Anything below 0 is an error signal.</returns>
114114
virtual int ClearData();
115+
116+
/// <summary>
117+
/// Copies the bitmap.
118+
/// </summary>
119+
/// <returns>The copied bitmap.</returns>
120+
std::unique_ptr<BITMAP> CopyBitmap();
115121
#pragma endregion
116122

117123
#pragma region Getters and Setters

Managers/ActivityMan.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "MultiplayerServerLobby.h"
2828
#include "MultiplayerGame.h"
2929

30+
#include "zip.h"
31+
#include "unzip.h"
3032

3133
namespace RTE {
3234

@@ -110,8 +112,17 @@ namespace RTE {
110112
modifiableScene->GetTerrain()->SetPresetName(fileName);
111113
modifiableScene->GetTerrain()->MigrateToModule(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName));
112114

115+
// Create zip sav file
116+
zipFile zippedSaveFile = zipOpen((g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ccsave").c_str(), APPEND_STATUS_CREATE);
117+
if (!zippedSaveFile) {
118+
g_ConsoleMan.PrintString("ERROR: Couldn't create zip save file!");
119+
return false;
120+
}
121+
122+
std::unique_ptr<std::stringstream> iniStream = std::make_unique<std::stringstream>();
123+
113124
// Block the main thread for a bit to let the Writer access the relevant data.
114-
std::unique_ptr<Writer> writer(std::make_unique<Writer>(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + "/Save.ini"));
125+
std::unique_ptr<Writer> writer(std::make_unique<Writer>(std::move(iniStream)));
115126
writer->NewPropertyWithValue("Activity", activity);
116127

117128
// Pull all stuff from MovableMan into the Scene for saving, so existing Actors/ADoors are saved, without transferring ownership, so the game can continue.
@@ -128,8 +139,22 @@ namespace RTE {
128139
writer->NewPropertyWithValue("PlaceUnitsIfSceneIsRestarted", g_SceneMan.GetPlaceUnitsOnLoad());
129140
writer->NewPropertyWithValue("Scene", modifiableScene.get());
130141

131-
auto saveWriterData = [](Writer* writerToSave) {
132-
writerToSave->EndWrite();
142+
auto saveWriterData = [&](Writer* writerToSave) {
143+
std::stringstream *stream = static_cast<std::stringstream *>(writerToSave->GetStream());
144+
stream->flush();
145+
146+
// Ugly copies, but eh. todo - use a string stream that just gives us a raw buffer to grab at
147+
std::string streamAsString = stream->str();
148+
149+
zip_fileinfo zfi = { 0 };
150+
151+
const int defaultCompression = 6;
152+
zipOpenNewFileInZip(zippedSaveFile, (fileName + ".ini").c_str(), &zfi, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, defaultCompression);
153+
zipWriteInFileInZip(zippedSaveFile, streamAsString.data(), streamAsString.size());
154+
zipCloseFileInZip(zippedSaveFile);
155+
156+
zipClose(zippedSaveFile, fileName.c_str());
157+
133158
delete writerToSave;
134159
};
135160

Menus/SaveLoadMenuGUI.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ namespace RTE {
8484

8585
std::string saveFilePath = g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/";
8686
for (const auto &entry : std::filesystem::directory_iterator(saveFilePath)) {
87-
if (entry.is_directory()) {
87+
if (entry.path().extension() == ".ccsave" && entry.path().filename() != "Index.ini") {
8888
SaveRecord record;
8989
record.SavePath = entry.path();
90-
record.SaveDate = std::filesystem::last_write_time(entry.path() / "Save.ini");
90+
record.SaveDate = entry.last_write_time();
9191
m_SaveGames.push_back(record);
9292
}
9393
}
9494

9595
std::for_each(std::execution::par_unseq,
9696
m_SaveGames.begin(), m_SaveGames.end(),
9797
[](SaveRecord &record) {
98-
Reader reader(record.SavePath.string() + "/Save.ini", true, nullptr, true);
98+
Reader reader(record.SavePath.string(), true, nullptr, true);
9999

100100
bool readActivity = false;
101101
bool readSceneName = false;
@@ -202,9 +202,9 @@ namespace RTE {
202202
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203203

204204
void SaveLoadMenuGUI::DeleteSave() {
205-
std::string saveFilePath = g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + m_SaveGameName->GetText();
205+
std::string saveFilePath = g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + m_SaveGameName->GetText() + ".ccsave";
206206

207-
std::filesystem::remove_all(saveFilePath);
207+
std::filesystem::remove(saveFilePath);
208208
g_GUISound.ConfirmSound()->Play();
209209

210210
PopulateSaveGamesList();

System/Writer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ namespace RTE {
126126
/// <returns>Whether the writer is ready to start accepting data streamed to it or not.</returns>
127127
bool WriterOK() const { return m_Stream.get() && m_Stream->good(); }
128128

129+
/// <summary>
130+
/// Returns the underlying stream.
131+
/// </summary>
132+
std::ostream * GetStream() { return m_Stream.get(); }
133+
129134
/// <summary>
130135
/// Flushes and closes the output stream of this Writer. This happens automatically at destruction but needs to be called manually if a written file must be read from in the same scope.
131136
/// </summary>

external/sources/allegro 4.4.3.1-custom/addons/loadpng/loadpng.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ APNG_FUNC(BITMAP *, load_memory_png, (AL_CONST void *buffer, int buffer_size, RG
6666
/* Save a bitmap to disk in PNG format. */
6767
APNG_FUNC(int, save_png, (AL_CONST char *filename, BITMAP *bmp, AL_CONST RGB *pal));
6868

69+
/* Save a bitmap to a PACKFILE in PNG format. */
70+
APNG_FUNC(int, save_png_pf, (PACKFILE *pack, BITMAP *bmp, AL_CONST RGB *pal));
71+
6972
/* Adds `PNG' to Allegro's internal file type table.
7073
* You can then just use load_bitmap and save_bitmap as usual.
7174
*/

external/sources/allegro 4.4.3.1-custom/addons/loadpng/savepng.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,17 @@ int save_png(AL_CONST char *filename, BITMAP *bmp, AL_CONST RGB *pal)
313313

314314
return result;
315315
}
316+
317+
int save_png_pf(PACKFILE *pack, BITMAP *bmp, AL_CONST RGB *pal)
318+
{
319+
int result;
320+
321+
ASSERT(pack);
322+
ASSERT(bmp);
323+
324+
acquire_bitmap(bmp);
325+
result = really_save_png(pack, bmp, pal);
326+
release_bitmap(bmp);
327+
328+
return result;
329+
}

0 commit comments

Comments
 (0)