MCPcopy Create free account
hub / github.com/ZDoom/Raze / WriteSavegame

Function WriteSavegame

source/core/savegamehelp.cpp:191–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189//=============================================================================
190
191bool WriteSavegame(const char* filename, const char *name)
192{
193 BufferWriter savepic;
194 FSerializer savegameinfo; // this is for displayable info about the savegame.
195 FRazeSerializer savegamesession; // saved game session settings.
196
197 char buf[100];
198 mysnprintf(buf, countof(buf), GAMENAME " %s", GetVersionString());
199 auto savesig = gi->GetSaveSig();
200 auto gs = PlayClock / 120;
201 FStringf timeStr("%02d:%02d", gs / 60, gs % 60);
202 auto lev = currentLevel;
203
204 savegameinfo.OpenWriter(true);
205 savegameinfo.AddString("Software", buf)
206 ("Save Version", savesig.currentsavever)
207 .AddString("Engine", savesig.savesig)
208 .AddString("Game Resource", fileSystem.GetResourceFileName(1))
209 .AddString("Map Name", lev->DisplayName())
210 .AddString("Creation Time", myasctime())
211 .AddString("Title", name)
212 .AddString("Map File", lev->fileName.GetChars())
213 .AddString("Map Label", lev->labelName.GetChars())
214 .AddString("Map Time", timeStr.GetChars());
215
216 const char *fn = lev->fileName.GetChars();
217 if (*fn == '/') fn++;
218 if (strncmp(fn, "file://", 7) != 0) // this only has meaning for non-usermaps
219 {
220 auto fileno = fileSystem.FindFile(fn);
221 auto mapfile = fileSystem.GetFileContainer(fileno);
222 auto mapcname = fileSystem.GetResourceFileName(mapfile);
223 if (mapcname) savegameinfo.AddString("Map Resource", mapcname);
224 else
225 {
226 return false; // this should never happen. Saving on a map that isn't present is impossible.
227 }
228 }
229
230
231
232 // Save the game state
233 savegamesession.OpenWriter(save_formatted);
234 SerializeSession(savegamesession);
235
236 WriteSavePic(&savepic, 240, 180);
237 mysnprintf(buf, countof(buf), GAMENAME " %s", GetVersionString());
238 // put some basic info into the PNG so that this isn't lost when the image gets extracted.
239 M_AppendPNGText(&savepic, "Software", buf);
240 M_AppendPNGText(&savepic, "Title", name);
241 M_AppendPNGText(&savepic, "Current Map", lev->labelName.GetChars());
242 M_FinishPNG(&savepic);
243
244 auto picdata = savepic.GetBuffer();
245 FileSys::FCompressedBuffer bufpng = { picdata->size(), picdata->size(), FileSys::METHOD_STORED, static_cast<unsigned int>(crc32(0, &(*picdata)[0], picdata->size())), (char*)&(*picdata)[0] };
246
247 TArray<FileSys::FCompressedBuffer> savegame_content;
248 TArray<FString> savegame_filenames;

Callers 1

G_DoSaveGameFunction · 0.85

Calls 15

GetVersionStringFunction · 0.85
myasctimeFunction · 0.85
SerializeSessionFunction · 0.85
WriteSavePicFunction · 0.85
M_AppendPNGTextFunction · 0.85
M_FinishPNGFunction · 0.85
WriteZipFunction · 0.85
OpenWriterMethod · 0.80
GetResourceFileNameMethod · 0.80
DisplayNameMethod · 0.80
FindFileMethod · 0.80
GetFileContainerMethod · 0.80

Tested by

no test coverage detected