mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-01 08:31:45 +00:00
- moved most of the root marking out of the garbage collector, replacing it with callbacks.
Yet another place where low level code was tied too tightly to the game instead of providing a proper interface.
This commit is contained in:
parent
933c1f6403
commit
74c5f83658
6 changed files with 39 additions and 32 deletions
|
@ -58,21 +58,9 @@
|
|||
|
||||
#include "dobject.h"
|
||||
#include "templates.h"
|
||||
#include "b_bot.h"
|
||||
#include "p_local.h"
|
||||
#include "g_game.h"
|
||||
#include "a_sharedglobal.h"
|
||||
#include "sbar.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "s_sndseq.h"
|
||||
#include "r_data/r_interpolate.h"
|
||||
#include "doomstat.h"
|
||||
#include "po_man.h"
|
||||
#include "r_utility.h"
|
||||
#include "menu/menu.h"
|
||||
#include "intermission/intermission.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "events.h"
|
||||
#include "stats.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
@ -112,8 +100,6 @@
|
|||
|
||||
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
||||
|
||||
extern DThinker *NextToThink;
|
||||
|
||||
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
||||
|
||||
namespace GC
|
||||
|
@ -274,26 +260,19 @@ void MarkArray(DObject **obj, size_t count)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
TArray<GCMarkerFunc> markers;
|
||||
void AddMarkerFunc(GCMarkerFunc func)
|
||||
{
|
||||
if (markers.Find(func) == markers.Size())
|
||||
markers.Push(func);
|
||||
}
|
||||
|
||||
static void MarkRoot()
|
||||
{
|
||||
Gray = NULL;
|
||||
Mark(StatusBar);
|
||||
M_MarkMenus();
|
||||
Mark(DIntermissionController::CurrentIntermission);
|
||||
Mark(staticEventManager.FirstEventHandler);
|
||||
Mark(staticEventManager.LastEventHandler);
|
||||
for (auto Level : AllLevels())
|
||||
Level->Mark();
|
||||
|
||||
// Mark players.
|
||||
for (int i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i])
|
||||
players[i].PropagateMark();
|
||||
}
|
||||
for (auto func : markers) func();
|
||||
|
||||
// NextToThink must not be freed while thinkers are ticking.
|
||||
Mark(NextToThink);
|
||||
// Mark soft roots.
|
||||
if (SoftRoots != NULL)
|
||||
{
|
||||
|
|
|
@ -154,6 +154,10 @@ namespace GC
|
|||
{
|
||||
MarkArray(&arr[0], arr.Size());
|
||||
}
|
||||
|
||||
using GCMarkerFunc = void(*)();
|
||||
void AddMarkerFunc(GCMarkerFunc func);
|
||||
|
||||
}
|
||||
|
||||
// A template class to help with handling read barriers. It does not
|
||||
|
|
|
@ -1115,7 +1115,7 @@ void PSpriteID::WriteValue(FSerializer &ar, const char *key, const void *addr) c
|
|||
|
||||
bool PSpriteID::ReadValue(FSerializer &ar, const char *key, void *addr) const
|
||||
{
|
||||
int32_t val;
|
||||
int32_t val = 0;
|
||||
#ifdef GZDOOM
|
||||
ar.Sprite(key, val, nullptr);
|
||||
#endif
|
||||
|
|
|
@ -2748,6 +2748,27 @@ static void Doom_CastSpriteIDToString(FString* a, unsigned int b)
|
|||
*a = (b >= sprites.Size()) ? "TNT1" : sprites[b].name;
|
||||
}
|
||||
|
||||
|
||||
extern DThinker* NextToThink;
|
||||
|
||||
static void GC_MarkGameRoots()
|
||||
{
|
||||
GC::Mark(DIntermissionController::CurrentIntermission);
|
||||
GC::Mark(staticEventManager.FirstEventHandler);
|
||||
GC::Mark(staticEventManager.LastEventHandler);
|
||||
for (auto Level : AllLevels())
|
||||
Level->Mark();
|
||||
|
||||
// Mark players.
|
||||
for (int i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i])
|
||||
players[i].PropagateMark();
|
||||
}
|
||||
|
||||
// NextToThink must not be freed while thinkers are ticking.
|
||||
GC::Mark(NextToThink);
|
||||
}
|
||||
//==========================================================================
|
||||
//
|
||||
// D_DoomMain
|
||||
|
@ -2764,6 +2785,7 @@ static int D_DoomMain_Internal (void)
|
|||
int argcount;
|
||||
FIWadManager *iwad_man;
|
||||
|
||||
GC::AddMarkerFunc(GC_MarkGameRoots);
|
||||
VM_CastSpriteIDToString = Doom_CastSpriteIDToString;
|
||||
|
||||
// Set up the button list. Mlook and Klook need a bit of extra treatment.
|
||||
|
|
|
@ -259,6 +259,7 @@ void ST_CreateStatusBar(bool bTitleLevel)
|
|||
StatusBar->Destroy();
|
||||
StatusBar = NULL;
|
||||
}
|
||||
GC::AddMarkerFunc([]() { GC::Mark(StatusBar); });
|
||||
|
||||
bool shouldWarn = true;
|
||||
|
||||
|
|
|
@ -952,6 +952,7 @@ void M_Init (void)
|
|||
try
|
||||
{
|
||||
M_ParseMenuDefs();
|
||||
GC::AddMarkerFunc(M_MarkMenus);
|
||||
}
|
||||
catch (CVMAbortException &err)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue