nServerLag Class Reference

lag tracker on server More...

List of all members.

Public Member Functions

 nServerLag ()
REAL Ping ()
REAL Credit ()
void Reset ()
void SetClient (int client)
void Report (REAL lag)
REAL CreditLeft ()
REAL TakeCredit (REAL lag)

Static Public Member Functions

static void Balance ()

Private Attributes

REAL creditUsed_
 the used lag credit
double lastTime_
 the last time lag credit was calculated
double lastLag_
 the last time lag was reported to the client
int client_
 the client this object is responsible for


Detailed Description

lag tracker on server

Definition at line 155 of file eLagCompensation.cpp.


Constructor & Destructor Documentation

nServerLag::nServerLag (  )  [inline]

Definition at line 158 of file eLagCompensation.cpp.

References Reset().

00159     {
00160         Reset();
00161     }

Here is the call graph for this function:


Member Function Documentation

REAL nServerLag::Ping (  )  [inline]

Definition at line 163 of file eLagCompensation.cpp.

References client_, nPingAverager::GetPing(), nConnectionInfo::ping, and sn_Connections.

Referenced by Report().

00164     {
00165         return sn_Connections[client_].ping.GetPing();
00166     }

Here is the call graph for this function:

Here is the caller graph for this function:

REAL nServerLag::Credit (  )  [inline]

Definition at line 168 of file eLagCompensation.cpp.

References se_lagCredit.

Referenced by CreditLeft(), Report(), Reset(), and TakeCredit().

00169     {
00170         return se_lagCredit;
00171     }

Here is the caller graph for this function:

void nServerLag::Reset (  )  [inline]

Definition at line 173 of file eLagCompensation.cpp.

References client_, Credit(), creditUsed_, lastLag_, lastTime_, se_lagCreditSweetSpot, and tSysTimeFloat().

Referenced by login_callback(), and nServerLag().

00174     {
00175         creditUsed_ = se_lagCreditSweetSpot * Credit();
00176         lastTime_ = lastLag_ = tSysTimeFloat();
00177         client_ = 0;
00178     }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerLag::SetClient ( int  client  )  [inline]

Definition at line 180 of file eLagCompensation.cpp.

References client_, MAXCLIENTS, and tASSERT.

Referenced by login_callback().

00181     {
00182         tASSERT( 1 <= client && client <= MAXCLIENTS );
00183 
00184         client_ = client;
00185     }

Here is the caller graph for this function:

void nServerLag::Report ( REAL  lag  )  [inline]

Definition at line 187 of file eLagCompensation.cpp.

References client_, Credit(), creditUsed_, EPS, lastLag_, Ping(), REAL, se_clientLagCompensation, se_lagCreditSingle, se_lagCreditSweetSpot, se_receiveLagMessageDescriptor, nMessage::Send(), nVersionFeature::Supported(), tNEW, tSysTimeFloat(), and weight.

Referenced by eLag::Report().

00188     {
00189         // see if it is useful to report
00190         if ( ! se_clientLagCompensation.Supported( client_ ) )
00191             return;
00192 
00193         // clamp
00194         lag = lag > se_lagCreditSingle ? se_lagCreditSingle : lag;
00195 
00196         // get info
00197         REAL credit = Credit();
00198         if ( credit < EPS )
00199             credit = EPS;
00200         REAL ping = Ping();
00201 
00202         // don't report too often
00203         double time = tSysTimeFloat();
00204         if ( time - lastLag_ < 4 * ping )
00205             return;
00206         lastLag_ = time;
00207 
00208         // send a simple message to the client
00209         nMessage * mess = tNEW( nMessage )( se_receiveLagMessageDescriptor );
00210         *mess << lag;
00211 
00212         // propose a weight to the client, it will determine how much impact the lag report has
00213         REAL weight = 1;
00214         if ( se_lagCreditSweetSpot > 0 )
00215         {
00216             weight = ( (creditUsed_+2*lag)/credit )/se_lagCreditSweetSpot;
00217         }
00218         *mess << weight;
00219 
00220         mess->Send( client_ );
00221     }

Here is the call graph for this function:

Here is the caller graph for this function:

REAL nServerLag::CreditLeft (  )  [inline]

Definition at line 223 of file eLagCompensation.cpp.

References Credit(), and creditUsed_.

