diff --git a/code/__DEFINES/MC.dm b/code/__DEFINES/MC.dm index 92d3f019820..cbcf2c1dd90 100644 --- a/code/__DEFINES/MC.dm +++ b/code/__DEFINES/MC.dm @@ -1,9 +1,9 @@ -#define MC_TICK_CHECK ( ( world.tick_usage > Master.current_ticklimit || src.state != SS_RUNNING ) ? pause() : 0 ) +#define MC_TICK_CHECK ( ( TICK_USAGE > Master.current_ticklimit || src.state != SS_RUNNING ) ? pause() : 0 ) #define MC_SPLIT_TICK_INIT(phase_count) var/original_tick_limit = Master.current_ticklimit; var/split_tick_phases = ##phase_count #define MC_SPLIT_TICK \ if(split_tick_phases > 1){\ - Master.current_ticklimit = ((original_tick_limit - world.tick_usage) / split_tick_phases) + world.tick_usage;\ + Master.current_ticklimit = ((original_tick_limit - TICK_USAGE) / split_tick_phases) + TICK_USAGE;\ --split_tick_phases;\ } else {\ Master.current_ticklimit = original_tick_limit;\ diff --git a/code/__DEFINES/_tick.dm b/code/__DEFINES/_tick.dm new file mode 100644 index 00000000000..93ac8ed70d6 --- /dev/null +++ b/code/__DEFINES/_tick.dm @@ -0,0 +1,10 @@ +#define TICK_LIMIT_RUNNING 80 +#define TICK_LIMIT_TO_RUN 78 +#define TICK_LIMIT_MC 70 +#define TICK_LIMIT_MC_INIT_DEFAULT 98 + +#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 + +#define TICK_CHECK ( TICK_USAGE > Master.current_ticklimit ) +#define CHECK_TICK if TICK_CHECK stoplag() diff --git a/code/__DEFINES/math.dm b/code/__DEFINES/math.dm index cb86b82efe9..534e0d3608b 100644 --- a/code/__DEFINES/math.dm +++ b/code/__DEFINES/math.dm @@ -14,7 +14,7 @@ //percent_of_tick_used * (ticklag * 100(to convert to ms)) / 100(percent ratio) //collapsed to percent_of_tick_used * tick_lag #define TICK_DELTA_TO_MS(percent_of_tick_used) ((percent_of_tick_used) * world.tick_lag) -#define TICK_USAGE_TO_MS(starting_tickusage) (TICK_DELTA_TO_MS(world.tick_usage-starting_tickusage)) +#define TICK_USAGE_TO_MS(starting_tickusage) (TICK_DELTA_TO_MS(TICK_USAGE_REAL - starting_tickusage)) #define PERCENT(val) (round(val*100, 0.1)) #define CLAMP01(x) (Clamp(x, 0, 1)) diff --git a/code/__DEFINES/tick.dm b/code/__DEFINES/tick.dm deleted file mode 100644 index 4c88fd643ea..00000000000 --- a/code/__DEFINES/tick.dm +++ /dev/null @@ -1,7 +0,0 @@ -#define TICK_LIMIT_RUNNING 80 -#define TICK_LIMIT_TO_RUN 78 -#define TICK_LIMIT_MC 70 -#define TICK_LIMIT_MC_INIT_DEFAULT 98 - -#define TICK_CHECK ( world.tick_usage > Master.current_ticklimit ) -#define CHECK_TICK if TICK_CHECK stoplag() diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index d62eed51597..d8920b0898b 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1241,7 +1241,7 @@ proc/pick_closest_path(value, list/matches = get_fancy_list_of_atom_types()) //Increases delay as the server gets more overloaded, //as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful -#define DELTA_CALC max(((max(world.tick_usage, world.cpu) / 100) * max(Master.sleep_delta,1)), 1) +#define DELTA_CALC max(((max(TICK_USAGE, world.cpu) / 100) * max(Master.sleep_delta,1)), 1) /proc/stoplag() if (!Master || !(Master.current_runlevel & RUNLEVELS_DEFAULT)) @@ -1253,7 +1253,7 @@ proc/pick_closest_path(value, list/matches = get_fancy_list_of_atom_types()) . += round(i*DELTA_CALC) sleep(i*world.tick_lag*DELTA_CALC) i *= 2 - while (world.tick_usage > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit)) + while (TICK_USAGE > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit)) #undef DELTA_CALC diff --git a/code/controllers/master.dm b/code/controllers/master.dm index b48cdad78c8..6981748198b 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -288,7 +288,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new //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, so longer sleeps are more likely to run first - if (world.tick_usage > TICK_LIMIT_MC) + if (TICK_USAGE > TICK_LIMIT_MC) sleep_delta += 2 current_ticklimit = TICK_LIMIT_RUNNING * 0.5 sleep(world.tick_lag * (processing + sleep_delta)) @@ -297,7 +297,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new sleep_delta = MC_AVERAGE_FAST(sleep_delta, 0) if (last_run + (world.tick_lag * processing) > world.time) sleep_delta += 1 - if (world.tick_usage > (TICK_LIMIT_MC*0.5)) + if (TICK_USAGE > (TICK_LIMIT_MC*0.5)) sleep_delta += 1 if (make_runtime) @@ -403,13 +403,13 @@ GLOBAL_REAL(Master, /datum/controller/master) = new //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) + 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 && world.tick_usage > TICK_LIMIT_RUNNING) + if (ran && TICK_USAGE > TICK_LIMIT_RUNNING) break queue_node_flags = queue_node.flags @@ -421,7 +421,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new //(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.tick_usage > TICK_LIMIT_RUNNING - TICK_USAGE && ran_non_ticker) queue_node.queued_priority += queue_priority_count * 0.10 queue_priority_count -= queue_node_priority queue_priority_count += queue_node.queued_priority @@ -433,7 +433,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new current_tick_budget = queue_priority_count_bg bg_calc = TRUE - tick_remaining = TICK_LIMIT_RUNNING - world.tick_usage + tick_remaining = TICK_LIMIT_RUNNING - TICK_USAGE if (current_tick_budget > 0 && queue_node_priority > 0) tick_precentage = tick_remaining / (current_tick_budget / queue_node_priority) @@ -442,7 +442,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new tick_precentage = max(tick_precentage*0.5, tick_precentage-queue_node.tick_overrun) - current_ticklimit = round(world.tick_usage + tick_precentage) + current_ticklimit = round(TICK_USAGE + tick_precentage) if (!(queue_node_flags & SS_TICKER)) ran_non_ticker = TRUE @@ -453,9 +453,9 @@ GLOBAL_REAL(Master, /datum/controller/master) = new queue_node.state = SS_RUNNING - tick_usage = world.tick_usage + tick_usage = TICK_USAGE var/state = queue_node.ignite(queue_node_paused) - tick_usage = world.tick_usage - tick_usage + tick_usage = TICK_USAGE - tick_usage if (state == SS_RUNNING) state = SS_IDLE diff --git a/code/controllers/subsystem/air.dm b/code/controllers/subsystem/air.dm index a9a177597a5..8eb7392db88 100644 --- a/code/controllers/subsystem/air.dm +++ b/code/controllers/subsystem/air.dm @@ -71,65 +71,65 @@ SUBSYSTEM_DEF(air) /datum/controller/subsystem/air/fire(resumed = 0) - var/timer = world.tick_usage + var/timer = TICK_USAGE_REAL if(currentpart == SSAIR_PIPENETS || !resumed) process_pipenets(resumed) - cost_pipenets = MC_AVERAGE(cost_pipenets, TICK_DELTA_TO_MS(world.tick_usage - timer)) + cost_pipenets = MC_AVERAGE(cost_pipenets, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) if(state != SS_RUNNING) return resumed = 0 currentpart = SSAIR_ATMOSMACHINERY if(currentpart == SSAIR_ATMOSMACHINERY) - timer = world.tick_usage + timer = TICK_USAGE_REAL process_atmos_machinery(resumed) - cost_atmos_machinery = MC_AVERAGE(cost_atmos_machinery, TICK_DELTA_TO_MS(world.tick_usage - timer)) + cost_atmos_machinery = MC_AVERAGE(cost_atmos_machinery, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) if(state != SS_RUNNING) return resumed = 0 currentpart = SSAIR_ACTIVETURFS if(currentpart == SSAIR_ACTIVETURFS) - timer = world.tick_usage + timer = TICK_USAGE_REAL process_active_turfs(resumed) - cost_turfs = MC_AVERAGE(cost_turfs, TICK_DELTA_TO_MS(world.tick_usage - timer)) + cost_turfs = MC_AVERAGE(cost_turfs, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) if(state != SS_RUNNING) return resumed = 0 currentpart = SSAIR_EXCITEDGROUPS if(currentpart == SSAIR_EXCITEDGROUPS) - timer = world.tick_usage + timer = TICK_USAGE_REAL process_excited_groups(resumed) - cost_groups = MC_AVERAGE(cost_groups, TICK_DELTA_TO_MS(world.tick_usage - timer)) + cost_groups = MC_AVERAGE(cost_groups, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) if(state != SS_RUNNING) return resumed = 0 currentpart = SSAIR_HIGHPRESSURE if(currentpart == SSAIR_HIGHPRESSURE) - timer = world.tick_usage + timer = TICK_USAGE_REAL process_high_pressure_delta(resumed) - cost_highpressure = MC_AVERAGE(cost_highpressure, TICK_DELTA_TO_MS(world.tick_usage - timer)) + cost_highpressure = MC_AVERAGE(cost_highpressure, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) if(state != SS_RUNNING) return resumed = 0 currentpart = SSAIR_HOTSPOTS if(currentpart == SSAIR_HOTSPOTS) - timer = world.tick_usage + timer = TICK_USAGE_REAL process_hotspots(resumed) - cost_hotspots = MC_AVERAGE(cost_hotspots, TICK_DELTA_TO_MS(world.tick_usage - timer)) + cost_hotspots = MC_AVERAGE(cost_hotspots, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) if(state != SS_RUNNING) return resumed = 0 currentpart = SSAIR_SUPERCONDUCTIVITY if(currentpart == SSAIR_SUPERCONDUCTIVITY) - timer = world.tick_usage + timer = TICK_USAGE_REAL process_super_conductivity(resumed) - cost_superconductivity = MC_AVERAGE(cost_superconductivity, TICK_DELTA_TO_MS(world.tick_usage - timer)) + cost_superconductivity = MC_AVERAGE(cost_superconductivity, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) if(state != SS_RUNNING) return resumed = 0 diff --git a/code/controllers/subsystem/garbage.dm b/code/controllers/subsystem/garbage.dm index b17f95b9983..8502280aafc 100644 --- a/code/controllers/subsystem/garbage.dm +++ b/code/controllers/subsystem/garbage.dm @@ -147,7 +147,7 @@ SUBSYSTEM_DEF(garbage) //this is purely to separate things profile wise. /datum/controller/subsystem/garbage/proc/HardDelete(datum/A) var/time = world.timeofday - var/tick = world.tick_usage + var/tick = TICK_USAGE var/ticktime = world.time var/type = A.type @@ -155,7 +155,7 @@ SUBSYSTEM_DEF(garbage) del(A) - tick = (world.tick_usage-tick+((world.time-ticktime)/world.tick_lag*100)) + tick = (TICK_USAGE-tick+((world.time-ticktime)/world.tick_lag*100)) if (tick > highest_del_tickusage) highest_del_tickusage = tick time = world.timeofday - time diff --git a/code/controllers/subsystem/server_maint.dm b/code/controllers/subsystem/server_maint.dm index 855c00b7282..ec34cfb8edb 100644 --- a/code/controllers/subsystem/server_maint.dm +++ b/code/controllers/subsystem/server_maint.dm @@ -33,7 +33,7 @@ SUBSYSTEM_DEF(server_maint) qdel(C) if (!(!C || world.time - C.connection_time < PING_BUFFER_TIME || C.inactivity >= (wait-1))) - winset(C, null, "command=.update_ping+[world.time+world.tick_lag*world.tick_usage/100]") + winset(C, null, "command=.update_ping+[world.time+world.tick_lag*TICK_USAGE_REAL/100]") if (MC_TICK_CHECK) //one day, when ss13 has 1000 people per server, you guys are gonna be glad I added this tick check return diff --git a/code/modules/client/verbs/ping.dm b/code/modules/client/verbs/ping.dm index 41bd1b889cf..de19d0d52ce 100644 --- a/code/modules/client/verbs/ping.dm +++ b/code/modules/client/verbs/ping.dm @@ -9,7 +9,7 @@ avgping = MC_AVERAGE_SLOW(avgping, ping) /client/proc/pingfromtime(time) - return ((world.time+world.tick_lag*world.tick_usage/100)-time)*100 + return ((world.time+world.tick_lag*TICK_USAGE_REAL/100)-time)*100 /client/verb/display_ping(time as num) set instant = TRUE @@ -19,4 +19,4 @@ /client/verb/ping() set name = "Ping" set category = "OOC" - winset(src, null, "command=.display_ping+[world.time+world.tick_lag*world.tick_usage/100]") \ No newline at end of file + winset(src, null, "command=.display_ping+[world.time+world.tick_lag*TICK_USAGE_REAL/100]") \ No newline at end of file diff --git a/tgstation.dme b/tgstation.dme index b018e5cd075..9353fa2c852 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -21,6 +21,7 @@ #include "code\__DATASTRUCTURES\linked_lists.dm" #include "code\__DATASTRUCTURES\priority_queue.dm" #include "code\__DATASTRUCTURES\stacks.dm" +#include "code\__DEFINES\_tick.dm" #include "code\__DEFINES\access.dm" #include "code\__DEFINES\admin.dm" #include "code\__DEFINES\antagonists.dm" @@ -70,7 +71,6 @@ #include "code\__DEFINES\status_effects.dm" #include "code\__DEFINES\subsystems.dm" #include "code\__DEFINES\tgui.dm" -#include "code\__DEFINES\tick.dm" #include "code\__DEFINES\time.dm" #include "code\__DEFINES\typeids.dm" #include "code\__DEFINES\vv.dm"