mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +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
|
// dearchive all the modifications
|
||||||
level.time = Scale (time[1], TICRATE, time[0]);
|
level.time = Scale (time[1], TICRATE, time[0]);
|
||||||
|
|
||||||
//G_ReadSnapshots(png);
|
G_ReadSnapshots(resfile);
|
||||||
|
G_ReadVisited(arc);
|
||||||
|
|
||||||
// load a base level
|
// load a base level
|
||||||
savegamerestore = true; // Use the player actors in the savegame
|
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
|
// delete the JSON buffers we created just above. Everything else will
|
||||||
// either still be needed or taken care of automatically.
|
// either still be needed or taken care of automatically.
|
||||||
delete[] savegame_content[1].mBuffer;
|
savegame_content[1].Clean();
|
||||||
delete[] savegame_content[2].mBuffer;
|
savegame_content[2].Clean();
|
||||||
|
|
||||||
// Check whether the file is ok by trying to open it.
|
// Check whether the file is ok by trying to open it.
|
||||||
FResourceFile *test = FResourceFile::OpenResourceFile(filename, nullptr, true);
|
FResourceFile *test = FResourceFile::OpenResourceFile(filename, nullptr, true);
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#define __G_GAME__
|
#define __G_GAME__
|
||||||
|
|
||||||
struct event_t;
|
struct event_t;
|
||||||
struct PNGHandle;
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef __G_HUB_H
|
#ifndef __G_HUB_H
|
||||||
#define __G_HUB_H
|
#define __G_HUB_H
|
||||||
|
|
||||||
struct PNGHandle;
|
|
||||||
struct cluster_info_t;
|
struct cluster_info_t;
|
||||||
struct wbstartstruct_t;
|
struct wbstartstruct_t;
|
||||||
class FSerializer;
|
class FSerializer;
|
||||||
|
|
|
@ -1568,7 +1568,7 @@ void G_WriteSnapshots(TArray<FString> &filenames, TArray<FCompressedBuffer> &buf
|
||||||
{
|
{
|
||||||
if (wadlevelinfos[i].Snapshot.mCompressedSize > 0)
|
if (wadlevelinfos[i].Snapshot.mCompressedSize > 0)
|
||||||
{
|
{
|
||||||
filename << wadlevelinfos[i].MapName << ".json";
|
filename << wadlevelinfos[i].MapName << ".map.json";
|
||||||
filename.ToLower();
|
filename.ToLower();
|
||||||
filenames.Push(filename);
|
filenames.Push(filename);
|
||||||
buffers.Push(wadlevelinfos[i].Snapshot);
|
buffers.Push(wadlevelinfos[i].Snapshot);
|
||||||
|
@ -1576,7 +1576,7 @@ void G_WriteSnapshots(TArray<FString> &filenames, TArray<FCompressedBuffer> &buf
|
||||||
}
|
}
|
||||||
if (TheDefaultLevelInfo.Snapshot.mCompressedSize > 0)
|
if (TheDefaultLevelInfo.Snapshot.mCompressedSize > 0)
|
||||||
{
|
{
|
||||||
filename << TheDefaultLevelInfo.MapName << ".json";
|
filename << TheDefaultLevelInfo.MapName << ".mapd.json";
|
||||||
filename.ToLower();
|
filename.ToLower();
|
||||||
filenames.Push(filename);
|
filenames.Push(filename);
|
||||||
buffers.Push(TheDefaultLevelInfo.Snapshot);
|
buffers.Push(TheDefaultLevelInfo.Snapshot);
|
||||||
|
@ -1629,45 +1629,48 @@ void G_WriteVisited(FSerializer &arc)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void G_ReadSnapshots(PNGHandle *png)
|
void G_ReadSnapshots(FResourceFile *resf)
|
||||||
{
|
{
|
||||||
DWORD chunkLen;
|
|
||||||
FString MapName;
|
FString MapName;
|
||||||
level_info_t *i;
|
level_info_t *i;
|
||||||
|
|
||||||
G_ClearSnapshots();
|
G_ClearSnapshots();
|
||||||
|
|
||||||
chunkLen = (DWORD)M_FindPNGChunk(png, SNAP_ID);
|
for (unsigned j = 0; j < resf->LumpCount(); j++)
|
||||||
while (chunkLen != 0)
|
|
||||||
{
|
{
|
||||||
#if 0
|
FResourceLump * resl = resf->GetLump(j);
|
||||||
FPNGChunkArchive arc(png->File->GetFile(), SNAP_ID, chunkLen);
|
if (resl != nullptr)
|
||||||
DWORD snapver;
|
{
|
||||||
|
auto ptr = strstr(resl->FullName, ".map.json");
|
||||||
arc << snapver;
|
if (ptr != nullptr)
|
||||||
arc << MapName;
|
{
|
||||||
i = FindLevelInfo(MapName);
|
ptrdiff_t maplen = ptr - resl->FullName.GetChars();
|
||||||
i->snapshot = new FCompressedMemFile;
|
FString mapname(resl->FullName.GetChars(), (size_t)maplen);
|
||||||
i->snapshot->Serialize(arc);
|
i = FindLevelInfo(mapname);
|
||||||
chunkLen = (DWORD)M_NextPNGChunk(png, SNAP_ID);
|
if (i != nullptr)
|
||||||
#endif
|
{
|
||||||
}
|
i->Snapshot = resl->GetRawData();
|
||||||
|
}
|
||||||
chunkLen = (DWORD)M_FindPNGChunk(png, DSNP_ID);
|
}
|
||||||
if (chunkLen != 0)
|
else
|
||||||
{
|
{
|
||||||
#if 0
|
auto ptr = strstr(resl->FullName, ".mapd.json");
|
||||||
FPNGChunkArchive arc(png->File->GetFile(), DSNP_ID, chunkLen);
|
if (ptr != nullptr)
|
||||||
DWORD snapver;
|
{
|
||||||
|
ptrdiff_t maplen = ptr - resl->FullName.GetChars();
|
||||||
arc << snapver;
|
FString mapname(resl->FullName.GetChars(), (size_t)maplen);
|
||||||
arc << MapName;
|
TheDefaultLevelInfo.Snapshot = resl->GetRawData();
|
||||||
TheDefaultLevelInfo.snapshot = new FCompressedMemFile;
|
}
|
||||||
TheDefaultLevelInfo.snapshot->Serialize(arc);
|
}
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
void G_ReadVisited(FSerializer &arc)
|
void G_ReadVisited(FSerializer &arc)
|
||||||
{
|
{
|
||||||
if (arc.BeginArray("visited"))
|
if (arc.BeginArray("visited"))
|
||||||
|
@ -1696,6 +1699,9 @@ void G_ReadVisited(FSerializer &arc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
CCMD(listsnapshots)
|
CCMD(listsnapshots)
|
||||||
|
@ -1752,7 +1758,6 @@ void P_WriteACSDefereds (FSerializer &arc)
|
||||||
void P_ReadACSDefereds (FSerializer &arc)
|
void P_ReadACSDefereds (FSerializer &arc)
|
||||||
{
|
{
|
||||||
FString MapName;
|
FString MapName;
|
||||||
size_t chunklen;
|
|
||||||
|
|
||||||
P_RemoveDefereds ();
|
P_RemoveDefereds ();
|
||||||
|
|
||||||
|
|
|
@ -532,8 +532,7 @@ void G_ClearSnapshots (void);
|
||||||
void P_RemoveDefereds ();
|
void P_RemoveDefereds ();
|
||||||
void G_SnapshotLevel (void);
|
void G_SnapshotLevel (void);
|
||||||
void G_UnSnapshotLevel (bool keepPlayers);
|
void G_UnSnapshotLevel (bool keepPlayers);
|
||||||
struct PNGHandle;
|
void G_ReadSnapshots (FResourceFile *);
|
||||||
void G_ReadSnapshots (PNGHandle *png);
|
|
||||||
void G_WriteSnapshots (TArray<FString> &, TArray<FCompressedBuffer> &);
|
void G_WriteSnapshots (TArray<FString> &, TArray<FCompressedBuffer> &);
|
||||||
void G_WriteVisited(FSerializer &arc);
|
void G_WriteVisited(FSerializer &arc);
|
||||||
void G_ReadVisited(FSerializer &arc);
|
void G_ReadVisited(FSerializer &arc);
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include "basictypes.h"
|
#include "basictypes.h"
|
||||||
#include "sfmt/SFMT.h"
|
#include "sfmt/SFMT.h"
|
||||||
|
|
||||||
struct PNGHandle;
|
|
||||||
class FSerializer;
|
class FSerializer;
|
||||||
|
|
||||||
class FRandom
|
class FRandom
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
class FFont;
|
class FFont;
|
||||||
class FileReader;
|
class FileReader;
|
||||||
struct line_t;
|
struct line_t;
|
||||||
struct PNGHandle;
|
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#ifndef __P_SAVEG_H__
|
#ifndef __P_SAVEG_H__
|
||||||
#define __P_SAVEG_H__
|
#define __P_SAVEG_H__
|
||||||
|
|
||||||
struct PNGHandle;
|
|
||||||
class FSerializer;
|
class FSerializer;
|
||||||
|
|
||||||
// Persistent storage/archiving.
|
// Persistent storage/archiving.
|
||||||
|
|
|
@ -306,17 +306,12 @@ FZipFile::~FZipFile()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FCompressedBuffer FZipFile::GetRawLump(int lumpnum)
|
FCompressedBuffer FZipLump::GetRawData()
|
||||||
{
|
{
|
||||||
if ((unsigned)lumpnum >= NumLumps)
|
FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)CompressedSize, Method, GPFlags, CRC32, new char[CompressedSize] };
|
||||||
{
|
if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress();
|
||||||
return{ 0,0,0,0,0,nullptr };
|
Owner->Reader->Seek(Position, SEEK_SET);
|
||||||
}
|
Owner->Reader->Read(cbuf.mBuffer, CompressedSize);
|
||||||
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);
|
|
||||||
return cbuf;
|
return cbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,28 +3,6 @@
|
||||||
|
|
||||||
#include "resourcefile.h"
|
#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
|
enum
|
||||||
{
|
{
|
||||||
LUMPFZIP_NEEDFILESTART = 128
|
LUMPFZIP_NEEDFILESTART = 128
|
||||||
|
@ -50,6 +28,7 @@ struct FZipLump : public FResourceLump
|
||||||
private:
|
private:
|
||||||
void SetLumpAddress();
|
void SetLumpAddress();
|
||||||
virtual int GetFileOffset();
|
virtual int GetFileOffset();
|
||||||
|
FCompressedBuffer GetRawData();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +47,6 @@ public:
|
||||||
virtual ~FZipFile();
|
virtual ~FZipFile();
|
||||||
bool Open(bool quiet);
|
bool Open(bool quiet);
|
||||||
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
|
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
|
||||||
FCompressedBuffer GetRawLump(int lumpnum);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "doomerrors.h"
|
#include "doomerrors.h"
|
||||||
#include "gi.h"
|
#include "gi.h"
|
||||||
#include "doomstat.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
|
// Returns the owner's FileReader if it can be used to access this lump
|
||||||
|
|
|
@ -8,6 +8,28 @@
|
||||||
class FResourceFile;
|
class FResourceFile;
|
||||||
class FTexture;
|
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
|
struct FResourceLump
|
||||||
{
|
{
|
||||||
friend class FResourceFile;
|
friend class FResourceFile;
|
||||||
|
@ -46,6 +68,7 @@ struct FResourceLump
|
||||||
virtual int GetIndexNum() const { return 0; }
|
virtual int GetIndexNum() const { return 0; }
|
||||||
void LumpNameSetup(FString iname);
|
void LumpNameSetup(FString iname);
|
||||||
void CheckEmbedded();
|
void CheckEmbedded();
|
||||||
|
virtual FCompressedBuffer GetRawData();
|
||||||
|
|
||||||
void *CacheLump();
|
void *CacheLump();
|
||||||
int ReleaseCache();
|
int ReleaseCache();
|
||||||
|
|
Loading…
Reference in a new issue