mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Fix crashing when using wasm backend at -O1
This commit is contained in:
parent
bece154d2b
commit
cecfe81452
13
src/Server.c
13
src/Server.c
@ -100,18 +100,21 @@ void Ping_Update(int id) {
|
||||
}
|
||||
|
||||
int Ping_AveragePingMS(void) {
|
||||
double totalMs = 0.0;
|
||||
int i, measures = 0;
|
||||
int i, measures = 0, totalMs = 0;
|
||||
|
||||
for (i = 0; i < Array_Elems(ping_entries); i++) {
|
||||
struct PingEntry entry = ping_entries[i];
|
||||
if (!entry.sent || !entry.recv) continue;
|
||||
|
||||
/* Half, because received->reply time is actually twice time it takes to send data */
|
||||
totalMs += (entry.recv - entry.sent) * 0.5;
|
||||
totalMs += (int)(entry.recv - entry.sent);
|
||||
measures++;
|
||||
}
|
||||
return measures == 0 ? 0 : (int)(totalMs / measures);
|
||||
|
||||
if (!measures) return 0;
|
||||
/* (recv - send) is time for packet to be sent to server and then sent back. */
|
||||
/* However for ping, only want time to send data to server, so half the total. */
|
||||
totalMs /= 2;
|
||||
return totalMs / measures;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user