Referenced by eLag::Credit().

00224     {
00225         return Credit() - creditUsed_;
00226     }

Here is the call graph for this function:

Here is the caller graph for this function:

REAL nServerLag::TakeCredit ( REAL  lag  )  [inline]

Definition at line 228 of file eLagCompensation.cpp.

References Balance(), con, Credit(), creditUsed_, dt, EPS, lastTime_, REAL, se_lagCreditSingle, se_lagCreditTime, se_lagThreshold, and tSysTimeFloat().

Referenced by eLag::TakeCredit().

00229     {
00230         lag -= se_lagThreshold;
00231         if ( lag > 0 )
00232         {
00233 #ifdef DEBUG_LAG
00234             REAL lagBefore = lag;
00235 #endif
00236 
00237             // if everyone is lagging, delete the used credit
00238             Balance();
00239 
00240             // clamp
00241             lag = lag > se_lagCreditSingle ? se_lagCreditSingle : lag;
00242 
00243             // get values
00244             REAL credit = Credit();
00245 
00246             // sanity check
00247             if ( se_lagCreditTime < EPS )
00248                 se_lagCreditTime = EPS;
00249 
00250             // timestep credit
00251             double time = tSysTimeFloat();
00252             REAL dt = time - lastTime_;
00253             lastTime_ = time;
00254             creditUsed_ -= dt * credit/se_lagCreditTime;
00255             if ( creditUsed_ < 0 )
00256                 creditUsed_ = 0;
00257 
00258             // see how much credit is left to be used
00259             REAL creditLeft = credit - creditUsed_;
00260             if ( lag > creditLeft )
00261                 lag = creditLeft;
00262             if ( lag < 0 )
00263                 lag = 0;
00264 
00265             // use it and return it
00266             creditUsed_ += lag;
00267 
00268 #ifdef DEBUG_LAG
00269             {
00270                 if ( lag > lagBefore )
00271                     con << "Requesting " << lagBefore << " seconds of lag credit, granting " << lag << ".\n";
00272                 else
00273                     con << "Granting " << lag << " seconds of lag credit.\n";
00274             }
00275 #endif
00276 
00277             lag += se_lagThreshold;
00278 
00279         }
00280 
00281         return lag;
00282     }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerLag::Balance (  )  [static]

Definition at line 295 of file eLagCompensation.cpp.

References creditUsed_, MAXCLIENTS, REAL, se_lagCredit, se_lagCreditSweetSpot, sn_Connections, and sn_NumUsers().

Referenced by TakeCredit().

00296 {
00297     int i;
00298 
00299     // only if many users are online
00300     if ( sn_NumUsers() <= 1 )
00301         return;
00302 
00303     // find the minimum used credit
00304     REAL minCredit = se_lagCredit;
00305     for ( i = MAXCLIENTS; i>0; --i )
00306     {
00307         if ( sn_Connections[i].socket )
00308         {
00309             REAL credit = se_serverLag[i].creditUsed_;
00310             if ( credit < minCredit )
00311                 minCredit = credit;
00312         }
00313     }
00314 
00315     // find out how much you can take away
00316     REAL amnesty = minCredit - se_lagCredit * se_lagCreditSweetSpot;
00317 
00318     // and take it away from everyone
00319     if ( amnesty > 0 )
00320         for ( i = MAXCLIENTS; i>0; --i )
00321             se_serverLag[i].creditUsed_ -= amnesty;
00322 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

REAL nServerLag::creditUsed_ [private]

the used lag credit

Definition at line 286 of file eLagCompensation.cpp.

Referenced by Balance(), CreditLeft(), Report(), Reset(), and TakeCredit().

double nServerLag::lastTime_ [private]

the last time lag credit was calculated

Definition at line 287 of file eLagCompensation.cpp.

Referenced by Reset(), and TakeCredit().

double nServerLag::lastLag_ [private]

the last time lag was reported to the client

Definition at line 288 of file eLagCompensation.cpp.

Referenced by Report(), and Reset().

int nServerLag::client_ [private]

the client this object is responsible for

Definition at line 289 of file eLagCompensation.cpp.

Referenced by Ping(), Report(), Reset(), and SetClient().


The documentation for this class was generated from the following file:
Generated on Sat Mar 15 23:50:34 2008 for Armagetron Advanced by  doxygen 1.5.4