Skip to content

Instantly share code, notes, and snippets.

@nielsmh
Created February 1, 2020 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielsmh/b6bfdef726c0b88080d8924c05c3606a to your computer and use it in GitHub Desktop.
Save nielsmh/b6bfdef726c0b88080d8924c05c3606a to your computer and use it in GitHub Desktop.
OpenTTD slowdown patch
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 748e4ab..3fb4cef 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -2051,6 +2051,13 @@ DEF_CONSOLE_CMD(ConFramerateWindow)
return true;
}
+DEF_CONSOLE_CMD(ConSetSlowdown)
+{
+ extern uint64 _fake_slowdown;
+ if (argc > 1) _fake_slowdown = atoi(argv[1]) * 1000;
+ return true;
+}
+
/*******************************
* console command registration
*******************************/
@@ -2183,6 +2190,7 @@ void IConsoleStdLibRegister()
#endif
IConsoleCmdRegister("fps", ConFramerate);
IConsoleCmdRegister("fps_wnd", ConFramerateWindow);
+ IConsoleCmdRegister("slowdown", ConSetSlowdown);
/* NewGRF development stuff */
IConsoleCmdRegister("reload_newgrfs", ConNewGRFReload, ConHookNewGRFDeveloperTool);
diff --git a/src/openttd.cpp b/src/openttd.cpp
index ffd30cf..04310a1 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1320,6 +1320,9 @@ static void CheckCaches()
}
}
+uint64 _fake_slowdown = 0;
+char _fake_slowdown_buf[100];
+
/**
* State controlling game loop.
* The state must not be changed from anywhere but here.
@@ -1348,6 +1351,11 @@ void StateGameLoop()
PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
if (HasModalProgress()) return;
+ for (uint64 slow = 0; slow < _fake_slowdown; slow++) {
+ SetDParam(0, slow);
+ GetString(_fake_slowdown_buf, STR_FRAMERATE_MS_GOOD, lastof(_fake_slowdown_buf));
+ }
+
Layouter::ReduceLineCache();
if (_game_mode == GM_EDITOR) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment