From 2e41fc6ef3f8ba824fd1eb04aff73303090255e9 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 17 Apr 2017 13:50:22 -0400 Subject: [PATCH] Adds defines for evenly splitting up a subsystem's time to fire --- code/__DEFINES/MC.dm | 10 ++++++++++ code/controllers/subsystem/lighting.dm | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/code/__DEFINES/MC.dm b/code/__DEFINES/MC.dm index 130e3dd671c6..eb148e7b5966 100644 --- a/code/__DEFINES/MC.dm +++ b/code/__DEFINES/MC.dm @@ -1,4 +1,14 @@ #define MC_TICK_CHECK ( ( world.tick_usage > GLOB.CURRENT_TICKLIMIT || src.state != SS_RUNNING ) ? pause() : 0 ) + +#define MC_SPLIT_TICK_INIT(phase_count) var/original_tick_limit = GLOB.CURRENT_TICKLIMIT; var/split_tick_phases = ##phase_count +#define MC_SPLIT_TICK \ + if(split_tick_phases > 1){\ + GLOB.CURRENT_TICKLIMIT = ((original_tick_limit - world.tick_usage) / split_tick_phases) + world.tick_usage;\ + --split_tick_phases;\ + } else {\ + GLOB.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)) diff --git a/code/controllers/subsystem/lighting.dm b/code/controllers/subsystem/lighting.dm index a6547cd9038a..128562916087 100644 --- a/code/controllers/subsystem/lighting.dm +++ b/code/controllers/subsystem/lighting.dm @@ -28,10 +28,9 @@ SUBSYSTEM_DEF(lighting) ..() /datum/controller/subsystem/lighting/fire(resumed, init_tick_checks) - var/real_tick_limit + MC_SPLIT_TICK_INIT(3) if(!init_tick_checks) - real_tick_limit = GLOB.CURRENT_TICKLIMIT - GLOB.CURRENT_TICKLIMIT = ((real_tick_limit - world.tick_usage) / 3) + world.tick_usage + MC_SPLIT_TICK var/i = 0 for (i in 1 to GLOB.lighting_update_lights.len) var/datum/light_source/L = GLOB.lighting_update_lights[i] @@ -57,7 +56,7 @@ SUBSYSTEM_DEF(lighting) i = 0 if(!init_tick_checks) - GLOB.CURRENT_TICKLIMIT = ((real_tick_limit - world.tick_usage)/2)+world.tick_usage + MC_SPLIT_TICK for (i in 1 to GLOB.lighting_update_corners.len) var/datum/lighting_corner/C = GLOB.lighting_update_corners[i] @@ -74,7 +73,7 @@ SUBSYSTEM_DEF(lighting) if(!init_tick_checks) - GLOB.CURRENT_TICKLIMIT = real_tick_limit + MC_SPLIT_TICK for (i in 1 to GLOB.lighting_update_objects.len) var/atom/movable/lighting_object/O = GLOB.lighting_update_objects[i]