- SW: serialize SO interpolations as JSON.

This commit is contained in:
Christoph Oelckers 2021-04-02 13:20:48 +02:00
parent 2d571586bd
commit c49c5fcf1d
3 changed files with 36 additions and 54 deletions

View file

@ -30,6 +30,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "game.h" #include "game.h"
#include "interpso.h" #include "interpso.h"
#include "serializer.h"
#include "names2.h" #include "names2.h"
BEGIN_SW_NS BEGIN_SW_NS
@ -398,58 +399,46 @@ void so_restoreinterpolations(void) // Stick at end of drawscree
} }
} }
int SaveSymDataInfo(MFILE_WRITE fil, void *ptr); void so_serializeinterpolations(FSerializer& arc)
int so_writeinterpolations(MFILE_WRITE fil)
{ {
int32_t i;
SECTOR_OBJECTp sop; SECTOR_OBJECTp sop;
so_interp *interp; so_interp* interp;
int saveisshot = 0;
for (sop = SectorObject, interp = so_interpdata; if (arc.BeginArray("sop_interp"))
sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++)
{ {
so_interp::interp_data *data = interp->data; for (sop = SectorObject, interp = so_interpdata; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++)
MWRITE(&interp->numinterpolations,sizeof(interp->numinterpolations),1,fil);
MWRITE(&interp->hasvator,sizeof(interp->hasvator),1,fil);
for (i = 0; i < interp->numinterpolations; i++, data++)
{ {
MWRITE(&data->curelement, sizeof(data->curelement), 1, fil); if (arc.BeginObject(nullptr))
MWRITE(&data->oldipos,sizeof(data->oldipos),1,fil);
MWRITE(&data->spriteofang,sizeof(data->spriteofang),1,fil);
}
}
return saveisshot;
}
int LoadSymDataInfo(MFILE_READ fil, void** ptr);
int so_readinterpolations(MFILE_READ fil)
{
int32_t i;
SECTOR_OBJECTp sop;
so_interp *interp;
int saveisshot = 0;
for (sop = SectorObject, interp = so_interpdata;
sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++)
{ {
so_interp::interp_data *data = interp->data; so_interp::interp_data* data = interp->data;
MREAD(&interp->numinterpolations,sizeof(interp->numinterpolations),1,fil); arc("numinterp", interp->numinterpolations)
MREAD(&interp->hasvator,sizeof(interp->hasvator),1,fil); ("hasvator", interp->hasvator);
for (i = 0; i < interp->numinterpolations; i++, data++) if (arc.BeginArray("data"))
{
for (int i = 0; i < interp->numinterpolations; i++, data++)
{
if (arc.BeginObject(nullptr))
{
arc("curelement", data->curelement)
("oldipos", data->oldipos)
("spriteofang", data->spriteofang)
.EndObject();
if (arc.isReading())
{ {
MREAD(&data->curelement, sizeof(data->curelement), 1, fil);
MREAD(&data->oldipos,sizeof(data->oldipos),1,fil);
MREAD(&data->spriteofang,sizeof(data->spriteofang),1,fil);
data->lastipos = data->lastoldipos = data->oldipos; data->lastipos = data->lastoldipos = data->oldipos;
data->lastangdiff = 0; data->lastangdiff = 0;
} }
}
}
arc.EndArray();
}
arc.EndObject();
interp->tic = 0; interp->tic = 0;
interp->lasttic = synctics; interp->lasttic = synctics;
} }
return saveisshot; }
arc.EndArray();
}
} }
END_SW_NS END_SW_NS

View file

@ -41,8 +41,7 @@ void so_setinterpolationtics(SECTOR_OBJECTp sop, int16_t locktics);
void so_updateinterpolations(void); void so_updateinterpolations(void);
void so_dointerpolations(int32_t smoothratio); void so_dointerpolations(int32_t smoothratio);
void so_restoreinterpolations(void); void so_restoreinterpolations(void);
int so_writeinterpolations(MFILE_WRITE fil); void so_serializeinterpolations(FSerializer& arc);
int so_readinterpolations(MFILE_READ fil);
END_SW_NS END_SW_NS

View file

@ -1178,6 +1178,7 @@ void GameInterface::SerializeGameState(FSerializer& arc)
preSerializePanelSprites(arc); preSerializePanelSprites(arc);
SerializeUser(arc); SerializeUser(arc);
SerializeSectUser(arc); SerializeSectUser(arc);
so_serializeinterpolations(arc);
arc("numplayers", numplayers) arc("numplayers", numplayers)
.Array("players", Player, numplayers) .Array("players", Player, numplayers)
("skill", Skill) ("skill", Skill)
@ -1422,10 +1423,6 @@ bool GameInterface::SaveGame()
#endif #endif
#endif #endif
// SO interpolations
saveisshot |= so_writeinterpolations(fil);
assert(!saveisshot);
return !saveisshot; return !saveisshot;
} }
@ -1525,9 +1522,6 @@ bool GameInterface::LoadGame()
#endif #endif
#endif #endif
// SO interpolations
saveisshot |= so_readinterpolations(fil);
if (saveisshot) { MCLOSE_READ(fil); return false; }
MCLOSE_READ(fil); MCLOSE_READ(fil);