From ee2766d00be3dd9309309dde3151668cd39e3c30 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 24 Sep 2016 01:47:44 +0200 Subject: [PATCH] - made adjustments for new savegame code. --- src/gl/dynlights/a_dynlight.cpp | 32 ++++++++++++++++++----------- src/gl/dynlights/gl_dynlight.h | 5 +++-- src/gl/renderer/gl_renderer.h | 2 +- src/gl/scene/gl_scene.cpp | 29 ++++++++++++++------------ src/gl/system/gl_framebuffer.cpp | 1 - src/gl/utility/gl_cycler.cpp | 21 ++++++++++++++----- src/gl/utility/gl_cycler.h | 35 +++++++++++--------------------- src/p_saveg.cpp | 2 ++ 8 files changed, 70 insertions(+), 57 deletions(-) diff --git a/src/gl/dynlights/a_dynlight.cpp b/src/gl/dynlights/a_dynlight.cpp index fcb945f01..36ef1b948 100644 --- a/src/gl/dynlights/a_dynlight.cpp +++ b/src/gl/dynlights/a_dynlight.cpp @@ -69,6 +69,7 @@ #include "r_utility.h" #include "portal.h" #include "doomstat.h" +#include "serializer.h" #include "gl/renderer/gl_renderer.h" @@ -154,24 +155,31 @@ static FRandom randLight; // // //========================================================================== -void ADynamicLight::Serialize(FArchive &arc) +void ADynamicLight::Serialize(FSerializer &arc) { Super::Serialize (arc); - arc << lightflags << lighttype; - arc << m_tickCount << m_currentRadius; - arc << m_Radius[0] << m_Radius[1]; + auto def = static_cast(GetDefault()); + arc("lightflags", lightflags, def->lightflags) + ("lighttype", lighttype, def->lighttype) + ("tickcount", m_tickCount, def->m_tickCount) + ("currentradius", m_currentRadius, def->m_currentRadius) + .Array("radius", m_Radius, def->m_Radius, 2); - if (lighttype == PulseLight) arc << m_lastUpdate << m_cycler; - if (arc.IsLoading()) - { - // The default constructor which is used for creating objects before deserialization will not set this variable. - // It needs to be true for all placed lights. - visibletoplayer = true; - LinkLight(); - } + if (lighttype == PulseLight) + arc("lastupdate", m_lastUpdate, def->m_lastUpdate) + ("cycler", m_cycler, def->m_cycler); } +void ADynamicLight::PostSerialize() +{ + Super::PostSerialize(); + // The default constructor which is used for creating objects before deserialization will not set this variable. + // It needs to be true for all placed lights. + visibletoplayer = true; + LinkLight(); +} + //========================================================================== // // [TS] diff --git a/src/gl/dynlights/gl_dynlight.h b/src/gl/dynlights/gl_dynlight.h index d92bf35c6..84965e318 100644 --- a/src/gl/dynlights/gl_dynlight.h +++ b/src/gl/dynlights/gl_dynlight.h @@ -32,7 +32,7 @@ EXTERN_CVAR(Bool, gl_lights) EXTERN_CVAR(Bool, gl_attachedlights) class ADynamicLight; -class FArchive; +class FSerializer; @@ -93,7 +93,8 @@ class ADynamicLight : public AActor DECLARE_CLASS (ADynamicLight, AActor) public: virtual void Tick(); - void Serialize(FArchive &arc); + void Serialize(FSerializer &arc); + void PostSerialize(); BYTE GetRed() const { return args[LIGHT_RED]; } BYTE GetGreen() const { return args[LIGHT_GREEN]; } BYTE GetBlue() const { return args[LIGHT_BLUE]; } diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index b95408521..71c52474a 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -169,7 +169,7 @@ public: void RenderScreenQuad(); void SetFixedColormap (player_t *player); - void WriteSavePic (player_t *player, FILE *file, int width, int height); + void WriteSavePic (player_t *player, FileWriter *file, int width, int height); void EndDrawScene(sector_t * viewsector); void UpdateCameraExposure(); void BloomScene(); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 528925b7a..0c76b4bb1 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -43,6 +43,7 @@ #include "a_hexenglobal.h" #include "p_local.h" #include "gl/gl_functions.h" +#include "serializer.h" #include "gl/dynlights/gl_lightbuffer.h" #include "gl/system/gl_interface.h" @@ -921,7 +922,7 @@ void FGLRenderer::RenderView (player_t* player) // //=========================================================================== -void FGLRenderer::WriteSavePic (player_t *player, FILE *file, int width, int height) +void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { GL_IRECT bounds; @@ -972,10 +973,10 @@ struct FGLInterface : public FRenderer void PrecacheSprite(FTexture *tex, SpriteHits &hits); void Precache(BYTE *texhitlist, TMap &actorhitlist) override; void RenderView(player_t *player) override; - void WriteSavePic (player_t *player, FILE *file, int width, int height) override; + void WriteSavePic (player_t *player, FileWriter *file, int width, int height) override; void StateChanged(AActor *actor) override; - void StartSerialize(FArchive &arc) override; - void EndSerialize(FArchive &arc) override; + void StartSerialize(FSerializer &arc) override; + void EndSerialize(FSerializer &arc) override; void RenderTextureView (FCanvasTexture *self, AActor *viewpoint, int fov) override; sector_t *FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel, bool back) override; void SetFogParams(int _fogdensity, PalEntry _outsidefogcolor, int _outsidefogdensity, int _skyfog) override; @@ -1195,20 +1196,22 @@ void FGLInterface::StateChanged(AActor *actor) // //=========================================================================== -void FGLInterface::StartSerialize(FArchive &arc) +void FGLInterface::StartSerialize(FSerializer &arc) { gl_DeleteAllAttachedLights(); + if (arc.BeginObject("glinfo")) + { + arc("fogdensity", fogdensity) + ("outsidefogdensity", outsidefogdensity) + ("skyfog", skyfog) + .EndObject(); + } } -void gl_SerializeGlobals(FArchive &arc) -{ - arc << fogdensity << outsidefogdensity << skyfog; -} - -void FGLInterface::EndSerialize(FArchive &arc) +void FGLInterface::EndSerialize(FSerializer &arc) { gl_RecreateAllAttachedLights(); - if (arc.IsLoading()) gl_InitPortals(); + if (arc.isReading()) gl_InitPortals(); } //=========================================================================== @@ -1244,7 +1247,7 @@ void FGLInterface::ClearBuffer(int color) // //=========================================================================== -void FGLInterface::WriteSavePic (player_t *player, FILE *file, int width, int height) +void FGLInterface::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { GLRenderer->WriteSavePic(player, file, width, height); } diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 1ca2f7edd..94eba0817 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -36,7 +36,6 @@ #include "vectors.h" #include "v_palette.h" #include "templates.h" -#include "farchive.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_framebuffer.h" diff --git a/src/gl/utility/gl_cycler.cpp b/src/gl/utility/gl_cycler.cpp index a12cb4851..b6d160925 100644 --- a/src/gl/utility/gl_cycler.cpp +++ b/src/gl/utility/gl_cycler.cpp @@ -34,19 +34,30 @@ */ #include +#include "serializer.h" #include "gl/utility/gl_cycler.h" //========================================================================== // -// +// This will never be called with a null-def, so don't bother with that case. // //========================================================================== -void FCycler::Serialize(FArchive & arc) +FSerializer &Serialize(FSerializer &arc, const char *key, FCycler &c, FCycler *def) { - arc << m_start << m_end << m_current - << m_time << m_cycle << m_increment << m_shouldCycle - << m_cycleType; + if (arc.BeginObject(key)) + { + arc("start", c.m_start, def->m_start) + ("end", c.m_end, def->m_end) + ("current", c.m_current, def->m_current) + ("time", c.m_time, def->m_time) + ("cycle", c.m_cycle, def->m_cycle) + ("increment", c.m_increment, def->m_increment) + ("shouldcycle", c.m_shouldCycle, def->m_shouldCycle) + .Enum("type", c.m_cycleType) + .EndObject(); + } + return arc; } //========================================================================== diff --git a/src/gl/utility/gl_cycler.h b/src/gl/utility/gl_cycler.h index 8a6b55581..42effce34 100644 --- a/src/gl/utility/gl_cycler.h +++ b/src/gl/utility/gl_cycler.h @@ -1,28 +1,24 @@ #ifndef __GL_CYCLER_H #define __GL_CYCLER_H -#include "farchive.h" +class FSerializer; -typedef enum +enum CycleType { - CYCLE_Linear, - CYCLE_Sin, - CYCLE_Cos, - CYCLE_SawTooth, - CYCLE_Square -} CycleType; - -inline FArchive &operator<< (FArchive &arc, CycleType &type) -{ - BYTE val = (BYTE)type; - arc << val; - type = (CycleType)val; - return arc; -} + CYCLE_Linear, + CYCLE_Sin, + CYCLE_Cos, + CYCLE_SawTooth, + CYCLE_Square +}; +class FCycler; +FSerializer &Serialize(FSerializer &arc, const char *key, FCycler &c, FCycler *def); class FCycler { + friend FSerializer &Serialize(FSerializer &arc, const char *key, FCycler &c, FCycler *def); + public: FCycler(); void Update(float diff); @@ -33,7 +29,6 @@ public: inline operator float () const { return m_current; } - void Serialize(FArchive & arc); protected: float m_start, m_end, m_current; float m_time, m_cycle; @@ -42,11 +37,5 @@ protected: CycleType m_cycleType; }; -inline FArchive &operator<< (FArchive &arc, FCycler &type) -{ - type.Serialize(arc); - return arc; -} - #endif diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 465760137..170273b43 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -271,6 +271,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t .Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0]) .Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1]) ("scrolls", scroll, nul) + // GZDoom exclusive: + .Array("reflect", p.reflect, def->reflect, 2) .EndObject(); if (arc.isReading() && !scroll.isZero())