Changeset 430c80e in network-game for server


Ignore:
Timestamp:
May 18, 2013, 8:14:14 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d69eb32
Parents:
a72bbde
Message:

Fixed elapsed time calculation for server-side player movement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    ra72bbde r430c80e  
    7474
    7575   return NULL;
    76 }
    77 
    78 void broadcastPlayerPositions(map<unsigned int, Player> &m, int sock)
    79 {
    80    map<unsigned int, Player>::iterator it, it2;
    81    NETWORK_MSG serverMsg;
    82 
    83    serverMsg.type = MSG_TYPE_PLAYER;   
    84 
    85    for (it = m.begin(); it != m.end(); it++)
    86    {
    87       it->second.serialize(serverMsg.buffer);
    88 
    89       for (it2 = m.begin(); it2 != m.end(); it2++)
    90       {
    91          if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
    92             error("sendMessage");
    93       }
    94    }
    9576}
    9677
     
    129110   bool broadcastResponse;
    130111   timespec ts;
    131    long timeLastUpdated = 0, curTime = 0, timeLastBroadcast = 0;
     112   int timeLastUpdated = 0, curTime = 0, timeLastBroadcast = 0;
    132113   while (true) {
    133114
     
    135116
    136117      clock_gettime(CLOCK_REALTIME, &ts);
    137       curTime = ts.tv_sec + ts.tv_nsec*1000000000;
    138 
    139       if (timeLastUpdated == 0 || (curTime-timeLastUpdated) >= 50000) {
     118      // make the number smaller so millis can fit in an int
     119      ts.tv_sec = ts.tv_sec & 0x3fffff;
     120      curTime = ts.tv_sec*1000 + ts.tv_nsec/1000000;
     121
     122      if (timeLastUpdated == 0 || (curTime-timeLastUpdated) >= 50) {
    140123         timeLastUpdated = curTime;
    141124
Note: See TracChangeset for help on using the changeset viewer.