Add step console command to advance n ticks

Cherry-picked from https://github.com/citymania-org/cmclient
Commit: 5ce2d21223a96934a83b8da43434c7a81f001ef0
pull/428/head
dP 4 years ago committed by Jonathan G Rennison
parent 50965bbce7
commit ca23e8abcf

@ -807,6 +807,19 @@ DEF_CONSOLE_CMD(ConUnpauseGame)
return true;
}
DEF_CONSOLE_CMD(ConStepGame)
{
if (argc == 0 || argc > 2) {
IConsoleHelp("Advances the game for a certain amount of ticks (default 1). Usage: 'step [n]'");
return true;
}
auto n = (argc > 1 ? atoi(argv[1]) : 1);
DoCommandP(0, PM_PAUSED_NORMAL, 0 | (n << 1), CMD_PAUSE);
return true;
}
DEF_CONSOLE_CMD(ConRcon)
{
if (argc == 0) {
@ -3651,6 +3664,7 @@ void IConsoleStdLibRegister()
IConsole::CmdRegister("pause", ConPauseGame, ConHookServerOrNoNetwork);
IConsole::CmdRegister("unpause", ConUnpauseGame, ConHookServerOrNoNetwork);
IConsole::CmdRegister("step", ConStepGame, ConHookNoNetwork);
IConsole::CmdRegister("company_pw", ConCompanyPassword, ConHookNeedNetwork);
IConsole::AliasRegister("company_password", "company_pw %+");

@ -53,6 +53,7 @@ std::atomic<bool> _exit_game;
GameMode _game_mode;
SwitchMode _switch_mode; ///< The next mainloop command.
PauseMode _pause_mode;
uint32 _pause_countdown;
Palette _cur_palette;
std::mutex _cur_palette_mutex;
std::string _switch_baseset;

@ -83,6 +83,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
ClearDesyncMsgLog();
_pause_mode = PM_UNPAUSED;
_pause_countdown = 0;
_game_speed = 100;
_tick_counter = 0;
_tick_skip_counter = 0;

@ -179,8 +179,9 @@ CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2,
} else {
PauseMode prev_mode = _pause_mode;
if (p2 == 0) {
if ((p2 & 1) == 0) {
_pause_mode = static_cast<PauseMode>(_pause_mode & (byte)~p1);
_pause_countdown = (p2 >> 1);
} else {
_pause_mode = static_cast<PauseMode>(_pause_mode | (byte)p1);
}

@ -1214,6 +1214,7 @@ void NetworkGameLoop()
}
NetworkExecuteLocalCommandQueue();
if (_pause_countdown > 0 && --_pause_countdown == 0) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
/* Then we make the frame */
StateGameLoop();

@ -513,6 +513,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
FixTitleGameZoom();
_pause_mode = PM_UNPAUSED;
_pause_countdown = 0;
_cursor.fix_at = false;
CheckForMissingGlyphs();
@ -1967,6 +1968,11 @@ void StateGameLoop()
}
if (_extra_aspects > 0) FlushDeferredAspectUpdates();
if (_pause_countdown > 0 && --_pause_countdown == 0) {
_pause_mode = PM_PAUSED_NORMAL;
SetWindowDirty(WC_MAIN_TOOLBAR, 0);
}
assert(IsLocalCompany());
}

@ -81,6 +81,7 @@ DECLARE_ENUM_AS_BIT_SET(PauseMode)
/** The current pause mode */
extern PauseMode _pause_mode;
extern uint32 _pause_countdown;
void AskExitGame();
void AskExitToGameMenu();

Loading…
Cancel
Save