From 8d57281101e52b4b1b768115a597867e96d114da Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 May 2023 10:55:50 +0200 Subject: [PATCH] - turn the SO's Animator and PostMoveAnimator into non-functions as well. What little is here can be done just as easily by more traditional means which are easier to serialize. --- source/games/sw/src/game.h | 11 +++++-- source/games/sw/src/morph.cpp | 17 ----------- source/games/sw/src/save.cpp | 5 +--- source/games/sw/src/saveable.cpp | 2 -- source/games/sw/src/sector.cpp | 16 +++++++---- source/games/sw/src/track.cpp | 49 +++++++++++--------------------- source/games/sw/src/weapon.cpp | 2 +- 7 files changed, 38 insertions(+), 64 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index c6e7a2900..370d27441 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1209,11 +1209,18 @@ enum extern TRACK Track[MAX_TRACKS]; +enum +{ + SOType_None = 0, + SOType_Floor = 1, + SOType_Tornado = 2, + SOType_AutoTurret = 3 +}; + struct SECTOR_OBJECT { bool PreMoveScale; - soANIMATORp PostMoveAnimator; - soANIMATORp Animator; + uint8_t AnimType; TObjPtr controller; TObjPtr sp_child; // child sprite that holds info for the sector object diff --git a/source/games/sw/src/morph.cpp b/source/games/sw/src/morph.cpp index add574c6e..2ca9863c7 100644 --- a/source/games/sw/src/morph.cpp +++ b/source/games/sw/src/morph.cpp @@ -533,21 +533,4 @@ void SpikeFloor(SECTOR_OBJECT* sop) // //--------------------------------------------------------------------------- -#include "saveable.h" - -static saveable_code saveable_morph_code[] = -{ - SAVE_CODE(MorphTornado), - SAVE_CODE(MorphFloor), -}; - -saveable_module saveable_morph = -{ - // code - saveable_morph_code, - SIZ(saveable_morph_code), - - // data - nullptr,0 -}; END_SW_NS diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 44d93ee5b..2a2e0b94d 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -693,10 +693,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, SECTOR_OBJECT& w, ("limit_ang_center", w.limit_ang_center, def->limit_ang_center) ("limit_ang_delta", w.limit_ang_delta, def->limit_ang_delta) ("premovescale", w.PreMoveScale, def->PreMoveScale); - - - SerializeCodePtr(arc, "postanimator", (void**)&w.PostMoveAnimator); - SerializeCodePtr(arc, "animator", (void**)&w.Animator); + ("animtype", w.AnimType, def->AnimType); arc.EndObject(); } diff --git a/source/games/sw/src/saveable.cpp b/source/games/sw/src/saveable.cpp index 5816ee1bf..43676ea58 100644 --- a/source/games/sw/src/saveable.cpp +++ b/source/games/sw/src/saveable.cpp @@ -50,7 +50,6 @@ void Saveable_Init(void) MODULE(jweapon) MODULE(lava) MODULE(miscactr) - MODULE(morph) MODULE(ninja) MODULE(panel) MODULE(player) @@ -61,7 +60,6 @@ void Saveable_Init(void) MODULE(skull) MODULE(sprite) MODULE(sumo) - MODULE(track) MODULE(weapon) MODULE(zilla) MODULE(zombie) diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 6230d7bbf..8cdfdde94 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -74,6 +74,9 @@ void DoRotatorMatch(PLAYER* pp, short match, bool); void DoSlidorOperate(PLAYER*, sectortype*); void DoSlidorMatch(PLAYER* pp, short match, bool); +void DoTornadoObject(SECTOR_OBJECT* sop); +void DoAutoTurretObject(SECTOR_OBJECT* sop); + void KillMatchingCrackSprites(short match); int DoTrapReset(short match); int DoTrapMatch(short match); @@ -392,8 +395,7 @@ void SectorSetup(void) memset(&SectorObject[ndx].so_actors, 0, sizeof(SectorObject[0].so_actors)); SectorObject[ndx].match_event_actor = nullptr; SectorObject[ndx].PreMoveScale = false; - SectorObject[ndx].PostMoveAnimator = nullptr; - SectorObject[ndx].Animator = nullptr; + SectorObject[ndx].AnimType = SOType_None; SectorObject[ndx].controller = nullptr; SectorObject[ndx].sp_child = nullptr; SectorObject[ndx].mid_sector = nullptr; @@ -2933,10 +2935,14 @@ void DoSector(void) } } - if (sop->Animator) + switch (sop->AnimType) { - (*sop->Animator)(sop); - continue; + case SOType_AutoTurret: + DoAutoTurretObject(sop); + break; + case SOType_Tornado: + DoTornadoObject(sop); + break; } // force sync SOs to be updated regularly diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index ae09b5d3a..431574bed 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -42,8 +42,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS DVector2 DoTrack(SECTOR_OBJECT* sop, short locktics); -void DoAutoTurretObject(SECTOR_OBJECT* sop); -void DoTornadoObject(SECTOR_OBJECT* sop); int PickJumpSpeed(DSWActor*, int pix_height); DSWActor* FindNearSprite(DSWActor, short); @@ -929,11 +927,6 @@ void SetupSectorObject(sectortype* sectp, short tag) // initialize stuff first time through if (sop->num_sectors == -1) { - void DoTornadoObject(SECTOR_OBJECT* sop); - void MorphTornado(SECTOR_OBJECT* sop); - void MorphFloor(SECTOR_OBJECT* sop); - void DoAutoTurretObject(SECTOR_OBJECT* sop); - memset(sop->sectp, 0, sizeof(sop->sectp)); memset(sop->so_actors, 0, sizeof(sop->so_actors)); sop->morph_wall_point = nullptr; @@ -987,8 +980,7 @@ void SetupSectorObject(sectortype* sectp, short tag) sop->morph_off = { 0,0 }; sop->PreMoveScale = false; - sop->PostMoveAnimator = nullptr; - sop->Animator = nullptr; + sop->AnimType = SOType_None; } switch (tag % 5) @@ -1074,7 +1066,7 @@ void SetupSectorObject(sectortype* sectp, short tag) break; case SO_AUTO_TURRET: - sop->Animator = DoAutoTurretObject; + sop->AnimType = SOType_AutoTurret; KillActor(actor); break; @@ -1087,9 +1079,8 @@ void SetupSectorObject(sectortype* sectp, short tag) sop->spin_speed = DAngle22_5 * (1. / 16); sop->last_ang = sop->ang; // animators - sop->Animator = DoTornadoObject; sop->PreMoveScale = true; - sop->PostMoveAnimator = MorphTornado; + sop->AnimType = SOType_Tornado; // clip sop->clipdist = 156.25; // morph point @@ -1106,7 +1097,7 @@ void SetupSectorObject(sectortype* sectp, short tag) sop->scale_type = SO_SCALE_NONE; sop->morph_speed = 7.5; sop->morph_z_speed = 7; - sop->PostMoveAnimator = MorphFloor; + sop->AnimType = SOType_Floor; sop->morph_dist_max = 250; sop->morph_rand_freq = 8; KillActor(actor); @@ -1841,8 +1832,18 @@ void RefreshPoints(SECTOR_OBJECT* sop, const DVector2& move, bool dynamic) MovePoints(sop, delta_ang_from_orig, move); // do morphing - angle independent - if (dynamic && sop->PostMoveAnimator) - (*sop->PostMoveAnimator)(sop); + if (dynamic) + { + switch (sop->AnimType) + { + case SOType_Floor: + MorphFloor(sop); + break; + case SOType_Tornado: + MorphTornado(sop); + break; + } + } } void KillSectorObjectSprites(SECTOR_OBJECT* sop) @@ -3465,22 +3466,4 @@ int ActorFollowTrack(DSWActor* actor, short locktics) } -#include "saveable.h" - -static saveable_code saveable_track_code[] = -{ - SAVE_CODE(DoTornadoObject), - SAVE_CODE(DoAutoTurretObject), -}; - -saveable_module saveable_track = -{ - // code - saveable_track_code, - SIZ(saveable_track_code), - - // data - nullptr,0 -}; - END_SW_NS diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 6ba664f59..8de589e0f 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -16107,7 +16107,7 @@ int InitTurretMgun(SECTOR_OBJECT* sop) double daz = npos.Z; // if its not operated by a player - if (sop->Animator) + if (sop->AnimType == SOType_AutoTurret) { // only auto aim for Z daang = DAngle90;