* sdf

* fsda

* fuck

* fuck2

* toolz

* sdaf

* sdfa

* saf

* sdfa

* sdfa

* sdf

* sdfa

* temp rename

* temp rename

* temp rename

* sdaf

* the pain is immensurable in the land of byond

* the curse of rah

* safd

* sadf

* sadf

* gf

* asf

* fssdfa

* sfd

* sadf

* sfda

* brah

* brah

* it's easier for you to fix this

* ffs

* brah

* brah
This commit is contained in:
Fluffy
2024-01-06 17:03:57 +01:00
committed by GitHub
parent 8c76cfa9ea
commit e867030c2e
331 changed files with 2348 additions and 1643 deletions
-4
View File
@@ -393,7 +393,6 @@ GLOBAL_LIST_EMPTY(gamemode_cache)
var/list/api_rate_limit_whitelist = list()
// Master Controller settings.
var/mc_init_tick_limit = TICK_LIMIT_MC_INIT_DEFAULT
var/fastboot = FALSE // If true, take some shortcuts during boot to speed it up for testing. Probably should not be used on production servers.
//UDP GELF Logging
@@ -962,9 +961,6 @@ GENERAL_PROTECT_DATUM(/datum/configuration)
if("api_rate_limit_whitelist")
GLOB.config.api_rate_limit_whitelist = text2list(value, ";")
if("mc_ticklimit_init")
GLOB.config.mc_init_tick_limit = text2num(value) || TICK_LIMIT_MC_INIT_DEFAULT
if("ipintel_email")
if (value != "ch@nge.me")
ipintel_email = value
+9 -10
View File
@@ -3,27 +3,26 @@
// The object used for the clickable stat() button.
var/obj/effect/statclick/statclick
/datum/controller/Destroy()
QDEL_NULL(statclick)
return ..()
/datum/controller/proc/Initialize()
//cleanup actions
/datum/controller/proc/Shutdown()
//when we enter dmm_suite.load_map
/datum/controller/proc/StartLoadingMap()
//when we exit dmm_suite.load_map
/datum/controller/proc/StopLoadingMap()
/datum/controller/proc/Recover()
/datum/controller/proc/stat_entry(msg)
/* Aurora shit */
// Called when SSexplosives begins processing explosions.
/datum/controller/proc/ExplosionStart()
// Called when SSexplosives finishes processing all queued explosions.
/datum/controller/proc/ExplosionEnd()
//when we enter dmm_suite.load_map
/datum/controller/proc/StartLoadingMap()
//when we exit dmm_suite.load_map
/datum/controller/proc/StopLoadingMap()
+182
View File
@@ -0,0 +1,182 @@
/**
* Failsafe
*
* Pretty much pokes the MC to make sure it's still alive.
**/
// See initialization order in /code/game/world.dm
GLOBAL_REAL(Failsafe, /datum/controller/failsafe)
/datum/controller/failsafe // This thing pretty much just keeps poking the master controller
name = "Failsafe"
// The length of time to check on the MC (in deciseconds).
// Set to 0 to disable.
var/processing_interval = 20
// The alert level. For every failed poke, we drop a DEFCON level. Once we hit DEFCON 1, restart the MC.
var/defcon = 5
//the world.time of the last check, so the mc can restart US if we hang.
// (Real friends look out for *eachother*)
var/lasttick = 0
// Track the MC iteration to make sure its still on track.
var/master_iteration = 0
var/running = TRUE
/datum/controller/failsafe/New()
// Highlander-style: there can only be one! Kill off the old and replace it with the new.
if(Failsafe != src)
if(istype(Failsafe))
qdel(Failsafe)
Failsafe = src
Initialize()
/datum/controller/failsafe/Initialize()
set waitfor = FALSE
Failsafe.Loop()
if (!Master || defcon == 0) //Master is gone/not responding and Failsafe just exited its loop
defcon = 3 //Reset defcon level as its used inside the emergency loop
while (defcon > 0)
var/recovery_result = emergency_loop()
if (recovery_result == 1) //Exit emergency loop and delete self if it was able to recover MC
break
else if (defcon == 1) //Exit Failsafe if we weren't able to recover the MC in the last stage
log_game("FailSafe: Failed to recover MC while in emergency state. Failsafe exiting.")
message_admins(SPAN_HIGHDANGER("Failsafe failed critically while trying to recreate broken MC. Please manually fix the MC or reboot the server. Failsafe exiting now."))
message_admins(SPAN_HIGHDANGER("You can try manually calling these two procs:."))
message_admins(SPAN_HIGHDANGER("/proc/recover_all_SS_and_recreate_master: Most stuff should still function but expect instability/runtimes/broken stuff."))
message_admins(SPAN_HIGHDANGER("/proc/delete_all_SS_and_recreate_master: Most stuff will be broken but basic stuff like movement and chat should still work."))
else if (recovery_result == -1) //Failed to recreate MC
defcon--
sleep(initial(processing_interval)) //Wait a bit until the next try
if(!QDELETED(src))
qdel(src) //when Loop() returns, we delete ourselves and let the mc recreate us
/datum/controller/failsafe/Destroy()
running = FALSE
..()
return QDEL_HINT_HARDDEL_NOW
/datum/controller/failsafe/proc/Loop()
while(running)
lasttick = world.time
if(!Master)
// Break out of the main loop so we go into emergency state
break
// Only poke it if overrides are not in effect.
if(processing_interval > 0)
if(Master.processing && Master.iteration)
if (defcon > 1 && (!Master.stack_end_detector || !Master.stack_end_detector.check()))
to_chat(GLOB.staff, SPAN_HIGHDANGER("ERROR: The Master Controller code stack has exited unexpectedly, Restarting..."))
defcon = 0
var/rtn = Recreate_MC()
if(rtn > 0)
master_iteration = 0
to_chat(GLOB.staff, SPAN_NOTICE("MC restarted successfully"))
else if(rtn < 0)
log_game("FailSafe: Could not restart MC, runtime encountered. Entering defcon 0")
to_chat(GLOB.staff, SPAN_HIGHDANGER("ERROR: DEFCON [defcon_pretty()]. Could not restart MC, runtime encountered. I will silently keep retrying."))
// Check if processing is done yet.
if(Master.iteration == master_iteration)
switch(defcon)
if(4,5)
--defcon
if(3)
message_admins(SPAN_NOTICE("Notice: DEFCON [defcon_pretty()]. The Master Controller has not fired in the last [(5-defcon) * processing_interval] ticks."))
--defcon
if(2)
to_chat(GLOB.staff, SPAN_HIGHDANGER("Warning: DEFCON [defcon_pretty()]. The Master Controller has not fired in the last [(5-defcon) * processing_interval] ticks. Automatic restart in [processing_interval] ticks."))
--defcon
if(1)
to_chat(GLOB.staff, SPAN_HIGHDANGER("Warning: DEFCON [defcon_pretty()]. The Master Controller has still not fired within the last [(5-defcon) * processing_interval] ticks. Killing and restarting..."))
--defcon
var/rtn = Recreate_MC()
if(rtn > 0)
defcon = 4
master_iteration = 0
to_chat(GLOB.staff, SPAN_NOTICE("MC restarted successfully"))
else if(rtn < 0)
log_game("FailSafe: Could not restart MC, runtime encountered. Entering defcon 0")
to_chat(GLOB.staff, SPAN_HIGHDANGER("ERROR: DEFCON [defcon_pretty()]. Could not restart MC, runtime encountered. I will silently keep retrying."))
//if the return number was 0, it just means the mc was restarted too recently, and it just needs some time before we try again
//no need to handle that specially when defcon 0 can handle it
if(0) //DEFCON 0! (mc failed to restart)
var/rtn = Recreate_MC()
if(rtn > 0)
defcon = 4
master_iteration = 0
to_chat(GLOB.staff, SPAN_NOTICE("MC restarted successfully"))
else
defcon = min(defcon + 1,5)
master_iteration = Master.iteration
if (defcon <= 1)
sleep(processing_interval*2)
else
sleep(processing_interval)
else
defcon = 5
sleep(initial(processing_interval))
//Emergency loop used when Master got deleted or the main loop exited while Defcon == 0
//Loop is driven externally so runtimes only cancel the current recovery attempt
/datum/controller/failsafe/proc/emergency_loop()
//The code in this proc should be kept as simple as possible, anything complicated like to_chat might rely on master existing and runtime
//The goal should always be to get a new Master up and running before anything else
. = -1
switch (defcon) //The lower defcon goes the harder we try to fix the MC
if (2 to 3) //Try to normally recreate the MC two times
. = Recreate_MC()
if (1) //Delete the old MC first so we don't transfer any info, in case that caused any issues
del(Master)
. = Recreate_MC()
if (. == 1) //We were able to create a new master
master_iteration = 0
SSticker.Recover(); //Recover the ticket system so the Masters runlevel gets set
Master.Initialize(10, FALSE, FALSE) //Need to manually start the MC, normally world.new would do this
to_chat(GLOB.staff, SPAN_NOTICE("Failsafe recovered MC while in emergency state [defcon_pretty()]"))
else
log_game("FailSafe: Failsafe in emergency state and was unable to recreate MC while in defcon state [defcon_pretty()].")
message_admins(SPAN_HIGHDANGER("Failsafe in emergency state and master down, trying to recreate MC while in defcon level [defcon_pretty()] failed."))
///Recreate all SSs which will still cause data survive due to Recover(), the new Master will then find and take them from global.vars
/proc/recover_all_SS_and_recreate_master()
del(Master)
var/list/subsytem_types = subtypesof(/datum/controller/subsystem)
sortTim(subsytem_types, GLOBAL_PROC_REF(cmp_subsystem_init))
for(var/I in subsytem_types)
new I
. = Recreate_MC()
if (. == 1) //We were able to create a new master
SSticker.Recover(); //Recover the ticket system so the Masters runlevel gets set
Master.Initialize(10, FALSE, FALSE) //Need to manually start the MC, normally world.new would do this
to_chat(GLOB.staff, SPAN_NOTICE("MC successfully recreated after recovering all subsystems!"))
else
message_admins(SPAN_HIGHDANGER("Failed to create new MC!"))
///Delete all existing SS to basically start over
/proc/delete_all_SS_and_recreate_master()
del(Master)
for(var/global_var in global.vars)
if (istype(global.vars[global_var], /datum/controller/subsystem))
del(global.vars[global_var])
. = Recreate_MC()
if (. == 1) //We were able to create a new master
SSticker.Recover(); //Recover the ticket system so the Masters runlevel gets set
Master.Initialize(10, FALSE, FALSE) //Need to manually start the MC, normally world.new would do this
to_chat(GLOB.staff, SPAN_NOTICE("MC successfully recreated after deleting and recreating all subsystems!"))
else
message_admins(SPAN_HIGHDANGER("Failed to create new MC!"))
/datum/controller/failsafe/proc/defcon_pretty()
return defcon
/datum/controller/failsafe/stat_entry(msg)
msg = "Defcon: [defcon_pretty()] (Interval: [Failsafe.processing_interval] | Iteration: [Failsafe.master_iteration])"
return msg
+2
View File
@@ -61,3 +61,5 @@ GLOBAL_REAL(GLOB, /datum/controller/global_vars)
// No, really, it's really bad.
makeDatumRefLists()
return SS_INIT_SUCCESS
+824
View File
@@ -0,0 +1,824 @@
/**
* StonedMC
*
* Designed to properly split up a given tick among subsystems
* Note: if you read parts of this code and think "why is it doing it that way"
* Odds are, there is a reason
*
**/
// See initialization order in /code/game/world.dm
GLOBAL_REAL(Master, /datum/controller/master)
/datum/controller/master
name = "Master"
/// Are we processing (higher values increase the processing delay by n ticks)
var/processing = TRUE
/// How many times have we ran
var/iteration = 0
/// Stack end detector to detect stack overflows that kill the mc's main loop
var/datum/stack_end_detector/stack_end_detector
/// world.time of last fire, for tracking lag outside of the mc
var/last_run
/// List of subsystems to process().
var/list/subsystems
///Most recent init stage to complete init.
var/static/init_stage_completed
// Vars for keeping track of tick drift.
var/init_timeofday
var/init_time
var/tickdrift = 0
/// Tickdrift as of last tick, w no averaging going on
var/olddrift = 0
/// How long is the MC sleeping between runs, read only (set by Loop() based off of anti-tick-contention heuristics)
var/sleep_delta = 1
/// Only run ticker subsystems for the next n ticks.
var/skip_ticks = 0
/// makes the mc main loop runtime
var/make_runtime = FALSE
var/initializations_finished_with_no_players_logged_in //I wonder what this could be?
/// The type of the last subsystem to be fire()'d.
var/last_type_processed
var/datum/controller/subsystem/queue_head //!Start of queue linked list
var/datum/controller/subsystem/queue_tail //!End of queue linked list (used for appending to the list)
var/queue_priority_count = 0 //Running total so that we don't have to loop thru the queue each run to split up the tick
var/queue_priority_count_bg = 0 //Same, but for background subsystems
var/map_loading = FALSE //!Are we loading in a new map?
var/current_runlevel //!for scheduling different subsystems for different stages of the round
var/sleep_offline_after_initializations = FALSE
/// During initialization, will be the instanced subsytem that is currently initializing.
/// Outside of initialization, returns null.
var/current_initializing_subsystem = null
/// The last decisecond we force dumped profiling information
/// Used to avoid spamming profile reads since they can be expensive (string memes)
var/last_profiled = 0
var/static/restart_clear = 0
var/static/restart_timeout = 0
var/static/restart_count = 0
var/static/random_seed
///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()
// if(!GLOB.config)
// SSpersistent_configuration = new
// Highlander-style: there can only be one! Kill off the old and replace it with the new.
if(!random_seed)
#ifdef UNIT_TEST
random_seed = 29051994 // How about 22475?
#else
random_seed = rand(1, 1e9)
#endif
rand_seed(random_seed)
var/list/_subsystems = list()
subsystems = _subsystems
if (Master != src)
if (istype(Master)) //If there is an existing MC take over his stuff and delete it
Recover()
qdel(Master)
Master = src
else
//Code used for first master on game boot or if existing master got deleted
Master = src
var/list/subsystem_types = subtypesof(/datum/controller/subsystem)
sortTim(subsystem_types, GLOBAL_PROC_REF(cmp_subsystem_init))
//Find any abandoned subsystem from the previous master (if there was any)
var/list/existing_subsystems = list()
for(var/global_var in global.vars)
if (istype(global.vars[global_var], /datum/controller/subsystem))
existing_subsystems += global.vars[global_var]
//Either init a new SS or if an existing one was found use that
for(var/I in subsystem_types)
var/ss_idx = existing_subsystems.Find(I)
if (ss_idx)
_subsystems += existing_subsystems[ss_idx]
else
_subsystems += new I
if(!GLOB)
new /datum/controller/global_vars
/datum/controller/master/Destroy()
..()
// Tell qdel() to Del() this object.
return QDEL_HINT_HARDDEL_NOW
/datum/controller/master/Shutdown()
processing = FALSE
sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_init))
reverse_range(subsystems)
for(var/datum/controller/subsystem/ss in subsystems)
log_world("Shutting down [ss.name] subsystem...")
if (ss.slept_count > 0)
log_world("Warning: Subsystem `[ss.name]` slept [ss.slept_count] times.")
ss.Shutdown()
log_world("Shutdown complete")
// Returns 1 if we created a new mc, 0 if we couldn't due to a recent restart,
// -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)
return 0
if (world.time < Master.restart_clear)
Master.restart_count *= 0.5
var/delay = 50 * ++Master.restart_count
Master.restart_timeout = world.time + delay
Master.restart_clear = world.time + (delay * 2)
if (Master) //Can only do this if master hasn't been deleted
Master.processing = FALSE //stop ticking this one
try
new/datum/controller/master()
catch
return -1
return 1
/datum/controller/master/Recover()
var/msg = "## DEBUG: [time2text(world.timeofday)] MC restarted. Reports:\n"
var/list/master_attributes = Master.vars
var/list/filtered_variables = list(
NAMEOF(src, name),
NAMEOF(src, parent_type),
NAMEOF(src, statclick),
NAMEOF(src, tag),
NAMEOF(src, type),
NAMEOF(src, vars),
)
for (var/varname in master_attributes - filtered_variables)
var/varval = master_attributes[varname]
if (isdatum(varval)) // Check if it has a type var.
var/datum/D = varval
msg += "\t [varname] = [D]([D.type])\n"
else
msg += "\t [varname] = [varval]\n"
log_world(msg)
var/datum/controller/subsystem/BadBoy = Master.last_type_processed
var/FireHim = FALSE
if(istype(BadBoy))
msg = null
LAZYINITLIST(BadBoy.failure_strikes)
switch(++BadBoy.failure_strikes[BadBoy.type])
if(2)
msg = "The [BadBoy.name] subsystem was the last to fire for 2 controller restarts. It will be recovered now and disabled if it happens again."
FireHim = TRUE
if(3)
msg = "The [BadBoy.name] subsystem seems to be destabilizing the MC and will be put offline."
BadBoy.flags |= SS_NO_FIRE
if(msg)
to_chat(GLOB.staff, SPAN_HIGHDANGER("[msg]"))
log_world(msg)
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)
else
to_chat(world, SPAN_HIGHDANGER("The Master Controller is having some issues, we will need to re-initialize EVERYTHING"))
Initialize(20, TRUE, FALSE)
// Please don't stuff random bullshit here,
// Make a subsystem, give it the SS_NO_FIRE flag, and do your work in it's Initialize()
/datum/controller/master/Initialize(delay, init_sss, tgs_prime)
set waitfor = 0
if(delay)
sleep(delay)
if(init_sss)
init_subtypes(/datum/controller/subsystem, subsystems)
init_stage_completed = 0
var/mc_started = FALSE
to_chat(world, SPAN_HIGHDANGER("Initializing subsystems..."))
var/list/stage_sorted_subsystems = new(INITSTAGE_MAX)
for (var/i in 1 to INITSTAGE_MAX)
stage_sorted_subsystems[i] = list()
// Sort subsystems by init_order, so they initialize in the correct order.
sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_init))
for (var/datum/controller/subsystem/subsystem as anything in subsystems)
var/subsystem_init_stage = subsystem.init_stage
if (!isnum(subsystem_init_stage) || subsystem_init_stage < 1 || subsystem_init_stage > INITSTAGE_MAX || round(subsystem_init_stage) != subsystem_init_stage)
stack_trace("ERROR: MC: subsystem `[subsystem.type]` has invalid init_stage: `[subsystem_init_stage]`. Setting to `[INITSTAGE_MAX]`")
subsystem_init_stage = subsystem.init_stage = INITSTAGE_MAX
stage_sorted_subsystems[subsystem_init_stage] += subsystem
// Sort subsystems by display setting for easy access.
sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_display))
var/start_timeofday = REALTIMEOFDAY
for (var/current_init_stage in 1 to INITSTAGE_MAX)
// Initialize subsystems.
for (var/datum/controller/subsystem/subsystem in stage_sorted_subsystems[current_init_stage])
init_subsystem(subsystem)
CHECK_TICK
current_initializing_subsystem = null
init_stage_completed = current_init_stage
if (!mc_started)
mc_started = TRUE
if (!current_runlevel)
SetRunLevel(1) // Intentionally not using the defines here because the MC doesn't care about them
// Loop.
Master.StartProcessing(0)
var/time = (REALTIMEOFDAY - start_timeofday) / 10
var/msg = "Initializations complete within [time] second[time == 1 ? "" : "s"]!"
to_chat(world, SPAN_HIGHDANGER("[msg]"))
log_world(msg)
// There was a toast notifications call here, but we do not use it currently
// Set world options.
world.change_fps((10 / GLOB.config.Ticklag))
var/initialized_tod = REALTIMEOFDAY
if(tgs_prime)
world.TgsInitializationComplete()
if(sleep_offline_after_initializations)
world.sleep_offline = TRUE
sleep(1 TICKS)
if(sleep_offline_after_initializations)
world.sleep_offline = FALSE
initializations_finished_with_no_players_logged_in = initialized_tod < REALTIMEOFDAY - 10
/**
* Initialize a given subsystem and handle the results.
*
* Arguments:
* * subsystem - the subsystem to initialize.
*/
/datum/controller/master/proc/init_subsystem(datum/controller/subsystem/subsystem)
var/static/list/valid_results = list(
SS_INIT_FAILURE,
SS_INIT_NONE,
SS_INIT_SUCCESS,
SS_INIT_NO_NEED,
SS_INIT_NO_MESSAGE,
)
if (subsystem.flags & SS_NO_INIT || subsystem.initialized) //Don't init SSs with the corresponding flag or if they already are initialized
return
current_initializing_subsystem = subsystem
rustg_time_reset(SS_INIT_TIMER_KEY)
var/result = subsystem.Initialize()
// Capture end time
var/time = rustg_time_milliseconds(SS_INIT_TIMER_KEY)
var/seconds = round(time / 1000, 0.01)
// There was a call to SSblackbox here to update the tally, since we don't have SSblackbox it's not ported over
// Gave invalid return value.
if(result && !(result in valid_results))
warning("[subsystem.name] subsystem initialized, returning invalid result [result]. This is a bug.")
// just returned ..() or didn't implement Initialize() at all
if(result == SS_INIT_NONE)
warning("[subsystem.name] subsystem does not implement Initialize() or it returns ..(). If the former is true, the SS_NO_INIT flag should be set for this subsystem.")
if(result != SS_INIT_FAILURE)
// Some form of success, implicit failure, or the SS in unused.
subsystem.initialized = TRUE
SEND_SIGNAL(subsystem, COMSIG_SUBSYSTEM_POST_INITIALIZE)
else
// The subsystem officially reports that it failed to init and wishes to be treated as such.
subsystem.initialized = FALSE
subsystem.can_fire = FALSE
// The rest of this proc is printing the world log and chat message.
var/message_prefix
// If true, print the chat message with boldwarning text.
var/chat_warning = FALSE
switch(result)
if(SS_INIT_FAILURE)
message_prefix = "Failed to initialize [subsystem.name] subsystem after"
chat_warning = TRUE
if(SS_INIT_SUCCESS, SS_INIT_NO_MESSAGE)
message_prefix = "Initialized [subsystem.name] subsystem within"
if(SS_INIT_NO_NEED)
// This SS is disabled or is otherwise shy.
return
else
// SS_INIT_NONE or an invalid value.
message_prefix = "Initialized [subsystem.name] subsystem with errors within"
chat_warning = TRUE
var/message = "[message_prefix] [seconds] second[seconds == 1 ? "" : "s"]!"
var/chat_message = chat_warning ? SPAN_HIGHDANGER(message) : SPAN_NOTICE(message)
if(result != SS_INIT_NO_MESSAGE)
to_chat(world, chat_message)
log_world(message)
/datum/controller/master/proc/SetRunLevel(new_runlevel)
var/old_runlevel = current_runlevel
testing("MC: Runlevel changed from [isnull(old_runlevel) ? "NULL" : old_runlevel] to [new_runlevel]")
current_runlevel = log(2, new_runlevel) + 1
if(current_runlevel < 1)
current_runlevel = old_runlevel
CRASH("Attempted to set invalid runlevel: [new_runlevel]")
// Starts the mc, and sticks around to restart it if the loop ever ends.
/datum/controller/master/proc/StartProcessing(delay)
set waitfor = 0
if(delay)
sleep(delay)
testing("Master starting processing")
var/started_stage
var/rtn = -2
do
started_stage = init_stage_completed
rtn = Loop(started_stage)
while (rtn == MC_LOOP_RTN_NEWSTAGES && processing > 0 && started_stage < init_stage_completed)
if (rtn >= MC_LOOP_RTN_GRACEFUL_EXIT || processing < 0)
return //this was suppose to happen.
//loop ended, restart the mc
log_game("MC crashed or runtimed, restarting")
message_admins("MC crashed or runtimed, restarting")
var/rtn2 = Recreate_MC()
if (rtn2 <= 0)
log_game("Failed to recreate MC (Error code: [rtn2]), it's up to the failsafe now")
message_admins("Failed to recreate MC (Error code: [rtn2]), it's up to the failsafe now")
Failsafe.defcon = 2
// Main loop.
/datum/controller/master/proc/Loop(init_stage)
. = -1
//Prep the loop (most of this is because we want MC restarts to reset as much state as we can, and because
// local vars rock
//all this shit is here so that flag edits can be refreshed by restarting the MC. (and for speed)
var/list/tickersubsystems = list()
var/list/runlevel_sorted_subsystems = list(list()) //ensure we always have at least one runlevel
var/timer = world.time
for (var/thing in subsystems)
var/datum/controller/subsystem/SS = thing
if (SS.flags & SS_NO_FIRE)
continue
if (SS.init_stage > init_stage)
continue
SS.queued_time = 0
SS.queue_next = null
SS.queue_prev = null
SS.state = SS_IDLE
if ((SS.flags & (SS_TICKER|SS_BACKGROUND)) == SS_TICKER)
tickersubsystems += SS
// Timer subsystems aren't allowed to bunch up, so we offset them a bit
timer += world.tick_lag * rand(0, 1)
SS.next_fire = timer
continue
var/ss_runlevels = SS.runlevels
var/added_to_any = FALSE
for(var/I in 1 to GLOB.bitflags.len)
if(ss_runlevels & GLOB.bitflags[I])
while(runlevel_sorted_subsystems.len < I)
runlevel_sorted_subsystems += list(list())
runlevel_sorted_subsystems[I] += SS
added_to_any = TRUE
if(!added_to_any)
WARNING("[SS.name] subsystem is not SS_NO_FIRE but also does not have any runlevels set!")
queue_head = null
queue_tail = null
//these sort by lower priorities first to reduce the number of loops needed to add subsequent SS's to the queue
//(higher subsystems will be sooner in the queue, adding them later in the loop means we don't have to loop thru them next queue add)
sortTim(tickersubsystems, GLOBAL_PROC_REF(cmp_subsystem_priority))
for(var/I in runlevel_sorted_subsystems)
sortTim(I, GLOBAL_PROC_REF(cmp_subsystem_priority))
I += tickersubsystems
var/cached_runlevel = current_runlevel
var/list/current_runlevel_subsystems = runlevel_sorted_subsystems[cached_runlevel]
init_timeofday = REALTIMEOFDAY
init_time = world.time
iteration = 1
var/error_level = 0
var/sleep_delta = 1
var/list/subsystems_to_check
//setup the stack overflow detector
stack_end_detector = new()
var/datum/stack_canary/canary = stack_end_detector.prime_canary()
canary.use_variable()
//the actual loop.
while (1)
var/newdrift = ((REALTIMEOFDAY - init_timeofday) - (world.time - init_time)) / world.tick_lag
tickdrift = max(0, MC_AVERAGE_FAST(tickdrift, newdrift))
var/starting_tick_usage = TICK_USAGE
if(newdrift - olddrift >= 4 SECONDS)
AttemptProfileDump(15 SECONDS)
olddrift = newdrift
if (init_stage != init_stage_completed)
return MC_LOOP_RTN_NEWSTAGES
if (processing <= 0)
Master.current_ticklimit = TICK_LIMIT_RUNNING
sleep(1 SECONDS)
continue
//Anti-tick-contention heuristics:
if (init_stage == INITSTAGE_MAX)
//if there are mutiple sleeping procs running before us hogging the cpu, we have to run later.
// (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
Master.current_ticklimit = TICK_LIMIT_RUNNING * 0.5
sleep(world.tick_lag * (processing * sleep_delta))
continue
//Byond resumed us late. assume it might have to do the same next tick
if (last_run + CEILING(world.tick_lag * (processing * sleep_delta), world.tick_lag) < world.time)
sleep_delta += 1
sleep_delta = MC_AVERAGE_FAST(sleep_delta, 1) //decay sleep_delta
if (starting_tick_usage > (TICK_LIMIT_MC*0.75)) //we ran 3/4 of the way into the tick
sleep_delta += 1
else
sleep_delta = 1
//debug
if (make_runtime)
var/datum/controller/subsystem/SS
SS.can_fire = 0
if (!Failsafe || (Failsafe.processing_interval > 0 && (Failsafe.lasttick+(Failsafe.processing_interval*5)) < world.time))
new/datum/controller/failsafe() // (re)Start the failsafe.
//now do the actual stuff
if (!skip_ticks)
var/checking_runlevel = current_runlevel
if(cached_runlevel != checking_runlevel)
//resechedule subsystems
var/list/old_subsystems = current_runlevel_subsystems
cached_runlevel = checking_runlevel
current_runlevel_subsystems = runlevel_sorted_subsystems[cached_runlevel]
//now we'll go through all the subsystems we want to offset and give them a next_fire
for(var/datum/controller/subsystem/SS as anything in current_runlevel_subsystems)
//we only want to offset it if it's new and also behind
if(SS.next_fire > world.time || (SS in old_subsystems))
continue
SS.next_fire = world.time + world.tick_lag * rand(0, DS2TICKS(min(SS.wait, 2 SECONDS)))
subsystems_to_check = current_runlevel_subsystems
else
subsystems_to_check = tickersubsystems
if (CheckQueue(subsystems_to_check) <= 0) //error processing queue
stack_trace("MC: CheckQueue failed. Current error_level is [round(error_level, 0.25)]")
if (!SoftReset(tickersubsystems, runlevel_sorted_subsystems))
error_level++
CRASH("MC: SoftReset() failed, exiting loop()")
if (error_level < 2) //except for the first strike, stop incrmenting our iteration so failsafe enters defcon
iteration++
else
cached_runlevel = null //3 strikes, Lets reset the runlevel lists
Master.current_ticklimit = TICK_LIMIT_RUNNING
sleep((1 SECONDS) * error_level)
error_level++
continue
if (queue_head)
if (RunQueue() <= 0) //error running queue
stack_trace("MC: RunQueue failed. Current error_level is [round(error_level, 0.25)]")
if (error_level > 1) //skip the first error,
if (!SoftReset(tickersubsystems, runlevel_sorted_subsystems))
error_level++
CRASH("MC: SoftReset() failed, exiting loop()")
if (error_level <= 2) //after 3 strikes stop incrmenting our iteration so failsafe enters defcon
iteration++
else
cached_runlevel = null //3 strikes, Lets also reset the runlevel lists
Master.current_ticklimit = TICK_LIMIT_RUNNING
sleep((1 SECONDS) * error_level)
error_level++
continue
error_level++
if (error_level > 0)
error_level = max(MC_AVERAGE_SLOW(error_level-1, error_level), 0)
if (!queue_head) //reset the counts if the queue is empty, in the off chance they get out of sync
queue_priority_count = 0
queue_priority_count_bg = 0
iteration++
last_run = world.time
if (skip_ticks)
skip_ticks--
src.sleep_delta = MC_AVERAGE_FAST(src.sleep_delta, sleep_delta)
// Force any verbs into overtime, to test how they perfrom under load
// For local ONLY
#ifdef VERB_STRESS_TEST
/// Target enough tick usage to only allow time for our maptick estimate and verb processing, and nothing else
var/overtime_target = TICK_LIMIT_RUNNING
// This will leave just enough cpu time for maptick, forcing verbs to run into overtime
// Use this for testing the worst case scenario, when maptick is spiking and usage is otherwise completely consumed
#ifdef FORCE_VERB_OVERTIME
overtime_target += TICK_BYOND_RESERVE
#endif
CONSUME_UNTIL(overtime_target)
#endif
if (init_stage != INITSTAGE_MAX)
Master.current_ticklimit = TICK_LIMIT_RUNNING * 2
else
Master.current_ticklimit = TICK_LIMIT_RUNNING
if (processing * sleep_delta <= world.tick_lag)
Master.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))
// This is what decides if something should run.
/datum/controller/master/proc/CheckQueue(list/subsystemstocheck)
. = 0 //so the mc knows if we runtimed
//we create our variables outside of the loops to save on overhead
var/datum/controller/subsystem/SS
var/SS_flags
for (var/thing in subsystemstocheck)
if (!thing)
subsystemstocheck -= thing
SS = thing
if (SS.state != SS_IDLE)
continue
if (SS.can_fire <= 0)
continue
if (SS.next_fire > world.time)
continue
SS_flags = SS.flags
if (SS_flags & SS_NO_FIRE)
subsystemstocheck -= SS
continue
if ((SS_flags & (SS_TICKER|SS_KEEP_TIMING)) == SS_KEEP_TIMING && SS.last_fire + (SS.wait * 0.75) > world.time)
continue
if (SS.postponed_fires >= 1)
SS.postponed_fires--
SS.update_nextfire()
continue
SS.enqueue()
. = 1
/// RunQueue - Run thru the queue of subsystems to run, running them while balancing out their allocated tick precentage
/// Returns 0 if runtimed, a negitive number for logic errors, and a positive number if the operation completed without errors
/datum/controller/master/proc/RunQueue()
. = 0
var/datum/controller/subsystem/queue_node
var/queue_node_flags
var/queue_node_priority
var/queue_node_paused
var/current_tick_budget
var/tick_precentage
var/tick_remaining
var/ran = TRUE //this is right
var/bg_calc //have we swtiched current_tick_budget to background mode yet?
var/tick_usage
//keep running while we have stuff to run and we haven't gone over a tick
// this is so subsystems paused eariler can use tick time that later subsystems never used
while (ran && queue_head && TICK_USAGE < TICK_LIMIT_MC)
ran = FALSE
bg_calc = FALSE
current_tick_budget = queue_priority_count
queue_node = queue_head
while (queue_node)
if (ran && TICK_USAGE > TICK_LIMIT_RUNNING)
break
queue_node_flags = queue_node.flags
queue_node_priority = queue_node.queued_priority
if (!(queue_node_flags & SS_TICKER) && skip_ticks)
queue_node = queue_node.queue_next
continue
if ((queue_node_flags & SS_BACKGROUND))
if (!bg_calc)
current_tick_budget = queue_priority_count_bg
bg_calc = TRUE
else if (bg_calc)
//error state, do sane fallback behavior
if (. == 0)
log_world("MC: Queue logic failure, non-background subsystem queued to run after a background subsystem: [queue_node] queue_prev:[queue_node.queue_prev]")
. = -1
current_tick_budget = queue_priority_count //this won't even be right, but is the best we have.
bg_calc = FALSE
tick_remaining = TICK_LIMIT_RUNNING - TICK_USAGE
if (queue_node_priority >= 0 && current_tick_budget > 0 && current_tick_budget >= queue_node_priority)
//Give the subsystem a precentage of the remaining tick based on the remaining priority
tick_precentage = tick_remaining * (queue_node_priority / current_tick_budget)
else
//error state
if (. == 0)
log_world("MC: tick_budget sync error. [json_encode(list(current_tick_budget, queue_priority_count, queue_priority_count_bg, bg_calc, queue_node, queue_node_priority))]")
. = -1
tick_precentage = tick_remaining //just because we lost track of priority calculations doesn't mean we can't try to finish off the run, if the error state persists, we don't want to stop ticks from happening
tick_precentage = max(tick_precentage*0.5, tick_precentage-queue_node.tick_overrun)
Master.current_ticklimit = round(TICK_USAGE + tick_precentage)
ran = TRUE
queue_node_paused = (queue_node.state == SS_PAUSED || queue_node.state == SS_PAUSING)
last_type_processed = queue_node
queue_node.state = SS_RUNNING
tick_usage = TICK_USAGE
var/state = queue_node.ignite(queue_node_paused)
tick_usage = TICK_USAGE - tick_usage
if (state == SS_RUNNING)
state = SS_IDLE
current_tick_budget -= queue_node_priority
if (tick_usage < 0)
tick_usage = 0
queue_node.tick_overrun = max(0, MC_AVG_FAST_UP_SLOW_DOWN(queue_node.tick_overrun, tick_usage-tick_precentage))
queue_node.state = state
if (state == SS_PAUSED)
queue_node.paused_ticks++
queue_node.paused_tick_usage += tick_usage
queue_node = queue_node.queue_next
continue
queue_node.ticks = MC_AVERAGE(queue_node.ticks, queue_node.paused_ticks)
tick_usage += queue_node.paused_tick_usage
queue_node.tick_usage = MC_AVERAGE_FAST(queue_node.tick_usage, tick_usage)
queue_node.cost = MC_AVERAGE_FAST(queue_node.cost, TICK_DELTA_TO_MS(tick_usage))
queue_node.paused_ticks = 0
queue_node.paused_tick_usage = 0
if (bg_calc) //update our running total
queue_priority_count_bg -= queue_node_priority
else
queue_priority_count -= queue_node_priority
queue_node.last_fire = world.time
queue_node.times_fired++
queue_node.update_nextfire()
queue_node.queued_time = 0
//remove from queue
queue_node.dequeue()
queue_node = queue_node.queue_next
if (. == 0)
. = 1
//resets the queue, and all subsystems, while filtering out the subsystem lists
// called if any mc's queue procs runtime or exit improperly.
/datum/controller/master/proc/SoftReset(list/ticker_SS, list/runlevel_SS)
. = 0
stack_trace("MC: SoftReset called, resetting MC queue state.")
if (!istype(subsystems) || !istype(ticker_SS) || !istype(runlevel_SS))
log_world("MC: SoftReset: Bad list contents: '[subsystems]' '[ticker_SS]' '[runlevel_SS]'")
return
var/subsystemstocheck = subsystems | ticker_SS
for(var/I in runlevel_SS)
subsystemstocheck |= I
for (var/thing in subsystemstocheck)
var/datum/controller/subsystem/SS = thing
if (!SS || !istype(SS))
//list(SS) is so if a list makes it in the subsystem list, we remove the list, not the contents
subsystems -= list(SS)
ticker_SS -= list(SS)
for(var/I in runlevel_SS)
I -= list(SS)
log_world("MC: SoftReset: Found bad entry in subsystem list, '[SS]'")
continue
if (SS.queue_next && !istype(SS.queue_next))
log_world("MC: SoftReset: Found bad data in subsystem queue, queue_next = '[SS.queue_next]'")
SS.queue_next = null
if (SS.queue_prev && !istype(SS.queue_prev))
log_world("MC: SoftReset: Found bad data in subsystem queue, queue_prev = '[SS.queue_prev]'")
SS.queue_prev = null
SS.queued_priority = 0
SS.queued_time = 0
SS.state = SS_IDLE
if (queue_head && !istype(queue_head))
log_world("MC: SoftReset: Found bad data in subsystem queue, queue_head = '[queue_head]'")
queue_head = null
if (queue_tail && !istype(queue_tail))
log_world("MC: SoftReset: Found bad data in subsystem queue, queue_tail = '[queue_tail]'")
queue_tail = null
queue_priority_count = 0
queue_priority_count_bg = 0
log_world("MC: SoftReset: Finished.")
. = 1
/// Warns us that the end of tick byond map_update will be laggier then normal, so that we can just skip running subsystems this tick.
/datum/controller/master/proc/laggy_byond_map_update_incoming()
if (!skip_ticks)
skip_ticks = 1
/datum/controller/master/stat_entry(msg)
msg = "(TickRate:[Master.processing]) (Iteration:[Master.iteration]) (TickLimit: [round(Master.current_ticklimit, 0.1)])"
return msg
/datum/controller/master/StartLoadingMap()
//disallow more than one map to load at once, multithreading it will just cause race conditions
while(map_loading)
stoplag()
for(var/S in subsystems)
var/datum/controller/subsystem/SS = S
SS.StartLoadingMap()
map_loading = TRUE
/datum/controller/master/StopLoadingMap(bounds = null)
map_loading = FALSE
for(var/S in subsystems)
var/datum/controller/subsystem/SS = S
SS.StopLoadingMap()
/datum/controller/master/proc/UpdateTickRate()
if (!processing)
return
var/client_count = length(GLOB.clients)
if (client_count < 60)
processing = 1
else if (client_count > 65)
processing = 1.1
/datum/controller/master/proc/OnConfigLoad()
for (var/thing in subsystems)
var/datum/controller/subsystem/SS = thing
SS.OnConfigLoad()
/// Attempts to dump our current profile info into a file, triggered if the MC thinks shit is going down
/// Accepts a delay in deciseconds of how long ago our last dump can be, this saves causing performance problems ourselves
/datum/controller/master/proc/AttemptProfileDump(delay)
if(REALTIMEOFDAY - last_profiled <= delay)
return FALSE
last_profiled = REALTIMEOFDAY
SSprofiler.DumpFile(allow_yield = FALSE)
-121
View File
@@ -1,121 +0,0 @@
#define FAILSAFE_MSG(msg) admin_notice("<big><em><span class='warning'>FAILSAFE: </span><font color='#ff8800'>[msg]</font></em></big>", R_DEBUG|R_ADMIN|R_DEV)
var/datum/controller/failsafe/Failsafe
/**
* #Failsafe Controller
*
* Pretty much pokes the MC to make sure it's still alive.
*/
/datum/controller/failsafe // This thing pretty much just keeps poking the master controller
name = "Failsafe"
// The length of time to check on the MC (in deciseconds).
// Set to 0 to disable.
var/processing_interval = 20
// The alert level. For every failed poke, we drop a DEFCON level. Once we hit DEFCON 1, restart the MC.
var/defcon = 5
//the world.time of the last check, so the mc can restart US if we hang.
// (Real friends look out for *eachother*)
var/lasttick = 0
// Track the MC iteration to make sure its still on track.
var/master_iteration = 0
/datum/controller/failsafe/New()
// Highlander-style: there can only be one! Kill off the old and replace it with the new.
if(Failsafe != src)
if(istype(Failsafe))
qdel(Failsafe)
Failsafe = src
Initialize()
/datum/controller/failsafe/Initialize()
set waitfor = 0
Failsafe.Loop()
qdel(Failsafe) //when Loop() returns, we delete ourselves and let the mc recreate us
/datum/controller/failsafe/Destroy()
..()
return QDEL_HINT_HARDDEL_NOW
/datum/controller/failsafe/proc/Loop()
while(1)
lasttick = world.time
if(!Master)
// Replace the missing Master! This should never, ever happen.
new /datum/controller/master()
// Only poke it if overrides are not in effect.
if(processing_interval > 0)
if(Master.processing && Master.iteration)
// Check if processing is done yet.
if(Master.iteration == master_iteration)
switch(defcon)
if(4,5)
--defcon
if(3)
FAILSAFE_MSG("Notice: DEFCON [defcon_pretty()]. The Master Controller has not fired in the last [(5-defcon) * processing_interval] ticks.")
--defcon
if(2)
FAILSAFE_MSG("Warning: DEFCON [defcon_pretty()]. The Master Controller has not fired in the last [(5-defcon) * processing_interval] ticks. Automatic restart in [processing_interval] ticks.")
--defcon
if(1)
FAILSAFE_MSG("Warning: DEFCON [defcon_pretty()]. The Master Controller has still not fired within the last [(5-defcon) * processing_interval] ticks. Killing and restarting...")
log_failsafe("MC has not fired within last [(5-defcon) * processing_interval] ticks, killing and restarting.")
--defcon
//Do not restart the MC if we are doing a REFERENCE_TRACKING hard lookup
#if !defined(GC_FAILURE_HARD_LOOKUP)
var/rtn = Recreate_MC()
#else
log_failsafe("MC was not actually recreated, because we're compiled with GC_FAILURE_HARD_LOOKUP.")
FAILSAFE_MSG("MC was not actually recreated, because we're compiled with GC_FAILURE_HARD_LOOKUP.")
var/rtn = TRUE
#endif
if(rtn > 0)
defcon = 4
master_iteration = 0
log_failsafe("MC restarted successfully.")
FAILSAFE_MSG("MC restarted successfully!")
else if(rtn < 0)
log_failsafe("Could not restart MC, runtime encountered. Entering defcon 0!")
FAILSAFE_MSG("ERROR: DEFCON [defcon_pretty()]. Unable to restart MC, runtime encountered. Silently retrying.")
//if the return number was 0, it just means the mc was restarted too recently, and it just needs some time before we try again
//no need to handle that specially when defcon 0 can handle it
if(0) //DEFCON 0! (mc failed to restart)
//Do not restart the MC if we are doing a REFERENCE_TRACKING hard lookup
#if !defined(GC_FAILURE_HARD_LOOKUP)
var/rtn = Recreate_MC()
#else
var/rtn = TRUE
log_failsafe("MC was not actually recreated, because we're compiled with GC_FAILURE_HARD_LOOKUP.")
FAILSAFE_MSG("MC was not actually recreated, because we're compiled with GC_FAILURE_HARD_LOOKUP.")
#endif
if(rtn > 0)
defcon = 4
master_iteration = 0
log_failsafe("MC restarted successfully.")
FAILSAFE_MSG("MC restarted successfully.")
else
defcon = min(defcon + 1,5)
master_iteration = Master.iteration
if (defcon <= 1)
sleep(processing_interval*2)
else
sleep(processing_interval)
else
defcon = 5
sleep(initial(processing_interval))
/datum/controller/failsafe/proc/defcon_pretty()
return defcon
/datum/controller/failsafe/stat_entry(msg)
msg = "Defcon: [defcon_pretty()] (Interval: [Failsafe.processing_interval] | Iteration: [Failsafe.master_iteration])"
return msg
#undef FAILSAFE_MSG
-673
View File
@@ -1,673 +0,0 @@
var/datum/controller/master/Master = new()
//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
var/CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
/**
* StonedMC
*
* Designed to properly split up a given tick among subsystems
* Note: if you read parts of this code and think "why is it doing it that way"
* Odds are, there is a reason
*/
/datum/controller/master
name = "Master"
// Are we processing (higher values increase the processing delay by n ticks)
var/processing = 1
// How many times have we ran
var/iteration = 0
// world.time of last fire, for tracking lag outside of the mc
var/last_run
// List of subsystems to process().
var/list/subsystems
/// Most recent init stage to complete init.
var/static/init_stage_completed
// Vars for keeping track of tick drift.
var/init_timeofday
var/init_time
var/tickdrift = 0
var/sleep_delta = 1
/// Only run ticker subsystems for the next n ticks
var/skip_ticks = 0
var/make_runtime = 0
var/initialization_time_taken
var/initializations_finished_with_no_players_logged_in //I wonder what this could be?
var/current_runlevel // scheduling SS for different stages of the round
var/initializing = FALSE
// The type of the last subsystem to be process()'d.
var/last_type_processed
var/datum/controller/subsystem/queue_head //Start of queue linked list
var/datum/controller/subsystem/queue_tail //End of queue linked list (used for appending to the list)
var/queue_priority_count = 0 //Running total so that we don't have to loop thru the queue each run to split up the tick
var/queue_priority_count_bg = 0 //Same, but for background subsystems
var/map_loading = FALSE //Are we loading in a new map?
var/static/restart_clear = 0
var/static/restart_timeout = 0
var/static/restart_count = 0
/datum/controller/master/New()
// Highlander-style: there can only be one! Kill off the old and replace it with the new.
subsystems = list()
if (Master != src)
if (istype(Master))
Recover()
qdel(Master)
else
init_subtypes(/datum/controller/subsystem, subsystems)
Master = src
if(!GLOB)
new /datum/controller/global_vars
/datum/controller/master/Destroy()
..()
// Tell qdel() to Del() this object.
return QDEL_HINT_HARDDEL_NOW
/datum/controller/master/Shutdown()
processing = FALSE
for(var/datum/controller/subsystem/ss in subsystems)
ss.Shutdown()
// Returns 1 if we created a new mc, 0 if we couldn't due to a recent restart,
// -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)
return 0
if (world.time < Master.restart_clear)
Master.restart_count *= 0.5
var/delay = 50 * ++Master.restart_count
Master.restart_timeout = world.time + delay
Master.restart_clear = world.time + (delay * 2)
Master.processing = 0 //stop ticking this one
try
new/datum/controller/master()
catch
return -1
return 1
/datum/controller/master/Recover()
var/msg = "## DEBUG: [time2text(world.timeofday)] MC restarted. Reports:\n"
for (var/varname in Master.vars)
switch (varname)
if("name", "tag", "bestF", "type", "parent_type", "vars", "statclick") // Built-in junk.
continue
else
var/varval = Master.vars[varname]
if (istype(varval, /datum)) // Check if it has a type var.
var/datum/D = varval
msg += "\t [varname] = [D]([D.type])\n"
else
msg += "\t [varname] = [varval]\n"
log_subsystem_mastercontroller(msg)
var/datum/controller/subsystem/BadBoy = Master.last_type_processed
var/FireHim = FALSE
if(istype(BadBoy))
msg = null
LAZYINITLIST(BadBoy.failure_strikes)
switch(++BadBoy.failure_strikes[BadBoy.type])
if(2)
msg = "The [BadBoy.name] subsystem was the last to fire for 2 controller restarts. It will be recovered now and disabled if it happens again."
FireHim = TRUE
//If we are running a REFERENCE_TRACKING with hard lookups, this is expected and we do not want the master controller
//to stop the garbage collector from working
#if !defined(GC_FAILURE_HARD_LOOKUP)
if(3)
msg = "The [BadBoy.name] subsystem seems to be destabilizing the MC and will be offlined."
BadBoy.flags |= SS_NO_FIRE
#endif
if(msg)
admin_notice("<span class='danger'>[msg]</span>", R_DEBUG | R_DEV)
log_subsystem_mastercontroller(msg)
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)
else
to_chat(world, "<span class='danger'><big>The Master Controller is having some issues, we will need to re-initialize EVERYTHING</big></span>")
Initialize(20, TRUE)
// Please don't stuff random bullshit here,
// Make a subsystem, give it the SS_NO_FIRE flag, and do your work in it's Initialize()
/datum/controller/master/Initialize(delay, init_sss)
set waitfor = 0
if(delay)
sleep(delay)
if(init_sss)
init_subtypes(/datum/controller/subsystem, subsystems)
world.log << "Initializing subsystems..."
log_subsystem_mastercontroller("Initializing subsystems...")
initializing = TRUE
init_stage_completed = 0
var/mc_started = FALSE
var/start_timeofday = REALTIMEOFDAY
// Initialize subsystems.
var/list/stage_sorted_subsystems = new(INITSTAGE_MAX)
for (var/i in 1 to INITSTAGE_MAX)
stage_sorted_subsystems[i] = list()
// Sort subsystems by init_order, so they initialize in the correct order.
sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_init))
for (var/datum/controller/subsystem/subsystem as anything in subsystems)
var/subsystem_init_stage = subsystem.init_stage
if (!isnum(subsystem_init_stage) || subsystem_init_stage < 1 || subsystem_init_stage > INITSTAGE_MAX || round(subsystem_init_stage) != subsystem_init_stage)
stack_trace("ERROR: MC: subsystem `[subsystem.type]` has invalid init_stage: `[subsystem_init_stage]`. Setting to `[INITSTAGE_MAX]`")
subsystem_init_stage = subsystem.init_stage = INITSTAGE_MAX
stage_sorted_subsystems[subsystem_init_stage] += subsystem
CURRENT_TICKLIMIT = TICK_LIMIT_MC_INIT
for(var/current_init_stage in 1 to INITSTAGE_MAX)
for (var/datum/controller/subsystem/SS in stage_sorted_subsystems[current_init_stage])
if (SS.flags & SS_NO_INIT)
continue
SS.StartInitialize(REALTIMEOFDAY)
CHECK_TICK
init_stage_completed = current_init_stage
if (!mc_started)
mc_started = TRUE
if (!current_runlevel)
SetRunLevel(1) // Intentionally not using the defines here because the MC doesn't care about them
// Loop.
Master.StartProcessing(0)
CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
var/time = (REALTIMEOFDAY - start_timeofday) / 10
initializing = FALSE
initialization_time_taken = time
var/msg = "Initializations complete within [time] second\s!"
log_subsystem_mastercontroller(msg)
admin_notice(SPAN_DANGER(msg), R_DEBUG)
world.log << msg
SetRunLevel(RUNLEVEL_LOBBY)
// Sort subsystems by display setting for easy access.
sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_display))
// Set world options.
#ifndef UNIT_TEST
world.sleep_offline = 1
#endif
world.TgsInitializationComplete()
world.change_tick_lag(GLOB.config.Ticklag)
var/initialized_tod = REALTIMEOFDAY
sleep(1)
initializations_finished_with_no_players_logged_in = initialized_tod < REALTIMEOFDAY - 10
// Loop.
Master.StartProcessing(10)
/datum/controller/master/proc/SetRunLevel(new_runlevel)
var/old_runlevel = current_runlevel
if(isnull(old_runlevel))
old_runlevel = "NULL"
testing("MC: Runlevel changed from [old_runlevel] to [new_runlevel].")
current_runlevel = log(2, new_runlevel) + 1
if(current_runlevel < 1)
CRASH("Attempted to set invalid runlevel: [new_runlevel]")
// Starts the mc, and sticks around to restart it if the loop ever ends.
/datum/controller/master/proc/StartProcessing(delay)
set waitfor = 0
if(delay)
sleep(delay)
var/started_stage
var/rtn = -2
do
started_stage = init_stage_completed
rtn = Loop(started_stage)
while (rtn == MC_LOOP_RTN_NEWSTAGES && processing > 0 && started_stage < init_stage_completed)
if (rtn >= MC_LOOP_RTN_GRACEFUL_EXIT || processing < 0)
return //this was suppose to happen.
//loop ended, restart the mc
log_game("MC crashed or runtimed, restarting")
message_admins("MC crashed or runtimed, restarting")
var/rtn2 = Recreate_MC()
if (rtn2 <= 0)
log_game("Failed to recreate MC (Error code: [rtn2]), it's up to the failsafe now")
message_admins("Failed to recreate MC (Error code: [rtn2]), it's up to the failsafe now")
Failsafe.defcon = 2
// Main loop.
/datum/controller/master/proc/Loop(init_stage)
. = -1
//Prep the loop (most of this is because we want MC restarts to reset as much state as we can, and because
// local vars rock
//all this shit is here so that flag edits can be refreshed by restarting the MC. (and for speed)
var/list/tickersubsystems = list()
var/list/runlevel_sorted_subsystems = list(list())
var/timer = world.time
for (var/thing in subsystems)
var/datum/controller/subsystem/SS = thing
if (SS.flags & SS_NO_FIRE)
continue
if (SS.init_stage > init_stage)
continue
SS.queued_time = 0
SS.queue_next = null
SS.queue_prev = null
SS.state = SS_IDLE
if (SS.flags & SS_TICKER)
tickersubsystems += SS
timer += world.tick_lag * rand(0, 1)
SS.next_fire = timer
continue
var/ss_runlevels = SS.runlevels
var/added_to_any = FALSE
for(var/I in 1 to bitflags.len)
if(ss_runlevels & bitflags[I])
while(runlevel_sorted_subsystems.len < I)
runlevel_sorted_subsystems += list(list())
runlevel_sorted_subsystems[I] += SS
added_to_any = TRUE
if(!added_to_any)
WARNING("[SS.name] subsystem is not SS_NO_FIRE but also does not have any runlevels set!")
queue_head = null
queue_tail = null
//these sort by lower priorities first to reduce the number of loops needed to add subsequent SS's to the queue
//(higher subsystems will be sooner in the queue, adding them later in the loop means we don't have to loop thru them next queue add)
sortTim(tickersubsystems, GLOBAL_PROC_REF(cmp_subsystem_priority))
for(var/level in runlevel_sorted_subsystems)
sortTim(level, GLOBAL_PROC_REF(cmp_subsystem_priority))
level += tickersubsystems
var/cached_runlevel = current_runlevel
var/list/current_runlevel_subsystems = runlevel_sorted_subsystems[cached_runlevel]
init_timeofday = REALTIMEOFDAY
init_time = world.time
iteration = 1
var/error_level = 0
var/sleep_delta = 1
var/list/subsystems_to_check
//the actual loop.
while (1)
tickdrift = max(0, MC_AVERAGE_FAST(tickdrift, (((REALTIMEOFDAY - init_timeofday) - (world.time - init_time)) / world.tick_lag)))
var/starting_tick_usage = world.tick_usage
if (init_stage != init_stage_completed)
return MC_LOOP_RTN_NEWSTAGES
if (processing <= 0)
CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
sleep(1 SECONDS)
continue
//Anti-tick-contention heuristics:
//if there are mutiple sleeping procs running before us hogging the cpu, we have to run later.
// (because sleeps are processed in the order received, longer sleeps are more likely to run first)
if (init_stage == INITSTAGE_MAX)
if (starting_tick_usage > TICK_LIMIT_MC)
sleep_delta *= 2
CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING * 0.5
sleep(world.tick_lag * (processing * sleep_delta))
continue
//Byond resumed us late. assume it might have to do the same next tick
if (last_run + CEILING(world.tick_lag * (processing * sleep_delta), world.tick_lag) < world.time)
sleep_delta += 1
sleep_delta = MC_AVERAGE_FAST(sleep_delta, 1) //decay sleep_delta
if (starting_tick_usage > (TICK_LIMIT_MC*0.75)) //we ran 3/4 of the way into the tick
sleep_delta += 1
else
sleep_delta = 1
// debug
if (make_runtime)
var/datum/controller/subsystem/SS
SS.can_fire = 0
// Check the failsafe's still alive.
if (!Failsafe || (Failsafe.processing_interval > 0 && (Failsafe.lasttick+(Failsafe.processing_interval*5)) < world.time))
new/datum/controller/failsafe() // (re)Start the failsafe.
if (!skip_ticks)
var/checking_runlevel = current_runlevel
if(cached_runlevel != checking_runlevel)
// reschedule subsystems
var/list/old_subsystems = current_runlevel_subsystems
cached_runlevel = checking_runlevel
current_runlevel_subsystems = runlevel_sorted_subsystems[cached_runlevel]
for(var/datum/controller/subsystem/SS as anything in current_runlevel_subsystems)
// we only want to offset it if it's new and also behind
if(SS.next_fire > world.time || (SS in old_subsystems))
continue
SS.next_fire = world.time + world.tick_lag * rand(0, DS2TICKS(min(SS.wait, 2 SECONDS)))
subsystems_to_check = current_runlevel_subsystems
else
subsystems_to_check = tickersubsystems
if (CheckQueue(subsystems_to_check) <= 0)
if (!SoftReset(tickersubsystems, runlevel_sorted_subsystems))
log_subsystem_mastercontroller("SoftReset() failed, crashing")
return
if (!error_level)
iteration++
error_level++
CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
sleep(10)
continue
if (queue_head)
if (RunQueue() <= 0)
if (!SoftReset(tickersubsystems, runlevel_sorted_subsystems))
log_subsystem_mastercontroller("SoftReset() failed, crashing")
return
if (!error_level)
iteration++
error_level++
CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING
sleep(10)
continue
error_level--
if (!queue_head) //reset the counts if the queue is empty, in the off chance they get out of sync
queue_priority_count = 0
queue_priority_count_bg = 0
iteration++
last_run = world.time
if(skip_ticks)
skip_ticks--
src.sleep_delta = MC_AVERAGE_FAST(src.sleep_delta, sleep_delta)
if (init_stage != INITSTAGE_MAX)
CURRENT_TICKLIMIT = TICK_LIMIT_RUNNING * 2
else
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
sleep(world.tick_lag * (processing * sleep_delta))
// This is what decides if something should run.
/datum/controller/master/proc/CheckQueue(list/subsystemstocheck)
. = 0 //so the mc knows if we runtimed
//we create our variables outside of the loops to save on overhead
var/datum/controller/subsystem/SS
var/SS_flags
for (var/thing in subsystemstocheck)
if (!thing)
subsystemstocheck -= thing
SS = thing
if (SS.state != SS_IDLE)
continue
if (SS.can_fire <= 0)
continue
if (SS.suspended > 0)
continue
if (SS.next_fire > world.time)
continue
SS_flags = SS.flags
if (SS_flags & SS_NO_FIRE)
subsystemstocheck -= SS
continue
if ((SS_flags & (SS_TICKER|SS_KEEP_TIMING)) == SS_KEEP_TIMING && SS.last_fire + (SS.wait * 0.75) > world.time)
continue
SS.enqueue()
. = 1
// Run thru the queue of subsystems to run, running them while balancing out their allocated tick precentage
/datum/controller/master/proc/RunQueue()
. = 0
var/datum/controller/subsystem/queue_node
var/queue_node_flags
var/queue_node_priority
var/queue_node_paused
var/current_tick_budget
var/tick_precentage
var/tick_remaining
var/ran = TRUE //this is right
var/ran_non_ticker = FALSE
var/bg_calc //have we swtiched current_tick_budget to background mode yet?
var/tick_usage
//keep running while we have stuff to run and we haven't gone over a tick
// this is so subsystems paused eariler can use tick time that later subsystems never used
while (ran && queue_head && world.tick_usage < TICK_LIMIT_MC)
ran = FALSE
bg_calc = FALSE
current_tick_budget = queue_priority_count
queue_node = queue_head
while (queue_node)
if (ran && world.tick_usage > TICK_LIMIT_RUNNING)
break
queue_node_flags = queue_node.flags
queue_node_priority = queue_node.queued_priority
if(!(queue_node_flags & SS_TICKER) && skip_ticks)
queue_node = queue_node.queue_next
continue
//super special case, subsystems where we can't make them pause mid way through
//if we can't run them this tick (without going over a tick)
//we bump up their priority and attempt to run them next tick
//(unless we haven't even ran anything this tick, since its unlikely they will ever be able run
// in those cases, so we just let them run)
if (queue_node_flags & SS_NO_TICK_CHECK)
if (queue_node.tick_usage > TICK_LIMIT_RUNNING - world.tick_usage && ran_non_ticker)
if (!(queue_node_flags & SS_BACKGROUND))
queue_node.queued_priority += queue_priority_count * 0.1
queue_priority_count -= queue_node_priority
queue_priority_count += queue_node.queued_priority
current_tick_budget -= queue_node_priority
queue_node = queue_node.queue_next
continue
if (!bg_calc && (queue_node_flags & SS_BACKGROUND))
current_tick_budget = queue_priority_count_bg
bg_calc = TRUE
tick_remaining = TICK_LIMIT_RUNNING - world.tick_usage
if (current_tick_budget > 0 && queue_node_priority > 0)
tick_precentage = tick_remaining / (current_tick_budget / queue_node_priority)
else
tick_precentage = tick_remaining
tick_precentage = max(tick_precentage * 0.5, tick_precentage - queue_node.tick_overrun)
CURRENT_TICKLIMIT = round(world.tick_usage + tick_precentage)
if (!(queue_node_flags & SS_TICKER))
ran_non_ticker = TRUE
ran = TRUE
queue_node_paused = (queue_node.state == SS_PAUSED || queue_node.state == SS_PAUSING)
last_type_processed = queue_node
queue_node.state = SS_RUNNING
tick_usage = world.tick_usage
var/state = queue_node.ignite(queue_node_paused)
tick_usage = world.tick_usage - tick_usage
if (state == SS_RUNNING)
state = SS_IDLE
current_tick_budget -= queue_node_priority
if (tick_usage < 0)
tick_usage = 0
queue_node.tick_overrun = max(0, MC_AVG_FAST_UP_SLOW_DOWN(queue_node.tick_overrun, tick_usage - tick_precentage))
queue_node.state = state
if (state == SS_PAUSED)
queue_node.paused_ticks++
queue_node.paused_tick_usage += tick_usage
queue_node = queue_node.queue_next
continue
queue_node.ticks = MC_AVERAGE(queue_node.ticks, queue_node.paused_ticks)
tick_usage += queue_node.paused_tick_usage
queue_node.tick_usage = MC_AVERAGE_FAST(queue_node.tick_usage, tick_usage)
queue_node.cost = MC_AVERAGE_FAST(queue_node.cost, TICK_DELTA_TO_MS(tick_usage))
queue_node.paused_ticks = 0
queue_node.paused_tick_usage = 0
if (bg_calc) //update our running total
queue_priority_count_bg -= queue_node_priority
else
queue_priority_count -= queue_node_priority
queue_node.last_fire = world.time
queue_node.times_fired++
if (queue_node_flags & SS_TICKER)
queue_node.next_fire = world.time + (world.tick_lag * queue_node.wait)
else if (queue_node_flags & SS_POST_FIRE_TIMING)
queue_node.next_fire = world.time + queue_node.wait + (world.tick_lag * (queue_node.tick_overrun/100))
else if (queue_node_flags & SS_KEEP_TIMING)
queue_node.next_fire += queue_node.wait
else
queue_node.next_fire = queue_node.queued_time + queue_node.wait + (world.tick_lag * (queue_node.tick_overrun/100))
queue_node.queued_time = 0
//remove from queue
queue_node.dequeue()
queue_node = queue_node.queue_next
. = 1
//resets the queue, and all subsystems, while filtering out the subsystem lists
// called if any mc's queue procs runtime or exit improperly.
/datum/controller/master/proc/SoftReset(list/ticker_SS, list/runlevel_SS)
. = 0
log_subsystem_mastercontroller("SoftReset called, resetting MC queue state.")
if (!istype(subsystems) || !istype(ticker_SS) || !istype(runlevel_SS))
log_subsystem_mastercontroller("SoftReset: Bad list contents: '[subsystems]' '[ticker_SS]' '[runlevel_SS]' Crashing!")
return
var/subsystemstocheck = subsystems + ticker_SS
for(var/I in runlevel_SS)
subsystemstocheck |= I
for (var/thing in subsystemstocheck)
var/datum/controller/subsystem/SS = thing
if (!SS || !istype(SS))
//list(SS) is so if a list makes it in the subsystem list, we remove the list, not the contents
subsystems -= list(SS)
ticker_SS -= list(SS)
for(var/I in runlevel_SS)
I -= list(SS)
log_subsystem_mastercontroller("SoftReset: Found bad entry in subsystem list, '[SS]'")
continue
if (SS.queue_next && !istype(SS.queue_next))
log_subsystem_mastercontroller("SoftReset: Found bad data in subsystem queue, queue_next = '[SS.queue_next]'")
SS.queue_next = null
if (SS.queue_prev && !istype(SS.queue_prev))
log_subsystem_mastercontroller("SoftReset: Found bad data in subsystem queue, queue_prev = '[SS.queue_prev]'")
SS.queue_prev = null
SS.queued_priority = 0
SS.queued_time = 0
SS.state = SS_IDLE
if (queue_head && !istype(queue_head))
log_subsystem_mastercontroller("SoftReset: Found bad data in subsystem queue, queue_head = '[queue_head]'")
queue_head = null
if (queue_tail && !istype(queue_tail))
log_subsystem_mastercontroller("SoftReset: Found bad data in subsystem queue, queue_tail = '[queue_tail]'")
queue_tail = null
queue_priority_count = 0
queue_priority_count_bg = 0
log_subsystem_mastercontroller("SoftReset: Finished.")
. = 1
/datum/controller/master/proc/laggy_byond_map_update_incoming()
if(!skip_ticks)
skip_ticks = 1
/datum/controller/master/stat_entry(msg)
msg = "(FPS:[world.fps]) (TickCount:[world.time/world.tick_lag]) (TickDrift:[round(Master.tickdrift,1)] \
([round((Master.tickdrift/(world.time/world.tick_lag))*100,0.1)]%)) \
(Internal Tick Usage: [round(MAPTICK_LAST_TICK_USAGE,0.1)]%) (TickRate:[Master.processing]) \
(Iteration:[Master.iteration]) (TickLimit: [round(CURRENT_TICKLIMIT, 0.1)])"
return msg
/datum/controller/master/ExplosionStart()
for (var/thing in subsystems)
var/datum/controller/subsystem/SS = thing
SS.ExplosionStart()
/datum/controller/master/ExplosionEnd()
for (var/thing in subsystems)
var/datum/controller/subsystem/SS = thing
SS.ExplosionEnd()
/world/proc/has_round_started()
if (SSticker.current_state >= GAME_STATE_PLAYING)
return TRUE
return FALSE
/datum/controller/master/StartLoadingMap()
//disallow more than one map to load at once, multithreading it will just cause race conditions
while(map_loading)
stoplag()
for(var/S in subsystems)
var/datum/controller/subsystem/SS = S
SS.StartLoadingMap()
map_loading = TRUE
/datum/controller/master/StopLoadingMap(bounds = null)
map_loading = FALSE
for(var/S in subsystems)
var/datum/controller/subsystem/SS = S
SS.StopLoadingMap()
+143 -115
View File
@@ -2,12 +2,21 @@
/datum/controller/subsystem
// Metadata; you should define these.
name = "fire coderbus" //name of the subsystem
var/init_order = SS_INIT_MISC //order of initialization. Higher numbers are initialized first, lower numbers later. Can be decimal and negative values.
var/wait = 20 //time to wait between each call to fire(). Must be a positive integer. In ticks if SS_TICKER, deciseconds otherwise.
var/priority = SS_PRIORITY_DEFAULT //When mutiple subsystems need to run in the same tick, higher priority subsystems will run first and be given a higher share of the tick before MC_TICK_CHECK triggers a sleep.
var/flags = 0 //see master_controller.dm in __defines. Most flags must be set on world start to take full effect. (You can also restart the mc to force them to process again)
/// Name of the subsystem - you must change this
name = "fire coderbus"
/// Order of initialization. Higher numbers are initialized first, lower numbers later. Use or create defines such as [INIT_ORDER_DEFAULT] so we can see the order in one file.
var/init_order = SS_INIT_MISC
/// Time to wait (in deciseconds) between each call to fire(). Must be a positive integer.
var/wait = 20
/// Priority Weight: When mutiple subsystems need to run in the same tick, higher priority subsystems will be given a higher share of the tick before MC_TICK_CHECK triggers a sleep, higher priority subsystems also run before lower priority subsystems
var/priority = FIRE_PRIORITY_DEFAULT
/// [Subsystem Flags][SS_NO_INIT] to control binary behavior. Flags must be set at compile time or before preinit finishes to take full effect. (You can also restart the mc to force them to process again)
var/flags = NONE
/// Which stage does this subsystem init at. Earlier stages can fire while later stages init.
var/init_stage = INITSTAGE_MAIN
@@ -15,41 +24,76 @@
/// This var is set to TRUE after the subsystem has been initialized.
var/initialized = FALSE
/// Levels of the game that the SS can fire. See __defines/subsystem_priority.dm
var/runlevels = RUNLEVELS_DEFAULT
//set to 0 to prevent fire() calls, mostly for admin use.
// use the SS_NO_FIRE flag instead for systems that never fire to keep it from even being added to the list
/// Set to 0 to prevent fire() calls, mostly for admin use or subsystems that may be resumed later
/// use the [SS_NO_FIRE] flag instead for systems that never fire to keep it from even being added to list that is checked every tick
var/can_fire = TRUE
// Similar to can_fire, but intended explicitly for subsystems that are asleep. Using this var instead of can_fire
// allows admins to disable subsystems without them re-enabling themselves.
var/suspended = FALSE
// Bookkeeping variables; probably shouldn't mess with these.
var/last_fire = 0 //last world.time we called fire()
var/next_fire = 0 //scheduled world.time for next fire()
var/cost = 0 //average time to execute
var/tick_usage = 0 //average tick usage
var/tick_overrun = 0 //average tick overrun
var/state = SS_IDLE //tracks the current state of the ss, running, paused, etc.
var/paused_ticks = 0 //ticks this ss is taking to run right now.
var/paused_tick_usage //total tick_usage of all of our runs while pausing this run
var/ticks = 1 //how many ticks does this ss take to run on avg.
var/times_fired = 0 //number of times we have called fire()
var/queued_time = 0 //time we entered the queue, (for timing and priority reasons)
var/queued_priority //we keep a running total to make the math easier, if priority changes mid-fire that would break our running total, so we store it here
///Bitmap of what game states can this subsystem fire at. See [RUNLEVELS_DEFAULT] for more details.
var/runlevels = RUNLEVELS_DEFAULT //points of the game at which the SS can fire
// Subsystem startup accounting - these variables cannot be trusted if the subsystem has crashed and been Recover()'d.
var/init_state = SS_INITSTATE_NONE // The current initialization state of this SS - this might be invalid if the subsystem has been Recover()'d.
var/init_time = 0 // How long the subsystem took to initialize, in seconds.
var/init_start = 0 // What timeofday did we start initializing?
var/init_finish // What timeofday did we finish initializing?
/*
* The following variables are managed by the MC and should not be modified directly.
*/
//linked list stuff for the queue
/// Last world.time the subsystem completed a run (as in wasn't paused by [MC_TICK_CHECK])
var/last_fire = 0
/// Scheduled world.time for next fire()
var/next_fire = 0
/// Running average of the amount of milliseconds it takes the subsystem to complete a run (including all resumes but not the time spent paused)
var/cost = 0
/// Running average of the amount of tick usage in percents of a tick it takes the subsystem to complete a run
var/tick_usage = 0
/// Running average of the amount of tick usage (in percents of a game tick) the subsystem has spent past its allocated time without pausing
var/tick_overrun = 0
/// How much of a tick (in percents of a tick) were we allocated last fire.
var/tick_allocation_last = 0
/// How much of a tick (in percents of a tick) do we get allocated by the mc on avg.
var/tick_allocation_avg = 0
/// Tracks the current execution state of the subsystem. Used to handle subsystems that sleep in fire so the mc doesn't run them again while they are sleeping
var/state = SS_IDLE
/// Tracks how many times a subsystem has ever slept in fire().
var/slept_count = 0
/// Tracks how many fires the subsystem has consecutively paused on in the current run
var/paused_ticks = 0
/// Tracks how much of a tick the subsystem has consumed in the current run
var/paused_tick_usage
/// Tracks how many fires the subsystem takes to complete a run on average.
var/ticks = 1
/// Tracks the amount of completed runs for the subsystem
var/times_fired = 0
/// How many fires have we been requested to postpone
var/postponed_fires = 0
/// Time the subsystem entered the queue, (for timing and priority reasons)
var/queued_time = 0
/// Priority at the time the subsystem entered the queue. Needed to avoid changes in priority (by admins and the like) from breaking things.
var/queued_priority
/// How many times we suspect a subsystem type has crashed the MC, 3 strikes and you're out!
var/static/list/failure_strikes
/// Next subsystem in the queue of subsystems to run this tick
var/datum/controller/subsystem/queue_next
/// Previous subsystem in the queue of subsystems to run this tick
var/datum/controller/subsystem/queue_prev
var/static/list/failure_strikes //How many times we suspect a subsystem type has crashed the MC, 3 strikes and you're out! This is an assoc list indexed by type.
//Do not blindly add vars here to the bottom, put it where it goes above
//If your var only has two values, put it in as a flag.
//Do not override
///datum/controller/subsystem/New()
@@ -63,13 +107,20 @@
//This is used so the mc knows when the subsystem sleeps. do not override.
/datum/controller/subsystem/proc/ignite(resumed = 0)
SHOULD_NOT_OVERRIDE(TRUE)
set waitfor = 0
set waitfor = FALSE
. = SS_IDLE
tick_allocation_last = Master.current_ticklimit-(TICK_USAGE)
tick_allocation_avg = MC_AVERAGE(tick_allocation_avg, tick_allocation_last)
. = SS_SLEEPING
fire(resumed)
. = state
if (state == SS_SLEEPING)
slept_count++
state = SS_IDLE
if (state == SS_PAUSING)
slept_count++
var/QT = queued_time
enqueue()
state = SS_PAUSED
@@ -87,13 +138,38 @@
dequeue()
can_fire = 0
flags |= SS_NO_FIRE
Master.subsystems -= src
if (Master)
Master.subsystems -= src
return ..()
return QDEL_HINT_HARDDEL_NOW
//Queue it to run.
// (we loop thru a linked list until we get to the end or find the right point)
// (this lets us sort our run order correctly without having to re-sort the entire already sorted list)
/** Update next_fire for the next run.
* reset_time (bool) - Ignore things that would normally alter the next fire, like tick_overrun, and last_fire. (also resets postpone)
*/
/datum/controller/subsystem/proc/update_nextfire(reset_time = FALSE)
var/queue_node_flags = flags
if (reset_time)
postponed_fires = 0
if (queue_node_flags & SS_TICKER)
next_fire = world.time + (world.tick_lag * wait)
else
next_fire = world.time + wait
return
if (queue_node_flags & SS_TICKER)
next_fire = world.time + (world.tick_lag * wait)
else if (queue_node_flags & SS_POST_FIRE_TIMING)
next_fire = world.time + wait + (world.tick_lag * (tick_overrun/100))
else if (queue_node_flags & SS_KEEP_TIMING)
next_fire += wait
else
next_fire = queued_time + wait + (world.tick_lag * (tick_overrun/100))
///Queue it to run.
/// (we loop thru a linked list until we get to the end or find the right point)
/// (this lets us sort our run order correctly without having to re-sort the entire already sorted list)
/datum/controller/subsystem/proc/enqueue()
var/SS_priority = priority
var/SS_flags = flags
@@ -157,9 +233,9 @@
queue_next.queue_prev = queue_prev
if (queue_prev)
queue_prev.queue_next = queue_next
if (src == Master.queue_tail)
if (Master && (src == Master.queue_tail))
Master.queue_tail = queue_prev
if (src == Master.queue_head)
if (Master && (src == Master.queue_head))
Master.queue_head = queue_next
queued_time = 0
if (state == SS_QUEUED)
@@ -168,66 +244,28 @@
/datum/controller/subsystem/proc/pause()
. = 1
if (state == SS_RUNNING)
state = SS_PAUSED
else if (state == SS_SLEEPING)
state = SS_PAUSING
switch(state)
if(SS_RUNNING)
state = SS_PAUSED
if(SS_SLEEPING)
state = SS_PAUSING
// Do not override - Wrapper for Initialize() so initialization status can be shown for subsystems that do not return parent.
/datum/controller/subsystem/proc/StartInitialize(timeofday)
init_state = SS_INITSTATE_STARTED
init_start = timeofday
. = Initialize(timeofday)
init_finish = REALTIMEOFDAY
if (!init_time)
init_time = (init_finish - init_start) / 10
init_state = SS_INITSTATE_DONE
/// Called after the config has been loaded or reloaded.
/datum/controller/subsystem/proc/OnConfigLoad()
//used to initialize the subsystem AFTER the map has loaded
/datum/controller/subsystem/Initialize(start_timeofday)
var/time = (REALTIMEOFDAY - start_timeofday) / 10
init_time = time
var/msg = "Initialized [name] subsystem within [time] second\s!"
admin_notice(SPAN_DANGER(msg), R_DEBUG)
/**
* Used to initialize the subsystem. This is expected to be overriden by subtypes.
*/
/datum/controller/subsystem/Initialize()
return SS_INIT_NONE
// Do not print to world.log if we're running the unit tests
#if !defined(UNIT_TEST)
world.log << "SS Init: [msg]"
#endif
log_subsystem_init(msg)
return time
//hook for printing stats to the "MC" statuspanel for admins to see performance and related stats etc.
/datum/controller/subsystem/stat_entry(msg)
if(can_fire && !(SS_NO_FIRE & flags) && !Master.initializing)
if(can_fire && !(SS_NO_FIRE & flags) && init_stage <= Master.init_stage_completed)
msg = "[round(cost,1)]ms|[round(tick_usage,1)]%([round(tick_overrun,1)]%)|[round(ticks,0.1)]\t[msg]"
else
msg = "OFFLINE\t[msg]"
return msg
// Generates the message shown before a subsystem during normal MC operation.
/datum/controller/subsystem/proc/stat_entry_run()
if (flags & SS_NO_FIRE)
. = "NO FIRE"
else if (can_fire && !suspended)
. = "[round(cost,1)]ms|[round(tick_usage,1)]%([round(tick_overrun,1)]%)|[round(ticks,0.1)]"
else if (!can_fire)
. = "OFFLINE"
else
. = "SUSPEND"
/datum/controller/subsystem/proc/init_state_letter()
if (flags & SS_NO_INIT)
return
switch (init_state)
if (SS_INITSTATE_NONE)
. = "W"
if (SS_INITSTATE_STARTED)
. = "L"
if (SS_INITSTATE_DONE)
. = "D"
/datum/controller/subsystem/proc/state_letter()
switch (state)
if (SS_RUNNING)
@@ -241,34 +279,24 @@
if (SS_IDLE)
. = " "
//could be used to postpone a costly subsystem for (default one) var/cycles, cycles
//for instance, during cpu intensive operations like explosions
/// Causes the next "cycle" fires to be missed. Effect is accumulative but can reset by calling update_nextfire(reset_time = TRUE)
/datum/controller/subsystem/proc/postpone(cycles = 1)
if(next_fire - world.time < wait)
next_fire += (wait*cycles)
if (can_fire && cycles >= 1)
postponed_fires += cycles
//usually called via datum/controller/subsystem/New() when replacing a subsystem (i.e. due to a recurring crash)
//should attempt to salvage what it can from the old instance of subsystem
/datum/controller/subsystem/Recover()
// Admin-disables this subsystem. Will show as OFFLINE in MC panel.
/datum/controller/subsystem/proc/disable()
can_fire = FALSE
/datum/controller/subsystem/vv_edit_var(var_name, var_value)
switch (var_name)
if (NAMEOF(src, can_fire))
//this is so the subsystem doesn't rapid fire to make up missed ticks causing more lag
if (var_value)
update_nextfire(reset_time = TRUE)
if (NAMEOF(src, queued_priority)) //editing this breaks things.
return FALSE
. = ..()
// Admin-enables this subsystem.
/datum/controller/subsystem/proc/enable()
if (!can_fire)
next_fire = world.time + wait
can_fire = TRUE
// Suspends this subsystem. Functionally identical to disable(), but shows SUSPEND in MC panel.
// Preferred over disable() for self-disabling subsystems.
/datum/controller/subsystem/proc/suspend()
suspended = TRUE
// Wakes a suspended subsystem.
/datum/controller/subsystem/proc/wake()
if (suspended)
suspended = FALSE
if (can_fire)
next_fire = world.time + wait
/* Aurora shit */
@@ -1,6 +1,6 @@
SUBSYSTEM_DEF(ai_obfuscation)
name = "AI Obfuscation"
flags = SS_NO_FIRE
flags = SS_NO_FIRE | SS_NO_INIT
var/list/image/obfuscation_images = list()
+3 -3
View File
@@ -160,7 +160,7 @@ Total Unsimulated Turfs: [world.maxx*world.maxy*world.maxz - simulated_turf_coun
admin_notice(SPAN_DANGER("Air settling completed in [(REALTIMEOFDAY - starttime)/10] seconds!"), R_DEBUG)
..(timeofday)
return SS_INIT_SUCCESS
/datum/controller/subsystem/air/fire(resumed = FALSE, no_mc_tick = FALSE)
if (!resumed)
@@ -440,7 +440,7 @@ Total Unsimulated Turfs: [world.maxx*world.maxy*world.maxz - simulated_turf_coun
active_edges -= E
/datum/controller/subsystem/air/ExplosionStart()
suspend()
can_fire = FALSE
/datum/controller/subsystem/air/ExplosionEnd()
wake()
can_fire = TRUE
+2
View File
@@ -18,6 +18,8 @@ SUBSYSTEM_DEF(alarm)
/datum/controller/subsystem/alarm/Initialize(timeofday)
all_handlers = list(atmosphere_alarm, camera_alarm, fire_alarm, motion_alarm, power_alarm)
return SS_INIT_SUCCESS
/datum/controller/subsystem/alarm/fire(resumed = FALSE)
if (!resumed)
current = all_handlers.Copy()
+4 -3
View File
@@ -13,7 +13,8 @@ SUBSYSTEM_DEF(ao)
/datum/controller/subsystem/ao/Initialize()
fire(FALSE, TRUE)
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/ao/fire(resumed = 0, no_mc_tick = FALSE)
var/list/curr = queue
@@ -38,7 +39,7 @@ SUBSYSTEM_DEF(ao)
return
/datum/controller/subsystem/ao/ExplosionStart()
suspend()
can_fire = FALSE
/datum/controller/subsystem/ao/ExplosionEnd()
wake()
can_fire = TRUE
+3 -3
View File
@@ -27,7 +27,7 @@ SUBSYSTEM_DEF(arrivals)
current_mobs.Cut()
else
// Sleep, we ain't doin' shit. on_hotzone_enter() will wake us.
suspend()
can_fire = FALSE
// Called when a living mob enters the shuttle area.
/datum/controller/subsystem/arrivals/proc/on_hotzone_enter(mob/living/M)
@@ -37,7 +37,7 @@ SUBSYSTEM_DEF(arrivals)
if (istype(M))
current_mobs += SOFTREF(M)
wake() // Wake the process.
can_fire = TRUE // Wake the process.
if (!wait_for_launch && shuttle.location == 1 && shuttle.moving_status == SHUTTLE_IDLE)
set_launch_countdown()
@@ -72,7 +72,7 @@ SUBSYSTEM_DEF(arrivals)
/datum/controller/subsystem/arrivals/proc/set_launch_countdown()
wait_for_launch = 1
launch_time = world.time + shuttle_launch_countdown
wake()
can_fire = TRUE
/datum/controller/subsystem/arrivals/proc/stop_launch_countdown()
wait_for_launch = 0
+2 -2
View File
@@ -14,7 +14,7 @@ SUBSYSTEM_DEF(assets)
newtransporttype = /datum/asset_transport/webroot
if (newtransporttype == transport.type)
return
return SS_INIT_SUCCESS
var/datum/asset_transport/newtransport = new newtransporttype ()
if (newtransport.validate_config())
@@ -29,7 +29,7 @@ SUBSYSTEM_DEF(assets)
transport.Initialize(cache)
. = ..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/assets/Recover()
cache = SSassets.cache
@@ -30,6 +30,8 @@ SUBSYSTEM_DEF(battle_monsters)
GenerateDatum(BATTLE_MONSTERS_GEN_TRAP)
GenerateDatum(BATTLE_MONSTERS_GEN_SPELL)
return SS_INIT_SUCCESS
/datum/controller/subsystem/battle_monsters/proc/CreateCard(var/identifier,var/turf/cardloc)
var/list/splitstring = dd_text2List(identifier,",")
var/obj/item/battle_monsters/card/new_card
+2 -1
View File
@@ -86,7 +86,8 @@ SUBSYSTEM_DEF(cargo)
var/datum/cargospawner/spawner = new
spawner.start()
qdel(spawner)
..()
return SS_INIT_SUCCESS
/*
Loading Data
+1 -1
View File
@@ -7,7 +7,7 @@ var/regex/is_http_protocol = regex("^https?://")
SUBSYSTEM_DEF(chat)
name = "Chat"
flags = SS_TICKER
flags = SS_TICKER | SS_NO_INIT
wait = 1
priority = SS_PRIORITY_CHAT
init_order = SS_INIT_CHAT
+2 -1
View File
@@ -87,7 +87,8 @@ SUBSYSTEM_DEF(chemistry)
log_subsystem_chemistry("Found [pre_secret_len] reactions.")
log_subsystem_chemistry("Loaded [load_secret_chemicals()] secret reactions.")
initialize_specific_heats() // must be after reactions
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/chemistry/fire(resumed = FALSE)
if (!resumed)
+2 -1
View File
@@ -15,7 +15,6 @@ SUBSYSTEM_DEF(cult)
var/tome_data = ""
/datum/controller/subsystem/cult/Initialize()
. = ..()
for(var/rune in subtypesof(/datum/rune))
var/datum/rune/R = new rune
runes_by_name[R.name] = rune
@@ -28,6 +27,8 @@ SUBSYSTEM_DEF(cult)
limited_runes[R.type] = R.max_number_allowed //The runes created will tick the counter down to zero.
tome_data += "</div>"
return SS_INIT_SUCCESS
/datum/controller/subsystem/cult/proc/add_rune(var/datum/rune/R)
if(check_rune_limit(R))
return FALSE
+2
View File
@@ -48,6 +48,8 @@ SUBSYSTEM_DEF(discord)
GLOB.config.load("config/discord.txt", "discord")
update_channels()
return SS_INIT_SUCCESS
/datum/controller/subsystem/discord/stat_entry(msg)
msg = "A: [active] C: [length(channels)] G: [length(channels_to_group)]"
return ..()
+1 -1
View File
@@ -25,7 +25,7 @@ SUBSYSTEM_DEF(docs)
log_config("SSdocs: invalid load option specified in config")
log_subsystem_documents("invalid load option specified in config")
..()
return SS_INIT_SUCCESS
/*
Fetching Data
+1 -1
View File
@@ -22,7 +22,7 @@ SUBSYSTEM_DEF(economy)
for(var/account in GLOB.department_funds)
create_department_account(account)
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/economy/Recover()
src.station_account = SSeconomy.station_account
+2 -1
View File
@@ -6,10 +6,11 @@ SUBSYSTEM_DEF(evac)
wait = 2 SECONDS
/datum/controller/subsystem/evac/Initialize()
. = ..()
if(!evacuation_controller)
evacuation_controller = new current_map.evac_controller_type ()
evacuation_controller.set_up()
return SS_INIT_SUCCESS
/datum/controller/subsystem/evac/fire()
evacuation_controller.process()
+2
View File
@@ -37,6 +37,8 @@ SUBSYSTEM_DEF(events)
if(current_map.use_overmap)
overmap_event_handler.create_events(current_map.overmap_z, current_map.overmap_size, current_map.overmap_event_areas)
return SS_INIT_SUCCESS
/datum/controller/subsystem/events/Recover()
active_events = SSevents.active_events
finished_events = SSevents.finished_events
+4 -4
View File
@@ -10,7 +10,7 @@ SUBSYSTEM_DEF(explosives)
priority = SS_PRIORITY_EXPLOSIVES
runlevels = RUNLEVELS_PLAYING
suspended = TRUE // Start disabled, explosions will wake us if need be.
can_fire = FALSE // Start disabled, explosions will wake us if need be.
var/list/work_queue = list()
var/ticks_without_work = 0
@@ -29,7 +29,7 @@ SUBSYSTEM_DEF(explosives)
ticks_without_work++
if (ticks_without_work > 5)
// All explosions handled, we can sleep now.
suspend()
can_fire = FALSE
mc_notified = FALSE
Master.ExplosionEnd()
@@ -417,8 +417,8 @@ SUBSYSTEM_DEF(explosives)
work_queue += data
// Wake it up from sleeping if necessary.
if (suspended)
wake()
if (!can_fire)
can_fire = TRUE
/datum/controller/subsystem/explosives/stat_entry(msg)
msg ="P:[work_queue.len]"
+2 -2
View File
@@ -25,10 +25,10 @@ SUBSYSTEM_DEF(fail2topic)
log_subsystem_fail2topic("Subsystem disabled due to it not supporting UNIX.")
if (!enabled)
suspended = TRUE
can_fire = FALSE
flags |= SS_NO_FIRE
. = ..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/fail2topic/fire()
while (rate_limiting.len)
+5 -3
View File
@@ -312,14 +312,15 @@ SUBSYSTEM_DEF(garbage)
testing("CANCELLED search for references to a [usr.client.running_find_references].")
usr.client.running_find_references = null
running_find_references = null
SSgarbage.enable()
SSgarbage.can_fire = TRUE
SSgarbage.update_nextfire(reset_time = TRUE)
return
if(!skip_alert && alert(usr, "Running this will lock everything up for 5+ minutes. Would you like to begin the search?", "Find References", "Yes", "No") != "Yes")
running_find_references = null
return
SSgarbage.disable() // Keeps the GC from failing to collect objects being searched for here
SSgarbage.can_fire = FALSE // Keeps the GC from failing to collect objects being searched for here
if(usr?.client)
usr.client.running_find_references = type
@@ -356,7 +357,8 @@ SUBSYSTEM_DEF(garbage)
usr.client.running_find_references = null
running_find_references = null
SSgarbage.enable() //restart the garbage collector
SSgarbage.can_fire = TRUE //restart the garbage collector
SSgarbage.update_nextfire(reset_time = TRUE) //restart the garbage collector
/datum/proc/search_var(potential_container, container_name, recursive_limit = 64, search_time = world.time)
//If we are performing a search without a check tick, we should avoid sleeping
+2 -1
View File
@@ -18,7 +18,6 @@ SUBSYSTEM_DEF(ghostroles)
src.spawners = SSghostroles.spawners
/datum/controller/subsystem/ghostroles/Initialize(start_timeofday)
. = ..()
for(var/spawner in subtypesof(/datum/ghostspawner))
CHECK_TICK
var/datum/ghostspawner/G = new spawner
@@ -39,6 +38,8 @@ SUBSYSTEM_DEF(ghostroles)
for(var/spawn_type in spawn_types)
spawn_atom[spawn_type] = list()
return SS_INIT_SUCCESS
//Adds a spawnpoint to the spawnpoint list
/datum/controller/subsystem/ghostroles/proc/add_spawnpoints(var/obj/effect/ghostspawpoint/P)
if(!P.identifier) //If the spawnpoint has no identifier -> Abort
@@ -13,13 +13,14 @@ SUBSYSTEM_DEF(hallucinations)
var/list/all_hallucinations = list()
/datum/controller/subsystem/hallucinations/Initialize()
. = ..()
for(var/T in subtypesof(/datum/hallucination))
all_hallucinations += T
hallucinated_phrases = file2list("code/modules/hallucinations/text_lists/hallucinated_phrases.txt")
hallucinated_actions = file2list("code/modules/hallucinations/text_lists/hallucinated_actions.txt") //important note when adding to this file: "you" will always be replaced by the hallucinator's name
hallucinated_thoughts = file2list("code/modules/hallucinations/text_lists/hallucinated_thoughts.txt")
return SS_INIT_SUCCESS
/datum/controller/subsystem/hallucinations/proc/get_hallucination(var/mob/living/carbon/C)
var/list/candidates = list()
for(var/T in all_hallucinations)
+2 -1
View File
@@ -73,7 +73,8 @@ SUBSYSTEM_DEF(icon_cache)
build_dust_cache()
build_space_cache()
setup_collar_mappings()
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/icon_cache/proc/setup_collar_mappings()
collar_states = list()
+2 -2
View File
@@ -82,7 +82,7 @@ SUBSYSTEM_DEF(icon_smooth)
if (GLOB.config.fastboot)
LOG_DEBUG("icon_smoothing: Skipping prebake, fastboot enabled.")
return ..()
return SS_INIT_SUCCESS
var/list/queue = smooth_queue
smooth_queue = list()
@@ -98,7 +98,7 @@ SUBSYSTEM_DEF(icon_smooth)
CHECK_TICK
. = ..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/icon_smooth/proc/add_to_queue(atom/thing)
SHOULD_NOT_SLEEP(TRUE)
+2 -1
View File
@@ -23,7 +23,8 @@ SUBSYSTEM_DEF(icon_update)
/datum/controller/subsystem/icon_update/Initialize()
fire(FALSE, TRUE)
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/icon_update/fire(resumed = FALSE, no_mc_tick = FALSE)
var/list/icon_update_queue_cache = icon_update_queue
@@ -209,7 +209,7 @@ SUBSYSTEM_DEF(atlas)
else
current_sector = selected_sector
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/atlas/proc/load_map_directory(directory, overwrite_default_z = FALSE)
. = 0
@@ -34,7 +34,7 @@ SUBSYSTEM_DEF(atoms)
InitializeAtoms()
initialized = INITIALIZATION_INNEW_REGULAR
return ..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/atoms/proc/InitializeAtoms(list/atoms, list/atoms_to_return)
if(initialized == INITIALIZATION_INSSATOMS)
@@ -24,7 +24,8 @@ SUBSYSTEM_DEF(holomap)
/datum/controller/subsystem/holomap/Initialize()
generate_all_minimaps()
LOG_DEBUG("SSholomap: [minimaps.len] maps.")
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/holomap/proc/generate_all_minimaps()
minimaps.len = world.maxz
@@ -35,7 +35,7 @@ SUBSYSTEM_DEF(finalize)
// Generate contact report.
generate_contact_report()
..()
return SS_INIT_SUCCESS
/proc/resort_all_areas()
GLOB.all_areas = list()
@@ -47,4 +47,4 @@ SUBSYSTEM_DEF(misc_early)
click_catchers = create_click_catcher()
..()
return SS_INIT_SUCCESS
@@ -37,7 +37,7 @@ SUBSYSTEM_DEF(misc_late)
if (GLOB.config.use_forumuser_api)
update_admins_from_api(TRUE)
..(timeofday)
return SS_INIT_SUCCESS
/proc/sorted_add_area(area/A)
GLOB.all_areas += A
@@ -19,6 +19,8 @@ SUBSYSTEM_DEF(persistent_configuration)
load_from_file("data/persistent_config.json")
return SS_INIT_SUCCESS
/datum/controller/subsystem/persistent_configuration/proc/load_from_file(filename)
var/file = file2text(filename)
@@ -82,7 +82,7 @@ SUBSYSTEM_DEF(xenoarch)
var/turf/simulated/mineral/artifact_turf = pop(artifacts_spawnturf_temp)
artifact_turf.artifact_find = new()
..()
return SS_INIT_SUCCESS
#undef XENOARCH_SPAWN_CHANCE
+2 -1
View File
@@ -10,4 +10,5 @@ SUBSYSTEM_DEF(ipintel)
/datum/controller/subsystem/ipintel/Initialize()
enabled = TRUE
. = ..()
return SS_INIT_SUCCESS
+2 -1
View File
@@ -22,7 +22,6 @@ SUBSYSTEM_DEF(jobs)
var/list/deferred_preference_sanitizations = list()
/datum/controller/subsystem/jobs/Initialize()
..()
SetupOccupations()
LoadJobs("config/jobs.txt")
@@ -32,6 +31,8 @@ SUBSYSTEM_DEF(jobs)
SSticker.setup_player_ready_list()
return SS_INIT_SUCCESS
/datum/controller/subsystem/jobs/Recover()
occupations = SSjobs.occupations
unassigned = SSjobs.unassigned
+2
View File
@@ -13,6 +13,8 @@ SUBSYSTEM_DEF(law)
else
load_from_code()
return SS_INIT_SUCCESS
/datum/controller/subsystem/law/proc/load_from_code()
for (var/L in subtypesof(/datum/law/low_severity))
low_severity += new L
+3 -3
View File
@@ -48,10 +48,10 @@ SUBSYSTEM_DEF(lighting)
/datum/controller/subsystem/lighting/ExplosionStart()
force_queued = TRUE
suspend()
can_fire = FALSE
/datum/controller/subsystem/lighting/ExplosionEnd()
wake()
can_fire = TRUE
if (!force_override)
force_queued = FALSE
@@ -108,7 +108,7 @@ SUBSYSTEM_DEF(lighting)
SSticker.OnRoundstart(CALLBACK(src, PROC_REF(handle_roundstart)))
#endif
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/lighting/fire(resumed = FALSE, no_mc_tick = FALSE)
if (!resumed)
+11 -9
View File
@@ -38,6 +38,7 @@ SUBSYSTEM_DEF(machinery)
priority = SS_PRIORITY_MACHINERY
init_order = SS_INIT_MACHINERY
flags = SS_POST_FIRE_TIMING
wait = 2 SECONDS
var/static/tmp/current_step = SSMACHINERY_PIPENETS
var/static/tmp/cost_pipenets = 0
@@ -87,7 +88,8 @@ SUBSYSTEM_DEF(machinery)
build_rcon_lists()
setup_atmos_machinery(machinery)
fire(FALSE, TRUE) // Tick machinery once to pare down the list so we don't hammer the server on round-start.
..(timeofday)
return SS_INIT_SUCCESS
/datum/controller/subsystem/machinery/fire(resumed = FALSE, no_mc_tick = FALSE)
var/timer
@@ -95,7 +97,7 @@ SUBSYSTEM_DEF(machinery)
timer = world.tick_usage
process_pipenets(resumed, no_mc_tick)
cost_pipenets = MC_AVERAGE(cost_pipenets, TICK_DELTA_TO_MS(world.tick_usage - timer))
if (state != SS_RUNNING && init_state == SS_INITSTATE_DONE)
if (state != SS_RUNNING && initialized)
return
current_step = SSMACHINERY_MACHINERY
resumed = FALSE
@@ -103,7 +105,7 @@ SUBSYSTEM_DEF(machinery)
timer = world.tick_usage
process_machinery(resumed, no_mc_tick)
cost_machinery = MC_AVERAGE(cost_machinery, TICK_DELTA_TO_MS(world.tick_usage - timer))
if(state != SS_RUNNING && init_state == SS_INITSTATE_DONE)
if(state != SS_RUNNING && initialized)
return
current_step = SSMACHINERY_POWERNETS
resumed = FALSE
@@ -111,7 +113,7 @@ SUBSYSTEM_DEF(machinery)
timer = world.tick_usage
process_powernets(resumed, no_mc_tick)
cost_powernets = MC_AVERAGE(cost_powernets, TICK_DELTA_TO_MS(world.tick_usage - timer))
if(state != SS_RUNNING && init_state == SS_INITSTATE_DONE)
if(state != SS_RUNNING && initialized)
return
current_step = SSMACHINERY_POWER_OBJECTS
resumed = FALSE
@@ -119,7 +121,7 @@ SUBSYSTEM_DEF(machinery)
timer = world.tick_usage
process_power_objects(resumed, no_mc_tick)
cost_power_objects = MC_AVERAGE(cost_power_objects, TICK_DELTA_TO_MS(world.tick_usage - timer))
if (state != SS_RUNNING && init_state == SS_INITSTATE_DONE)
if (state != SS_RUNNING && initialized)
return
current_step = SSMACHINERY_PIPENETS
@@ -165,7 +167,7 @@ SUBSYSTEM_DEF(machinery)
network.isprocessing = null
pipenets -= network
continue
network.process()
network.process(wait * 0.1)
if (no_mc_tick)
CHECK_TICK
else if (MC_TICK_CHECK)
@@ -203,7 +205,7 @@ SUBSYSTEM_DEF(machinery)
continue
//process_all was moved here because of calls overhead for no benefits
if(HAS_FLAG(machine.processing_flags, MACHINERY_PROCESS_SELF))
if(machine.process() == PROCESS_KILL)
if(machine.process(wait * 0.1) == PROCESS_KILL)
STOP_PROCESSING_MACHINE(machine, MACHINERY_PROCESS_SELF)
processing -= machine
if (no_mc_tick)
@@ -267,10 +269,10 @@ SUBSYSTEM_DEF(machinery)
return ..()
/datum/controller/subsystem/machinery/ExplosionStart()
suspend()
can_fire = FALSE
/datum/controller/subsystem/machinery/ExplosionEnd()
wake()
can_fire = TRUE
/datum/controller/subsystem/machinery/proc/build_rcon_lists()
rcon_smes_units.Cut()
+2 -1
View File
@@ -18,7 +18,8 @@ SUBSYSTEM_DEF(mapping)
current_map.build_away_sites()
current_map.build_exoplanets()
. = ..(timeofday)
return SS_INIT_SUCCESS
/datum/controller/subsystem/mapping/Recover()
flags |= SS_NO_INIT
+2 -1
View File
@@ -10,7 +10,8 @@ SUBSYSTEM_DEF(materials)
/datum/controller/subsystem/materials/Initialize()
create_material_lists()
. = ..()
return SS_INIT_SUCCESS
/**
* Initialize the lists of materials, if they are not initialized already
+2
View File
@@ -57,6 +57,8 @@ SUBSYSTEM_DEF(mobs)
mtl_incorporeal = typecacheof(mtl_incorporeal)
return SS_INIT_SUCCESS
/datum/controller/subsystem/mobs/stat_entry(msg)
msg = "P:[GLOB.mob_list.len]"
return ..()
+2 -2
View File
@@ -63,7 +63,7 @@ SUBSYSTEM_DEF(mob_ai)
return
/datum/controller/subsystem/mob_ai/ExplosionStart()
suspend()
can_fire = FALSE
/datum/controller/subsystem/mob_ai/ExplosionEnd()
wake()
can_fire = TRUE
+2 -2
View File
@@ -19,7 +19,7 @@ SUBSYSTEM_DEF(news)
INVOKE_ASYNC(src, PROC_REF(load_from_forums))
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/news/proc/load_from_forums()
if (!GLOB.config.forum_api_path || !global.forum_api_key)
@@ -79,7 +79,7 @@ SUBSYSTEM_DEF(news)
var/datum/computer_file/data/news_article/news = new()
news.filename = "[channel.channel_name] vol. [total_vol_count - count_pulled + news_count]"
news.stored_data = post["content"]
ntnet_global.available_news.Add(news)
GLOB.ntnet_global.available_news.Add(news)
if (news_count > archive_limit)
news.archived = 1
+12 -9
View File
@@ -2,12 +2,15 @@ SUBSYSTEM_DEF(nightlight)
name = "Night Lighting"
wait = 5 MINUTES
init_order = SS_INIT_NIGHT
flags = SS_BACKGROUND | SS_NO_TICK_CHECK | SS_NO_FIRE
flags = SS_BACKGROUND | SS_NO_FIRE
priority = SS_PRIORITY_NIGHT
var/isactive = FALSE
var/disable_type = NL_NOT_DISABLED
/datum/controller/subsystem/nightlight/Initialize(start_timeofday)
return SS_INIT_SUCCESS
/datum/controller/subsystem/nightlight/stat_entry(msg)
msg = "A:[isactive] T:[worldtime2hours()] D:[disable_type]"
return ..()
@@ -19,14 +22,14 @@ SUBSYSTEM_DEF(nightlight)
/datum/controller/subsystem/nightlight/proc/temp_disable(time = -1)
if (disable_type != NL_PERMANENT_DISABLE)
disable_type = NL_TEMPORARY_DISABLE
suspend()
can_fire = FALSE
deactivate(FALSE)
if (time > 0)
addtimer(CALLBACK(src, PROC_REF(end_temp_disable)), time, TIMER_UNIQUE | TIMER_OVERRIDE)
/datum/controller/subsystem/nightlight/proc/end_temp_disable()
if (disable_type == NL_TEMPORARY_DISABLE)
wake()
can_fire = TRUE
// 'whitelisted' areas are areas that have nightmode explicitly enabled
@@ -61,10 +64,10 @@ SUBSYSTEM_DEF(nightlight)
/datum/controller/subsystem/nightlight/proc/is_active()
return isactive
/datum/controller/subsystem/nightlight/enable()
..()
disable_type = NL_NOT_DISABLED
// /datum/controller/subsystem/nightlight/enable()
// ..()
// disable_type = NL_NOT_DISABLED
/datum/controller/subsystem/nightlight/disable()
..()
disable_type = NL_PERMANENT_DISABLE
// /datum/controller/subsystem/nightlight/disable()
// ..()
// disable_type = NL_PERMANENT_DISABLE
+2 -1
View File
@@ -20,7 +20,8 @@ SUBSYSTEM_DEF(overlays)
/datum/controller/subsystem/overlays/Initialize()
initialized = TRUE
Flush()
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/overlays/Recover()
overlay_icon_state_caches = SSoverlays.overlay_icon_state_caches
+1 -1
View File
@@ -1,7 +1,7 @@
SUBSYSTEM_DEF(pai)
name = "pAI"
init_order = SS_INIT_MISC_FIRST
flags = SS_NO_FIRE
flags = SS_NO_FIRE | SS_NO_INIT
var/list/pai_software_by_key
var/list/default_pai_software
+1 -1
View File
@@ -78,7 +78,7 @@ SUBSYSTEM_DEF(plants)
plant_gene_datums[gene_mask] = G
gene_masked_list += (list(list("tag" = gene_tag, "mask" = gene_mask)))
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/plants/Recover()
if (istype(SSplants))
@@ -101,7 +101,7 @@ PROCESSING_SUBSYSTEM_DEF(electronics)
printer_recipe_list_upgraded += list(list(path = "[O.type]", name = "[O.name]", desc = "[O.desc]", "basic" = TRUE, "category" = category))
..()
return SS_INIT_SUCCESS
#undef IC_SPAWN_DEFAULT
#undef IC_SPAWN_RESEARCH
@@ -13,7 +13,8 @@ PROCESSING_SUBSYSTEM_DEF(ntsl2)
/datum/controller/subsystem/processing/ntsl2/Initialize(timeofday)
attempt_connect()
..()
return SS_INIT_SUCCESS
/*
* Builds request object meant to do certain action. Returns FALSE (0) when there was an issue.
@@ -34,7 +34,7 @@ SUBSYSTEM_DEF(processing)
STOP_PROCESSING(src, D)
/datum/controller/subsystem/processing/ExplosionStart()
suspend()
can_fire = FALSE
/datum/controller/subsystem/processing/ExplosionEnd()
wake()
can_fire = TRUE
@@ -3,7 +3,7 @@ var/global/list/psychic_ranks_to_strings = list("Psionically Sensitive", "Psioni
PROCESSING_SUBSYSTEM_DEF(psi)
name = "Psionics"
priority = SS_PRIORITY_PSYCHICS
flags = SS_BACKGROUND
flags = SS_BACKGROUND | SS_NO_INIT
var/checking_nlom = FALSE
var/last_nlom_awareness_check = 0
@@ -38,7 +38,8 @@ SUBSYSTEM_DEF(shuttle)
LAZYDISTINCTADD(shuttles_to_initialize, shuttle_type)
block_queue = FALSE
clear_init_queue()
. = ..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/shuttle/fire(resumed = FALSE)
if (!resumed)
+62 -44
View File
@@ -1,59 +1,77 @@
#define PROFILER_PATH(file) "./data/logs/[game_id]/profiler/[##file]"
#define PROFILER_FILENAME "profiler.json"
#define SENDMAPS_FILENAME "sendmaps.json"
SUBSYSTEM_DEF(profiler)
name = "Profiler"
wait = 1
priority = SS_PRIORITY_PROFILE
flags = SS_TICKER
init_order = INIT_ORDER_PROFILER
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
wait = 3000
var/fetch_cost = 0
var/write_cost = 0
var/last_fire_rt = 0
var/threshold = 0
var/next_restart = 0
var/restart_period = 0
/datum/controller/subsystem/profiler/stat_entry(msg)
msg += "F:[round(fetch_cost,1)]ms"
msg += "|W:[round(write_cost,1)]ms"
return msg
/datum/controller/subsystem/profiler/Initialize()
if (!GLOB.config.profiler_is_enabled)
..()
flags |= SS_NO_FIRE
return
if(GLOB.config.profiler_is_enabled)
StartProfiling()
else
StopProfiling() //Stop the early start profiler
return SS_INIT_SUCCESS
restart_period = GLOB.config.profiler_restart_period
threshold = GLOB.config.profiler_timeout_threshold
..()
/datum/controller/subsystem/profiler/Shutdown()
. = ..()
if (GLOB.config.profiler_is_enabled)
DumpData()
world.Profile(PROFILE_CLEAR, type="sendmaps")
/datum/controller/subsystem/profiler/OnConfigLoad()
if(GLOB.config.profiler_is_enabled)
StartProfiling()
can_fire = TRUE
else
StopProfiling()
can_fire = FALSE
/datum/controller/subsystem/profiler/fire()
. = world.timeofday
DumpFile()
if (!last_fire_rt)
last_fire_rt = .
next_restart = world.time + restart_period
world.Profile(PROFILE_START)
world.Profile(PROFILE_START, type="sendmaps")
/datum/controller/subsystem/profiler/Shutdown()
if(GLOB.config.profiler_is_enabled)
DumpFile(allow_yield = FALSE)
world.Profile(PROFILE_CLEAR, type = "sendmaps")
return ..()
if (. - last_fire_rt > threshold)
DumpData()
else if (world.time > next_restart)
RestartProfiler()
/datum/controller/subsystem/profiler/proc/StartProfiling()
world.Profile(PROFILE_START)
world.Profile(PROFILE_START, type = "sendmaps")
last_fire_rt = .
/datum/controller/subsystem/profiler/proc/StopProfiling()
world.Profile(PROFILE_STOP)
world.Profile(PROFILE_STOP, type = "sendmaps")
/datum/controller/subsystem/profiler/proc/DumpData()
log_perf("Profiler: dump profile after CPU spike.")
admin_notice(SPAN_DANGER("Profiler: dump profile after CPU spike."), R_SERVER|R_DEV)
/datum/controller/subsystem/profiler/proc/DumpFile(allow_yield = TRUE)
var/timer = TICK_USAGE_REAL
var/current_profile_data = world.Profile(PROFILE_REFRESH, format = "json")
var/current_sendmaps_data = world.Profile(PROFILE_REFRESH, type = "sendmaps", format="json")
fetch_cost = MC_AVERAGE(fetch_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
if(allow_yield)
CHECK_TICK
var/name = "[game_id]_[time2text(world.timeofday, "hh-mm-ss")]"
text2file(world.Profile(PROFILE_REFRESH, "json"), "data/logs/[game_id]/profiler/[name].json")
text2file(world.Profile(PROFILE_REFRESH, type = "sendmaps", format = "json"), "data/logs/[game_id]/profiler/[name]_sendmaps.json")
if(!length(current_profile_data)) //Would be nice to have explicit proc to check this
stack_trace("Warning, profiling stopped manually before dump.")
var/prof_file = file(PROFILER_PATH(PROFILER_FILENAME))
if(fexists(prof_file))
fdel(prof_file)
if(!length(current_sendmaps_data)) //Would be nice to have explicit proc to check this
stack_trace("Warning, sendmaps profiling stopped manually before dump.")
var/sendmaps_file = file(PROFILER_PATH(SENDMAPS_FILENAME))
if(fexists(sendmaps_file))
fdel(sendmaps_file)
/datum/controller/subsystem/profiler/proc/RestartProfiler()
world.Profile(PROFILE_CLEAR)
world.Profile(PROFILE_CLEAR, type="sendmaps")
next_restart = world.time + restart_period
timer = TICK_USAGE_REAL
WRITE_FILE(prof_file, current_profile_data)
WRITE_FILE(sendmaps_file, current_sendmaps_data)
write_cost = MC_AVERAGE(write_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
#undef PROFILER_FILENAME
#undef SENDMAPS_FILENAME
#undef PROFILER_PATH
+2 -1
View File
@@ -20,7 +20,6 @@ SUBSYSTEM_DEF(records)
var/list/accents = list()
/datum/controller/subsystem/records/Initialize()
..()
for(var/type in localized_fields)
localized_fields[type] = compute_localized_field(type)
@@ -28,6 +27,8 @@ SUBSYSTEM_DEF(records)
InitializeReligions()
InitializeAccents()
return SS_INIT_SUCCESS
/datum/controller/subsystem/records/PreInit()
records = list()
records_locked = list()
+2 -1
View File
@@ -20,7 +20,6 @@ SUBSYSTEM_DEF(distress)
feedback_set("responseteam_count", 0)
/datum/controller/subsystem/distress/Initialize(start_timeofday)
. = ..()
var/list/all_teams = subtypesof(/datum/responseteam)
for(var/team in all_teams)
CHECK_TICK
@@ -29,6 +28,8 @@ SUBSYSTEM_DEF(distress)
available_teams += ert
all_ert_teams += ert
return SS_INIT_SUCCESS
/datum/controller/subsystem/distress/stat_entry(msg)
msg = "CC:[can_call_ert]"
return ..()
+2 -1
View File
@@ -30,9 +30,10 @@ SUBSYSTEM_DEF(skybox)
background_color = SSatlas.current_sector.starlight_color
/datum/controller/subsystem/skybox/Initialize()
. = ..()
build_space_appearances()
return SS_INIT_SUCCESS
/datum/controller/subsystem/skybox/Recover()
skybox_cache = SSskybox.skybox_cache
@@ -117,8 +117,6 @@ SUBSYSTEM_DEF(spatial_grid)
var/number_of_oranges_ears = NUMBER_OF_PREGENERATED_ORANGES_EARS
/datum/controller/subsystem/spatial_grid/Initialize(start_timeofday)
. = ..()
cells_on_x_axis = SPATIAL_GRID_CELLS_PER_SIDE(world.maxx)
cells_on_y_axis = SPATIAL_GRID_CELLS_PER_SIDE(world.maxy)
@@ -141,6 +139,8 @@ SUBSYSTEM_DEF(spatial_grid)
RegisterSignal(SSdcs, COMSIG_GLOB_NEW_Z, PROC_REF(propogate_spatial_grid_to_new_z))
RegisterSignal(SSdcs, COMSIG_GLOB_EXPANDED_WORLD_BOUNDS, PROC_REF(after_world_bounds_expanded))
return SS_INIT_SUCCESS
///add a movable to the pre init queue for whichever type is specified so that when the subsystem initializes they get added to the grid
/datum/controller/subsystem/spatial_grid/proc/enter_pre_init_queue(atom/movable/waiting_movable, type)
RegisterSignal(waiting_movable, COMSIG_PARENT_PREQDELETED, PROC_REF(queued_item_deleted), override = TRUE)
@@ -404,7 +404,7 @@ SUBSYSTEM_DEF(spatial_grid)
* * exclusive_type - either null or a valid contents channel. if you just want to remove a single type from the grid cell then use this
*/
/datum/controller/subsystem/spatial_grid/proc/exit_cell(atom/movable/old_target, turf/target_turf, exclusive_type)
if(init_state != SS_INITSTATE_DONE)
if(!initialized)
return
if(!target_turf || !old_target?.important_recursive_contents)
@@ -448,7 +448,7 @@ SUBSYSTEM_DEF(spatial_grid)
///find the cell this movable is associated with and removes it from all lists
/datum/controller/subsystem/spatial_grid/proc/force_remove_from_cell(atom/movable/to_remove, datum/spatial_grid_cell/input_cell)
if(init_state != SS_INITSTATE_DONE)
if(!initialized)
remove_from_pre_init_queue(to_remove)//the spatial grid doesnt exist yet, so just take it out of the queue
return
@@ -473,7 +473,7 @@ SUBSYSTEM_DEF(spatial_grid)
if(remove_from_cells)
queue_list -= to_remove
if(init_state != SS_INITSTATE_DONE)
if(!initialized)
return queues_containing_movable
var/list/containing_cells = list()
+3 -1
View File
@@ -1,7 +1,7 @@
SUBSYSTEM_DEF(statistics)
name = "Statistics & Inactivity"
wait = 1 MINUTE
flags = SS_NO_TICK_CHECK | SS_BACKGROUND
flags = SS_BACKGROUND
priority = SS_PRIORITY_STATISTICS
var/kicked_clients = 0
@@ -45,6 +45,8 @@ GENERAL_PROTECT_DATUM(/datum/controller/subsystem/statistics)
sortTim(simple_statistics, GLOBAL_PROC_REF(cmp_name_asc), TRUE)
return SS_INIT_SUCCESS
/datum/controller/subsystem/statistics/fire()
// Handle AFK.
if(GLOB.config.kick_inactive)
+2 -1
View File
@@ -2,6 +2,7 @@ SUBSYSTEM_DEF(statpanels)
name = "Stat Panels"
wait = 4
init_order = SS_INIT_MISC_FIRST
flags = SS_NO_INIT
priority = SS_PRIORITY_STATPANELS
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
init_stage = INITSTAGE_EARLY
@@ -203,7 +204,7 @@ SUBSYSTEM_DEF(statpanels)
list("Instances:", "[num2text(world.contents.len, 10)]"),
list("World Time:", "[world.time]"),
list("Globals:", GLOB.stat_entry(), text_ref(GLOB)),
list("Byond:", "(FPS:[world.fps]) (TickCount:[world.time/world.tick_lag]) (TickDrift:[round(Master.tickdrift,1)]([round((Master.tickdrift/(world.time/world.tick_lag))*100,0.1)]%)) (Internal Tick Usage: [round(MAPTICK_LAST_TICK_USAGE,0.1)]%)"),
list("Byond:", "(FPS:[world.fps]) (TickCount:[world.time/world.tick_lag]) (TickDrift:[round(Master.tickdrift,1)]([round((Master.tickdrift/(world.time/world.tick_lag))*100,0.1)]%)) (Internal Tick Usage: [round(MAPTICK_LAST_INTERNAL_TICK_USAGE,0.1)]%)"),
list("Master Controller:", Master.stat_entry(), text_ref(Master)),
list("Failsafe Controller:", Failsafe.stat_entry(), text_ref(Failsafe)),
list("","")
+1 -1
View File
@@ -48,7 +48,7 @@ SUBSYSTEM_DEF(stickyban)
cache[ckey] = ban
world.SetConfig("ban", ckey, list2stickyban(ban))
return ..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/stickyban/proc/Populatedbcache()
var/newdbcache = list() //so if we runtime or the db connection dies we don't kill the existing cache
+2 -1
View File
@@ -35,7 +35,8 @@ SUBSYSTEM_DEF(sunlight)
CHECK_TICK
LOG_DEBUG("sunlight: [light_points.len] sun emitters.")
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/sunlight/proc/set_overall_light(...)
. = 0
+3 -2
View File
@@ -11,7 +11,6 @@ var/datum/controller/subsystem/ticker/SSticker
name = "Ticker"
priority = SS_PRIORITY_TICKER
flags = SS_NO_TICK_CHECK
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
init_order = SS_INIT_LOBBY
@@ -74,6 +73,8 @@ var/datum/controller/subsystem/ticker/SSticker
pregame()
restart_timeout = GLOB.config.restart_timeout
return SS_INIT_SUCCESS
/datum/controller/subsystem/ticker/stat_entry(msg)
var/state = ""
switch (current_state)
@@ -423,7 +424,7 @@ var/datum/controller/subsystem/ticker/SSticker
pregame_timeleft = LOBBY_TIME
LOG_DEBUG("SSticker: lobby reset due to game setup failure, using pregame time [LOBBY_TIME]s.")
else
var/mc_init_time = round(Master.initialization_time_taken, 1)
var/mc_init_time = round(Master.init_timeofday, 1)
var/dynamic_time = LOBBY_TIME - mc_init_time
total_players = length(GLOB.player_list)
LAZYINITLIST(ready_player_jobs)
+2 -2
View File
@@ -1,14 +1,14 @@
SUBSYSTEM_DEF(trade)
name = "Trade"
wait = 1 MINUTE
flags = SS_NO_TICK_CHECK
runlevels = RUNLEVELS_PLAYING
var/list/traders = list() //List of all nearby traders
/datum/controller/subsystem/trade/Initialize()
for(var/i in 1 to rand(1,3))
generateTrader(1)
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/trade/Recover()
traders = SStrade.traders
@@ -22,7 +22,8 @@ SUBSYSTEM_DEF(virtualreality)
robots[network] = list()
for(var/network in boundnetworks)
bounded[network] = list()
..()
return SS_INIT_SUCCESS
/datum/controller/subsystem/virtualreality/proc/add_mech(var/mob/living/heavy_vehicle/mech, var/network)
+4 -1
View File
@@ -1,7 +1,7 @@
SUBSYSTEM_DEF(vote)
name = "Voting"
wait = 1 SECOND
flags = SS_KEEP_TIMING | SS_NO_TICK_CHECK
flags = SS_KEEP_TIMING | SS_KEEP_TIMING
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
priority = SS_PRIORITY_VOTE
@@ -22,6 +22,7 @@ SUBSYSTEM_DEF(vote)
/datum/controller/subsystem/vote/Initialize(timeofday)
next_transfer_time = GLOB.config.vote_autotransfer_initial
return SS_INIT_SUCCESS
/datum/controller/subsystem/vote/fire(resumed = FALSE)
if (mode)
@@ -40,6 +41,8 @@ SUBSYSTEM_DEF(vote)
autotransfer()
next_transfer_time += GLOB.config.vote_autotransfer_interval
return SS_INIT_SUCCESS
/datum/controller/subsystem/vote/proc/autotransfer()
initiate_vote("crew_transfer","the server", 1)
LOG_DEBUG("The server has called a crew transfer vote")
+8 -6
View File
@@ -25,7 +25,7 @@ SUBSYSTEM_DEF(zcopy)
// for admin proc-call
/datum/controller/subsystem/zcopy/proc/update_all()
disable()
can_fire = FALSE
LOG_DEBUG("SSzcopy: update_all() invoked.")
var/turf/T // putting the declaration up here totally speeds it up, right?
@@ -52,11 +52,11 @@ SUBSYSTEM_DEF(zcopy)
LOG_DEBUG("SSzcopy: [num_upd + num_amupd] turf updates queued ([num_upd] direct, [num_amupd] indirect), [num_del] orphans destroyed.")
enable()
can_fire = TRUE
// for admin proc-call
/datum/controller/subsystem/zcopy/proc/hard_reset()
disable()
can_fire = FALSE
LOG_DEBUG("SSzcopy: hard_reset() invoked.")
var/num_deleted = 0
var/num_turfs = 0
@@ -77,7 +77,7 @@ SUBSYSTEM_DEF(zcopy)
LOG_DEBUG("SSzcopy: deleted [num_deleted] overlays, and queued [num_turfs] turfs for update.")
enable()
can_fire = TRUE
/datum/controller/subsystem/zcopy/stat_entry(msg)
msg = "Mx: [json_encode(zlev_maximums)] | \
@@ -98,6 +98,8 @@ SUBSYSTEM_DEF(zcopy)
// Flush the queue.
fire(FALSE, TRUE)
return SS_INIT_SUCCESS
// If you add a new Zlevel or change Z-connections, call this.
/datum/controller/subsystem/zcopy/proc/calculate_zstack_limits()
zlev_maximums = new(world.maxz)
@@ -115,10 +117,10 @@ SUBSYSTEM_DEF(zcopy)
log_subsystem("zcopy", "Z-Level maximums: [json_encode(zlev_maximums)]")
/datum/controller/subsystem/zcopy/StartLoadingMap()
suspend()
can_fire = FALSE
/datum/controller/subsystem/zcopy/StopLoadingMap()
wake()
can_fire = TRUE
/datum/controller/subsystem/zcopy/fire(resumed, no_mc_tick)
if (!resumed)
+1 -1
View File
@@ -17,7 +17,7 @@
return
var/list/available_controllers = list()
for(var/datum/controller/subsystem/SS in Master.subsystems)
if (!Master.initializing && SS.flags & SS_NO_DISPLAY)
if (MC_RUNNING() && SS.flags & SS_NO_DISPLAY)
continue
available_controllers[SS.name] = SS
available_controllers["Evacuation Controller"] = evacuation_controller