From a542e9914360d16456310a77d2bedea2807accc0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 19 Sep 2016 13:36:58 +0200 Subject: [PATCH] - a few more --- src/g_shared/a_weaponpiece.cpp | 14 ++- src/g_shared/a_weaponpiece.h | 10 +- src/r_data/r_interpolate.cpp | 55 ++++++----- src/r_data/r_interpolate.h | 3 +- src/serializer.cpp | 10 +- src/serializer.h | 5 + src/zzz_old.cpp | 163 +++++++++++++++++++++++++++++++++ 7 files changed, 228 insertions(+), 32 deletions(-) diff --git a/src/g_shared/a_weaponpiece.cpp b/src/g_shared/a_weaponpiece.cpp index 7068fe275d..aefce18c1c 100644 --- a/src/g_shared/a_weaponpiece.cpp +++ b/src/g_shared/a_weaponpiece.cpp @@ -1,7 +1,7 @@ #include "a_pickups.h" #include "a_weaponpiece.h" #include "doomstat.h" -#include "farchive.h" +#include "serializer.h" IMPLEMENT_CLASS(PClassWeaponPiece) IMPLEMENT_CLASS (AWeaponHolder) @@ -17,10 +17,11 @@ void PClassWeaponPiece::ReplaceClassRef(PClass *oldclass, PClass *newclass) } -void AWeaponHolder::Serialize(FArchive &arc) +void AWeaponHolder::Serialize(FSerializer &arc) { Super::Serialize(arc); - arc << PieceMask << PieceWeapon; + arc("piecemask", PieceMask) + ("pieceweapon", PieceWeapon); } @@ -29,10 +30,13 @@ IMPLEMENT_POINTY_CLASS (AWeaponPiece) END_POINTERS -void AWeaponPiece::Serialize(FArchive &arc) +void AWeaponPiece::Serialize(FSerializer &arc) { Super::Serialize (arc); - arc << WeaponClass << FullWeapon << PieceValue; + auto def = (AWeaponPiece*)GetDefault(); + arc("weaponclass", WeaponClass, def->WeaponClass) + ("fullweapon", FullWeapon) + ("piecevalue", PieceValue, def->PieceValue); } //========================================================================== diff --git a/src/g_shared/a_weaponpiece.h b/src/g_shared/a_weaponpiece.h index 4f201fe19d..0ab11a80f5 100644 --- a/src/g_shared/a_weaponpiece.h +++ b/src/g_shared/a_weaponpiece.h @@ -15,7 +15,8 @@ class AWeaponPiece : public AInventory protected: bool PrivateShouldStay (); public: - void Serialize(FArchive &arc); + DECLARE_OLD_SERIAL + void Serialize(FSerializer &arc); bool TryPickup (AActor *&toucher); bool TryPickupRestricted (AActor *&toucher); bool ShouldStay (); @@ -23,7 +24,7 @@ public: virtual void PlayPickupSound (AActor *toucher); int PieceValue; - PClassWeapon *WeaponClass; + PClassActor *WeaponClass; TObjPtr FullWeapon; }; @@ -35,7 +36,8 @@ class AWeaponHolder : public AInventory public: int PieceMask; - const PClass * PieceWeapon; + PClassActor * PieceWeapon; - void Serialize(FArchive &arc); + DECLARE_OLD_SERIAL + void Serialize(FSerializer &arc); }; diff --git a/src/r_data/r_interpolate.cpp b/src/r_data/r_interpolate.cpp index 4b826c56b8..38cb7a7a5a 100644 --- a/src/r_data/r_interpolate.cpp +++ b/src/r_data/r_interpolate.cpp @@ -39,7 +39,7 @@ #include "p_local.h" #include "i_system.h" #include "po_man.h" -#include "farchive.h" +#include "serializer.h" //========================================================================== // @@ -66,7 +66,8 @@ public: void UpdateInterpolation(); void Restore(); void Interpolate(double smoothratio); - void Serialize(FArchive &arc); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); size_t PointerSubstitution (DObject *old, DObject *notOld); size_t PropagateMark(); }; @@ -94,7 +95,8 @@ public: void UpdateInterpolation(); void Restore(); void Interpolate(double smoothratio); - void Serialize(FArchive &arc); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); }; @@ -121,7 +123,8 @@ public: void UpdateInterpolation(); void Restore(); void Interpolate(double smoothratio); - void Serialize(FArchive &arc); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); }; //========================================================================== @@ -147,7 +150,8 @@ public: void UpdateInterpolation(); void Restore(); void Interpolate(double smoothratio); - void Serialize(FArchive &arc); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); }; @@ -370,11 +374,11 @@ void DInterpolation::Destroy() // //========================================================================== -void DInterpolation::Serialize(FArchive &arc) +void DInterpolation::Serialize(FSerializer &arc) { Super::Serialize(arc); - arc << refcount; - if (arc.IsLoading()) + arc("refcount", refcount); + if (arc.isReading()) { interpolator.AddInterpolation(this); } @@ -516,10 +520,14 @@ void DSectorPlaneInterpolation::Interpolate(double smoothratio) // //========================================================================== -void DSectorPlaneInterpolation::Serialize(FArchive &arc) +void DSectorPlaneInterpolation::Serialize(FSerializer &arc) { Super::Serialize(arc); - arc << sector << ceiling << oldheight << oldtexz << attached; + arc("sector", sector) + ("ceiling", ceiling) + ("oldheight", oldheight) + ("oldtexz", oldtexz) + ("attached", attached); } //========================================================================== @@ -648,10 +656,13 @@ void DSectorScrollInterpolation::Interpolate(double smoothratio) // //========================================================================== -void DSectorScrollInterpolation::Serialize(FArchive &arc) +void DSectorScrollInterpolation::Serialize(FSerializer &arc) { Super::Serialize(arc); - arc << sector << ceiling << oldx << oldy; + arc("sector", sector) + ("ceiling", ceiling) + ("oldx", oldx) + ("oldy", oldy); } @@ -739,10 +750,13 @@ void DWallScrollInterpolation::Interpolate(double smoothratio) // //========================================================================== -void DWallScrollInterpolation::Serialize(FArchive &arc) +void DWallScrollInterpolation::Serialize(FSerializer &arc) { Super::Serialize(arc); - arc << side << part << oldx << oldy; + arc("side", side) + ("part", part) + ("oldx", oldx) + ("oldy", oldy); } //========================================================================== @@ -855,15 +869,14 @@ void DPolyobjInterpolation::Interpolate(double smoothratio) // //========================================================================== -void DPolyobjInterpolation::Serialize(FArchive &arc) +void DPolyobjInterpolation::Serialize(FSerializer &arc) { Super::Serialize(arc); - int po = int(poly - polyobjs); - arc << po << oldverts; - poly = polyobjs + po; - - arc << oldcx << oldcy; - if (arc.IsLoading()) bakverts.Resize(oldverts.Size()); + arc("poly", poly) + ("oldverts", oldverts) + ("oldcx", oldcx) + ("oldcy", oldcy); + if (arc.isReading()) bakverts.Resize(oldverts.Size()); } diff --git a/src/r_data/r_interpolate.h b/src/r_data/r_interpolate.h index e49500e571..8fc98c44ca 100644 --- a/src/r_data/r_interpolate.h +++ b/src/r_data/r_interpolate.h @@ -31,7 +31,8 @@ public: virtual void UpdateInterpolation() = 0; virtual void Restore() = 0; virtual void Interpolate(double smoothratio) = 0; - virtual void Serialize(FArchive &arc); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); }; //========================================================================== diff --git a/src/serializer.cpp b/src/serializer.cpp index fe4a76ba5c..d675a3cf9f 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -3,7 +3,9 @@ #define RAPIDJSON_HAS_CXX11_RANGE_FOR 1 #define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag -//#define PRETTY +#ifdef _DEBUG +#define PRETTY +#endif #include "rapidjson/rapidjson.h" #include "rapidjson/writer.h" @@ -26,6 +28,7 @@ #include "d_player.h" #include "r_data/r_interpolate.h" #include "g_shared/a_sharedglobal.h" +#include "po_man.h" char nulspace[1024 * 1024 * 4]; @@ -802,6 +805,11 @@ FSerializer &SerializePointer(FSerializer &arc, const char *key, T *&value, T ** return arc; } +FSerializer &Serialize(FSerializer &arc, const char *key, FPolyObj *&value, FPolyObj **defval) +{ + return SerializePointer(arc, key, value, defval, polyobjs); +} + FSerializer &Serialize(FSerializer &arc, const char *key, side_t *&value, side_t **defval) { return SerializePointer(arc, key, value, defval, sides); diff --git a/src/serializer.h b/src/serializer.h index b85405a1fa..5a87c63fce 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -26,6 +26,10 @@ public: public: + ~FSerializer() + { + Close(); + } bool OpenWriter(); bool OpenReader(const char *buffer, size_t length); void Close(); @@ -114,6 +118,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, uint16_t &value, uint1 FSerializer &Serialize(FSerializer &arc, const char *key, double &value, double *defval); FSerializer &Serialize(FSerializer &arc, const char *key, float &value, float *defval); FSerializer &Serialize(FSerializer &arc, const char *key, side_t *&value, side_t **defval); +FSerializer &Serialize(FSerializer &arc, const char *key, FPolyObj *&value, FPolyObj **defval); FSerializer &Serialize(FSerializer &arc, const char *key, sector_t *&value, sector_t **defval); FSerializer &Serialize(FSerializer &arc, const char *key, player_t *&value, player_t **defval); FSerializer &Serialize(FSerializer &arc, const char *key, line_t *&value, line_t **defval); diff --git a/src/zzz_old.cpp b/src/zzz_old.cpp index 952afcdb8b..37486164fc 100644 --- a/src/zzz_old.cpp +++ b/src/zzz_old.cpp @@ -2,6 +2,7 @@ #include "a_doomglobal.h" #include "ravenshared.h" +#include "a_weaponpiece.h" // For NULL states, which aren't owned by any actor, the owner // is recorded as AActor with the following state. AActor should @@ -874,6 +875,168 @@ void APuzzleItem::Serialize(FArchive &arc) arc << PuzzleItemNumber; } +class DSectorPlaneInterpolation : public DInterpolation +{ + DECLARE_CLASS(DSectorPlaneInterpolation, DInterpolation) + + sector_t *sector; + double oldheight, oldtexz; + double bakheight, baktexz; + bool ceiling; + TArray attached; + + +public: + + DSectorPlaneInterpolation() {} + DSectorPlaneInterpolation(sector_t *sector, bool plane, bool attach); + void Destroy(); + void UpdateInterpolation(); + void Restore(); + void Interpolate(double smoothratio); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); + size_t PointerSubstitution(DObject *old, DObject *notOld); + size_t PropagateMark(); +}; + +//========================================================================== +// +// +// +//========================================================================== + +class DSectorScrollInterpolation : public DInterpolation +{ + DECLARE_CLASS(DSectorScrollInterpolation, DInterpolation) + + sector_t *sector; + double oldx, oldy; + double bakx, baky; + bool ceiling; + +public: + + DSectorScrollInterpolation() {} + DSectorScrollInterpolation(sector_t *sector, bool plane); + void Destroy(); + void UpdateInterpolation(); + void Restore(); + void Interpolate(double smoothratio); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); +}; + + +//========================================================================== +// +// +// +//========================================================================== + +class DWallScrollInterpolation : public DInterpolation +{ + DECLARE_CLASS(DWallScrollInterpolation, DInterpolation) + + side_t *side; + int part; + double oldx, oldy; + double bakx, baky; + +public: + + DWallScrollInterpolation() {} + DWallScrollInterpolation(side_t *side, int part); + void Destroy(); + void UpdateInterpolation(); + void Restore(); + void Interpolate(double smoothratio); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); +}; + +//========================================================================== +// +// +// +//========================================================================== + +class DPolyobjInterpolation : public DInterpolation +{ + DECLARE_CLASS(DPolyobjInterpolation, DInterpolation) + + FPolyObj *poly; + TArray oldverts, bakverts; + double oldcx, oldcy; + double bakcx, bakcy; + +public: + + DPolyobjInterpolation() {} + DPolyobjInterpolation(FPolyObj *poly); + void Destroy(); + void UpdateInterpolation(); + void Restore(); + void Interpolate(double smoothratio); + DECLARE_OLD_SERIAL + virtual void Serialize(FSerializer &arc); +}; + +void DInterpolation::Serialize(FArchive &arc) +{ + Super::Serialize(arc); + arc << refcount; + if (arc.IsLoading()) + { + interpolator.AddInterpolation(this); + } +} +//========================================================================== +// +// +// +//========================================================================== + +void DSectorPlaneInterpolation::Serialize(FArchive &arc) +{ + Super::Serialize(arc); + arc << sector << ceiling << oldheight << oldtexz << attached; +} + +void DSectorScrollInterpolation::Serialize(FArchive &arc) +{ + Super::Serialize(arc); + arc << sector << ceiling << oldx << oldy; +} +void DWallScrollInterpolation::Serialize(FArchive &arc) +{ + Super::Serialize(arc); + arc << side << part << oldx << oldy; +} + +void DPolyobjInterpolation::Serialize(FArchive &arc) +{ + Super::Serialize(arc); + int po = int(poly - polyobjs); + arc << po << oldverts; + poly = polyobjs + po; + + arc << oldcx << oldcy; + if (arc.IsLoading()) bakverts.Resize(oldverts.Size()); +} + +void AWeaponHolder::Serialize(FArchive &arc) +{ + Super::Serialize(arc); + arc << PieceMask << PieceWeapon; +} + +void AWeaponPiece::Serialize(FArchive &arc) +{ + Super::Serialize(arc); + arc << WeaponClass << FullWeapon << PieceValue; +} + #endif \ No newline at end of file