mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-13 11:43:31 +00:00
Partially ports the GLOB system
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
|
||||
/datum/controller/process/nanoui/statProcess()
|
||||
..()
|
||||
stat(null, "[nanomanager.processing_uis.len] UIs")
|
||||
stat(null, "[GLOB.nanomanager.processing_uis.len] UIs")
|
||||
|
||||
/datum/controller/process/nanoui/doWork()
|
||||
for(last_object in nanomanager.processing_uis)
|
||||
for(last_object in GLOB.nanomanager.processing_uis)
|
||||
var/datum/nanoui/NUI = last_object
|
||||
if(istype(NUI) && !QDELETED(NUI))
|
||||
try
|
||||
@@ -16,4 +16,4 @@
|
||||
catchException(e, NUI)
|
||||
else
|
||||
catchBadType(NUI)
|
||||
nanomanager.processing_uis -= NUI
|
||||
GLOB.nanomanager.processing_uis -= NUI
|
||||
59
code/controllers/globals.dm
Normal file
59
code/controllers/globals.dm
Normal file
@@ -0,0 +1,59 @@
|
||||
GLOBAL_REAL(GLOB, /datum/controller/global_vars)
|
||||
|
||||
/datum/controller/global_vars
|
||||
name = "Global Variables"
|
||||
|
||||
var/list/gvars_datum_protected_varlist
|
||||
var/list/gvars_datum_in_built_vars
|
||||
var/list/gvars_datum_init_order
|
||||
|
||||
/datum/controller/global_vars/New()
|
||||
if(GLOB)
|
||||
CRASH("Multiple instances of global variable controller created")
|
||||
GLOB = src
|
||||
|
||||
var/datum/controller/exclude_these = new
|
||||
gvars_datum_in_built_vars = exclude_these.vars + list("gvars_datum_protected_varlist", "gvars_datum_in_built_vars", "gvars_datum_init_order")
|
||||
|
||||
log_world("[vars.len - gvars_datum_in_built_vars.len] global variables")
|
||||
|
||||
Initialize(exclude_these)
|
||||
|
||||
/datum/controller/global_vars/Destroy(force)
|
||||
crash_with("There was an attempt to qdel the global vars holder!")
|
||||
if(!force)
|
||||
return QDEL_HINT_LETMELIVE
|
||||
|
||||
QDEL_NULL(statclick)
|
||||
gvars_datum_protected_varlist.Cut()
|
||||
gvars_datum_in_built_vars.Cut()
|
||||
|
||||
GLOB = null
|
||||
|
||||
return ..()
|
||||
|
||||
/datum/controller/global_vars/stat_entry()
|
||||
if(!statclick)
|
||||
statclick = new/obj/effect/statclick/debug(null, "Initializing...", src)
|
||||
|
||||
stat("Globals:", statclick.update("Edit"))
|
||||
|
||||
/datum/controller/global_vars/VV_hidden()
|
||||
return ..() + gvars_datum_protected_varlist
|
||||
|
||||
/datum/controller/global_vars/Initialize(var/exclude_these)
|
||||
gvars_datum_init_order = list()
|
||||
gvars_datum_protected_varlist = list("gvars_datum_protected_varlist")
|
||||
|
||||
//See https://github.com/tgstation/tgstation/issues/26954
|
||||
for(var/I in typesof(/datum/controller/global_vars/proc))
|
||||
var/CLEANBOT_RETURNS = "[I]"
|
||||
pass(CLEANBOT_RETURNS)
|
||||
|
||||
for(var/I in (vars - gvars_datum_in_built_vars))
|
||||
var/start_tick = world.time
|
||||
call(src, "InitGlobal[I]")()
|
||||
var/end_tick = world.time
|
||||
if(end_tick - start_tick)
|
||||
warning("Global [I] slept during initialization!")
|
||||
QDEL_NULL(exclude_these)
|
||||
@@ -6,7 +6,21 @@
|
||||
* Odds are, there is a reason
|
||||
*
|
||||
**/
|
||||
var/datum/controller/master/Master = new()
|
||||
|
||||
//This is the ABSOLUTE ONLY THING that should init globally like this
|
||||
GLOBAL_REAL(Master, /datum/controller/master) = new
|
||||
|
||||
//THIS IS THE INIT ORDER
|
||||
//Master -> SSPreInit -> GLOB -> world -> config -> SSInit -> Failsafe
|
||||
//GOT IT MEMORIZED?
|
||||
GLOBAL_VAR_INIT(MC_restart_clear, 0)
|
||||
GLOBAL_VAR_INIT(MC_restart_timeout, 0)
|
||||
GLOBAL_VAR_INIT(MC_restart_count, 0)
|
||||
|
||||
//current tick limit, assigned by the queue controller before running a subsystem.
|
||||
//used by check_tick as well so that the procs subsystems call can obey that SS's tick limits
|
||||
GLOBAL_VAR_INIT(CURRENT_TICKLIMIT, TICK_LIMIT_RUNNING)
|
||||
|
||||
|
||||
/datum/controller/master
|
||||
name = "Master"
|
||||
@@ -48,10 +62,6 @@ var/datum/controller/master/Master = new()
|
||||
var/static/restart_timeout = 0
|
||||
var/static/restart_count = 0
|
||||
|
||||
//current tick limit, assigned before running a subsystem.
|
||||
//used by CHECK_TICK as well so that the procs subsystems call can obey that SS's tick limits
|
||||
var/static/current_ticklimit = TICK_LIMIT_RUNNING
|
||||
|
||||
/datum/controller/master/New()
|
||||
// Highlander-style: there can only be one! Kill off the old and replace it with the new.
|
||||
var/list/_subsystems = list()
|
||||
@@ -67,6 +77,9 @@ var/datum/controller/master/Master = new()
|
||||
_subsystems += new I
|
||||
Master = src
|
||||
|
||||
if(!GLOB)
|
||||
new /datum/controller/global_vars
|
||||
|
||||
/datum/controller/master/Destroy()
|
||||
..()
|
||||
// Tell qdel() to Del() this object.
|
||||
@@ -85,14 +98,14 @@ var/datum/controller/master/Master = new()
|
||||
// -1 if we encountered a runtime trying to recreate it
|
||||
/proc/Recreate_MC()
|
||||
. = -1 //so if we runtime, things know we failed
|
||||
if (world.time < Master.restart_timeout)
|
||||
if (world.time < GLOB.MC_restart_timeout)
|
||||
return 0
|
||||
if (world.time < Master.restart_clear)
|
||||
Master.restart_count *= 0.5
|
||||
if (world.time < GLOB.MC_restart_clear)
|
||||
GLOB.MC_restart_count *= 0.5
|
||||
|
||||
var/delay = 50 * ++Master.restart_count
|
||||
Master.restart_timeout = world.time + delay
|
||||
Master.restart_clear = world.time + (delay * 2)
|
||||
var/delay = 50 * ++GLOB.MC_restart_count
|
||||
GLOB.MC_restart_timeout = world.time + delay
|
||||
GLOB.MC_restart_clear = world.time + (delay * 2)
|
||||
Master.processing = FALSE //stop ticking this one
|
||||
try
|
||||
new/datum/controller/master()
|
||||
@@ -136,6 +149,7 @@ var/datum/controller/master/Master = new()
|
||||
if (istype(Master.subsystems))
|
||||
if(FireHim)
|
||||
Master.subsystems += new BadBoy.type //NEW_SS_GLOBAL will remove the old one
|
||||
|
||||
subsystems = Master.subsystems
|
||||
current_runlevel = Master.current_runlevel
|
||||
StartProcessing(10)
|
||||
@@ -162,13 +176,13 @@ var/datum/controller/master/Master = new()
|
||||
|
||||
var/start_timeofday = REALTIMEOFDAY
|
||||
// Initialize subsystems.
|
||||
current_ticklimit = config.tick_limit_mc_init
|
||||
GLOB.CURRENT_TICKLIMIT = config.tick_limit_mc_init
|
||||
for (var/datum/controller/subsystem/SS in subsystems)
|
||||
if (SS.flags & SS_NO_INIT)
|
||||
continue
|
||||
SS.Initialize(REALTIMEOFDAY)
|
||||
CHECK_TICK
|
||||
current_ticklimit = TICK_LIMIT_RUNNING
|
||||
GLOB.CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
|
||||
var/time = (REALTIMEOFDAY - start_timeofday) / 10
|
||||
|
||||
var/msg = "Initializations complete within [time] second[time == 1 ? "" : "s"]!"
|
||||
@@ -277,7 +291,7 @@ var/datum/controller/master/Master = new()
|
||||
tickdrift = max(0, MC_AVERAGE_FAST(tickdrift, (((REALTIMEOFDAY - init_timeofday) - (world.time - init_time)) / world.tick_lag)))
|
||||
var/starting_tick_usage = TICK_USAGE
|
||||
if (processing <= 0)
|
||||
current_ticklimit = TICK_LIMIT_RUNNING
|
||||
GLOB.CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
|
||||
sleep(10)
|
||||
continue
|
||||
|
||||
@@ -286,7 +300,7 @@ var/datum/controller/master/Master = new()
|
||||
// (because sleeps are processed in the order received, longer sleeps are more likely to run first)
|
||||
if (starting_tick_usage > TICK_LIMIT_MC) //if there isn't enough time to bother doing anything this tick, sleep a bit.
|
||||
sleep_delta *= 2
|
||||
current_ticklimit = TICK_LIMIT_RUNNING * 0.5
|
||||
GLOB.CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING * 0.5
|
||||
sleep(world.tick_lag * (processing * sleep_delta))
|
||||
continue
|
||||
|
||||
@@ -332,7 +346,7 @@ var/datum/controller/master/Master = new()
|
||||
if (!error_level)
|
||||
iteration++
|
||||
error_level++
|
||||
current_ticklimit = TICK_LIMIT_RUNNING
|
||||
GLOB.CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
|
||||
sleep(10)
|
||||
continue
|
||||
|
||||
@@ -344,7 +358,7 @@ var/datum/controller/master/Master = new()
|
||||
if (!error_level)
|
||||
iteration++
|
||||
error_level++
|
||||
current_ticklimit = TICK_LIMIT_RUNNING
|
||||
GLOB.CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
|
||||
sleep(10)
|
||||
continue
|
||||
error_level--
|
||||
@@ -355,9 +369,9 @@ var/datum/controller/master/Master = new()
|
||||
iteration++
|
||||
last_run = world.time
|
||||
src.sleep_delta = MC_AVERAGE_FAST(src.sleep_delta, sleep_delta)
|
||||
current_ticklimit = TICK_LIMIT_RUNNING
|
||||
GLOB.CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
|
||||
if (processing * sleep_delta <= world.tick_lag)
|
||||
current_ticklimit -= (TICK_LIMIT_RUNNING * 0.25) //reserve the tail 1/4 of the next tick for the mc if we plan on running next tick
|
||||
GLOB.CURRENT_TICKLIMIT -= (TICK_LIMIT_RUNNING * 0.25) //reserve the tail 1/4 of the next tick for the mc if we plan on running next tick
|
||||
sleep(world.tick_lag * (processing * sleep_delta))
|
||||
|
||||
|
||||
@@ -449,7 +463,7 @@ var/datum/controller/master/Master = new()
|
||||
// Reduce tick allocation for subsystems that overran on their last tick.
|
||||
tick_precentage = max(tick_precentage*0.5, tick_precentage-queue_node.tick_overrun)
|
||||
|
||||
current_ticklimit = round(TICK_USAGE + tick_precentage)
|
||||
GLOB.CURRENT_TICKLIMIT = round(TICK_USAGE + tick_precentage)
|
||||
|
||||
if (!(queue_node_flags & SS_TICKER))
|
||||
ran_non_ticker = TRUE
|
||||
|
||||
@@ -53,4 +53,4 @@ datum/controller/game_controller/proc/setup_objects()
|
||||
populate_antag_type_list()
|
||||
|
||||
//Set up spawn points.
|
||||
populate_spawn_points()
|
||||
populate_spawn_points()
|
||||
@@ -125,7 +125,7 @@
|
||||
debug_variables(alarm_manager)
|
||||
feedback_add_details("admin_verb", "DAlarm")
|
||||
if("Nano")
|
||||
debug_variables(nanomanager)
|
||||
debug_variables(GLOB.nanomanager)
|
||||
feedback_add_details("admin_verb", "DNano")
|
||||
if("Chemistry")
|
||||
debug_variables(chemistryProcess)
|
||||
|
||||
Reference in New Issue
Block a user