Skip to content

Commit

Permalink
Various remote module and network lobby refactorings, corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
klei1984 committed Oct 27, 2023
1 parent 5c4ccff commit 4d22674
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 126 deletions.
4 changes: 2 additions & 2 deletions src/dialogmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/game_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/helpmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
70 changes: 42 additions & 28 deletions src/networkmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -251,16 +251,20 @@ void NetworkMenu::ButtonInit(int32_t index) {
image_id = static_cast<ResourceID>(image_id + 1);
}

buttons[index] = new (std::nothrow)
Button(image_id, static_cast<ResourceID>(control->image_id + 1), control->bounds.ulx, control->bounds.uly);
buttons[index] = new (std::nothrow) Button(image_id, static_cast<ResourceID>(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<ResourceID>(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);
Expand Down Expand Up @@ -320,16 +324,18 @@ 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);

for (int32_t i = 0; i < NETWORK_MENU_IMAGE_COUNT; ++i) {
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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -519,6 +522,9 @@ void NetworkMenu::EventScenarioButton() {
Reinit(true);
NetSync(team_index);
DrawScreen();

} else {
Reinit(true);
}
}

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

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -877,7 +887,7 @@ void NetworkMenu::NetSync(int32_t team) {
game_found = false;

while (!game_found) {
Remote_NetSync();
Remote_UiProcessNetPackets();

if (!host_node) {
break;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;

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

Expand Down
Loading

0 comments on commit 4d22674

Please sign in to comment.