From 10740106f28e823099093ebb01aa665edf0741f8 Mon Sep 17 00:00:00 2001 From: ZehM4tt Date: Mon, 19 Jun 2017 17:41:28 +0200 Subject: [PATCH] Fix causing asserts with DEBUG_DESYNC and loading new maps. (#5650) Moved input handling out of game_logic_update back to game_update, should be executed per frame not tick. Placed gInUpdateCode at the proper locations. --- src/openrct2/game.c | 82 ++++++++++------------ src/openrct2/game.h | 1 + src/openrct2/network/network.cpp | 1 - src/openrct2/scenario/scenario.c | 2 +- src/openrct2/title/TitleScreen.cpp | 4 ++ src/openrct2/title/TitleSequencePlayer.cpp | 4 ++ 6 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/openrct2/game.c b/src/openrct2/game.c index 9320254d4c..bf4e8866cb 100644 --- a/src/openrct2/game.c +++ b/src/openrct2/game.c @@ -65,6 +65,7 @@ uint8 gGamePaused = 0; sint32 gGameSpeed = 1; float gDayNightCycle = 0; bool gInUpdateCode = false; +bool gInMapInitCode = false; sint32 gGameCommandNestLevel; bool gGameCommandIsNetworked; @@ -279,6 +280,8 @@ void update_palette_effects() void game_update() { + gInUpdateCode = true; + sint32 i, numUpdates; // 0x006E3AEC // screen_game_process_mouse_input(); @@ -307,10 +310,39 @@ void game_update() map_animation_invalidate_all(); // Special case because we set numUpdates to 0, otherwise in game_logic_update. - game_handle_input(); network_update(); } + if (!gOpenRCT2Headless) + { + input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false); + + // the flickering frequency is reduced by 4, compared to the original + // it was done due to inability to reproduce original frequency + // and decision that the original one looks too fast + if (gCurrentTicks % 4 == 0) + gWindowMapFlashingFlags ^= (1 << 15); + + // Handle guest map flashing + gWindowMapFlashingFlags &= ~(1 << 1); + if (gWindowMapFlashingFlags & (1 << 0)) + gWindowMapFlashingFlags |= (1 << 1); + gWindowMapFlashingFlags &= ~(1 << 0); + + // Handle staff map flashing + gWindowMapFlashingFlags &= ~(1 << 3); + if (gWindowMapFlashingFlags & (1 << 2)) + gWindowMapFlashingFlags |= (1 << 3); + gWindowMapFlashingFlags &= ~(1 << 2); + + window_map_tooltip_update_visibility(); + + // Input + gUnk141F568 = gUnk13CA740; + + game_handle_input(); + } + // Update the game one or more times for (i = 0; i < numUpdates; i++) { game_logic_update(); @@ -341,6 +373,7 @@ void game_update() window_dispatch_update_all(); gGameCommandNestLevel = 0; + gInUpdateCode = false; } void game_logic_update() @@ -355,49 +388,10 @@ void game_logic_update() } } - /////////////////////////// - // network_update() when downloaded a map will call game_init_all(), which - // leaves gInUpdateCode false. Don't call network_update() when in update code. - gInUpdateCode = true; - /////////////////////////// - - // Separated out processing commands in network_update which could call scenario_rand where gInUpdateCode is false. - // All commands that are received are first queued and then executed where gInUpdateCode is set to true. - network_process_game_commands(); - gScreenAge++; if (gScreenAge == 0) gScreenAge--; - if (!gOpenRCT2Headless) - { - input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false); - - // the flickering frequency is reduced by 4, compared to the original - // it was done due to inability to reproduce original frequency - // and decision that the original one looks too fast - if (gCurrentTicks % 4 == 0) - gWindowMapFlashingFlags ^= (1 << 15); - - // Handle guest map flashing - gWindowMapFlashingFlags &= ~(1 << 1); - if (gWindowMapFlashingFlags & (1 << 0)) - gWindowMapFlashingFlags |= (1 << 1); - gWindowMapFlashingFlags &= ~(1 << 0); - - // Handle staff map flashing - gWindowMapFlashingFlags &= ~(1 << 3); - if (gWindowMapFlashingFlags & (1 << 2)) - gWindowMapFlashingFlags |= (1 << 3); - gWindowMapFlashingFlags &= ~(1 << 2); - - window_map_tooltip_update_visibility(); - - // Input - gUnk141F568 = gUnk13CA740; - game_handle_input(); - } - sub_68B089(); scenario_update(); climate_update(); @@ -416,10 +410,6 @@ void game_logic_update() ride_measurements_update(); news_item_update_current(); - /////////////////////////// - gInUpdateCode = false; - /////////////////////////// - map_animation_invalidate_all(); vehicle_sounds_update(); peep_update_crowd_noise(); @@ -1420,7 +1410,7 @@ void game_load_or_quit_no_save_prompt() */ void game_init_all(sint32 mapSize) { - gInUpdateCode = true; + gInMapInitCode = true; map_init(mapSize); park_init(); @@ -1435,7 +1425,7 @@ void game_init_all(sint32 mapSize) news_item_init_queue(); user_string_clear_all(); - gInUpdateCode = false; + gInMapInitCode = false; window_new_ride_init_vars(); window_guest_list_init_vars_a(); diff --git a/src/openrct2/game.h b/src/openrct2/game.h index 26fb839aa4..1f205694b7 100644 --- a/src/openrct2/game.h +++ b/src/openrct2/game.h @@ -148,6 +148,7 @@ extern uint8 gGamePaused; extern sint32 gGameSpeed; extern float gDayNightCycle; extern bool gInUpdateCode; +extern bool gInMapInitCode; extern sint32 gGameCommandNestLevel; extern bool gGameCommandIsNetworked; diff --git a/src/openrct2/network/network.cpp b/src/openrct2/network/network.cpp index a7b049a18f..6ebef0f31c 100644 --- a/src/openrct2/network/network.cpp +++ b/src/openrct2/network/network.cpp @@ -388,7 +388,6 @@ uint8 Network::GetPlayerID() void Network::Update() { _closeLock = true; - assert(gInUpdateCode == false); switch (GetMode()) { case NETWORK_MODE_SERVER: diff --git a/src/openrct2/scenario/scenario.c b/src/openrct2/scenario/scenario.c index 88e5f49fb2..de0931bb1c 100644 --- a/src/openrct2/scenario/scenario.c +++ b/src/openrct2/scenario/scenario.c @@ -604,7 +604,7 @@ uint32 dbg_scenario_rand(const char *file, const char *function, const uint32 li { fprintf(fp, "Tick: %d, Rand: %08X - REF: %s:%u %s (%p)\n", gCurrentTicks, gScenarioSrand1, file, line, function, data); } - if (!gInUpdateCode) { + if (!gInUpdateCode && !gInMapInitCode) { log_warning("scenario_rand called from outside game update"); assert(false); } diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index 9db015fe33..986bf2712f 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -168,6 +168,8 @@ extern "C" void title_update() { + gInUpdateCode = true; + screenshot_check(); title_handle_keyboard_input(); @@ -196,6 +198,8 @@ extern "C" gSavedAge++; game_handle_input(); + + gInUpdateCode = false; } void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y) diff --git a/src/openrct2/title/TitleSequencePlayer.cpp b/src/openrct2/title/TitleSequencePlayer.cpp index 18feca31f9..e9a2cca464 100644 --- a/src/openrct2/title/TitleSequencePlayer.cpp +++ b/src/openrct2/title/TitleSequencePlayer.cpp @@ -197,6 +197,8 @@ public: } // Keep updating until we reach target position + gInUpdateCode = true; + while (_position < targetPosition) { if (Update()) @@ -209,6 +211,8 @@ public: } } + gInUpdateCode = false; + _waitCounter = 0; }