mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-27 09:20:51 +00:00
- save sectors and walls as JSON
This is not optimized yet so saves are a bit larger than necessary.
This commit is contained in:
parent
cb8d2eb94c
commit
fd31da3115
3 changed files with 103 additions and 49 deletions
|
@ -179,12 +179,8 @@ enum {
|
|||
|
||||
#include "buildtypes.h"
|
||||
|
||||
using sectortype = sectortypev7;
|
||||
using usectortype = sectortypev7;
|
||||
|
||||
using walltype = walltypev7;
|
||||
using uwalltype = walltypev7;
|
||||
|
||||
using usectortype = sectortype;
|
||||
using uwalltype = walltype;
|
||||
using uspritetype = spritetype;
|
||||
|
||||
using uspriteptr_t = uspritetype const *;
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
#ifndef buildtypes_h__
|
||||
#define buildtypes_h__
|
||||
|
||||
#undef WALLTYPE
|
||||
#undef SECTORTYPE
|
||||
#undef SPRITETYPE
|
||||
|
||||
#define StructTracker(tracker, type) type
|
||||
#define StructName(name) name
|
||||
|
||||
//ceilingstat/floorstat:
|
||||
// bit 0: 1 = parallaxing, 0 = not "P"
|
||||
// bit 1: 1 = groudraw, 0 = not
|
||||
|
@ -29,24 +22,24 @@
|
|||
//////////////////// Version 7 map format ////////////////////
|
||||
|
||||
//40 bytes
|
||||
typedef struct
|
||||
struct sectortype
|
||||
{
|
||||
StructTracker(Sector, int16_t) wallptr, wallnum;
|
||||
StructTracker(Sector, int32_t) ceilingz, floorz;
|
||||
StructTracker(Sector, uint16_t) ceilingstat, floorstat;
|
||||
StructTracker(Sector, int16_t) ceilingpicnum, ceilingheinum;
|
||||
StructTracker(Sector, int8_t) ceilingshade;
|
||||
StructTracker(Sector, uint8_t) ceilingpal, /*CM_FLOORZ:*/ ceilingxpanning, ceilingypanning;
|
||||
StructTracker(Sector, int16_t) floorpicnum, floorheinum;
|
||||
StructTracker(Sector, int8_t) floorshade;
|
||||
StructTracker(Sector, uint8_t) floorpal, floorxpanning, floorypanning;
|
||||
StructTracker(Sector, uint8_t) /*CM_CEILINGZ:*/ visibility, fogpal;
|
||||
int16_t wallptr, wallnum;
|
||||
int32_t ceilingz, floorz;
|
||||
uint16_t ceilingstat, floorstat;
|
||||
int16_t ceilingpicnum, ceilingheinum;
|
||||
int8_t ceilingshade;
|
||||
uint8_t ceilingpal, /*CM_FLOORZ:*/ ceilingxpanning, ceilingypanning;
|
||||
int16_t floorpicnum, floorheinum;
|
||||
int8_t floorshade;
|
||||
uint8_t floorpal, floorxpanning, floorypanning;
|
||||
uint8_t /*CM_CEILINGZ:*/ visibility, fogpal;
|
||||
union {
|
||||
StructTracker(Sector, int16_t) lotag, type;
|
||||
int16_t lotag, type;
|
||||
};
|
||||
StructTracker(Sector, int16_t) hitag;
|
||||
StructTracker(Sector, int16_t) extra;
|
||||
} StructName(sectortypev7);
|
||||
int16_t hitag;
|
||||
int16_t extra;
|
||||
};
|
||||
|
||||
//cstat:
|
||||
// bit 0: 1 = Blocking wall (use with clipmove, getzrange) "B"
|
||||
|
@ -63,7 +56,7 @@ typedef struct
|
|||
// bits 12-15: reserved (14: temp use by editor)
|
||||
|
||||
//32 bytes
|
||||
struct walltypev7
|
||||
struct walltype
|
||||
{
|
||||
union {
|
||||
struct
|
||||
|
@ -85,9 +78,9 @@ struct walltypev7
|
|||
|
||||
#if 0
|
||||
// make sure we do not accidentally copy this
|
||||
walltypev7() = default;
|
||||
walltypev7(const walltypev7&) = delete;
|
||||
walltypev7& operator=(const walltypev7&) = delete;
|
||||
walltype() = default;
|
||||
walltype(const walltypev7&) = delete;
|
||||
walltype& operator=(const walltypev7&) = delete;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
@ -226,9 +219,6 @@ using tspritetype = spritetype;
|
|||
|
||||
//////////////////// END Version 7 map format ////////////////
|
||||
|
||||
#undef StructTracker
|
||||
#undef StructName
|
||||
|
||||
#ifndef buildtypes_h__enums
|
||||
#define buildtypes_h__enums
|
||||
#endif
|
||||
|
|
|
@ -62,6 +62,7 @@ void LoadEngineState();
|
|||
void SaveEngineState();
|
||||
void WriteSavePic(FileWriter* file, int width, int height);
|
||||
extern FString BackupSaveGame;
|
||||
void SerializeMap(FSerializer &arc);
|
||||
|
||||
CVAR(String, cl_savedir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
|
||||
|
@ -73,6 +74,7 @@ CVAR(String, cl_savedir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|||
|
||||
static void SerializeSession(FSerializer& arc)
|
||||
{
|
||||
SerializeMap(arc);
|
||||
SerializeStatistics(arc);
|
||||
SECRET_Serialize(arc);
|
||||
Mus_Serialize(arc);
|
||||
|
@ -458,15 +460,89 @@ void CheckMagic(FileReader& fr)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
#define V(x) x
|
||||
static spritetype zsp;
|
||||
static sectortype zsec;
|
||||
static walltype zwal;
|
||||
|
||||
FSerializer &Serialize(FSerializer &arc, const char *key, sectortype &c, sectortype *def)
|
||||
{
|
||||
def = &zsec;
|
||||
if (arc.isReading()) c = {};
|
||||
if (arc.BeginObject(key))
|
||||
{
|
||||
arc("wallptr", c.wallptr, def->wallptr)
|
||||
("wallnum", c.wallnum, def->wallnum)
|
||||
("ceilingz", c.ceilingz, def->ceilingz)
|
||||
("floorz", c.floorz, def->floorz)
|
||||
("ceilingstat", c.ceilingstat, def->ceilingstat)
|
||||
("floorstat", c.floorstat, def->floorstat)
|
||||
("ceilingpicnum", c.ceilingpicnum, def->ceilingpicnum)
|
||||
("ceilingheinum", c.ceilingheinum, def->ceilingheinum)
|
||||
("ceilingshade", c.ceilingshade, def->ceilingshade)
|
||||
("ceilingpal", c.ceilingpal, def->ceilingpal)
|
||||
("ceilingxpanning", c.ceilingxpanning, def->ceilingxpanning)
|
||||
("ceilingypanning", c.ceilingypanning, def->ceilingypanning)
|
||||
("floorpicnum", c.floorpicnum, def->floorpicnum)
|
||||
("floorheinum", c.floorheinum, def->floorheinum)
|
||||
("floorshade", c.floorshade, def->floorshade)
|
||||
("floorpal", c.floorpal, def->floorpal)
|
||||
("floorxpanning", c.floorxpanning, def->floorxpanning)
|
||||
("floorypanning", c.floorypanning, def->floorypanning)
|
||||
("visibility", c.visibility, def->visibility)
|
||||
("fogpal", c.fogpal, def->fogpal)
|
||||
("lotag", c.lotag, def->lotag)
|
||||
("hitag", c.hitag, def->hitag)
|
||||
("extra", c.extra, def->extra)
|
||||
.EndObject();
|
||||
}
|
||||
return arc;
|
||||
}
|
||||
|
||||
FSerializer &Serialize(FSerializer &arc, const char *key, walltype &c, walltype *def)
|
||||
{
|
||||
def = &zwal;
|
||||
if (arc.isReading()) c = {};
|
||||
if (arc.BeginObject(key))
|
||||
{
|
||||
arc("x", c.x, def->x)
|
||||
("y", c.y, def->y)
|
||||
("point2", c.point2, def->point2)
|
||||
("nextwall", c.nextwall, def->nextwall)
|
||||
("nextsector", c.nextsector, def->nextsector)
|
||||
("cstat", c.cstat, def->cstat)
|
||||
("picnum", c.picnum, def->picnum)
|
||||
("overpicnum", c.overpicnum, def->overpicnum)
|
||||
("shade", c.shade, def->shade)
|
||||
("pal", c.pal, def->pal)
|
||||
("xrepeat", c.xrepeat, def->xrepeat)
|
||||
("yrepeat", c.yrepeat, def->yrepeat)
|
||||
("xpanning", c.xpanning, def->xpanning)
|
||||
("ypanning", c.ypanning, def->ypanning)
|
||||
("lotag", c.lotag, def->lotag)
|
||||
("hitag", c.hitag, def->hitag)
|
||||
("extra", c.extra, def->extra)
|
||||
.EndObject();
|
||||
}
|
||||
return arc;
|
||||
}
|
||||
|
||||
void SerializeMap(FSerializer& arc)
|
||||
{
|
||||
if (arc.BeginObject("engine"))
|
||||
{
|
||||
arc ("numsectors", numsectors)
|
||||
.Array("sectors", sector, numsectors)
|
||||
("numwalls", numwalls)
|
||||
.Array("walls", wall, numwalls)
|
||||
.EndObject();
|
||||
}
|
||||
|
||||
}
|
||||
void SaveEngineState()
|
||||
{
|
||||
auto fw = WriteSavegameChunk("engine.bin");
|
||||
fw->Write(&numsectors, sizeof(numsectors));
|
||||
fw->Write(sector, sizeof(sectortype) * numsectors);
|
||||
WriteMagic(fw);
|
||||
fw->Write(&numwalls, sizeof(numwalls));
|
||||
fw->Write(wall, sizeof(walltype) * numwalls);
|
||||
WriteMagic(fw);
|
||||
fw->Write(sprite, sizeof(spritetype) * MAXSPRITES);
|
||||
WriteMagic(fw);
|
||||
fw->Write(headspritesect, sizeof(headspritesect));
|
||||
|
@ -515,16 +591,8 @@ void LoadEngineState()
|
|||
auto fr = ReadSavegameChunk("engine.bin");
|
||||
if (fr.isOpen())
|
||||
{
|
||||
memset(sector, 0, sizeof(sector[0]) * MAXSECTORS);
|
||||
memset(wall, 0, sizeof(wall[0]) * MAXWALLS);
|
||||
memset(sprite, 0, sizeof(sprite[0]) * MAXSPRITES);
|
||||
|
||||
fr.Read(&numsectors, sizeof(numsectors));
|
||||
fr.Read(sector, sizeof(sectortype) * numsectors);
|
||||
CheckMagic(fr);
|
||||
fr.Read(&numwalls, sizeof(numwalls));
|
||||
fr.Read(wall, sizeof(walltype) * numwalls);
|
||||
CheckMagic(fr);
|
||||
fr.Read(sprite, sizeof(spritetype) * MAXSPRITES);
|
||||
CheckMagic(fr);
|
||||
fr.Read(headspritesect, sizeof(headspritesect));
|
||||
|
|
Loading…
Reference in a new issue