Skip to content

Commit 44a0d78

Browse files
committed
Prototyping for zip saves...
1 parent 7656ea9 commit 44a0d78

File tree

8 files changed

+99
-4
lines changed

8 files changed

+99
-4
lines changed

Entities/Scene.cpp

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

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

10701093
//////////////////////////////////////////////////////////////////////////////////////////
10711094
// 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
@@ -397,6 +402,8 @@ EntityAllocation(Scene)
397402

398403
int SaveData(std::string pathBase, bool doAsyncSaves = true);
399404

405+
std::vector<SceneLayerInfo> Scene::GetCopiedSceneLayerBitmaps()
406+
400407

401408
//////////////////////////////////////////////////////////////////////////////////////////
402409
// Virtual method: SavePreview

Entities/SceneLayer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ namespace RTE {
235235
return 0;
236236
}
237237

238+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
239+
240+
template <bool TRACK_DRAWINGS>
241+
std::unique_ptr<BITMAP> SceneLayerImpl<TRACK_DRAWINGS>::CopyBitmap() {
242+
BITMAP* outputBitmap = create_bitmap_ex(bitmap_color_depth(m_MainBitmap), m_MainBitmap->w, m_MainBitmap->h);
243+
if (m_MainBitmap) {
244+
outputBitmap = create_bitmap_ex(bitmap_color_depth(m_MainBitmap), m_MainBitmap->w, m_MainBitmap->h);
245+
blit(m_MainBitmap, outputBitmap, 0, 0, 0, 0, m_MainBitmap->w, m_MainBitmap->h);
246+
}
247+
return std::unique_ptr<BITMAP>(outputBitmap);
248+
}
249+
238250
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
239251

240252
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: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include "MultiplayerServerLobby.h"
2626
#include "MultiplayerGame.h"
2727

28+
#include "zip.h"
29+
#include "unzip.h"
30+
2831
namespace RTE {
2932

3033
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -105,8 +108,17 @@ namespace RTE {
105108
modifiableScene->GetTerrain()->SetPresetName(fileName);
106109
modifiableScene->GetTerrain()->MigrateToModule(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName));
107110

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

112124
// Pull all stuff from MovableMan into the Scene for saving, so existing Actors/ADoors are saved, without transferring ownership, so the game can continue.
@@ -123,9 +135,22 @@ namespace RTE {
123135
writer->NewPropertyWithValue("PlaceUnitsIfSceneIsRestarted", g_SceneMan.GetPlaceUnitsOnLoad());
124136
writer->NewPropertyWithValue("Scene", modifiableScene.get());
125137

126-
auto saveWriterData = [this](std::unique_ptr<Writer> writerToSave) {
127-
// Explicitly flush to disk. This'll happen anyways at the end of this scope, but otherwise this lambda looks rather empty :)
128-
writerToSave->EndWrite();
138+
auto saveWriterData = [&](std::unique_ptr<Writer> writerToSave) {
139+
std::stringstream *stream = static_cast<std::stringstream *>(writerToSave->GetStream());
140+
stream->flush();
141+
142+
// Ugly copies, but eh. todo - use a string stream that just gives us a raw buffer to grab at
143+
std::string streamAsString = stream->str();
144+
145+
zip_fileinfo zfi = { 0 };
146+
147+
const int defaultCompression = 6;
148+
zipOpenNewFileInZip(zippedSaveFile, (fileName + ".ini").c_str(), &zfi, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, defaultCompression);
149+
zipWriteInFileInZip(zippedSaveFile, streamAsString.data(), streamAsString.size());
150+
zipCloseFileInZip(zippedSaveFile);
151+
152+
zipClose(zippedSaveFile, fileName.c_str());
153+
129154
DecrementSavingThreadCount();
130155
};
131156

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)