Code: Select all
Modified: trunk/rts/Game/GameServer.cpp
===================================================================
--- trunk/rts/Game/GameServer.cpp 2008-11-23 19:52:13 UTC (rev 7094)
+++ trunk/rts/Game/GameServer.cpp 2008-11-23 22:18:44 UTC (rev 7095)
@@ -424,14 +424,16 @@
if (serverframenum > 0) {
//send info about the players
int curpos=0;
+ static int ping[MAX_PLAYERS];
+ static float cpu[MAX_PLAYERS];
float refCpu=0.0f;
for (unsigned a = 0; a < players.size(); ++a) {
if (players[a].myState >= GameParticipant::INGAME) {
Broadcast(CBaseNetProtocol::Get().SendPlayerInfo(a, players[a].cpuUsage, players[a].ping));
if (players[a].cpuUsage > refCpu)
refCpu = players[a].cpuUsage;
- cpuUsages[curpos]=players[a].cpuUsage;
- pings[curpos]=players[a].ping;
+ cpu[curpos]=players[a].cpuUsage;
+ ping[curpos]=players[a].ping;
++curpos;
}
}
@@ -439,15 +441,15 @@
medianCpu=0.0f;
medianPing=0;
if(enforceSpeed && curpos>0) {
- std::sort(cpuUsages,cpuUsages+curpos);
- std::sort(pings,pings+curpos);
+ std::sort(cpu,cpu+curpos);
+ std::sort(ping,ping+curpos);
int midpos=curpos/2;
- medianCpu=cpuUsages[midpos];
- medianPing=pings[midpos];
+ medianCpu=cpu[midpos];
+ medianPing=ping[midpos];
if(midpos*2==curpos) {
- medianCpu=(medianCpu+cpuUsages[midpos-1])/2.0f;
- medianPing=(medianPing+pings[midpos-1])/2;
+ medianCpu=(medianCpu+cpu[midpos-1])/2.0f;
+ medianPing=(medianPing+ping[midpos-1])/2;
}
refCpu=medianCpu;
}
Modified: trunk/rts/Game/GameServer.h
===================================================================
--- trunk/rts/Game/GameServer.h 2008-11-23 19:52:13 UTC (rev 7094)
+++ trunk/rts/Game/GameServer.h 2008-11-23 22:18:44 UTC (rev 7095)
@@ -170,9 +170,7 @@
std::vector<GameParticipant> players;
boost::scoped_ptr<GameTeam> teams[MAX_TEAMS];
- float cpuUsages[MAX_PLAYERS];
float medianCpu;
- int pings[MAX_PLAYERS];
int medianPing;
int enforceSpeed;
/////////////////// game settings ///////////////////
I've fixed this, but please don't make code pointlessly non re-entrant.
If it was by accident then this can serve as an example for others
