From: havoc Date: Fri, 28 Mar 2003 13:22:06 +0000 (+0000) Subject: refactored NET_SendToAll, it is debatable whether it is more readable or not, but... X-Git-Tag: xonotic-v0.1.0preview~6703 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fdc383f68458695b081a8418beb36d7097c6f455;p=xonotic%2Fdarkplaces.git refactored NET_SendToAll, it is debatable whether it is more readable or not, but it works the same, and is shorter, and I think it is slightly more understandable than the mess it used to be git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2868 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/net_main.c b/net_main.c index e29480a3..0d085bbe 100644 --- a/net_main.c +++ b/net_main.c @@ -708,7 +708,7 @@ returns -1 if the connection died int NET_SendMessage (qsocket_t *sock, sizebuf_t *data) { int r; - + if (!sock) return -1; @@ -730,7 +730,7 @@ int NET_SendMessage (qsocket_t *sock, sizebuf_t *data) int NET_SendUnreliableMessage (qsocket_t *sock, sizebuf_t *data) { int r; - + if (!sock) return -1; @@ -760,7 +760,7 @@ message to be transmitted. qboolean NET_CanSendMessage (qsocket_t *sock) { int r; - + if (!sock) return false; @@ -770,7 +770,7 @@ qboolean NET_CanSendMessage (qsocket_t *sock) SetNetTime(); r = sfunc.CanSendMessage(sock); - + return r; } @@ -808,71 +808,43 @@ int NET_SendToAll(sizebuf_t *data, int blocktime) double start; int i; int count = 0; - qboolean state1 [MAX_SCOREBOARD]; - qboolean state2 [MAX_SCOREBOARD]; + qbyte state [MAX_SCOREBOARD]; - for (i=0, host_client = svs.clients ; inetconnection) - continue; - if (host_client->active) - { - if (host_client->netconnection->driver == 0) - { - NET_SendMessage(host_client->netconnection, data); - state1[i] = true; - state2[i] = true; - continue; - } - count++; - state1[i] = false; - state2[i] = false; - } - else - { - state1[i] = true; - state2[i] = true; - } - } + for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++) + state[i] = (host_client->netconnection && host_client->active) ? 0 : 2; + // for every player (simultaneously) wait for the first CanSendMessage + // and send the message, then wait for a second CanSendMessage (verifying + // it was received) start = Sys_DoubleTime(); - while (count) + do { count = 0; - for (i=0, host_client = svs.clients ; inetconnection)) - { - state1[i] = true; - NET_SendMessage(host_client->netconnection, data); - } - else - { - NET_GetMessage (host_client->netconnection); - } - count++; - continue; - } - - if (! state2[i]) + if (state[i] < 2) { + // need to send to this one if (NET_CanSendMessage (host_client->netconnection)) { - state2[i] = true; + if (state[i] == 0) + { + if (NET_SendMessage (host_client->netconnection, data) == 1) + state[i] = 2; // connection lost + else + count++; + } + state[i]++; } else { NET_GetMessage (host_client->netconnection); + count++; } - count++; - continue; } } - if ((Sys_DoubleTime() - start) > blocktime) - break; } + while (count && (Sys_DoubleTime() - start) < blocktime); return count; }