From 2645d41b5f410b7223e062fd124152e3dedb9522 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 19 Oct 2014 03:48:29 +0000 Subject: [PATCH] Convert net_udp to range_for --- similar/main/net_udp.cpp | 136 +++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index 8e774cbe3..5733ee9d5 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -104,7 +104,7 @@ static int net_udp_start_game(void); int UDP_num_sendto = 0, UDP_len_sendto = 0, UDP_num_recvfrom = 0, UDP_len_recvfrom = 0; UDP_mdata_info UDP_MData; UDP_sequence_packet UDP_Seq; -int UDP_mdata_queue_highest = 0; +unsigned UDP_mdata_queue_highest; array UDP_mdata_queue; UDP_mdata_check UDP_mdata_trace[MAX_PLAYERS]; UDP_sequence_packet UDP_sync_player; // For rejoin object syncing @@ -1169,9 +1169,9 @@ int net_udp_endlevel(int *secret) net_udp_listen(); net_udp_send_endlevel_packet(); - for (int i=0; isides) { - if ( ((tm = seg->sides[j].tmap_num2) != 0) && + if ( ((tm = j.tmap_num2) != 0) && ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) && ((bm = Effects[ec].dest_bm_num) != -1) ) { if (vector & (1 << count)) { - seg->sides[j].tmap_num2 = bm | (tm&0xc000); + j.tmap_num2 = bm | (tm&0xc000); } count++; Assert(count < 32); @@ -1924,11 +1924,11 @@ static void net_udp_resend_sync_due_to_packet_loss() static void net_udp_add_player(UDP_sequence_packet *p) { - for (int i=0; iplayer.protocol.udp.addr) + if (i.protocol.udp.addr == p->player.protocol.udp.addr) { - Netgame.players[i].LastPacketTime = timer_query(); + i.LastPacketTime = timer_query(); return; // already got them } } @@ -2005,8 +2005,8 @@ void net_udp_update_netgame(void) { // Update the netgame struct with current game variables Netgame.numconnected=0; - for (int i=0;i(i), (CALLSIGN_LEN+1)); len += CALLSIGN_LEN + 1; } - for (int i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.locations) { - PUT_INTEL_INT(buf + len, Netgame.locations[i]); len += 4; + PUT_INTEL_INT(buf + len, i); len += 4; } - for (int i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.kills) { - for (int j = 0; j < MAX_PLAYERS; j++) + range_for (auto &j, i) { - PUT_INTEL_SHORT(buf + len, Netgame.kills[i][j]); len += 2; + PUT_INTEL_SHORT(buf + len, j); len += 2; } } PUT_INTEL_SHORT(buf + len, Netgame.segments_checksum); len += 2; PUT_INTEL_SHORT(buf + len, Netgame.team_kills[0]); len += 2; PUT_INTEL_SHORT(buf + len, Netgame.team_kills[1]); len += 2; - for (int i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.killed) { - PUT_INTEL_SHORT(buf + len, Netgame.killed[i]); len += 2; + PUT_INTEL_SHORT(buf + len, i); len += 2; } - for (int i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.player_kills) { - PUT_INTEL_SHORT(buf + len, Netgame.player_kills[i]); len += 2; + PUT_INTEL_SHORT(buf + len, i); len += 2; } PUT_INTEL_INT(buf + len, Netgame.KillGoal); len += 4; PUT_INTEL_INT(buf + len, Netgame.PlayTimeAllowed); len += 4; PUT_INTEL_INT(buf + len, Netgame.level_time); len += 4; PUT_INTEL_INT(buf + len, Netgame.control_invul_time); len += 4; PUT_INTEL_INT(buf + len, Netgame.monitor_vector); len += 4; - for (int i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.player_score) { - PUT_INTEL_INT(buf + len, Netgame.player_score[i]); len += 4; + PUT_INTEL_INT(buf + len, i); len += 4; } - for (int i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.player_flags) { - buf[len] = Netgame.player_flags[i]; len++; + buf[len] = i; len++; } PUT_INTEL_SHORT(buf + len, Netgame.PacketsPerSec); len += 2; buf[len] = Netgame.PacketLossPrevention; len++; @@ -2467,40 +2467,40 @@ static void net_udp_process_game_info(ubyte *data, int, const _sockaddr &game_ad i.copy(reinterpret_cast(&data[len]), (CALLSIGN_LEN+1)); len += CALLSIGN_LEN + 1; } - for (unsigned i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.locations) { - Netgame.locations[i] = GET_INTEL_INT(&(data[len])); len += 4; + i = GET_INTEL_INT(&(data[len])); len += 4; } - for (unsigned i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.kills) { - for (int j = 0; j < MAX_PLAYERS; j++) + range_for (auto &j, i) { - Netgame.kills[i][j] = GET_INTEL_SHORT(&(data[len])); len += 2; + j = GET_INTEL_SHORT(&(data[len])); len += 2; } } Netgame.segments_checksum = GET_INTEL_SHORT(&(data[len])); len += 2; Netgame.team_kills[0] = GET_INTEL_SHORT(&(data[len])); len += 2; Netgame.team_kills[1] = GET_INTEL_SHORT(&(data[len])); len += 2; - for (unsigned i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.killed) { - Netgame.killed[i] = GET_INTEL_SHORT(&(data[len])); len += 2; + i = GET_INTEL_SHORT(&(data[len])); len += 2; } - for (unsigned i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.player_kills) { - Netgame.player_kills[i] = GET_INTEL_SHORT(&(data[len])); len += 2; + i = GET_INTEL_SHORT(&(data[len])); len += 2; } Netgame.KillGoal = GET_INTEL_INT(&(data[len])); len += 4; Netgame.PlayTimeAllowed = GET_INTEL_INT(&(data[len])); len += 4; Netgame.level_time = GET_INTEL_INT(&(data[len])); len += 4; Netgame.control_invul_time = GET_INTEL_INT(&(data[len])); len += 4; Netgame.monitor_vector = GET_INTEL_INT(&(data[len])); len += 4; - for (unsigned i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.player_score) { - Netgame.player_score[i] = GET_INTEL_INT(&(data[len])); len += 4; + i = GET_INTEL_INT(&(data[len])); len += 4; } - for (unsigned i = 0; i < MAX_PLAYERS; i++) + range_for (auto &i, Netgame.player_flags) { - Netgame.player_flags[i] = data[len]; len++; + i = data[len]; len++; } Netgame.PacketsPerSec = GET_INTEL_SHORT(&(data[len])); len += 2; Netgame.PacketLossPrevention = data[len]; len++; @@ -3390,10 +3390,10 @@ void net_udp_read_sync_packet( ubyte * data, int data_len, const _sockaddr &send Player_num = -1; - for (int i=0; i spd(new start_poll_data{}); @@ -3669,9 +3669,9 @@ abort: // Count number of players chosen N_players = 0; - for (int i=0; i