From 2ec545c42b75053954e54804b1011cc2f4c95a33 Mon Sep 17 00:00:00 2001 From: Atermonera Date: Sun, 22 Mar 2020 17:16:48 -0700 Subject: [PATCH] Merge pull request #6883 from VOREStation/vplk-port-tickrate-change Safely change world.fps for SStimer --- code/controllers/master.dm | 2 +- code/game/world.dm | 14 ++++++++++++++ code/modules/admin/verbs/fps.dm | 23 +++++++++++++++++++++++ code/modules/admin/verbs/mapping.dm | 2 +- code/modules/admin/verbs/ticklag.dm | 24 ------------------------ vorestation.dme | 2 +- 6 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 code/modules/admin/verbs/fps.dm delete mode 100644 code/modules/admin/verbs/ticklag.dm diff --git a/code/controllers/master.dm b/code/controllers/master.dm index 0b292e45c44..644ab8d2f0d 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -196,7 +196,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new #else world.sleep_offline = 1 #endif - world.fps = config.fps + world.change_fps(config.fps) var/initialized_tod = REALTIMEOFDAY sleep(1) initializations_finished_with_no_players_logged_in = initialized_tod < REALTIMEOFDAY - 10 diff --git a/code/game/world.dm b/code/game/world.dm index 4d3c8eb22cc..52927b7dd72 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -646,4 +646,18 @@ proc/establish_old_db_connection() maxz++ max_z_changed() +// Call this to change world.fps, don't modify it directly. +/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() + +// Called whenver world.tick_lag or world.fps are changed. +/world/proc/on_tickrate_change() + SStimer?.reset_buckets() + #undef FAILED_DB_CONNECTION_CUTOFF diff --git a/code/modules/admin/verbs/fps.dm b/code/modules/admin/verbs/fps.dm new file mode 100644 index 00000000000..fbafc004dbf --- /dev/null +++ b/code/modules/admin/verbs/fps.dm @@ -0,0 +1,23 @@ +//Merged Doohl's and the existing ticklag as they both had good elements about them ~ +//Replaces the old Ticklag verb, fps is easier to understand +/client/proc/set_server_fps() + set category = "Debug" + set name = "Set Server FPS" + set desc = "Sets game speed in frames-per-second. Can potentially break the game" + + if(!check_rights(R_DEBUG)) + return + + var/new_fps = round(input("Sets game frames-per-second. Can potentially break the game (default: [config.fps])", "FPS", world.fps) as num|null) + if(new_fps <= 0) + to_chat(src, "Error: set_server_fps(): Invalid world.fps value. No changes made.") + return + if(new_fps > config.fps * 1.5) + if(alert(src, "You are setting fps to a high value:\n\t[new_fps] frames-per-second\n\tconfig.fps = [config.fps]", "Warning!", "Confirm", "ABORT-ABORT-ABORT") != "Confirm") + return + + var/msg = "[key_name(src)] has modified world.fps to [new_fps]" + log_admin(msg, 0) + message_admins(msg, 0) + world.change_fps(new_fps) + feedback_add_details("admin_verb", "SETFPS") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! diff --git a/code/modules/admin/verbs/mapping.dm b/code/modules/admin/verbs/mapping.dm index 5dd933abef6..12e0bd6d968 100644 --- a/code/modules/admin/verbs/mapping.dm +++ b/code/modules/admin/verbs/mapping.dm @@ -139,7 +139,7 @@ var/list/debug_verbs = list ( ,/client/proc/cmd_assume_direct_control ,/client/proc/jump_to_dead_group ,/client/proc/startSinglo - ,/client/proc/ticklag + ,/client/proc/set_server_fps ,/client/proc/cmd_admin_grantfullaccess ,/client/proc/kaboom ,/client/proc/cmd_admin_areatest diff --git a/code/modules/admin/verbs/ticklag.dm b/code/modules/admin/verbs/ticklag.dm deleted file mode 100644 index 3c34f0f35a9..00000000000 --- a/code/modules/admin/verbs/ticklag.dm +++ /dev/null @@ -1,24 +0,0 @@ -//Merged Doohl's and the existing ticklag as they both had good elements about them ~Carn - -/client/proc/ticklag() - set category = "Debug" - set name = "Set Ticklag" - set desc = "Sets a new tick lag. Recommend you don't mess with this too much! Stable, time-tested ticklag value is 0.9" - - if(!check_rights(R_DEBUG)) return - - var/newtick = input("Sets a new tick lag. Please don't mess with this too much! The stable, time-tested ticklag value is 0.9","Lag of Tick", world.tick_lag) as num|null - //I've used ticks of 2 before to help with serious singulo lags - if(newtick && newtick <= 2 && newtick > 0) - log_admin("[key_name(src)] has modified world.tick_lag to [newtick]", 0) - message_admins("[key_name(src)] has modified world.tick_lag to [newtick]", 0) - world.tick_lag = newtick - feedback_add_details("admin_verb","TICKLAG") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! - - switch(alert("Enable Tick Compensation?","Tick Comp is currently: [config.Tickcomp]","Yes","No")) - if("Yes") config.Tickcomp = 1 - else config.Tickcomp = 0 - else - to_chat(src, "Error: ticklag(): Invalid world.ticklag value. No changes made.") - - diff --git a/vorestation.dme b/vorestation.dme index 25c5888cdc8..782dd211af4 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -1553,6 +1553,7 @@ #include "code\modules\admin\verbs\debug_vr.dm" #include "code\modules\admin\verbs\diagnostics.dm" #include "code\modules\admin\verbs\dice.dm" +#include "code\modules\admin\verbs\fps.dm" #include "code\modules\admin\verbs\getlogs.dm" #include "code\modules\admin\verbs\grief_fixers.dm" #include "code\modules\admin\verbs\lightning_strike.dm" @@ -1567,7 +1568,6 @@ #include "code\modules\admin\verbs\smite.dm" #include "code\modules\admin\verbs\smite_vr.dm" #include "code\modules\admin\verbs\striketeam.dm" -#include "code\modules\admin\verbs\ticklag.dm" #include "code\modules\admin\verbs\tripAI.dm" #include "code\modules\admin\verbs\SDQL2\SDQL_2.dm" #include "code\modules\admin\verbs\SDQL2\SDQL_2_parser.dm"