- GC setup for Duke.

This commit is contained in:
Christoph Oelckers 2021-12-05 14:00:22 +01:00
parent 5d09748af9
commit fa62b20d76
6 changed files with 50 additions and 14 deletions

View file

@ -158,6 +158,10 @@ namespace GC
{
MarkArray((DObject **)(obj), count);
}
template<class T> void MarkArray(TObjPtr<T>* obj, size_t count)
{
MarkArray((DObject**)(obj), count);
}
template<class T> void MarkArray(TArray<T> &arr)
{
MarkArray(&arr[0], arr.Size());

View file

@ -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;

View file

@ -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

View file

@ -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<DDukeActor*> camsprite;
inline TObjPtr<DDukeActor*> BellSprite;
inline TObjPtr<DDukeActor*> spriteq[1024];
inline TObjPtr<DDukeActor*> 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<CraneDef> 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];

View file

@ -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()
{

View file

@ -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<DDukeActor*> 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<DDukeActor*> temp_actor, seek_actor;
spritetype* s; // direct reference to the corresponding sprite.
TArray<GameVarValue> uservars;
@ -163,7 +163,7 @@ struct user_defs
int m_ffire, ffire, m_player_skill, multimode;
int player_skill, marker;
DDukeActor* cameraactor;
TObjPtr<DDukeActor*> cameraactor;
};
@ -178,7 +178,7 @@ struct CraneDef
{
int x, y, z;
int polex, poley;
DDukeActor* poleactor;
TObjPtr<DDukeActor*> 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<DDukeActor*> actor;
TObjPtr<DDukeActor*> 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;