From b996d5c6b2a34f9a1f3de2f88bfc347f0cdb1da5 Mon Sep 17 00:00:00 2001 From: Leshana Date: Wed, 7 Jun 2017 13:55:34 -0400 Subject: [PATCH] Ports utility macros to let subsystems divide their time among a few tasks Port of https://github.com/tgstation/tgstation/pull/26324 --- code/__defines/MC.dm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/code/__defines/MC.dm b/code/__defines/MC.dm index 08b8d223ec7..59fb0d4db73 100644 --- a/code/__defines/MC.dm +++ b/code/__defines/MC.dm @@ -1,4 +1,15 @@ #define MC_TICK_CHECK ( ( world.tick_usage > CURRENT_TICKLIMIT || src.state != SS_RUNNING ) ? pause() : 0 ) + +// Used for splitting up your remaining time into phases, if you want to evenly divide it. +#define MC_SPLIT_TICK_INIT(phase_count) var/original_tick_limit = CURRENT_TICKLIMIT; var/split_tick_phases = ##phase_count +#define MC_SPLIT_TICK \ + if(split_tick_phases > 1){\ + CURRENT_TICKLIMIT = ((original_tick_limit - world.tick_usage) / split_tick_phases) + world.tick_usage;\ + --split_tick_phases;\ + } else {\ + CURRENT_TICKLIMIT = original_tick_limit;\ + } + // Used to smooth out costs to try and avoid oscillation. #define MC_AVERAGE_FAST(average, current) (0.7 * (average) + 0.3 * (current)) #define MC_AVERAGE(average, current) (0.8 * (average) + 0.2 * (current))