mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-27 22:42:57 +00:00
- read snapshots from zip.
This commit is contained in:
parent
f93e4813d1
commit
5dfc396bb9
12 changed files with 90 additions and 76 deletions
|
@ -1962,7 +1962,8 @@ void G_DoLoadGame ()
|
|||
// dearchive all the modifications
|
||||
level.time = Scale (time[1], TICRATE, time[0]);
|
||||
|
||||
//G_ReadSnapshots(png);
|
||||
G_ReadSnapshots(resfile);
|
||||
G_ReadVisited(arc);
|
||||
|
||||
// load a base level
|
||||
savegamerestore = true; // Use the player actors in the savegame
|
||||
|
@ -2268,8 +2269,8 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio
|
|||
|
||||
// delete the JSON buffers we created just above. Everything else will
|
||||
// either still be needed or taken care of automatically.
|
||||
delete[] savegame_content[1].mBuffer;
|
||||
delete[] savegame_content[2].mBuffer;
|
||||
savegame_content[1].Clean();
|
||||
savegame_content[2].Clean();
|
||||
|
||||
// Check whether the file is ok by trying to open it.
|
||||
FResourceFile *test = FResourceFile::OpenResourceFile(filename, nullptr, true);
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define __G_GAME__
|
||||
|
||||
struct event_t;
|
||||
struct PNGHandle;
|
||||
|
||||
|
||||
//
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef __G_HUB_H
|
||||
#define __G_HUB_H
|
||||
|
||||
struct PNGHandle;
|
||||
struct cluster_info_t;
|
||||
struct wbstartstruct_t;
|
||||
class FSerializer;
|
||||
|
|
|
@ -1568,7 +1568,7 @@ void G_WriteSnapshots(TArray<FString> &filenames, TArray<FCompressedBuffer> &buf
|
|||
{
|
||||
if (wadlevelinfos[i].Snapshot.mCompressedSize > 0)
|
||||
{
|
||||
filename << wadlevelinfos[i].MapName << ".json";
|
||||
filename << wadlevelinfos[i].MapName << ".map.json";
|
||||
filename.ToLower();
|
||||
filenames.Push(filename);
|
||||
buffers.Push(wadlevelinfos[i].Snapshot);
|
||||
|
@ -1576,7 +1576,7 @@ void G_WriteSnapshots(TArray<FString> &filenames, TArray<FCompressedBuffer> &buf
|
|||
}
|
||||
if (TheDefaultLevelInfo.Snapshot.mCompressedSize > 0)
|
||||
{
|
||||
filename << TheDefaultLevelInfo.MapName << ".json";
|
||||
filename << TheDefaultLevelInfo.MapName << ".mapd.json";
|
||||
filename.ToLower();
|
||||
filenames.Push(filename);
|
||||
buffers.Push(TheDefaultLevelInfo.Snapshot);
|
||||
|
@ -1629,44 +1629,47 @@ void G_WriteVisited(FSerializer &arc)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void G_ReadSnapshots(PNGHandle *png)
|
||||
void G_ReadSnapshots(FResourceFile *resf)
|
||||
{
|
||||
DWORD chunkLen;
|
||||
FString MapName;
|
||||
level_info_t *i;
|
||||
|
||||
G_ClearSnapshots();
|
||||
|
||||
chunkLen = (DWORD)M_FindPNGChunk(png, SNAP_ID);
|
||||
while (chunkLen != 0)
|
||||
for (unsigned j = 0; j < resf->LumpCount(); j++)
|
||||
{
|
||||
#if 0
|
||||
FPNGChunkArchive arc(png->File->GetFile(), SNAP_ID, chunkLen);
|
||||
DWORD snapver;
|
||||
|
||||
arc << snapver;
|
||||
arc << MapName;
|
||||
i = FindLevelInfo(MapName);
|
||||
i->snapshot = new FCompressedMemFile;
|
||||
i->snapshot->Serialize(arc);
|
||||
chunkLen = (DWORD)M_NextPNGChunk(png, SNAP_ID);
|
||||
#endif
|
||||
}
|
||||
|
||||
chunkLen = (DWORD)M_FindPNGChunk(png, DSNP_ID);
|
||||
if (chunkLen != 0)
|
||||
FResourceLump * resl = resf->GetLump(j);
|
||||
if (resl != nullptr)
|
||||
{
|
||||
#if 0
|
||||
FPNGChunkArchive arc(png->File->GetFile(), DSNP_ID, chunkLen);
|
||||
DWORD snapver;
|
||||
auto ptr = strstr(resl->FullName, ".map.json");
|
||||
if (ptr != nullptr)
|
||||
{
|
||||
ptrdiff_t maplen = ptr - resl->FullName.GetChars();
|
||||
FString mapname(resl->FullName.GetChars(), (size_t)maplen);
|
||||
i = FindLevelInfo(mapname);
|
||||
if (i != nullptr)
|
||||
{
|
||||
i->Snapshot = resl->GetRawData();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto ptr = strstr(resl->FullName, ".mapd.json");
|
||||
if (ptr != nullptr)
|
||||
{
|
||||
ptrdiff_t maplen = ptr - resl->FullName.GetChars();
|
||||
FString mapname(resl->FullName.GetChars(), (size_t)maplen);
|
||||
TheDefaultLevelInfo.Snapshot = resl->GetRawData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arc << snapver;
|
||||
arc << MapName;
|
||||
TheDefaultLevelInfo.snapshot = new FCompressedMemFile;
|
||||
TheDefaultLevelInfo.snapshot->Serialize(arc);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void G_ReadVisited(FSerializer &arc)
|
||||
{
|
||||
|
@ -1696,6 +1699,9 @@ void G_ReadVisited(FSerializer &arc)
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
CCMD(listsnapshots)
|
||||
|
@ -1752,7 +1758,6 @@ void P_WriteACSDefereds (FSerializer &arc)
|
|||
void P_ReadACSDefereds (FSerializer &arc)
|
||||
{
|
||||
FString MapName;
|
||||
size_t chunklen;
|
||||
|
||||
P_RemoveDefereds ();
|
||||
|
||||
|
|
|
@ -532,8 +532,7 @@ void G_ClearSnapshots (void);
|
|||
void P_RemoveDefereds ();
|
||||
void G_SnapshotLevel (void);
|
||||
void G_UnSnapshotLevel (bool keepPlayers);
|
||||
struct PNGHandle;
|
||||
void G_ReadSnapshots (PNGHandle *png);
|
||||
void G_ReadSnapshots (FResourceFile *);
|
||||
void G_WriteSnapshots (TArray<FString> &, TArray<FCompressedBuffer> &);
|
||||
void G_WriteVisited(FSerializer &arc);
|
||||
void G_ReadVisited(FSerializer &arc);
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "basictypes.h"
|
||||
#include "sfmt/SFMT.h"
|
||||
|
||||
struct PNGHandle;
|
||||
class FSerializer;
|
||||
|
||||
class FRandom
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
class FFont;
|
||||
class FileReader;
|
||||
struct line_t;
|
||||
struct PNGHandle;
|
||||
|
||||
|
||||
enum
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#ifndef __P_SAVEG_H__
|
||||
#define __P_SAVEG_H__
|
||||
|
||||
struct PNGHandle;
|
||||
class FSerializer;
|
||||
|
||||
// Persistent storage/archiving.
|
||||
|
|
|
@ -306,17 +306,12 @@ FZipFile::~FZipFile()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FCompressedBuffer FZipFile::GetRawLump(int lumpnum)
|
||||
FCompressedBuffer FZipLump::GetRawData()
|
||||
{
|
||||
if ((unsigned)lumpnum >= NumLumps)
|
||||
{
|
||||
return{ 0,0,0,0,0,nullptr };
|
||||
}
|
||||
FZipLump *lmp = &Lumps[lumpnum];
|
||||
|
||||
FCompressedBuffer cbuf = { (unsigned)lmp->LumpSize, (unsigned)lmp->CompressedSize, lmp->Method, lmp->GPFlags, lmp->CRC32, new char[lmp->CompressedSize] };
|
||||
Reader->Seek(lmp->Position, SEEK_SET);
|
||||
Reader->Read(cbuf.mBuffer, lmp->CompressedSize);
|
||||
FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)CompressedSize, Method, GPFlags, CRC32, new char[CompressedSize] };
|
||||
if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress();
|
||||
Owner->Reader->Seek(Position, SEEK_SET);
|
||||
Owner->Reader->Read(cbuf.mBuffer, CompressedSize);
|
||||
return cbuf;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,28 +3,6 @@
|
|||
|
||||
#include "resourcefile.h"
|
||||
|
||||
// This holds a compresed Zip entry with all needed info to decompress it.
|
||||
struct FCompressedBuffer
|
||||
{
|
||||
unsigned mSize;
|
||||
unsigned mCompressedSize;
|
||||
int mMethod;
|
||||
int mZipFlags;
|
||||
unsigned mCRC32;
|
||||
char *mBuffer;
|
||||
|
||||
bool Decompress(char *destbuffer);
|
||||
void Clean()
|
||||
{
|
||||
mSize = mCompressedSize = 0;
|
||||
if (mBuffer != nullptr)
|
||||
{
|
||||
delete[] mBuffer;
|
||||
mBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
LUMPFZIP_NEEDFILESTART = 128
|
||||
|
@ -50,6 +28,7 @@ struct FZipLump : public FResourceLump
|
|||
private:
|
||||
void SetLumpAddress();
|
||||
virtual int GetFileOffset();
|
||||
FCompressedBuffer GetRawData();
|
||||
};
|
||||
|
||||
|
||||
|
@ -68,7 +47,6 @@ public:
|
|||
virtual ~FZipFile();
|
||||
bool Open(bool quiet);
|
||||
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
|
||||
FCompressedBuffer GetRawLump(int lumpnum);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "doomerrors.h"
|
||||
#include "gi.h"
|
||||
#include "doomstat.h"
|
||||
#include "w_zip.h"
|
||||
|
||||
|
||||
//==========================================================================
|
||||
|
@ -191,6 +192,23 @@ void FResourceLump::CheckEmbedded()
|
|||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// this is just for completeness. For non-Zips only an uncompressed lump can
|
||||
// be returned.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FCompressedBuffer FResourceLump::GetRawData()
|
||||
{
|
||||
FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)LumpSize, METHOD_STORED, 0, 0, new char[LumpSize] };
|
||||
memcpy(cbuf.mBuffer, CacheLump(), LumpSize);
|
||||
cbuf.mCRC32 = crc32(0, (BYTE*)cbuf.mBuffer, LumpSize);
|
||||
ReleaseCache();
|
||||
return cbuf;
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Returns the owner's FileReader if it can be used to access this lump
|
||||
|
|
|
@ -8,6 +8,28 @@
|
|||
class FResourceFile;
|
||||
class FTexture;
|
||||
|
||||
// This holds a compresed Zip entry with all needed info to decompress it.
|
||||
struct FCompressedBuffer
|
||||
{
|
||||
unsigned mSize;
|
||||
unsigned mCompressedSize;
|
||||
int mMethod;
|
||||
int mZipFlags;
|
||||
unsigned mCRC32;
|
||||
char *mBuffer;
|
||||
|
||||
bool Decompress(char *destbuffer);
|
||||
void Clean()
|
||||
{
|
||||
mSize = mCompressedSize = 0;
|
||||
if (mBuffer != nullptr)
|
||||
{
|
||||
delete[] mBuffer;
|
||||
mBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct FResourceLump
|
||||
{
|
||||
friend class FResourceFile;
|
||||
|
@ -46,6 +68,7 @@ struct FResourceLump
|
|||
virtual int GetIndexNum() const { return 0; }
|
||||
void LumpNameSetup(FString iname);
|
||||
void CheckEmbedded();
|
||||
virtual FCompressedBuffer GetRawData();
|
||||
|
||||
void *CacheLump();
|
||||
int ReleaseCache();
|
||||
|
|
Loading…
Reference in a new issue