Skip to content

Commit

Permalink
Revert "Revert some global var changes"
Browse files Browse the repository at this point in the history
  • Loading branch information
Bierkraan authored May 13, 2024
1 parent 6ff6e5c commit f945a0e
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions code/controllers/mc/globals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,11 @@ GLOBAL_REAL(GLOB, /datum/controller/global_vars)

var/datum/controller/exclude_these = new
gvars_datum_in_built_vars = exclude_these.vars + list(NAMEOF(src, gvars_datum_protected_varlist), NAMEOF(src, gvars_datum_in_built_vars), NAMEOF(src, gvars_datum_init_order))
qdel(exclude_these)
QDEL_IN(exclude_these, 0) //signal logging isn't ready

var/global_vars = vars.len - gvars_datum_in_built_vars.len
var/global_procs = length(typesof(/datum/controller/global_vars/proc))
log_world("[vars.len - gvars_datum_in_built_vars.len] global variables")

report_progress("[global_vars] global variables")
report_progress("[global_procs] global init procs")

try
if(global_vars == global_procs)
Initialize()
else
crash_with("Expected [global_vars] global init procs, were [global_procs].")
catch(var/exception/e)
to_world_log("Vars to be initialized: [json_encode((vars - gvars_datum_in_built_vars))]")
to_world_log("Procs used to initialize: [json_encode(typesof(/datum/controller/global_vars/proc))]")
throw e
Initialize()

/datum/controller/global_vars/Destroy(force)
// This is done to prevent an exploit where admins can get around protected vars
Expand All @@ -44,8 +32,18 @@ GLOBAL_REAL(GLOB, /datum/controller/global_vars)
/datum/controller/global_vars/Initialize()
gvars_datum_init_order = list()
gvars_datum_protected_varlist = list(NAMEOF(src, gvars_datum_protected_varlist) = TRUE)
for(var/I in typesof(/datum/controller/global_vars/proc))
var/list/global_procs = typesof(/datum/controller/global_vars/proc)
var/expected_len = vars.len - gvars_datum_in_built_vars.len
if(global_procs.len != expected_len)
warning("Unable to detect all global initialization procs! Expected [expected_len] got [global_procs.len]!")
if(global_procs.len)
var/list/expected_global_procs = vars - gvars_datum_in_built_vars
for(var/I in global_procs)
expected_global_procs -= replacetext("[I]", "InitGlobal", "")
log_world("Missing procs: [expected_global_procs.Join(", ")]")
for(var/I in global_procs)
var/start_tick = world.time
call(src, I)()
if(world.time - start_tick)
warning("[I] slept during initialization!")
var/end_tick = world.time
if(end_tick - start_tick)
warning("Global [replacetext("[I]", "InitGlobal", "")] slept during initialization!")

0 comments on commit f945a0e

Please sign in to comment.