diff --git a/byond-extools.dll b/byond-extools.dll new file mode 100644 index 0000000000..a83ea1e543 Binary files /dev/null and b/byond-extools.dll differ diff --git a/code/__DEFINES/_tick.dm b/code/__DEFINES/_tick.dm index 10b815e547..fc6147c430 100644 --- a/code/__DEFINES/_tick.dm +++ b/code/__DEFINES/_tick.dm @@ -1,13 +1,28 @@ -#define TICK_LIMIT_RUNNING 80 +/// Percentage of tick to leave for master controller to run +#define MAPTICK_MC_MIN_RESERVE 70 +/// internal_tick_usage is updated every tick by extools +#define MAPTICK_LAST_INTERNAL_TICK_USAGE ((GLOB.internal_tick_usage / world.tick_lag) * 100) +/// Tick limit while running normally +#define TICK_BYOND_RESERVE 2 +#define TICK_LIMIT_RUNNING (max(100 - TICK_BYOND_RESERVE - MAPTICK_LAST_INTERNAL_TICK_USAGE, MAPTICK_MC_MIN_RESERVE)) +/// Tick limit used to resume things in stoplag #define TICK_LIMIT_TO_RUN 70 +/// Tick limit for MC while running #define TICK_LIMIT_MC 70 -#define TICK_LIMIT_MC_INIT_DEFAULT 98 +/// Tick limit while initializing +#define TICK_LIMIT_MC_INIT_DEFAULT (100 - TICK_BYOND_RESERVE) -#define TICK_USAGE world.tick_usage //for general usage -#define TICK_USAGE_REAL world.tick_usage //to be used where the result isn't checked +/// for general usage of tick_usage +#define TICK_USAGE world.tick_usage +/// to be used where the result isn't checked +#define TICK_USAGE_REAL world.tick_usage +/// Returns true if tick_usage is above the limit #define TICK_CHECK ( TICK_USAGE > Master.current_ticklimit ) +/// runs stoplag if tick_usage is above the limit #define CHECK_TICK ( TICK_CHECK ? stoplag() : 0 ) +/// Returns true if tick usage is above 95, for high priority usage #define TICK_CHECK_HIGH_PRIORITY ( TICK_USAGE > 95 ) +/// runs stoplag if tick_usage is above 95, for high priority usage #define CHECK_TICK_HIGH_PRIORITY ( TICK_CHECK_HIGH_PRIORITY? stoplag() : 0 ) diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index cadc1113c5..3abef3a61c 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -132,8 +132,15 @@ #define RUNLEVELS_DEFAULT (RUNLEVEL_SETUP | RUNLEVEL_GAME | RUNLEVEL_POSTGAME) - - +// SSair run section +#define SSAIR_PIPENETS 1 +#define SSAIR_ATMOSMACHINERY 2 +#define SSAIR_REACTQUEUE 3 +#define SSAIR_EXCITEDGROUPS 4 +#define SSAIR_HIGHPRESSURE 5 +#define SSAIR_HOTSPOTS 6 +#define SSAIR_SUPERCONDUCTIVITY 7 +#define SSAIR_REBUILD_PIPENETS 8 #define COMPILE_OVERLAYS(A)\ if (TRUE) {\ diff --git a/code/_globalvars/misc.dm b/code/_globalvars/misc.dm index af483bf888..b039e6d114 100644 --- a/code/_globalvars/misc.dm +++ b/code/_globalvars/misc.dm @@ -33,3 +33,5 @@ GLOBAL_VAR(bible_icon_state) GLOBAL_VAR(bible_item_state) GLOBAL_VAR(holy_weapon_type) GLOBAL_VAR(holy_armor_type) + +GLOBAL_VAR_INIT(internal_tick_usage, 0.2 * world.tick_lag) diff --git a/code/controllers/master.dm b/code/controllers/master.dm index 8772fac5af..db828539af 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -36,6 +36,9 @@ GLOBAL_REAL(Master, /datum/controller/master) = new var/sleep_delta = 1 + ///Only run ticker subsystems for the next n ticks. + var/skip_ticks = 0 + var/make_runtime = 0 var/initializations_finished_with_no_players_logged_in //I wonder what this could be? @@ -335,7 +338,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new new/datum/controller/failsafe() // (re)Start the failsafe. //now do the actual stuff - if (!queue_head || !(iteration % 3)) + if (!skip_ticks) var/checking_runlevel = current_runlevel if(cached_runlevel != checking_runlevel) //resechedule subsystems @@ -381,6 +384,8 @@ GLOBAL_REAL(Master, /datum/controller/master) = new iteration++ last_run = world.time + if (skip_ticks) + skip_ticks-- src.sleep_delta = MC_AVERAGE_FAST(src.sleep_delta, sleep_delta) current_ticklimit = TICK_LIMIT_RUNNING if (processing * sleep_delta <= world.tick_lag) @@ -444,10 +449,12 @@ GLOBAL_REAL(Master, /datum/controller/master) = new 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 //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 @@ -455,14 +462,15 @@ GLOBAL_REAL(Master, /datum/controller/master) = new // 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 - TICK_USAGE && ran_non_ticker) - 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 + 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 ((queue_node_flags & SS_BACKGROUND) && !bg_calc) + if (!bg_calc && (queue_node_flags & SS_BACKGROUND)) current_tick_budget = queue_priority_count_bg bg_calc = TRUE @@ -515,7 +523,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new queue_node.paused_ticks = 0 queue_node.paused_tick_usage = 0 - if (queue_node_flags & SS_BACKGROUND) //update our running total + if (bg_calc) //update our running total queue_priority_count_bg -= queue_node_priority else queue_priority_count -= queue_node_priority @@ -583,14 +591,19 @@ GLOBAL_REAL(Master, /datum/controller/master) = new 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() if(!statclick) statclick = new/obj/effect/statclick/debug(null, "Initializing...", src) - stat("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)]%))") - stat("Master Controller:", statclick.update("(TickRate:[Master.processing]) (Iteration:[Master.iteration])")) + stat("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)]%)") + stat("Master Controller:", statclick.update("(TickRate:[Master.processing]) (Iteration:[Master.iteration]) (TickLimit: [round(Master.current_ticklimit, 0.1)])")) + /datum/controller/master/StartLoadingMap() //disallow more than one map to load at once, multithreading it will just cause race conditions diff --git a/code/controllers/subsystem/air.dm b/code/controllers/subsystem/air.dm index 13facc7666..d8c7724333 100644 --- a/code/controllers/subsystem/air.dm +++ b/code/controllers/subsystem/air.dm @@ -1,11 +1,3 @@ -#define SSAIR_PIPENETS 1 -#define SSAIR_ATMOSMACHINERY 2 -#define SSAIR_REACTQUEUE 3 -#define SSAIR_EXCITEDGROUPS 4 -#define SSAIR_HIGHPRESSURE 5 -#define SSAIR_HOTSPOTS 6 -#define SSAIR_SUPERCONDUCTIVITY 7 - SUBSYSTEM_DEF(air) name = "Atmospherics" init_order = INIT_ORDER_AIR @@ -20,6 +12,7 @@ SUBSYSTEM_DEF(air) var/cost_hotspots = 0 var/cost_superconductivity = 0 var/cost_pipenets = 0 + var/cost_rebuilds = 0 var/cost_atmos_machinery = 0 var/list/excited_groups = list() @@ -27,6 +20,7 @@ SUBSYSTEM_DEF(air) var/list/turf_react_queue = list() var/list/hotspots = list() var/list/networks = list() + var/list/pipenets_needing_rebuilt = list() var/list/obj/machinery/atmos_machinery = list() var/list/pipe_init_dirs_cache = list() @@ -39,7 +33,7 @@ SUBSYSTEM_DEF(air) var/list/currentrun = list() - var/currentpart = SSAIR_PIPENETS + var/currentpart = SSAIR_REBUILD_PIPENETS var/map_loading = TRUE var/list/queued_for_activation @@ -52,6 +46,7 @@ SUBSYSTEM_DEF(air) msg += "HS:[round(cost_hotspots,1)]|" msg += "SC:[round(cost_superconductivity,1)]|" msg += "PN:[round(cost_pipenets,1)]|" + msg += "RB:[round(cost_rebuilds,1)]|" msg += "AM:[round(cost_atmos_machinery,1)]" msg += "} " msg += "AT:[active_turfs.len]|" @@ -77,6 +72,18 @@ SUBSYSTEM_DEF(air) /datum/controller/subsystem/air/fire(resumed = 0) var/timer = TICK_USAGE_REAL + if(currentpart == SSAIR_REBUILD_PIPENETS) + var/list/pipenet_rebuilds = pipenets_needing_rebuilt + for(var/thing in pipenet_rebuilds) + var/obj/machinery/atmospherics/AT = thing + AT.build_network() + cost_rebuilds = MC_AVERAGE(cost_rebuilds, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + pipenets_needing_rebuilt.Cut() + if(state != SS_RUNNING) + return + resumed = FALSE + currentpart = SSAIR_PIPENETS + if(currentpart == SSAIR_PIPENETS || !resumed) process_pipenets(resumed) cost_pipenets = MC_AVERAGE(cost_pipenets, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) @@ -137,9 +144,7 @@ SUBSYSTEM_DEF(air) if(state != SS_RUNNING) return resumed = 0 - currentpart = SSAIR_PIPENETS - - + currentpart = SSAIR_REBUILD_PIPENETS /datum/controller/subsystem/air/proc/process_pipenets(resumed = 0) if (!resumed) @@ -156,6 +161,9 @@ SUBSYSTEM_DEF(air) if(MC_TICK_CHECK) return +/datum/controller/subsystem/air/proc/add_to_rebuild_queue(atmos_machine) + if(istype(atmos_machine, /obj/machinery/atmospherics)) + pipenets_needing_rebuilt += atmos_machine /datum/controller/subsystem/air/proc/process_atmos_machinery(resumed = 0) var/seconds = wait * 0.1 diff --git a/code/game/world.dm b/code/game/world.dm index 1d719ee138..94cfb0baca 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -8,6 +8,8 @@ GLOBAL_LIST(topic_status_cache) //This happens after the Master subsystem new(s) (it's a global datum) //So subsystems globals exist, but are not initialised /world/New() + if(fexists("byond-extools.dll")) + call("byond-extools.dll", "maptick_initialize")() enable_debugger() world.Profile(PROFILE_START) diff --git a/code/modules/atmospherics/machinery/atmosmachinery.dm b/code/modules/atmospherics/machinery/atmosmachinery.dm index 864edfdbe6..8f5ab7dd5e 100644 --- a/code/modules/atmospherics/machinery/atmosmachinery.dm +++ b/code/modules/atmospherics/machinery/atmosmachinery.dm @@ -64,6 +64,7 @@ nullifyNode(i) SSair.atmos_machinery -= src + SSair.pipenets_needing_rebuilt -= src dropContents() if(pipe_vision_img) diff --git a/code/modules/atmospherics/machinery/components/binary_devices/circulator.dm b/code/modules/atmospherics/machinery/components/binary_devices/circulator.dm index 73cb8eeecb..c164dc5ae3 100644 --- a/code/modules/atmospherics/machinery/components/binary_devices/circulator.dm +++ b/code/modules/atmospherics/machinery/components/binary_devices/circulator.dm @@ -116,7 +116,7 @@ if(node2) node2.atmosinit() node2.addMember(src) - build_network() + SSair.add_to_rebuild_queue(src) return TRUE diff --git a/code/modules/atmospherics/machinery/components/components_base.dm b/code/modules/atmospherics/machinery/components/components_base.dm index 63a03b1d40..a45728d51f 100644 --- a/code/modules/atmospherics/machinery/components/components_base.dm +++ b/code/modules/atmospherics/machinery/components/components_base.dm @@ -144,7 +144,7 @@ var/datum/pipeline/parent = parents[i] if(!parent) stack_trace("Component is missing a pipenet! Rebuilding...") - build_network() + SSair.add_to_rebuild_queue(src) parent.update = 1 /obj/machinery/atmospherics/components/returnPipenets() diff --git a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm index e013a86fd2..38042fe64d 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm @@ -447,6 +447,6 @@ if(node) node.atmosinit() node.addMember(src) - build_network() + SSair.add_to_rebuild_queue(src) #undef CRYOMOBS diff --git a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm index dbe3c0b90b..dddfdf08c1 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/thermomachine.dm @@ -116,7 +116,7 @@ if(node) node.atmosinit() node.addMember(src) - build_network() + SSair.add_to_rebuild_queue(src) return TRUE /obj/machinery/atmospherics/components/unary/thermomachine/ui_status(mob/user) diff --git a/code/modules/atmospherics/machinery/pipes/layermanifold.dm b/code/modules/atmospherics/machinery/pipes/layermanifold.dm index 33092f5354..bc8fd6777d 100644 --- a/code/modules/atmospherics/machinery/pipes/layermanifold.dm +++ b/code/modules/atmospherics/machinery/pipes/layermanifold.dm @@ -31,7 +31,7 @@ nodes = list() for(var/obj/machinery/atmospherics/A in needs_nullifying) A.disconnect(src) - A.build_network() + SSair.add_to_rebuild_queue(A) /obj/machinery/atmospherics/pipe/layer_manifold/proc/get_all_connected_nodes() return front_nodes + back_nodes + nodes diff --git a/code/modules/atmospherics/machinery/pipes/pipes.dm b/code/modules/atmospherics/machinery/pipes/pipes.dm index 1e513b846c..c466a422b2 100644 --- a/code/modules/atmospherics/machinery/pipes/pipes.dm +++ b/code/modules/atmospherics/machinery/pipes/pipes.dm @@ -22,7 +22,7 @@ var/obj/machinery/atmospherics/oldN = nodes[i] ..() if(oldN) - oldN.build_network() + SSair.add_to_rebuild_queue(oldN) /obj/machinery/atmospherics/pipe/destroy_network() QDEL_NULL(parent) diff --git a/code/modules/atmospherics/machinery/portable/canister.dm b/code/modules/atmospherics/machinery/portable/canister.dm index a41bdee3b6..03463ff0f7 100644 --- a/code/modules/atmospherics/machinery/portable/canister.dm +++ b/code/modules/atmospherics/machinery/portable/canister.dm @@ -159,7 +159,6 @@ /obj/machinery/portable_atmospherics/canister/proto name = "prototype canister" - /obj/machinery/portable_atmospherics/canister/proto/default name = "prototype canister" desc = "The best way to fix an atmospheric emergency... or the best way to introduce one." @@ -172,7 +171,6 @@ can_min_release_pressure = (ONE_ATMOSPHERE / 30) prototype = TRUE - /obj/machinery/portable_atmospherics/canister/proto/default/oxygen name = "prototype canister" desc = "A prototype canister for a prototype bike, what could go wrong?" @@ -181,8 +179,6 @@ filled = 1 release_pressure = ONE_ATMOSPHERE*2 - - /obj/machinery/portable_atmospherics/canister/New(loc, datum/gas_mixture/existing_mixture) ..() if(existing_mixture) @@ -192,7 +188,7 @@ pump = new(src, FALSE) pump.on = TRUE pump.stat = 0 - pump.build_network() + SSair.add_to_rebuild_queue(pump) update_icon() @@ -208,6 +204,7 @@ air_contents.gases[gas_type] = (maximum_pressure * filled) * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature) if(starter_temp) air_contents.temperature = starter_temp + /obj/machinery/portable_atmospherics/canister/air/create_gas() air_contents.gases[/datum/gas/oxygen] = (O2STANDARD * maximum_pressure * filled) * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature) air_contents.gases[/datum/gas/nitrogen] = (N2STANDARD * maximum_pressure * filled) * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature) diff --git a/code/modules/atmospherics/machinery/portable/pump.dm b/code/modules/atmospherics/machinery/portable/pump.dm index 18e4da621a..377e9285e3 100644 --- a/code/modules/atmospherics/machinery/portable/pump.dm +++ b/code/modules/atmospherics/machinery/portable/pump.dm @@ -20,7 +20,7 @@ pump = new(src, FALSE) pump.on = TRUE pump.stat = 0 - pump.build_network() + SSair.add_to_rebuild_queue(pump) /obj/machinery/portable_atmospherics/pump/Destroy() var/turf/T = get_turf(src) diff --git a/code/modules/shuttle/on_move.dm b/code/modules/shuttle/on_move.dm index 701c153783..8c1b3fa955 100644 --- a/code/modules/shuttle/on_move.dm +++ b/code/modules/shuttle/on_move.dm @@ -249,7 +249,7 @@ All ShuttleMove procs go here A.atmosinit() if(A.returnPipenet()) A.addMember(src) - build_network() + SSair.add_to_rebuild_queue(src) else // atmosinit() calls update_icon(), so we don't need to call it update_icon()