From d697800325a052e3a7cdb88e2d5e7df9cf27aec5 Mon Sep 17 00:00:00 2001 From: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Date: Fri, 6 Oct 2023 03:09:50 -0400 Subject: [PATCH] world.fps and SStimers safety check (#9478) * https://github.com/tgstation/tgstation/pull/45236 * uncomment unused --- code/controllers/master.dm | 2 +- code/game/world.dm | 23 +++++++++++++++++++++++ code/modules/admin/verbs/fps.dm | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/code/controllers/master.dm b/code/controllers/master.dm index 230d880be63d9..9e56eb1435216 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -234,7 +234,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new // Sort subsystems by display setting for easy access. sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_display)) // Set world options. - world.fps = CONFIG_GET(number/fps) + world.change_fps(CONFIG_GET(number/fps)) var/initialized_tod = REALTIMEOFDAY if(sleep_offline_after_initializations) diff --git a/code/game/world.dm b/code/game/world.dm index a9d2320094faa..e4aed1eec9f7c 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -411,6 +411,29 @@ GLOBAL_VAR(restart_counter) /world/proc/refresh_atmos_grid() +/world/proc/change_fps(new_value = 20) + if(new_value <= 0) + CRASH("change_fps() called with [new_value] new_value.") + if(fps == new_value) + return //No change required. + + fps = new_value + on_tickrate_change() + +/* UNUSED. uncomment if using +/world/proc/change_tick_lag(new_value = 0.5) + if(new_value <= 0) + CRASH("change_tick_lag() called with [new_value] new_value.") + if(tick_lag == new_value) + return //No change required. + + tick_lag = new_value + on_tickrate_change() +*/ + +/world/proc/on_tickrate_change() + SStimer?.reset_buckets() + /world/proc/init_byond_tracy() var/library diff --git a/code/modules/admin/verbs/fps.dm b/code/modules/admin/verbs/fps.dm index 2b65d2a44c5a0..a738955052612 100644 --- a/code/modules/admin/verbs/fps.dm +++ b/code/modules/admin/verbs/fps.dm @@ -23,4 +23,4 @@ SSblackbox.record_feedback("nested tally", "admin_toggle", 1, list("Set Server FPS", "[new_fps]")) //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! CONFIG_SET(number/fps, new_fps) - world.fps = new_fps + world.change_fps(new_fps)