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.
This commit is contained in:
ZehM4tt 2017-06-19 17:41:28 +02:00 committed by Michał Janiszewski
parent 7c4ee751cc
commit 10740106f2
6 changed files with 46 additions and 48 deletions

View File

@ -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();

View File

@ -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;

View File

@ -388,7 +388,6 @@ uint8 Network::GetPlayerID()
void Network::Update()
{
_closeLock = true;
assert(gInUpdateCode == false);
switch (GetMode()) {
case NETWORK_MODE_SERVER:

View File

@ -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);
}

View File

@ -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)

View File

@ -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;
}