diff --git a/source/common/objects/dobjgc.h b/source/common/objects/dobjgc.h index d01e52cf6..bd33a896c 100644 --- a/source/common/objects/dobjgc.h +++ b/source/common/objects/dobjgc.h @@ -158,6 +158,10 @@ namespace GC { MarkArray((DObject **)(obj), count); } + template void MarkArray(TObjPtr* obj, size_t count) + { + MarkArray((DObject**)(obj), count); + } template void MarkArray(TArray &arr) { MarkArray(&arr[0], arr.Size()); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 8e255facc..7472281c4 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -47,6 +47,12 @@ void SetDispatcher(); void InitCheats(); int registerosdcommands(void); +//--------------------------------------------------------------------------- +// +// DObject stuff - everything GC related. +// +//--------------------------------------------------------------------------- + IMPLEMENT_CLASS(DDukeActor, false, true) IMPLEMENT_POINTERS_START(DDukeActor) IMPLEMENT_POINTER(ownerActor) @@ -64,6 +70,32 @@ size_t DDukeActor::PropagateMark() return uservars.Size() + Super::PropagateMark(); } +static void markgcroots() +{ + GC::Mark(camsprite); + GC::Mark(BellSprite); + GC::MarkArray(spriteq, countof(spriteq)); + GC::Mark(currentCommentarySprite); + GC::Mark(ud.cameraactor); + for (auto& crn : cranes) GC::Mark(crn.poleactor); + for (auto& pl : ps) + { + GC::Mark(pl.actor); + GC::Mark(pl.actorsqu); + GC::Mark(pl.wackedbyactor); + GC::Mark(pl.on_crane); + GC::Mark(pl.holoduke_on); + GC::Mark(pl.somethingonplayer); + GC::Mark(pl.access_spritenum); + GC::Mark(pl.dummyplayersprite); + GC::Mark(pl.newOwner); + for (auto& var : pl.uservars) + { + var.Mark(); + } + } +} + //--------------------------------------------------------------------------- // // game specific command line args go here. @@ -303,6 +335,7 @@ int GameInterface::GetCurrentSkill() void GameInterface::app_init() { SetupActors(RUNTIME_CLASS(DDukeActor)); + GC::AddMarkerFunc(markgcroots); if (isRR()) C_SetNotifyFontScale(0.5); ud.god = 0; diff --git a/source/games/duke/src/global.cpp b/source/games/duke/src/global.cpp index d1614accc..1a642b358 100644 --- a/source/games/duke/src/global.cpp +++ b/source/games/duke/src/global.cpp @@ -56,7 +56,6 @@ player_struct ps[MAXPLAYERS]; //------------------------------------------------------------------------- int lastvisinc; // weapon flash -DDukeActor* camsprite; // active camera int earthquaketime; int global_random; // readonly - one single global per-frame random value. Ugh... @@ -69,7 +68,6 @@ int hulkspawn; // Spawn a hulk? int lastlevel; // Set at the end of RRRA's E2L7. short fakebubba_spawn, mamaspawn_count, banjosound; // RRRA special effects short BellTime; -DDukeActor* BellSprite /* word_119BE0*/; int WindTime, WindDir; uint8_t enemysizecheat /*raat607*/, ufospawnsminion, pistonsound, chickenphase /* raat605*/, RRRA_ExitedLevel, fogactive; @@ -93,7 +91,6 @@ bool sound445done; // used in checksectors_r. This was local state inside int spriteqamount = 64; // internal sprite queue int spriteqloc; -DDukeActor* spriteq[1024]; animwalltype animwall[MAXANIMWALLS]; // animated walls int numanimwalls; int animatecnt; // sector plane movement diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index 1d78eb3ed..c2b005c94 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -7,6 +7,7 @@ #include "constants.h" #include "types.h" #include "d_net.h" +#include "serialize_obj.h" BEGIN_DUKE_NS @@ -44,6 +45,12 @@ struct DukeGameInfo extern DukeGameInfo gs; +inline TObjPtr camsprite; +inline TObjPtr BellSprite; +inline TObjPtr spriteq[1024]; +inline TObjPtr currentCommentarySprite; + + extern int otherp; // transient helper, MP only extern int actor_tog; // cheat state extern intptr_t apScriptGameEvent[]; @@ -64,7 +71,6 @@ extern animwalltype animwall[MAXANIMWALLS]; extern int numanimwalls; extern int animatecnt; extern int numclouds; -extern DDukeActor* camsprite; extern int numcyclers; extern int earthquaketime; extern int global_random; @@ -91,7 +97,6 @@ extern float cloudx; extern float cloudy; extern int cloudclock; -extern DDukeActor *spriteq[1024]; extern Cycler cyclers[MAXCYCLERS]; extern sectortype* mirrorsector[64]; extern walltype* mirrorwall[64]; @@ -121,7 +126,6 @@ extern TArray cranes; extern int WindTime, WindDir; extern short fakebubba_spawn, mamaspawn_count, banjosound; extern short BellTime; -extern DDukeActor* BellSprite /* word_119BE0*/; extern uint8_t enemysizecheat /*raat607*/, ufospawnsminion, pistonsound, chickenphase /* raat605*/, RRRA_ExitedLevel, fogactive; extern uint32_t everyothertime; extern player_orig po[MAXPLAYERS]; diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index b1ec56fc5..2f63b5266 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -55,8 +55,6 @@ CVAR(Bool, wt_commentary, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) BEGIN_DUKE_NS static FSoundID currentCommentarySound; -static DDukeActor* currentCommentarySprite; // todo: GC this once actors become objects - void UnmuteSounds() { diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 42969eaef..385a84967 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -34,7 +34,7 @@ class DDukeActor : public DCoreActor public: uint8_t cgg; uint8_t spriteextra; // moved here for easier maintenance. This was originally a hacked in field in the sprite structure called 'filler'. - DDukeActor* ownerActor, * hitOwnerActor; + TObjPtr ownerActor, hitOwnerActor; short picnum, ang, extra, movflag; short tempang, dispicnum; short timetosleep; @@ -49,7 +49,7 @@ public: walltype* temp_walls[2]; // SE20 + SE128 sectortype* temp_sect, *actorstayput; - DDukeActor* temp_actor, *seek_actor; + TObjPtr temp_actor, seek_actor; spritetype* s; // direct reference to the corresponding sprite. TArray uservars; @@ -163,7 +163,7 @@ struct user_defs int m_ffire, ffire, m_player_skill, multimode; int player_skill, marker; - DDukeActor* cameraactor; + TObjPtr cameraactor; }; @@ -178,7 +178,7 @@ struct CraneDef { int x, y, z; int polex, poley; - DDukeActor* poleactor; + TObjPtr poleactor; }; struct player_struct @@ -227,7 +227,8 @@ struct player_struct sectortype* cursector; sectortype* one_parallax_sectnum; // wall + sector references. Make them pointers later? walltype* access_wall; - DDukeActor* actor; + TObjPtr actor; + TObjPtr actorsqu, wackedbyactor, on_crane, holoduke_on, somethingonplayer, access_spritenum, dummyplayersprite, newOwner; short last_extra, subweapon; short ammo_amount[MAX_WEAPONS], frag, fraggedself; @@ -241,7 +242,6 @@ struct player_struct short cheat_phase; short extra_extra8, quick_kick, last_quick_kick; short heat_amount, timebeforeexit, customexitsound; - DDukeActor* actorsqu, *wackedbyactor, *on_crane, *holoduke_on, *somethingonplayer, *access_spritenum, *dummyplayersprite, *newOwner; short weaprecs[256], weapreccnt; unsigned int interface_toggle_flag;