From eac9b720eeb9c36bc4a7e9cf41eb21b48ad29ad1 Mon Sep 17 00:00:00 2001 From: jensj12 Date: Sun, 23 Sep 2018 23:40:47 +0200 Subject: [PATCH] Add #7726: Shortcut to advance one tick (#7851) --- data/language/en-GB.txt | 1 + distribution/changelog.txt | 1 + src/openrct2-ui/input/KeyboardShortcut.cpp | 9 +++++++ src/openrct2-ui/input/KeyboardShortcuts.h | 1 + src/openrct2-ui/windows/ShortcutKeys.cpp | 1 + src/openrct2/Game.cpp | 1 + src/openrct2/Game.h | 1 + src/openrct2/GameState.cpp | 30 +++++++++++++++++----- src/openrct2/localisation/StringIds.h | 2 ++ 9 files changed, 40 insertions(+), 7 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index b7a0da5217..7f2d9608f4 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3728,6 +3728,7 @@ STR_6264 :Always use system file browser STR_6265 :{SMALLFONT}{BLACK}When enabled, your operating system's file browser will be used instead of OpenRCT2's. STR_6266 :Open custom content folder STR_6267 :Open tile inspector +STR_6268 :Advance to next tick ############# # Scenarios # diff --git a/distribution/changelog.txt b/distribution/changelog.txt index dd436137a7..032790353f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.2.1+ (in development) ------------------------------------------------------------------------ +- Feature: [#7726] Add shortcut to advance one tick. - Feature: [#7956, #7964] Add sprite font glyphs for Hungarian and some Czech letters. - Feature: [#7971] Toolbox option to open custom content folder. - Feature: [#7980] Allow data path for RCT1 to be specified by a command line argument. diff --git a/src/openrct2-ui/input/KeyboardShortcut.cpp b/src/openrct2-ui/input/KeyboardShortcut.cpp index 8c383a6b91..cac8494fb8 100644 --- a/src/openrct2-ui/input/KeyboardShortcut.cpp +++ b/src/openrct2-ui/input/KeyboardShortcut.cpp @@ -757,6 +757,14 @@ static void shortcut_open_tile_inspector() context_open_window(WC_TILE_INSPECTOR); } +static void shortcut_advance_to_next_tick() +{ + if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_MANAGER)) + return; + + gDoSingleUpdate = true; +} + namespace { const shortcut_action shortcut_table[SHORTCUT_COUNT] = { @@ -830,6 +838,7 @@ namespace shortcut_view_clipping, shortcut_highlight_path_issues_toggle, shortcut_open_tile_inspector, + shortcut_advance_to_next_tick, }; } // anonymous namespace diff --git a/src/openrct2-ui/input/KeyboardShortcuts.h b/src/openrct2-ui/input/KeyboardShortcuts.h index dbe64c7f26..9b546be59e 100644 --- a/src/openrct2-ui/input/KeyboardShortcuts.h +++ b/src/openrct2-ui/input/KeyboardShortcuts.h @@ -94,6 +94,7 @@ enum SHORTCUT_VIEW_CLIPPING, SHORTCUT_HIGHLIGHT_PATH_ISSUES_TOGGLE, SHORTCUT_TILE_INSPECTOR, + SHORTCUT_ADVANCE_TO_NEXT_TICK, SHORTCUT_COUNT, diff --git a/src/openrct2-ui/windows/ShortcutKeys.cpp b/src/openrct2-ui/windows/ShortcutKeys.cpp index 53f3dc6652..a0db7fb12c 100644 --- a/src/openrct2-ui/windows/ShortcutKeys.cpp +++ b/src/openrct2-ui/windows/ShortcutKeys.cpp @@ -149,6 +149,7 @@ const rct_string_id ShortcutStringIds[SHORTCUT_COUNT] = { STR_SHORTCUT_VIEW_CLIPPING, STR_SHORTCUT_HIGHLIGHT_PATH_ISSUES_TOGGLE, STR_SHORTCUT_OPEN_TILE_INSPECTOR, + STR_ADVANCE_TO_NEXT_TICK, }; // clang-format on diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index a3d37a4f27..47ec60c5c2 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -68,6 +68,7 @@ uint16_t gTicksSinceLastUpdate; uint8_t gGamePaused = 0; int32_t gGameSpeed = 1; +bool gDoSingleUpdate = false; float gDayNightCycle = 0; bool gInUpdateCode = false; bool gInMapInitCode = false; diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index dbcca96c55..3cd9cee834 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -140,6 +140,7 @@ extern uint32_t gCurrentTicks; extern uint16_t gTicksSinceLastUpdate; extern uint8_t gGamePaused; extern int32_t gGameSpeed; +extern bool gDoSingleUpdate; extern float gDayNightCycle; extern bool gInUpdateCode; extern bool gInMapInitCode; diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index f49c265829..31909657c6 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -111,17 +111,27 @@ void GameState::Update() } } + bool didRunSingleFrame = false; if (game_is_paused()) { - numUpdates = 0; - // Update the animation list. Note this does not - // increment the map animation. - map_animation_invalidate_all(); + if (gDoSingleUpdate && network_get_mode() == NETWORK_MODE_NONE) + { + didRunSingleFrame = true; + pause_toggle(); + numUpdates = 1; + } + else + { + numUpdates = 0; + // Update the animation list. Note this does not + // increment the map animation. + map_animation_invalidate_all(); - // Special case because we set numUpdates to 0, otherwise in game_logic_update. - network_update(); + // Special case because we set numUpdates to 0, otherwise in game_logic_update. + network_update(); - network_process_game_commands(); + network_process_game_commands(); + } } // Update the game one or more times @@ -184,7 +194,13 @@ void GameState::Update() window_dispatch_update_all(); + if (didRunSingleFrame && game_is_not_paused() && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) + { + pause_toggle(); + } + gGameCommandNestLevel = 0; + gDoSingleUpdate = false; gInUpdateCode = false; } diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index d73f33b518..5311d509f9 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -3895,6 +3895,8 @@ enum STR_SHORTCUT_OPEN_TILE_INSPECTOR = 6267, + STR_ADVANCE_TO_NEXT_TICK = 6268, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 };