Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8623 in orxonox.OLD for trunk/src/lib/network/connection_monitor.cc


Ignore:
Timestamp:
Jun 20, 2006, 1:39:01 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network branche back here
merged with command:
svn merge -r8230:HEAD https://svn.orxonox.net/orxonox/branches/network .
conflicts resolved in favour of the network branche (conflicts were in network)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/connection_monitor.cc

    r8068 r8623  
    130130
    131131/**
     132 * remove old packets
     133 * @param packetHistory
     134 * @param tick
     135 */
     136void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick )
     137{
     138  while ( packetHistory.begin()->first < tick - MSECS_TO_CALC_BWIDTH )
     139    packetHistory.erase( packetHistory.begin() );
     140}
     141
     142/**
    132143 * calculate bandwidth out of packethistory
    133144 * @param packetHistory packet history
     
    135146 * @return bandwidth in bytes/sec
    136147 */
    137 float ConnectionMonitor::calculateBandWidth( std::map< int, int > packetHistory, int tick )
    138 {
    139   // delete old packets
    140   while ( packetHistory.begin()->first < tick - MSECS_TO_CALC_BWIDTH )
    141     packetHistory.erase( packetHistory.begin() );
     148float ConnectionMonitor::calculateBandWidth( std::map< int, int > & packetHistory, int tick )
     149{
     150  removeOldPackets( packetHistory, tick );
    142151 
    143152  float res = 0.0f;
    144  
     153#if 0
    145154  for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )
    146155  {
     
    155164 
    156165  res *= 1000.0f;
    157  
     166#endif
     167
     168  for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )
     169  {
     170    res += it->second;
     171  }
     172 
     173  if ( packetHistory.size() <= 1 )
     174    res = 0.0f;
     175  else
     176    res /= (float)(tick - packetHistory.begin()->first);
     177 
     178  res *= 1000.0f;
     179
    158180  return res;
    159181}
Note: See TracChangeset for help on using the changeset viewer.