From c49c5fcf1dbfbe0938a98b78609c74dc0fdc7e9d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 2 Apr 2021 13:20:48 +0200 Subject: [PATCH] - SW: serialize SO interpolations as JSON. --- source/games/sw/src/interpso.cpp | 79 ++++++++++++++------------------ source/games/sw/src/interpso.h | 3 +- source/games/sw/src/save.cpp | 8 +--- 3 files changed, 36 insertions(+), 54 deletions(-) diff --git a/source/games/sw/src/interpso.cpp b/source/games/sw/src/interpso.cpp index 744d2ba6a..197e5c68b 100644 --- a/source/games/sw/src/interpso.cpp +++ b/source/games/sw/src/interpso.cpp @@ -30,6 +30,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "game.h" #include "interpso.h" +#include "serializer.h" #include "names2.h" BEGIN_SW_NS @@ -398,58 +399,46 @@ void so_restoreinterpolations(void) // Stick at end of drawscree } } -int SaveSymDataInfo(MFILE_WRITE fil, void *ptr); - -int so_writeinterpolations(MFILE_WRITE fil) +void so_serializeinterpolations(FSerializer& arc) { - int32_t i; SECTOR_OBJECTp sop; - so_interp *interp; - int saveisshot = 0; + so_interp* interp; - for (sop = SectorObject, interp = so_interpdata; - sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++) + if (arc.BeginArray("sop_interp")) { - so_interp::interp_data *data = interp->data; - MWRITE(&interp->numinterpolations,sizeof(interp->numinterpolations),1,fil); - MWRITE(&interp->hasvator,sizeof(interp->hasvator),1,fil); - for (i = 0; i < interp->numinterpolations; i++, data++) + for (sop = SectorObject, interp = so_interpdata; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++, interp++) { - MWRITE(&data->curelement, sizeof(data->curelement), 1, fil); - MWRITE(&data->oldipos,sizeof(data->oldipos),1,fil); - MWRITE(&data->spriteofang,sizeof(data->spriteofang),1,fil); + if (arc.BeginObject(nullptr)) + { + so_interp::interp_data* data = interp->data; + arc("numinterp", interp->numinterpolations) + ("hasvator", interp->hasvator); + 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()) + { + data->lastipos = data->lastoldipos = data->oldipos; + data->lastangdiff = 0; + } + } + } + arc.EndArray(); + } + arc.EndObject(); + interp->tic = 0; + interp->lasttic = synctics; + } } + arc.EndArray(); } - 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; - MREAD(&interp->numinterpolations,sizeof(interp->numinterpolations),1,fil); - MREAD(&interp->hasvator,sizeof(interp->hasvator),1,fil); - for (i = 0; i < interp->numinterpolations; i++, data++) - { - 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->lastangdiff = 0; - } - interp->tic = 0; - interp->lasttic = synctics; - } - return saveisshot; } END_SW_NS diff --git a/source/games/sw/src/interpso.h b/source/games/sw/src/interpso.h index 512b61c9e..b22254dad 100644 --- a/source/games/sw/src/interpso.h +++ b/source/games/sw/src/interpso.h @@ -41,8 +41,7 @@ void so_setinterpolationtics(SECTOR_OBJECTp sop, int16_t locktics); void so_updateinterpolations(void); void so_dointerpolations(int32_t smoothratio); void so_restoreinterpolations(void); -int so_writeinterpolations(MFILE_WRITE fil); -int so_readinterpolations(MFILE_READ fil); +void so_serializeinterpolations(FSerializer& arc); END_SW_NS diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 3f3b4a462..fa2338ab2 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -1178,6 +1178,7 @@ void GameInterface::SerializeGameState(FSerializer& arc) preSerializePanelSprites(arc); SerializeUser(arc); SerializeSectUser(arc); + so_serializeinterpolations(arc); arc("numplayers", numplayers) .Array("players", Player, numplayers) ("skill", Skill) @@ -1422,10 +1423,6 @@ bool GameInterface::SaveGame() #endif #endif - // SO interpolations - saveisshot |= so_writeinterpolations(fil); - assert(!saveisshot); - return !saveisshot; } @@ -1525,9 +1522,6 @@ bool GameInterface::LoadGame() #endif #endif - // SO interpolations - saveisshot |= so_readinterpolations(fil); - if (saveisshot) { MCLOSE_READ(fil); return false; } MCLOSE_READ(fil);