From a5000ead4c27d88074beeae76d7afb318f8accda Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 19 Sep 2016 19:58:04 +0200 Subject: [PATCH] - another batch. --- src/g_doom/a_bossbrain.cpp | 2 +- src/g_heretic/a_dsparil.cpp | 2 +- src/g_shared/a_action.cpp | 9 +++-- src/g_shared/a_flashfader.cpp | 12 +++--- src/g_shared/a_lightning.cpp | 38 +++++------------ src/g_shared/a_lightning.h | 4 +- src/g_shared/a_quake.cpp | 24 +++++++---- src/g_shared/a_sharedglobal.h | 4 +- src/g_shared/a_specialspot.cpp | 74 ++++++++++++++-------------------- src/g_shared/a_specialspot.h | 12 +++--- src/p_sectors.cpp | 16 +++++--- 11 files changed, 89 insertions(+), 108 deletions(-) diff --git a/src/g_doom/a_bossbrain.cpp b/src/g_doom/a_bossbrain.cpp index e6fd5f16df..b0e7259105 100644 --- a/src/g_doom/a_bossbrain.cpp +++ b/src/g_doom/a_bossbrain.cpp @@ -120,7 +120,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_BrainSpit) bool isdefault = false; // shoot a cube at current target - targ = state->GetNextInList(PClass::FindClass("BossTarget"), G_SkillProperty(SKILLP_EasyBossBrain)); + targ = state->GetNextInList(PClass::FindActor("BossTarget"), G_SkillProperty(SKILLP_EasyBossBrain)); if (targ != NULL) { diff --git a/src/g_heretic/a_dsparil.cpp b/src/g_heretic/a_dsparil.cpp index 124cb14034..f5870f09ec 100644 --- a/src/g_heretic/a_dsparil.cpp +++ b/src/g_heretic/a_dsparil.cpp @@ -148,7 +148,7 @@ void P_DSparilTeleport (AActor *actor) DSpotState *state = DSpotState::GetSpotState(); if (state == NULL) return; - spot = state->GetSpotWithMinMaxDistance(PClass::FindClass("BossSpot"), actor->X(), actor->Y(), 128, 0); + spot = state->GetSpotWithMinMaxDistance(PClass::FindActor("BossSpot"), actor->X(), actor->Y(), 128, 0); if (spot == NULL) return; prev = actor->Pos(); diff --git a/src/g_shared/a_action.cpp b/src/g_shared/a_action.cpp index 3e3231c15e..c0ec37d09b 100644 --- a/src/g_shared/a_action.cpp +++ b/src/g_shared/a_action.cpp @@ -11,7 +11,7 @@ #include "p_enemy.h" #include "statnums.h" #include "templates.h" -#include "farchive.h" +#include "serializer.h" #include "r_data/r_translate.h" static FRandom pr_freezedeath ("FreezeDeath"); @@ -361,7 +361,7 @@ class DCorpsePointer : public DThinker public: DCorpsePointer (AActor *ptr); void Destroy (); - void Serialize(FArchive &arc); + void Serialize(FSerializer &arc); TObjPtr Corpse; DWORD Count; // Only the first corpse pointer's count is valid. private: @@ -435,10 +435,11 @@ void DCorpsePointer::Destroy () Super::Destroy (); } -void DCorpsePointer::Serialize(FArchive &arc) +void DCorpsePointer::Serialize(FSerializer &arc) { Super::Serialize(arc); - arc << Corpse << Count; + arc("corpse", Corpse) + ("count", Count); } diff --git a/src/g_shared/a_flashfader.cpp b/src/g_shared/a_flashfader.cpp index 736f9e0da3..71673e5c7d 100644 --- a/src/g_shared/a_flashfader.cpp +++ b/src/g_shared/a_flashfader.cpp @@ -1,7 +1,7 @@ #include "a_sharedglobal.h" #include "g_level.h" #include "d_player.h" -#include "farchive.h" +#include "serializer.h" IMPLEMENT_POINTY_CLASS (DFlashFader) DECLARE_POINTER (ForWho) @@ -26,13 +26,13 @@ void DFlashFader::Destroy () Super::Destroy(); } -void DFlashFader::Serialize(FArchive &arc) +void DFlashFader::Serialize(FSerializer &arc) { Super::Serialize (arc); - arc << TotalTics << StartTic << ForWho; - for (int i = 1; i >= 0; --i) - for (int j = 3; j >= 0; --j) - arc << Blends[i][j]; + arc("totaltics", TotalTics) + ("starttic", StartTic) + ("forwho", ForWho) + .Array("blends", Blends[0], 8); } void DFlashFader::Tick () diff --git a/src/g_shared/a_lightning.cpp b/src/g_shared/a_lightning.cpp index 72bde00787..3eaedffc9c 100644 --- a/src/g_shared/a_lightning.cpp +++ b/src/g_shared/a_lightning.cpp @@ -9,7 +9,7 @@ #include "r_sky.h" #include "g_level.h" #include "r_state.h" -#include "farchive.h" +#include "serializer.h" static FRandom pr_lightning ("Lightning"); @@ -19,44 +19,24 @@ DLightningThinker::DLightningThinker () : DThinker (STAT_LIGHTNING) { Stopped = false; - LightningLightLevels = NULL; LightningFlashCount = 0; NextLightningFlash = ((pr_lightning()&15)+5)*35; // don't flash at level start - LightningLightLevels = new short[numsectors]; - clearbufshort(LightningLightLevels, numsectors, SHRT_MAX); + LightningLightLevels.Resize(numsectors); + clearbufshort(&LightningLightLevels[0], numsectors, SHRT_MAX); } DLightningThinker::~DLightningThinker () { - if (LightningLightLevels != NULL) - { - delete[] LightningLightLevels; - } } -void DLightningThinker::Serialize(FArchive &arc) +void DLightningThinker::Serialize(FSerializer &arc) { - int i; - short *lights; - Super::Serialize (arc); - - arc << Stopped << NextLightningFlash << LightningFlashCount; - - if (arc.IsLoading ()) - { - if (LightningLightLevels != NULL) - { - delete[] LightningLightLevels; - } - LightningLightLevels = new short[numsectors]; - } - lights = LightningLightLevels; - for (i = numsectors; i > 0; ++lights, --i) - { - arc << *lights; - } + arc("stopped", Stopped) + ("next", NextLightningFlash) + ("count", LightningFlashCount) + ("levels", LightningLightLevels); } void DLightningThinker::Tick () @@ -107,7 +87,7 @@ void DLightningThinker::LightningFlash () tempSec->SetLightLevel(LightningLightLevels[j]); } } - clearbufshort(LightningLightLevels, numsectors, SHRT_MAX); + clearbufshort(&LightningLightLevels[0], numsectors, SHRT_MAX); level.flags &= ~LEVEL_SWAPSKIES; } return; diff --git a/src/g_shared/a_lightning.h b/src/g_shared/a_lightning.h index cca8d1fcc5..62a2604740 100644 --- a/src/g_shared/a_lightning.h +++ b/src/g_shared/a_lightning.h @@ -13,7 +13,7 @@ class DLightningThinker : public DThinker public: DLightningThinker (); ~DLightningThinker (); - void Serialize(FArchive &arc); + void Serialize(FSerializer &arc); void Tick (); void ForceLightning (int mode); void TerminateLightning(); @@ -24,7 +24,7 @@ protected: int NextLightningFlash; int LightningFlashCount; bool Stopped; - short *LightningLightLevels; + TArray LightningLightLevels; }; void P_StartLightning (); diff --git a/src/g_shared/a_quake.cpp b/src/g_shared/a_quake.cpp index 13194a06e8..98e505b2b9 100644 --- a/src/g_shared/a_quake.cpp +++ b/src/g_shared/a_quake.cpp @@ -8,7 +8,7 @@ #include "s_sound.h" #include "a_sharedglobal.h" #include "statnums.h" -#include "farchive.h" +#include "serializer.h" #include "d_player.h" #include "r_utility.h" @@ -64,15 +64,23 @@ DEarthquake::DEarthquake(AActor *center, int intensityX, int intensityY, int int // //========================================================================== -void DEarthquake::Serialize(FArchive &arc) +void DEarthquake::Serialize(FSerializer &arc) { Super::Serialize (arc); - arc << m_Spot << m_Intensity << m_Countdown - << m_TremorRadius << m_DamageRadius - << m_QuakeSFX << m_Flags << m_CountdownStart - << m_WaveSpeed - << m_Falloff << m_Highpoint << m_MiniCount - << m_RollIntensity << m_RollWave; + arc("spot", m_Spot) + ("intensity", m_Intensity) + ("countdown", m_Countdown) + ("tremorradius", m_TremorRadius) + ("damageradius", m_DamageRadius) + ("quakesfx", m_QuakeSFX) + ("quakeflags", m_Flags) + ("countdownstart", m_CountdownStart) + ("wavespeed", m_WaveSpeed) + ("falloff", m_Falloff) + ("highpoint", m_Highpoint) + ("minicount", m_MiniCount) + ("rollintensity", m_RollIntensity) + ("rollwave", m_RollWave); } //========================================================================== diff --git a/src/g_shared/a_sharedglobal.h b/src/g_shared/a_sharedglobal.h index dd332fae1b..7f4168563c 100644 --- a/src/g_shared/a_sharedglobal.h +++ b/src/g_shared/a_sharedglobal.h @@ -122,7 +122,7 @@ public: float r2, float g2, float b2, float a2, float time, AActor *who); void Destroy (); - void Serialize(FArchive &arc); + void Serialize(FSerializer &arc); void Tick (); AActor *WhoFor() { return ForWho; } void Cancel (); @@ -165,7 +165,7 @@ public: int damrad, int tremrad, FSoundID quakesfx, int flags, double waveSpeedX, double waveSpeedY, double waveSpeedZ, int falloff, int highpoint, double rollIntensity, double rollWave); - void Serialize(FArchive &arc); + void Serialize(FSerializer &arc); void Tick (); TObjPtr m_Spot; double m_TremorRadius, m_DamageRadius; diff --git a/src/g_shared/a_specialspot.cpp b/src/g_shared/a_specialspot.cpp index a0469fb40f..1d8d1f72d5 100644 --- a/src/g_shared/a_specialspot.cpp +++ b/src/g_shared/a_specialspot.cpp @@ -39,7 +39,7 @@ #include "i_system.h" #include "thingdef/thingdef.h" #include "doomstat.h" -#include "farchive.h" +#include "serializer.h" #include "a_pickups.h" static FRandom pr_spot ("SpecialSpot"); @@ -58,7 +58,7 @@ TObjPtr DSpotState::SpotState; struct FSpotList { - const PClass *Type; + PClassActor *Type; TArray Spots; unsigned Index; int SkipCount; @@ -68,7 +68,7 @@ struct FSpotList { } - FSpotList(const PClass *type) + FSpotList(PClassActor *type) { Type = type; Index = 0; @@ -82,17 +82,6 @@ struct FSpotList // //---------------------------------------------------------------------------- - void Serialize(FArchive &arc) - { - arc << Type << Spots << Index << SkipCount << numcalls; - } - - //---------------------------------------------------------------------------- - // - // - // - //---------------------------------------------------------------------------- - bool Add(ASpecialSpot *newspot) { for(unsigned i = 0; i < Spots.Size(); i++) @@ -194,6 +183,26 @@ struct FSpotList // //---------------------------------------------------------------------------- +FSerializer &Serialize(FSerializer &arc, const char *key, FSpotList &list, FSpotList *def) +{ + if (arc.BeginObject(key)) + { + arc("type", list.Type) + ("spots", list.Spots) + ("index", list.Index) + ("skipcount", list.SkipCount) + ("numcalls", list.numcalls) + .EndObject(); + } + return arc; +} + +//---------------------------------------------------------------------------- +// +// +// +//---------------------------------------------------------------------------- + DSpotState::DSpotState () : DThinker (STAT_INFO) { @@ -215,10 +224,6 @@ DSpotState::DSpotState () void DSpotState::Destroy () { - for(unsigned i = 0; i < SpotLists.Size(); i++) - { - delete SpotLists[i]; - } SpotLists.Clear(); SpotLists.ShrinkToFit(); @@ -254,13 +259,13 @@ DSpotState *DSpotState::GetSpotState(bool create) // //---------------------------------------------------------------------------- -FSpotList *DSpotState::FindSpotList(const PClass *type) +FSpotList *DSpotState::FindSpotList(PClassActor *type) { for(unsigned i = 0; i < SpotLists.Size(); i++) { - if (SpotLists[i]->Type == type) return SpotLists[i]; + if (SpotLists[i].Type == type) return &SpotLists[i]; } - return SpotLists[SpotLists.Push(new FSpotList(type))]; + return &SpotLists[SpotLists.Push(FSpotList(type))]; } //---------------------------------------------------------------------------- @@ -295,27 +300,10 @@ bool DSpotState::RemoveSpot(ASpecialSpot *spot) // //---------------------------------------------------------------------------- -void DSpotState::Serialize(FArchive &arc) +void DSpotState::Serialize(FSerializer &arc) { Super::Serialize(arc); - if (arc.IsStoring()) - { - arc.WriteCount(SpotLists.Size()); - for(unsigned i = 0; i < SpotLists.Size(); i++) - { - SpotLists[i]->Serialize(arc); - } - } - else - { - unsigned c = arc.ReadCount(); - SpotLists.Resize(c); - for(unsigned i = 0; i < SpotLists.Size(); i++) - { - SpotLists[i] = new FSpotList; - SpotLists[i]->Serialize(arc); - } - } + arc("spots", SpotLists); } //---------------------------------------------------------------------------- @@ -324,7 +312,7 @@ void DSpotState::Serialize(FArchive &arc) // //---------------------------------------------------------------------------- -ASpecialSpot *DSpotState::GetNextInList(const PClass *type, int skipcounter) +ASpecialSpot *DSpotState::GetNextInList(PClassActor *type, int skipcounter) { FSpotList *list = FindSpotList(type); if (list != NULL) return list->GetNextInList(skipcounter); @@ -337,7 +325,7 @@ ASpecialSpot *DSpotState::GetNextInList(const PClass *type, int skipcounter) // //---------------------------------------------------------------------------- -ASpecialSpot *DSpotState::GetSpotWithMinMaxDistance(const PClass *type, double x, double y, double mindist, double maxdist) +ASpecialSpot *DSpotState::GetSpotWithMinMaxDistance(PClassActor *type, double x, double y, double mindist, double maxdist) { FSpotList *list = FindSpotList(type); if (list != NULL) return list->GetSpotWithMinMaxDistance(x, y, mindist, maxdist); @@ -350,7 +338,7 @@ ASpecialSpot *DSpotState::GetSpotWithMinMaxDistance(const PClass *type, double x // //---------------------------------------------------------------------------- -ASpecialSpot *DSpotState::GetRandomSpot(const PClass *type, bool onlyonce) +ASpecialSpot *DSpotState::GetRandomSpot(PClassActor *type, bool onlyonce) { FSpotList *list = FindSpotList(type); if (list != NULL) return list->GetRandomSpot(onlyonce); diff --git a/src/g_shared/a_specialspot.h b/src/g_shared/a_specialspot.h index db148b19dc..8fe38608aa 100644 --- a/src/g_shared/a_specialspot.h +++ b/src/g_shared/a_specialspot.h @@ -22,7 +22,7 @@ class DSpotState : public DThinker { DECLARE_CLASS(DSpotState, DThinker) static TObjPtr SpotState; - TArray SpotLists; + TArray SpotLists; public: @@ -31,13 +31,13 @@ public: void Destroy (); void Tick (); static DSpotState *GetSpotState(bool create = true); - FSpotList *FindSpotList(const PClass *type); + FSpotList *FindSpotList(PClassActor *type); bool AddSpot(ASpecialSpot *spot); bool RemoveSpot(ASpecialSpot *spot); - void Serialize(FArchive &arc); - ASpecialSpot *GetNextInList(const PClass *type, int skipcounter); - ASpecialSpot *GetSpotWithMinMaxDistance(const PClass *type, double x, double y, double mindist, double maxdist); - ASpecialSpot *GetRandomSpot(const PClass *type, bool onlyonce = false); + void Serialize(FSerializer &arc); + ASpecialSpot *GetNextInList(PClassActor *type, int skipcounter); + ASpecialSpot *GetSpotWithMinMaxDistance(PClassActor *type, double x, double y, double mindist, double maxdist); + ASpecialSpot *GetRandomSpot(PClassActor *type, bool onlyonce = false); }; diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index eb1742aa8d..5ed4cd1442 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1055,12 +1055,16 @@ double sector_t::NextLowestFloorAt(double x, double y, double z, int flags, doub FSerializer &Serialize(FSerializer &arc, const char *key, secspecial_t &spec, secspecial_t *def) { - arc("special", spec.special) - ("damageamount", spec.damageamount) - ("damagetype", spec.damagetype) - ("damageinterval", spec.damageinterval) - ("leakydamage", spec.leakydamage) - ("flags", spec.Flags); + if (arc.BeginObject(key)) + { + arc("special", spec.special) + ("damageamount", spec.damageamount) + ("damagetype", spec.damagetype) + ("damageinterval", spec.damageinterval) + ("leakydamage", spec.leakydamage) + ("flags", spec.Flags) + .EndObject(); + } return arc; }