mirror of https://github.com/OpenRCT2/OpenRCT2.git
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:
parent
7c4ee751cc
commit
10740106f2
|
@ -65,6 +65,7 @@ uint8 gGamePaused = 0;
|
||||||
sint32 gGameSpeed = 1;
|
sint32 gGameSpeed = 1;
|
||||||
float gDayNightCycle = 0;
|
float gDayNightCycle = 0;
|
||||||
bool gInUpdateCode = false;
|
bool gInUpdateCode = false;
|
||||||
|
bool gInMapInitCode = false;
|
||||||
sint32 gGameCommandNestLevel;
|
sint32 gGameCommandNestLevel;
|
||||||
bool gGameCommandIsNetworked;
|
bool gGameCommandIsNetworked;
|
||||||
|
|
||||||
|
@ -279,6 +280,8 @@ void update_palette_effects()
|
||||||
|
|
||||||
void game_update()
|
void game_update()
|
||||||
{
|
{
|
||||||
|
gInUpdateCode = true;
|
||||||
|
|
||||||
sint32 i, numUpdates;
|
sint32 i, numUpdates;
|
||||||
|
|
||||||
// 0x006E3AEC // screen_game_process_mouse_input();
|
// 0x006E3AEC // screen_game_process_mouse_input();
|
||||||
|
@ -307,10 +310,39 @@ void game_update()
|
||||||
map_animation_invalidate_all();
|
map_animation_invalidate_all();
|
||||||
|
|
||||||
// Special case because we set numUpdates to 0, otherwise in game_logic_update.
|
// Special case because we set numUpdates to 0, otherwise in game_logic_update.
|
||||||
game_handle_input();
|
|
||||||
network_update();
|
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
|
// Update the game one or more times
|
||||||
for (i = 0; i < numUpdates; i++) {
|
for (i = 0; i < numUpdates; i++) {
|
||||||
game_logic_update();
|
game_logic_update();
|
||||||
|
@ -341,6 +373,7 @@ void game_update()
|
||||||
window_dispatch_update_all();
|
window_dispatch_update_all();
|
||||||
|
|
||||||
gGameCommandNestLevel = 0;
|
gGameCommandNestLevel = 0;
|
||||||
|
gInUpdateCode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_logic_update()
|
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++;
|
gScreenAge++;
|
||||||
if (gScreenAge == 0)
|
if (gScreenAge == 0)
|
||||||
gScreenAge--;
|
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();
|
sub_68B089();
|
||||||
scenario_update();
|
scenario_update();
|
||||||
climate_update();
|
climate_update();
|
||||||
|
@ -416,10 +410,6 @@ void game_logic_update()
|
||||||
ride_measurements_update();
|
ride_measurements_update();
|
||||||
news_item_update_current();
|
news_item_update_current();
|
||||||
|
|
||||||
///////////////////////////
|
|
||||||
gInUpdateCode = false;
|
|
||||||
///////////////////////////
|
|
||||||
|
|
||||||
map_animation_invalidate_all();
|
map_animation_invalidate_all();
|
||||||
vehicle_sounds_update();
|
vehicle_sounds_update();
|
||||||
peep_update_crowd_noise();
|
peep_update_crowd_noise();
|
||||||
|
@ -1420,7 +1410,7 @@ void game_load_or_quit_no_save_prompt()
|
||||||
*/
|
*/
|
||||||
void game_init_all(sint32 mapSize)
|
void game_init_all(sint32 mapSize)
|
||||||
{
|
{
|
||||||
gInUpdateCode = true;
|
gInMapInitCode = true;
|
||||||
|
|
||||||
map_init(mapSize);
|
map_init(mapSize);
|
||||||
park_init();
|
park_init();
|
||||||
|
@ -1435,7 +1425,7 @@ void game_init_all(sint32 mapSize)
|
||||||
news_item_init_queue();
|
news_item_init_queue();
|
||||||
user_string_clear_all();
|
user_string_clear_all();
|
||||||
|
|
||||||
gInUpdateCode = false;
|
gInMapInitCode = false;
|
||||||
|
|
||||||
window_new_ride_init_vars();
|
window_new_ride_init_vars();
|
||||||
window_guest_list_init_vars_a();
|
window_guest_list_init_vars_a();
|
||||||
|
|
|
@ -148,6 +148,7 @@ extern uint8 gGamePaused;
|
||||||
extern sint32 gGameSpeed;
|
extern sint32 gGameSpeed;
|
||||||
extern float gDayNightCycle;
|
extern float gDayNightCycle;
|
||||||
extern bool gInUpdateCode;
|
extern bool gInUpdateCode;
|
||||||
|
extern bool gInMapInitCode;
|
||||||
extern sint32 gGameCommandNestLevel;
|
extern sint32 gGameCommandNestLevel;
|
||||||
extern bool gGameCommandIsNetworked;
|
extern bool gGameCommandIsNetworked;
|
||||||
|
|
||||||
|
|
|
@ -388,7 +388,6 @@ uint8 Network::GetPlayerID()
|
||||||
void Network::Update()
|
void Network::Update()
|
||||||
{
|
{
|
||||||
_closeLock = true;
|
_closeLock = true;
|
||||||
assert(gInUpdateCode == false);
|
|
||||||
|
|
||||||
switch (GetMode()) {
|
switch (GetMode()) {
|
||||||
case NETWORK_MODE_SERVER:
|
case NETWORK_MODE_SERVER:
|
||||||
|
|
|
@ -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);
|
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");
|
log_warning("scenario_rand called from outside game update");
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,8 @@ extern "C"
|
||||||
|
|
||||||
void title_update()
|
void title_update()
|
||||||
{
|
{
|
||||||
|
gInUpdateCode = true;
|
||||||
|
|
||||||
screenshot_check();
|
screenshot_check();
|
||||||
title_handle_keyboard_input();
|
title_handle_keyboard_input();
|
||||||
|
|
||||||
|
@ -196,6 +198,8 @@ extern "C"
|
||||||
gSavedAge++;
|
gSavedAge++;
|
||||||
|
|
||||||
game_handle_input();
|
game_handle_input();
|
||||||
|
|
||||||
|
gInUpdateCode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y)
|
void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y)
|
||||||
|
|
|
@ -197,6 +197,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep updating until we reach target position
|
// Keep updating until we reach target position
|
||||||
|
gInUpdateCode = true;
|
||||||
|
|
||||||
while (_position < targetPosition)
|
while (_position < targetPosition)
|
||||||
{
|
{
|
||||||
if (Update())
|
if (Update())
|
||||||
|
@ -209,6 +211,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gInUpdateCode = false;
|
||||||
|
|
||||||
_waitCounter = 0;
|
_waitCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue