From 4d226741d38afbd9d03f2ee62ea2505e20d48bda Mon Sep 17 00:00:00 2001 From: klei1984 <53688147+klei1984@users.noreply.github.com> Date: Fri, 27 Oct 2023 19:41:23 +0200 Subject: [PATCH] Various remote module and network lobby refactorings, corrections --- src/dialogmenu.cpp | 4 +- src/game_manager.cpp | 10 ++--- src/helpmenu.cpp | 12 +++--- src/menu.cpp | 8 ++-- src/networkmenu.cpp | 70 +++++++++++++++++++++-------------- src/remote.cpp | 69 +++++++++++++++++----------------- src/remote.hpp | 6 +-- src/repairshopmenu.cpp | 12 +++--- src/saveloadmenu.cpp | 6 +-- src/transport_udp_default.cpp | 1 + src/units_manager.cpp | 68 ++++++++++++++++++---------------- src/units_manager.hpp | 8 ++-- 12 files changed, 148 insertions(+), 126 deletions(-) diff --git a/src/dialogmenu.cpp b/src/dialogmenu.cpp index 89d3c33f..585bbfdd 100644 --- a/src/dialogmenu.cpp +++ b/src/dialogmenu.cpp @@ -202,8 +202,8 @@ void DialogMenu::Run() { ProcessKey(key); if (Remote_IsNetworkGame) { - if (Remote_ProcessFrame()) { - UnitsManager_ProcessRemoteOrders(); + if (Remote_UiProcessTick()) { + UnitsManager_ProcessOrders(); } } else { if (is_ingame) { diff --git a/src/game_manager.cpp b/src/game_manager.cpp index 602baa32..e5357a8c 100644 --- a/src/game_manager.cpp +++ b/src/game_manager.cpp @@ -2035,7 +2035,7 @@ void GameManager_GameSetup(int32_t game_state) { MouseEvent::Clear(); - if (GameManager_PlayScenarioIntro && !ini_get_setting(INI_GAME_FILE_TYPE)) { + if (GameManager_PlayScenarioIntro && ini_get_setting(INI_GAME_FILE_TYPE) == GAME_TYPE_CUSTOM) { Color* palette; GameManager_LandingSequence.DeleteButtons(); @@ -5133,8 +5133,8 @@ void GameManager_ProcessState(bool process_tick, bool clear_mouse_events) { } if (Remote_IsNetworkGame) { - if (Remote_ProcessFrame()) { - UnitsManager_ProcessRemoteOrders(); + if (Remote_UiProcessTick()) { + UnitsManager_ProcessOrders(); } } else { @@ -5196,14 +5196,14 @@ bool GameManager_ProcessTick(bool render_screen) { } if (Remote_IsNetworkGame) { - Remote_ProcessTick(); + Remote_Synchronize(); } Paths_LastTimeStamp = time_stamp; Paths_TimeBenchmarkDisable = false; if (GameManager_GameState != GAME_STATE_11) { - UnitsManager_ProcessRemoteOrders(); + UnitsManager_ProcessOrders(); } GameManager_Render(); diff --git a/src/helpmenu.cpp b/src/helpmenu.cpp index eade84d2..d82a1278 100644 --- a/src/helpmenu.cpp +++ b/src/helpmenu.cpp @@ -444,15 +444,15 @@ bool HelpMenu::Run(int32_t mode) { GameManager_GameState == GAME_STATE_9_END_TURN) { GameManager_ProcessState(false, false); } else if (Remote_GameState) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); if (Remote_GameState == 2) { event_click_cancel = true; } } else if (Remote_IsNetworkGame) { - if (Remote_ProcessFrame()) { - UnitsManager_ProcessRemoteOrders(); + if (Remote_UiProcessTick()) { + UnitsManager_ProcessOrders(); } } } @@ -501,14 +501,14 @@ void HelpMenu_Menu(HelpSectionId section_id, int32_t window_index, bool mode) { GameManager_GameState == GAME_STATE_9_END_TURN) { GameManager_ProcessState(false, false); } else if (Remote_GameState) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); if (Remote_GameState == 2) { break; } } else if (Remote_IsNetworkGame) { - if (Remote_ProcessFrame()) { - UnitsManager_ProcessRemoteOrders(); + if (Remote_UiProcessTick()) { + UnitsManager_ProcessOrders(); } } } diff --git a/src/menu.cpp b/src/menu.cpp index 994736ca..3d30c77a 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -1658,7 +1658,7 @@ int32_t menu_clan_select_menu_loop(int32_t team) { do { if (Remote_GameState) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); } if (Remote_GameState == 2) { @@ -1744,7 +1744,7 @@ int32_t menu_planet_select_menu_loop() { do { if (Remote_GameState == 1) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); } planet_select_menu.key = get_input(); @@ -1800,7 +1800,7 @@ int32_t menu_options_menu_loop(int32_t game_mode) { do { if (Remote_GameState == 1) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); } game_config_menu.key = get_input(); @@ -1957,7 +1957,7 @@ int32_t GameSetupMenu_Menu(int32_t game_file_type, bool flag1, bool flag2) { do { if (Remote_GameState == 1) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); } game_setup_menu.key = get_input(); diff --git a/src/networkmenu.cpp b/src/networkmenu.cpp index 7ddaaed7..e8d014a7 100644 --- a/src/networkmenu.cpp +++ b/src/networkmenu.cpp @@ -129,7 +129,7 @@ bool NetworkMenu_MenuLoop(bool is_host_mode) { } } - if (Remote_NetSync()) { + if (Remote_UiProcessNetPackets()) { network_menu.is_gui_update_needed = false; network_menu.SetupScenario(false); @@ -251,16 +251,20 @@ void NetworkMenu::ButtonInit(int32_t index) { image_id = static_cast(image_id + 1); } - buttons[index] = new (std::nothrow) - Button(image_id, static_cast(control->image_id + 1), control->bounds.ulx, control->bounds.uly); + buttons[index] = new (std::nothrow) Button(image_id, static_cast(control->image_id + 1), + WindowManager_ScaleUlx(window, control->bounds.ulx), + WindowManager_ScaleUly(window, control->bounds.uly)); buttons[index]->Copy(clan_logo, 41, 40); + } else if (control->image_id == INVALID_ID) { - buttons[index] = new (std::nothrow) - Button(control->bounds.ulx, control->bounds.uly, control->bounds.lrx - control->bounds.ulx, - control->bounds.lry - control->bounds.uly); + buttons[index] = new (std::nothrow) Button( + WindowManager_ScaleUlx(window, control->bounds.ulx), WindowManager_ScaleUly(window, control->bounds.uly), + control->bounds.lrx - control->bounds.ulx, control->bounds.lry - control->bounds.uly); + } else { buttons[index] = new (std::nothrow) Button(control->image_id, static_cast(control->image_id + 1), - control->bounds.ulx, control->bounds.uly); + WindowManager_ScaleUlx(window, control->bounds.ulx), + WindowManager_ScaleUly(window, control->bounds.uly)); if (control->label) { buttons[index]->SetCaption(control->label); @@ -320,7 +324,8 @@ void NetworkMenu::Init() { WindowManager_LoadBigImage(MULTGAME, window, window->width, false, false, -1, -1, true); Text_SetFont(GNW_TEXT_FONT_1); - Text_TextBox(window, _(6637), 28, 403, 106, 25, true); + Text_TextBox(window, _(6637), WindowManager_ScaleUlx(window, 28), WindowManager_ScaleUly(window, 403), 106, 25, + true); Text_SetFont(GNW_TEXT_FONT_5); @@ -328,8 +333,9 @@ void NetworkMenu::Init() { MenuTitleItem *menu_item = &network_menu_titles[i]; images[i] = new (std::nothrow) - Image(menu_item->bounds.ulx, menu_item->bounds.uly, menu_item->bounds.lrx - menu_item->bounds.ulx + 1, - menu_item->bounds.lry - menu_item->bounds.uly + 1); + Image(WindowManager_ScaleUlx(window, menu_item->bounds.ulx), + WindowManager_ScaleUly(window, menu_item->bounds.uly), + menu_item->bounds.lrx - menu_item->bounds.ulx + 1, menu_item->bounds.lry - menu_item->bounds.uly + 1); images[i]->Copy(window); } @@ -429,7 +435,7 @@ void NetworkMenu::EventTextWindow() { break; } - Remote_NetSync(); + Remote_UiProcessNetPackets(); key_press = get_input(); } while (key_press != GNW_KB_KEY_ESCAPE && key_press != 1020); @@ -497,9 +503,6 @@ void NetworkMenu::EventScenarioButton() { DeleteButtons(); if (GameSetupMenu_Menu(GAME_TYPE_MULTI_PLAYER_SCENARIO, false)) { - } else { - Reinit(true); - team_index = player_team; ini_game_file_number = ini_get_setting(INI_GAME_FILE_NUMBER); multi_scenario_id = ini_game_file_number; @@ -519,6 +522,9 @@ void NetworkMenu::EventScenarioButton() { Reinit(true); NetSync(team_index); DrawScreen(); + + } else { + Reinit(true); } } @@ -611,8 +617,10 @@ void NetworkMenu::DrawScreen() { minimap_world_index = ini_world_index; - buffer_position = &window->buffer[network_menu_titles[MENU_ITEM_MAP_PICT].bounds.ulx + - network_menu_titles[MENU_ITEM_MAP_PICT].bounds.uly * window->width]; + buffer_position = + &window->buffer[WindowManager_ScaleUlx(window, network_menu_titles[MENU_ITEM_MAP_PICT].bounds.ulx) + + WindowManager_ScaleUly(window, network_menu_titles[MENU_ITEM_MAP_PICT].bounds.uly) * + window->width]; Menu_LoadPlanetMinimap(minimap_world_index, buffer_position, window->width); } @@ -694,7 +702,8 @@ void NetworkMenu::DrawTextLine(int32_t line_index, char *text, int32_t height, b uly = line_index * height + menu_item->bounds.uly; width = menu_item->bounds.lrx - ulx; - Text_TextBox(window->buffer, window->width, text, ulx, uly, width, height, COLOR_GREEN, horizontal_align); + Text_TextBox(window->buffer, window->width, text, WindowManager_ScaleUlx(window, ulx), + WindowManager_ScaleUly(window, uly), width, height, COLOR_GREEN, horizontal_align); } void NetworkMenu::ResetJar(int32_t team) { @@ -715,7 +724,7 @@ void NetworkMenu::UpdateSaveSettings(struct SaveFormatHeader *save_file_header) is_multi_scenario = true; for (int32_t i = 0; i < TRANSPORT_MAX_TEAM_COUNT; ++i) { - strcpy(default_team_names[i], team_names[i]); + strcpy(default_team_names[i], save_file_header->team_name[i]); } rng_seed = save_file_header->rng_seed; @@ -786,6 +795,7 @@ int32_t NetworkMenu::SetupScenario(int32_t mode) { if (ini_get_setting(INI_GAME_FILE_TYPE) == GAME_TYPE_MULTI) { NetSync(save_file_header); + } else { int32_t player_team_local; @@ -859,7 +869,7 @@ void NetworkMenu::LeaveGame(uint16_t team_node) { void NetworkMenu::NetSync(int32_t team) { bool game_found; - Remote_NetSync(); + Remote_UiProcessNetPackets(); if (player_team != -1) { ResetJar(player_team); @@ -877,7 +887,7 @@ void NetworkMenu::NetSync(int32_t team) { game_found = false; while (!game_found) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); if (!host_node) { break; @@ -952,7 +962,9 @@ void NetworkMenu::Reinit(int32_t palette_from_image) { mouse_hide(); WindowManager_LoadBigImage(MULTGAME, window, window->width, palette_from_image, false, -1, -1, true); Text_SetFont(GNW_TEXT_FONT_1); - Text_TextBox(window, _(90a9), 28, 403, 106, 25, true); + Text_TextBox(window, _(90a9), WindowManager_ScaleUlx(window, 28), WindowManager_ScaleUly(window, 403), 106, 25, + true); + minimap_world_index = -1; DrawScreen(); mouse_show(); } @@ -964,9 +976,10 @@ TextEdit *NetworkMenu::CreateTextEdit(int32_t index) { control = &network_menu_controls[index]; text_buffer[0] = '\0'; - text_edit = new (std::nothrow) TextEdit(window, text_buffer, index == 18 ? 120 : 30, control->bounds.ulx, - control->bounds.uly, control->bounds.lrx - control->bounds.ulx + 1, - control->bounds.lry - control->bounds.uly + 1, 0xA2, GNW_TEXT_FONT_5); + text_edit = new (std::nothrow) + TextEdit(window, text_buffer, index == 18 ? 120 : 30, WindowManager_ScaleUlx(window, control->bounds.ulx), + WindowManager_ScaleUly(window, control->bounds.uly), control->bounds.lrx - control->bounds.ulx + 1, + control->bounds.lry - control->bounds.uly + 1, 0xA2, GNW_TEXT_FONT_5); text_edit->LoadBgImage(); return text_edit; @@ -1083,7 +1096,7 @@ void NetworkMenu::DrawJars() { images[3 + i]->Write(window); images[9 + i]->Write(window); - if (is_multi_scenario && default_team_names[i][0] != '\0') { + if (is_multi_scenario && default_team_names[i][0] == '\0') { delete buttons[button_index]; buttons[button_index] = nullptr; @@ -1135,9 +1148,10 @@ void NetworkMenu::DrawJoinScreen() { } if (i) { - draw_line(window->buffer, 640, network_menu_controls[index].bounds.ulx, - network_menu_controls[index].bounds.uly, network_menu_controls[index].bounds.lrx, - network_menu_controls[index].bounds.uly, COLOR_GREEN); + draw_line(window->buffer, 640, WindowManager_ScaleUlx(window, network_menu_controls[index].bounds.ulx), + WindowManager_ScaleUlx(window, network_menu_controls[index].bounds.uly), + network_menu_controls[index].bounds.lrx, network_menu_controls[index].bounds.uly, + COLOR_GREEN); } } diff --git a/src/remote.cpp b/src/remote.cpp index 370a39ba..f99c220a 100644 --- a/src/remote.cpp +++ b/src/remote.cpp @@ -67,7 +67,7 @@ bool Remote_IsHostMode; bool Remote_IsNetworkGame; bool Remote_UpdatePauseTimer; bool Remote_UnpauseGameEvent; -bool Remote_SendP1SyncFrame; +bool Remote_SendSynchFrame; uint32_t Remote_PauseTimeStamp; uint32_t Remote_TimeoutTimeStamp; uint32_t Remote_RngSeed; @@ -446,8 +446,7 @@ void Remote_Init() { Remote_RngSeed = 0; GameManager_PlayerTeam = 0; Remote_FrameSyncCounter2 = 0; - Remote_SendP1SyncFrame = true; - /// \todo Remote_byte_1759C5 = 0; + Remote_SendSynchFrame = true; Remote_RemotePlayerCount = 0; Remote_P51_Signal = false; @@ -698,19 +697,19 @@ void Remote_SetupConnection() { Remote_NetworkMenu->connection_state = 1; } -bool Remote_NetSync() { +bool Remote_UiProcessNetPackets() { Remote_ProcessNetPackets(); return Remote_NetworkMenu->is_gui_update_needed; } -bool Remote_ProcessFrame(bool mode) { +bool Remote_UiProcessTick(bool mode) { bool result; Remote_ProcessNetPackets(); if (timer_get() - Paths_LastTimeStamp >= TIMER_FPS_TO_MS(24)) { - Remote_ProcessTick(mode); + Remote_Synchronize(mode); Paths_LastTimeStamp = timer_get(); @@ -1021,14 +1020,14 @@ int32_t Remote_CheckUnpauseEvent() { return Remote_UnpauseGameEvent; } -void Remote_ProcessTick(bool mode) { +void Remote_Synchronize(bool async_mode) { Remote_ProcessNetPackets(); if (GameManager_GameState == GAME_STATE_3_MAIN_MENU || GameManager_GameState == GAME_STATE_7_SITE_SELECT || GameManager_GameState == GAME_STATE_10 || GameManager_GameState == GAME_STATE_12 || GameManager_GameState == GAME_STATE_13) { Remote_TimeoutTimeStamp = timer_get(); - Remote_SendP1SyncFrame = true; + Remote_SendSynchFrame = true; } else { uint32_t time_stamp = timer_get(); @@ -1038,27 +1037,29 @@ void Remote_ProcessTick(bool mode) { Remote_ProcessNetPackets(); MouseEvent::ProcessInput(); - if (Remote_SendP1SyncFrame || timer_elapsed_time(time_stamp) > TIMER_FPS_TO_MS(2)) { + if (Remote_SendSynchFrame || timer_elapsed_time(time_stamp) > TIMER_FPS_TO_MS(2)) { Remote_SendNetPacket_Signal(REMOTE_PACKET_01, GameManager_PlayerTeam, Remote_FrameSyncCounter2); + time_stamp = timer_get(); + Remote_SendSynchFrame = false; } stay_in_loop = false; for (int32_t team = 0; team < TRANSPORT_MAX_TEAM_COUNT; ++team) { - UnitsManager_TeamInfo[team].team_type = TEAM_TYPE_REMOTE; - - if (((Remote_FrameSyncCounter2 - 1) & 0x3F) == Remote_FrameSyncCounter2values[team]) { - if (timer_elapsed_time(Remote_TimeoutTimeStamp) > REMOTE_RESPONSE_TIMEOUT) { - Remote_ResponseTimeout(team, true); - break; + if (UnitsManager_TeamInfo[team].team_type == TEAM_TYPE_REMOTE) { + if (((Remote_FrameSyncCounter2 - 1) & 0x3F) == Remote_FrameSyncCounter2values[team]) { + if (timer_elapsed_time(Remote_TimeoutTimeStamp) > REMOTE_RESPONSE_TIMEOUT) { + Remote_ResponseTimeout(team, true); + break; - } else { - stay_in_loop = true; + } else { + stay_in_loop = true; + } } } } - if (stay_in_loop && mode) { + if (stay_in_loop && async_mode) { Remote_TimeoutTimeStamp = timer_get(); return; @@ -1067,7 +1068,7 @@ void Remote_ProcessTick(bool mode) { Remote_FrameSyncCounter2 = (Remote_FrameSyncCounter2 + 1) & 0x3F; Remote_TimeoutTimeStamp = timer_get(); - Remote_SendP1SyncFrame = true; + Remote_SendSynchFrame = true; } } @@ -1087,7 +1088,7 @@ void Remote_WaitBeginTurnAcknowledge() { bool stay_in_loop = true; while (stay_in_loop && Remote_IsNetworkGame) { - Remote_ProcessFrame(true); + Remote_UiProcessTick(true); if (timer_elapsed_time(time_stamp_ping) > REMOTE_PING_TIME_PERIOD) { Remote_SendNetPacket_Signal(REMOTE_PACKET_00, GameManager_PlayerTeam, @@ -1131,7 +1132,7 @@ void Remote_WaitEndTurnAcknowledge() { bool stay_in_loop = true; while (stay_in_loop && Remote_IsNetworkGame) { - Remote_ProcessFrame(true); + Remote_UiProcessTick(true); if (timer_elapsed_time(time_stamp_ping) > REMOTE_PING_TIME_PERIOD) { Remote_SendNetPacket_Signal(REMOTE_PACKET_52, GameManager_PlayerTeam, @@ -1267,19 +1268,19 @@ int32_t Remote_SiteSelectMenu() { } void Remote_LeaveGame(uint16_t team, bool mode) { - if (UnitsManager_TeamInfo[UnitsManager_Team].team_type != TEAM_TYPE_REMOTE) { - uint16_t source_team = UnitsManager_Team; + if (UnitsManager_TeamInfo[UnitsManager_DelayedReactionsTeam].team_type != TEAM_TYPE_REMOTE) { + uint16_t source_team = UnitsManager_DelayedReactionsTeam; do { - UnitsManager_Team = (UnitsManager_Team + 1) % TRANSPORT_MAX_TEAM_COUNT; + UnitsManager_DelayedReactionsTeam = (UnitsManager_DelayedReactionsTeam + 1) % TRANSPORT_MAX_TEAM_COUNT; - } while (UnitsManager_Team != source_team && - UnitsManager_TeamInfo[UnitsManager_Team].team_type != TEAM_TYPE_REMOTE); + } while (UnitsManager_DelayedReactionsTeam != source_team && + UnitsManager_TeamInfo[UnitsManager_DelayedReactionsTeam].team_type != TEAM_TYPE_REMOTE); - if (UnitsManager_Team != source_team) { - ++UnitsManager_UnknownCounter; + if (UnitsManager_DelayedReactionsTeam != source_team) { + ++UnitsManager_DelayedReactionsSyncCounter; - Remote_SendNetPacket_46(UnitsManager_Team, false, UnitsManager_UnknownCounter); + Remote_SendNetPacket_46(UnitsManager_DelayedReactionsTeam, false, UnitsManager_DelayedReactionsSyncCounter); } } @@ -1326,7 +1327,7 @@ bool Remote_CheckDesync(uint16_t team, uint16_t crc_checksum) { bool stay_in_loop = true; while (stay_in_loop && Remote_IsNetworkGame) { - Remote_ProcessFrame(true); + Remote_UiProcessTick(true); if (timer_elapsed_time(time_stamp_ping) > REMOTE_PING_TIME_PERIOD) { Remote_SendNetPacket_45(team, Remote_NextTurnIndices[team], crc_checksum); @@ -2933,12 +2934,12 @@ void Remote_ReceiveNetPacket_46(NetPacket& packet) { packet >> counter; if (state) { - UnitsManager_byte_178170 = true; + UnitsManager_DelayedReactionsPending = true; } - if (counter > UnitsManager_UnknownCounter) { - UnitsManager_Team = entity_id; - UnitsManager_UnknownCounter = counter; + if (counter > UnitsManager_DelayedReactionsSyncCounter) { + UnitsManager_DelayedReactionsTeam = entity_id; + UnitsManager_DelayedReactionsSyncCounter = counter; } } diff --git a/src/remote.hpp b/src/remote.hpp index 17a31cfb..a99d2288 100644 --- a/src/remote.hpp +++ b/src/remote.hpp @@ -87,14 +87,14 @@ enum : uint8_t { void Remote_Deinit(); void Remote_SetupConnection(); int32_t Remote_Lobby(bool is_host_mode); -bool Remote_NetSync(); -bool Remote_ProcessFrame(bool mode = false); +bool Remote_UiProcessNetPackets(); +bool Remote_UiProcessTick(bool mode = false); bool Remote_CheckRestartAfterDesyncEvent(); void Remote_RegisterMenu(NetworkMenu* menu); void Remote_ProcessNetPackets(); void Remote_AnalyzeDesync(); int32_t Remote_CheckUnpauseEvent(); -void Remote_ProcessTick(bool mode = false); +void Remote_Synchronize(bool mode = false); void Remote_WaitBeginTurnAcknowledge(); void Remote_WaitEndTurnAcknowledge(); int32_t Remote_SiteSelectMenu(); diff --git a/src/repairshopmenu.cpp b/src/repairshopmenu.cpp index ce96eaf8..7536dd9a 100644 --- a/src/repairshopmenu.cpp +++ b/src/repairshopmenu.cpp @@ -707,7 +707,7 @@ void RepairShopMenu::Reload(UnitInfo *target_unit) { RepairShopMenu_ProcessOrders(&*repairshop, ORDER_RELOAD, false); } else { - UnitsManager_ProcessRemoteOrders(); + UnitsManager_ProcessOrders(); } } } @@ -721,7 +721,7 @@ void RepairShopMenu::Repair(UnitInfo *target_unit) { RepairShopMenu_ProcessOrders(&*repairshop, ORDER_REPAIR, false); } else { - UnitsManager_ProcessRemoteOrders(); + UnitsManager_ProcessOrders(); } } } @@ -735,7 +735,7 @@ void RepairShopMenu::Upgrade(UnitInfo *target_unit) { RepairShopMenu_ProcessOrders(&*repairshop, ORDER_UPGRADE, false); } else { - UnitsManager_ProcessRemoteOrders(); + UnitsManager_ProcessOrders(); } } } @@ -844,7 +844,7 @@ void RepairShopMenu_OnClick_ActivateAll(ButtonID bid, intptr_t value) { } else { while (unit->orders == ORDER_ACTIVATE) { - UnitsManager_ProcessRemoteOrders(); + UnitsManager_ProcessOrders(); GameManager_ProcessState(true); } } @@ -981,11 +981,11 @@ void RepairShopMenu_ProcessOrders(UnitInfo *unit, uint8_t order, bool process_ti GameManager_ProcessState(process_tick); } - while (!Remote_ProcessFrame()) { + while (!Remote_UiProcessTick()) { ; } - UnitsManager_ProcessRemoteOrders(); + UnitsManager_ProcessOrders(); } void RepairShopMenu::Draw(bool draw_to_screen) { diff --git a/src/saveloadmenu.cpp b/src/saveloadmenu.cpp index 173f4b1d..a006a118 100644 --- a/src/saveloadmenu.cpp +++ b/src/saveloadmenu.cpp @@ -478,7 +478,7 @@ int32_t SaveLoadMenu_MenuLoop(int32_t is_saving_allowed) { do { if (Remote_GameState == 1) { - Remote_NetSync(); + Remote_UiProcessNetPackets(); } key = get_input(); @@ -1107,8 +1107,8 @@ bool SaveLoadMenu_Load(int32_t save_slot, int32_t game_file_type, bool ini_load_ SaveLoadMenu_TeamClearUnitList(UnitsManager_MobileAirUnits, team); SaveLoadMenu_TeamClearUnitList(UnitsManager_ParticleUnits, team); - if (team == UnitsManager_Team) { - ++UnitsManager_Team; + if (team == UnitsManager_DelayedReactionsTeam) { + ++UnitsManager_DelayedReactionsTeam; } } diff --git a/src/transport_udp_default.cpp b/src/transport_udp_default.cpp index 17a4e6f7..d65b7f09 100644 --- a/src/transport_udp_default.cpp +++ b/src/transport_udp_default.cpp @@ -140,6 +140,7 @@ bool TransportUdpDefault::Init(int32_t mode) { SetError("Network not available."); result = false; + } else { UdpPacket = SDLNet_AllocPacket(TRANSPORT_MAX_PACKET_SIZE); SDL_assert(UdpPacket); diff --git a/src/units_manager.cpp b/src/units_manager.cpp index 76f8320e..2b377bc0 100644 --- a/src/units_manager.cpp +++ b/src/units_manager.cpp @@ -115,7 +115,7 @@ static bool UnitsManager_Popup_IsReady(UnitInfo* unit); static void UnitsManager_ClearPins(SmartList* units); static void UnitsManager_ProcessOrder(UnitInfo* unit); -static void UnitsManager_ProcessOrders(SmartList* units); +static void UnitsManager_ProcessUnitOrders(SmartList* units); static void UnitsManager_FinishUnitScaling(UnitInfo* unit); static void UnitsManager_ActivateEngineer(UnitInfo* unit); static void UnitsManager_DeployMasterBuilderInit(UnitInfo* unit); @@ -188,10 +188,6 @@ static void UnitsManager_ProcessOrderDisable(UnitInfo* unit); static void UnitsManager_ProcessOrderUpgrade(UnitInfo* unit); static void UnitsManager_ProcessOrderLayMine(UnitInfo* unit); -uint16_t UnitsManager_Team; - -uint32_t UnitsManager_UnknownCounter; - SmartList UnitsManager_GroundCoverUnits; SmartList UnitsManager_MobileLandSeaUnits; SmartList UnitsManager_ParticleUnits; @@ -207,9 +203,12 @@ SmartPointer UnitsManager_Units[PLAYER_TEAM_MAX]; SmartList UnitsManager_DelayedAttackTargets[PLAYER_TEAM_MAX]; +bool UnitsManager_DelayedReactionsPending; +uint16_t UnitsManager_DelayedReactionsTeam; +uint32_t UnitsManager_DelayedReactionsSyncCounter; + bool UnitsManager_OrdersPending; bool UnitsManager_byte_179448; -bool UnitsManager_byte_178170; bool UnitsManager_TimeBenchmarkInit; uint8_t UnitsManager_TimeBenchmarkNextIndex; @@ -3139,14 +3138,14 @@ void UnitsManager_InitPopupMenus() { UnitsManager_PendingAttacks.Clear(); - UnitsManager_Team = PLAYER_TEAM_RED; + UnitsManager_DelayedReactionsTeam = PLAYER_TEAM_RED; - UnitsManager_UnknownCounter = 0; + UnitsManager_DelayedReactionsSyncCounter = 0; for (int32_t team = PLAYER_TEAM_RED; team < PLAYER_TEAM_MAX - 1; ++team) { if (UnitsManager_TeamInfo[team].team_type != TEAM_TYPE_NONE && UnitsManager_TeamInfo[team].team_type != TEAM_TYPE_ELIMINATED) { - UnitsManager_Team = team; + UnitsManager_DelayedReactionsTeam = team; break; } } @@ -3695,7 +3694,7 @@ void UnitsManager_ScaleUnit(UnitInfo* unit, int32_t state) { unit->RefreshScreen(); } -void UnitsManager_ProcessRemoteOrders() { +void UnitsManager_ProcessOrders() { UnitsManager_EffectCounter = 5; Ai_ClearTasksPendingFlags(); @@ -3707,11 +3706,11 @@ void UnitsManager_ProcessRemoteOrders() { UnitsManager_OrdersPending = false; UnitsManager_byte_179448 = false; - UnitsManager_ProcessOrders(&UnitsManager_GroundCoverUnits); - UnitsManager_ProcessOrders(&UnitsManager_MobileLandSeaUnits); - UnitsManager_ProcessOrders(&UnitsManager_StationaryUnits); - UnitsManager_ProcessOrders(&UnitsManager_MobileAirUnits); - UnitsManager_ProcessOrders(&UnitsManager_ParticleUnits); + UnitsManager_ProcessUnitOrders(&UnitsManager_GroundCoverUnits); + UnitsManager_ProcessUnitOrders(&UnitsManager_MobileLandSeaUnits); + UnitsManager_ProcessUnitOrders(&UnitsManager_StationaryUnits); + UnitsManager_ProcessUnitOrders(&UnitsManager_MobileAirUnits); + UnitsManager_ProcessUnitOrders(&UnitsManager_ParticleUnits); if (Remote_IsNetworkGame) { Remote_ProcessNetPackets(); @@ -3727,10 +3726,15 @@ void UnitsManager_ProcessRemoteOrders() { (*unit_it).state = ORDER_STATE_ATTACK_BEGINNING; } else { + AiLog log("%s at [%i,%i] cannot fire.", UnitsManager_BaseUnits[(*unit_it).unit_type].singular_name, + (*unit_it).grid_x + 1, (*unit_it).grid_y + 1); + (*unit_it).UpdatePinCount((*unit_it).target_grid_x, (*unit_it).target_grid_x, -1); (*unit_it).RestoreOrders(); if ((*unit_it).orders == ORDER_FIRE) { + log.Log("Error, unit's prior orders were fire orders."); + (*unit_it).orders = ORDER_AWAIT; (*unit_it).state = ORDER_STATE_1; } @@ -5149,7 +5153,7 @@ void UnitsManager_ProcessOrder(UnitInfo* unit) { } } -void UnitsManager_ProcessOrders(SmartList* units) { +void UnitsManager_ProcessUnitOrders(SmartList* units) { for (SmartList::Iterator it = units->Begin(); it != units->End(); ++it) { UnitsManager_ProcessOrder(&*it); } @@ -5191,7 +5195,7 @@ bool UnitsManager_IsFactory(ResourceID unit_type) { void UnitsManager_AddToDelayedReactionList(UnitInfo* unit) { if (!ini_get_setting(INI_DISABLE_FIRE)) { UnitsManager_DelayedAttackTargets[unit->team].PushBack(*unit); - UnitsManager_byte_178170 = true; + UnitsManager_DelayedReactionsPending = true; } } @@ -5204,7 +5208,7 @@ void UnitsManager_ClearDelayedReaction(SmartList* units) { } void UnitsManager_ClearDelayedReactions() { - UnitsManager_byte_178170 = false; + UnitsManager_DelayedReactionsPending = false; UnitsManager_ClearDelayedReaction(&UnitsManager_MobileLandSeaUnits); UnitsManager_ClearDelayedReaction(&UnitsManager_MobileAirUnits); @@ -5471,7 +5475,7 @@ bool UnitsManager_PursueEnemy(UnitInfo* unit) { } else { UnitsManager_Units[unit->team] = unit; - UnitsManager_byte_178170 = true; + UnitsManager_DelayedReactionsPending = true; result = true; } @@ -6478,35 +6482,37 @@ bool UnitsManager_AssessAttacks() { } if (are_attacks_delayed) { - if (UnitsManager_TeamInfo[UnitsManager_Team].team_type == TEAM_TYPE_REMOTE) { + if (UnitsManager_TeamInfo[UnitsManager_DelayedReactionsTeam].team_type == TEAM_TYPE_REMOTE) { result = true; } else { are_attacks_delayed = false; - int32_t team = UnitsManager_Team; + int32_t team = UnitsManager_DelayedReactionsTeam; do { - if (UnitsManager_CheckDelayedReactions(UnitsManager_Team)) { + if (UnitsManager_CheckDelayedReactions(UnitsManager_DelayedReactionsTeam)) { are_attacks_delayed = true; } - UnitsManager_Team = (UnitsManager_Team + 1) % 4; + UnitsManager_DelayedReactionsTeam = + (UnitsManager_DelayedReactionsTeam + 1) % TRANSPORT_MAX_TEAM_COUNT; - if (UnitsManager_TeamInfo[UnitsManager_Team].team_type == TEAM_TYPE_REMOTE) { + if (UnitsManager_TeamInfo[UnitsManager_DelayedReactionsTeam].team_type == TEAM_TYPE_REMOTE) { if (are_attacks_delayed) { - UnitsManager_byte_178170 = true; + UnitsManager_DelayedReactionsPending = true; - } else if (UnitsManager_byte_178170) { - UnitsManager_byte_178170 = false; + } else if (UnitsManager_DelayedReactionsPending) { + UnitsManager_DelayedReactionsPending = false; } else { UnitsManager_ClearDelayedReactions(); } - ++UnitsManager_UnknownCounter; + ++UnitsManager_DelayedReactionsSyncCounter; - Remote_SendNetPacket_46(UnitsManager_Team, are_attacks_delayed, UnitsManager_UnknownCounter); + Remote_SendNetPacket_46(UnitsManager_DelayedReactionsTeam, are_attacks_delayed, + UnitsManager_DelayedReactionsSyncCounter); return true; } @@ -6515,7 +6521,7 @@ bool UnitsManager_AssessAttacks() { return true; } - } while (team != UnitsManager_Team); + } while (team != UnitsManager_DelayedReactionsTeam); UnitsManager_ClearDelayedReactions(); @@ -6523,7 +6529,7 @@ bool UnitsManager_AssessAttacks() { } } else { - UnitsManager_byte_178170 = 0; + UnitsManager_DelayedReactionsPending = false; result = false; } diff --git a/src/units_manager.hpp b/src/units_manager.hpp index e636765b..661585f7 100644 --- a/src/units_manager.hpp +++ b/src/units_manager.hpp @@ -32,9 +32,9 @@ struct PopupFunctions { bool (*test)(UnitInfo* unit); }; -extern uint16_t UnitsManager_Team; +extern uint16_t UnitsManager_DelayedReactionsTeam; -extern uint32_t UnitsManager_UnknownCounter; +extern uint32_t UnitsManager_DelayedReactionsSyncCounter; extern SmartList UnitsManager_GroundCoverUnits; extern SmartList UnitsManager_MobileLandSeaUnits; @@ -52,7 +52,7 @@ extern SmartList UnitsManager_DelayedAttackTargets[PLAYER_TEAM_MAX]; extern bool UnitsManager_OrdersPending; extern bool UnitsManager_byte_179448; -extern bool UnitsManager_byte_178170; +extern bool UnitsManager_DelayedReactionsPending; extern int8_t UnitsManager_EffectCounter; extern int8_t UnitsManager_byte_17947D; @@ -73,7 +73,7 @@ void UnitsManager_InitPopupMenus(); int32_t UnitsManager_GetStealthChancePercentage(UnitInfo* unit1, UnitInfo* unit2, int32_t order); SmartPointer UnitsManager_SpawnUnit(ResourceID unit_type, uint16_t team, int32_t grid_x, int32_t grid_y, UnitInfo* parent); -void UnitsManager_ProcessRemoteOrders(); +void UnitsManager_ProcessOrders(); void UnitsManager_NewOrderWhileScaling(UnitInfo* unit); void UnitsManager_CheckIfUnitDestroyed(UnitInfo* unit); void UnitsManager_SetNewOrderInt(UnitInfo* unit, int32_t order, int32_t state);