Skip to content

Commit 4de5aa1

Browse files
committed
saving zips! need to do loading next
1 parent 5863694 commit 4de5aa1

File tree

144 files changed

+3480
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+3480
-105
lines changed

RTEA.vcxproj

Lines changed: 26 additions & 26 deletions
Large diffs are not rendered by default.

RTEA.vcxproj.filters

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,6 @@
484484
<ClInclude Include="Source\Entities\Round.h">
485485
<Filter>Entities</Filter>
486486
</ClInclude>
487-
<ClInclude Include="Source\System\NetworkMessages.h">
488-
<Filter>System</Filter>
489-
</ClInclude>
490487
<ClInclude Include="Source\System\InputScheme.h">
491488
<Filter>System</Filter>
492489
</ClInclude>
@@ -657,6 +654,12 @@
657654
<ClInclude Include="Source\Renderer\raylib\rlutils.h">
658655
<Filter>Renderer\raylib</Filter>
659656
</ClInclude>
657+
<ClInclude Include="Source\Renderer\raylib\rlutil.h" />
658+
<ClInclude Include="Source\GUI\imgui\imgui_internal.h" />
659+
<ClInclude Include="Source\GUI\imgui\imstb_rectpack.h" />
660+
<ClInclude Include="Source\GUI\imgui\imstb_textedit.h" />
661+
<ClInclude Include="Source\GUI\imgui\imstd_truetype.h" />
662+
<ClInclude Include="Source\GUI\imgui\backends\imgui_impl_opengl3_loader.h" />
660663
</ItemGroup>
661664
<ItemGroup>
662665
<ClCompile Include="Source\System\Box.cpp">

Source/Managers/ActivityMan.cpp

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

31+
#include "fmem.h"
32+
3133
using namespace RTE;
3234

3335
ActivityMan::ActivityMan() {
@@ -109,13 +111,6 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
109111
modifiableScene->GetTerrain()->SetPresetName(fileName);
110112
modifiableScene->GetTerrain()->MigrateToModule(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName));
111113

112-
// Create zip sav file
113-
zipFile zippedSaveFile = zipOpen((g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ccsave").c_str(), APPEND_STATUS_CREATE);
114-
if (!zippedSaveFile) {
115-
g_ConsoleMan.PrintString("ERROR: Couldn't create zip save file!");
116-
return false;
117-
}
118-
119114
std::unique_ptr<std::stringstream> iniStream = std::make_unique<std::stringstream>();
120115

121116
// Block the main thread for a bit to let the Writer access the relevant data.
@@ -137,9 +132,11 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
137132
writer->NewPropertyWithValue("Scene", modifiableScene.get());
138133

139134
// Get BITMAPS so save into our zip
140-
std::vector<SceneLayerInfo> sceneLayerInfos = scene->GetCopiedSceneLayerBitmaps();
135+
// I tired std::moving this into the function directly but threadpool really doesn't like that
136+
std::vector<SceneLayerInfo>* sceneLayerInfos = new std::vector<SceneLayerInfo>();
137+
*sceneLayerInfos = std::move(scene->GetCopiedSceneLayerBitmaps());
141138

142-
auto saveWriterData = [&](Writer* writerToSave, std::vector<SceneLayerInfo>&& sceneLayerInfos) {
139+
auto saveWriterData = [fileName, sceneLayerInfos](Writer* writerToSave) {
143140
std::stringstream* stream = static_cast<std::stringstream*>(writerToSave->GetStream());
144141
stream->flush();
145142

@@ -148,6 +145,13 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
148145

149146
zip_fileinfo zfi = {0};
150147

148+
// Create zip sav file
149+
zipFile zippedSaveFile = zipOpen((g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ccsave").c_str(), APPEND_STATUS_CREATE);
150+
if (!zippedSaveFile) {
151+
g_ConsoleMan.PrintString("ERROR: Couldn't create zip save file!");
152+
return;
153+
}
154+
151155
const int defaultCompression = 6;
152156
zipOpenNewFileInZip(zippedSaveFile, (fileName + ".ini").c_str(), &zfi, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, defaultCompression);
153157
zipWriteInFileInZip(zippedSaveFile, streamAsString.data(), streamAsString.size());
@@ -156,22 +160,38 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
156160
PALETTE palette;
157161
get_palette(palette);
158162

159-
for (const SceneLayerInfo& layerInfo : sceneLayerInfos)
163+
for (const SceneLayerInfo& layerInfo : *sceneLayerInfos)
160164
{
161-
// Allego lacks the fucking ability to save/load png from a byte stream
162-
// AAAAAAAAAAAAAAAAAAAAAAAAAAA
163-
//zipOpenNewFileInZip(zippedSaveFile, (fileName + " " + layerInfo.name + ".png").c_str(), &zfi, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, defaultCompression);
164-
//zipWriteInFileInZip(zippedSaveFile, streamAsString.data(), streamAsString.size());
165-
//zipCloseFileInZip(zippedSaveFile);
165+
// A bit of a finicky workaround, but to save a png to memory we create a memory stream and send that into allegro to save into
166+
fmem memStructure;
167+
fmem_init(&memStructure);
168+
169+
// Save the png to our memory stream
170+
FILE* stream = fmem_open(&memStructure, "w");
171+
save_stream_png(stream, layerInfo.bitmap.get(), palette);
172+
fflush(stream);
173+
174+
// Actually get the memory
175+
void* buffer;
176+
size_t size;
177+
fmem_mem(&memStructure, &buffer, &size);
178+
179+
zipOpenNewFileInZip(zippedSaveFile, (fileName + " " + layerInfo.name + ".png").c_str(), &zfi, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, defaultCompression);
180+
zipWriteInFileInZip(zippedSaveFile, static_cast<const char*>(buffer), size);
181+
zipCloseFileInZip(zippedSaveFile);
182+
183+
fclose(stream);
184+
fmem_term(&memStructure);
166185
}
167186

168187
zipClose(zippedSaveFile, fileName.c_str());
169188

170189
delete writerToSave;
190+
delete sceneLayerInfos;
171191
};
172192

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

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

0 commit comments

Comments
 (0)