mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
Standardize MC subsystem initialization boilerplate
* Based on https://github.com/tgstation/tgstation/pull/25386 * Create macro for defining new subsystem types. * Create PreInit proc to handle setup that needs to be done before the map loads * Rename garbage_controller subsystem to garbage so it matches its global SSgarbage variable name.
This commit is contained in:
@@ -51,3 +51,11 @@
|
|||||||
#define SS_PAUSED 3 //paused by mc_tick_check
|
#define SS_PAUSED 3 //paused by mc_tick_check
|
||||||
#define SS_SLEEPING 4 //fire() slept.
|
#define SS_SLEEPING 4 //fire() slept.
|
||||||
#define SS_PAUSING 5 //in the middle of pausing
|
#define SS_PAUSING 5 //in the middle of pausing
|
||||||
|
|
||||||
|
// Standard way to define a global subsystem, keep boilerplate organized here!
|
||||||
|
#define SUBSYSTEM_DEF(X) var/datum/controller/subsystem/##X/SS##X;\
|
||||||
|
/datum/controller/subsystem/##X/New(){\
|
||||||
|
NEW_SS_GLOBAL(SS##X);\
|
||||||
|
PreInit();\
|
||||||
|
}\
|
||||||
|
/datum/controller/subsystem/##X
|
||||||
|
|||||||
@@ -27,8 +27,15 @@
|
|||||||
var/datum/controller/subsystem/queue_next
|
var/datum/controller/subsystem/queue_next
|
||||||
var/datum/controller/subsystem/queue_prev
|
var/datum/controller/subsystem/queue_prev
|
||||||
|
|
||||||
// Used to initialize the subsystem BEFORE the map has loaded
|
//Do not override
|
||||||
/datum/controller/subsystem/New()
|
/datum/controller/subsystem/New()
|
||||||
|
return
|
||||||
|
|
||||||
|
// Used to initialize the subsystem BEFORE the map has loaded
|
||||||
|
// Called AFTER Recover if that is called
|
||||||
|
// Prefer to use Initialize if possible
|
||||||
|
/datum/controller/subsystem/proc/PreInit()
|
||||||
|
return
|
||||||
|
|
||||||
//This is used so the mc knows when the subsystem sleeps. do not override.
|
//This is used so the mc knows when the subsystem sleeps. do not override.
|
||||||
/datum/controller/subsystem/proc/ignite(resumed = 0)
|
/datum/controller/subsystem/proc/ignite(resumed = 0)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
var/datum/controller/subsystem/garbage_collector/SSgarbage
|
//
|
||||||
|
// Garbage Collector Subsystem - Implements qdel() and the GC queue
|
||||||
/datum/controller/subsystem/garbage_collector
|
//
|
||||||
|
SUBSYSTEM_DEF(garbage)
|
||||||
name = "Garbage"
|
name = "Garbage"
|
||||||
priority = 15
|
priority = 15
|
||||||
wait = 5
|
wait = 5
|
||||||
@@ -34,10 +35,7 @@ var/datum/controller/subsystem/garbage_collector/SSgarbage
|
|||||||
var/list/qdel_list = list() // list of all types that have been qdel()eted
|
var/list/qdel_list = list() // list of all types that have been qdel()eted
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/New()
|
/datum/controller/subsystem/garbage/stat_entry(msg)
|
||||||
NEW_SS_GLOBAL(SSgarbage)
|
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/stat_entry(msg)
|
|
||||||
msg += "Q:[queue.len]|D:[delslasttick]|G:[gcedlasttick]|"
|
msg += "Q:[queue.len]|D:[delslasttick]|G:[gcedlasttick]|"
|
||||||
msg += "GR:"
|
msg += "GR:"
|
||||||
if (!(delslasttick+gcedlasttick))
|
if (!(delslasttick+gcedlasttick))
|
||||||
@@ -52,14 +50,14 @@ var/datum/controller/subsystem/garbage_collector/SSgarbage
|
|||||||
msg += "TGR:[round((totalgcs/(totaldels+totalgcs))*100, 0.01)]%"
|
msg += "TGR:[round((totalgcs/(totaldels+totalgcs))*100, 0.01)]%"
|
||||||
..(msg)
|
..(msg)
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/fire()
|
/datum/controller/subsystem/garbage/fire()
|
||||||
HandleToBeQueued()
|
HandleToBeQueued()
|
||||||
if(state == SS_RUNNING)
|
if(state == SS_RUNNING)
|
||||||
HandleQueue()
|
HandleQueue()
|
||||||
|
|
||||||
//If you see this proc high on the profile, what you are really seeing is the garbage collection/soft delete overhead in byond.
|
//If you see this proc high on the profile, what you are really seeing is the garbage collection/soft delete overhead in byond.
|
||||||
//Don't attempt to optimize, not worth the effort.
|
//Don't attempt to optimize, not worth the effort.
|
||||||
/datum/controller/subsystem/garbage_collector/proc/HandleToBeQueued()
|
/datum/controller/subsystem/garbage/proc/HandleToBeQueued()
|
||||||
var/list/tobequeued = src.tobequeued
|
var/list/tobequeued = src.tobequeued
|
||||||
var/starttime = world.time
|
var/starttime = world.time
|
||||||
var/starttimeofday = world.timeofday
|
var/starttimeofday = world.timeofday
|
||||||
@@ -70,7 +68,7 @@ var/datum/controller/subsystem/garbage_collector/SSgarbage
|
|||||||
Queue(ref)
|
Queue(ref)
|
||||||
tobequeued.Cut(1, 2)
|
tobequeued.Cut(1, 2)
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/proc/HandleQueue()
|
/datum/controller/subsystem/garbage/proc/HandleQueue()
|
||||||
delslasttick = 0
|
delslasttick = 0
|
||||||
gcedlasttick = 0
|
gcedlasttick = 0
|
||||||
var/time_to_kill = world.time - collection_timeout // Anything qdel() but not GC'd BEFORE this time needs to be manually del()
|
var/time_to_kill = world.time - collection_timeout // Anything qdel() but not GC'd BEFORE this time needs to be manually del()
|
||||||
@@ -124,12 +122,12 @@ var/datum/controller/subsystem/garbage_collector/SSgarbage
|
|||||||
++gcedlasttick
|
++gcedlasttick
|
||||||
++totalgcs
|
++totalgcs
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/proc/QueueForQueuing(datum/A)
|
/datum/controller/subsystem/garbage/proc/QueueForQueuing(datum/A)
|
||||||
if (istype(A) && A.gc_destroyed == GC_CURRENTLY_BEING_QDELETED)
|
if (istype(A) && A.gc_destroyed == GC_CURRENTLY_BEING_QDELETED)
|
||||||
tobequeued += A
|
tobequeued += A
|
||||||
A.gc_destroyed = GC_QUEUED_FOR_QUEUING
|
A.gc_destroyed = GC_QUEUED_FOR_QUEUING
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/proc/Queue(datum/A)
|
/datum/controller/subsystem/garbage/proc/Queue(datum/A)
|
||||||
if (!istype(A) || (!isnull(A.gc_destroyed) && A.gc_destroyed >= 0))
|
if (!istype(A) || (!isnull(A.gc_destroyed) && A.gc_destroyed >= 0))
|
||||||
return
|
return
|
||||||
if (A.gc_destroyed == GC_QUEUED_FOR_HARD_DEL)
|
if (A.gc_destroyed == GC_QUEUED_FOR_HARD_DEL)
|
||||||
@@ -145,12 +143,12 @@ var/datum/controller/subsystem/garbage_collector/SSgarbage
|
|||||||
|
|
||||||
queue[refid] = gctime
|
queue[refid] = gctime
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/proc/HardQueue(datum/A)
|
/datum/controller/subsystem/garbage/proc/HardQueue(datum/A)
|
||||||
if (istype(A) && A.gc_destroyed == GC_CURRENTLY_BEING_QDELETED)
|
if (istype(A) && A.gc_destroyed == GC_CURRENTLY_BEING_QDELETED)
|
||||||
tobequeued += A
|
tobequeued += A
|
||||||
A.gc_destroyed = GC_QUEUED_FOR_HARD_DEL
|
A.gc_destroyed = GC_QUEUED_FOR_HARD_DEL
|
||||||
|
|
||||||
/datum/controller/subsystem/garbage_collector/Recover()
|
/datum/controller/subsystem/garbage/Recover()
|
||||||
if (istype(SSgarbage.queue))
|
if (istype(SSgarbage.queue))
|
||||||
queue |= SSgarbage.queue
|
queue |= SSgarbage.queue
|
||||||
if (istype(SSgarbage.tobequeued))
|
if (istype(SSgarbage.tobequeued))
|
||||||
|
|||||||
Reference in New Issue
Block a user