nPingAverager Class Reference

averager for pings, detects lag More...

#include <nNetwork.h>

Collaboration diagram for nPingAverager:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 nPingAverager ()
 constructor
 ~nPingAverager ()
 destructor
 operator REAL () const
 conversion to number == GetPing()
REAL GetPing () const
 returns the current best estimate for the ping
REAL GetPingSnail () const
 returns the extremely longterm average ping
REAL GetPingSlow () const
 returns the longterm average ping
REAL GetPingFast () const
 returns the shortterm average ping
bool IsSpiking () const
 returns whether a lag spike is currently in process
void Timestep (REAL decay)
 lets all values decay, so they can be replaced by new ones
void Add (REAL value, REAL weight)
 adds a value to the average
void Add (REAL value)
 adds a value to the average
void Reset ()
 resets average to zero
nAverager const & GetSnailAverager (void) const
 Gets extremely slow averager.
nPingAverager const & GetSnailAverager (nAverager &snail) const
 Gets extremely slow averager.
nAverager const & GetSlowAverager (void) const
 Gets slow, reliable averager.
nPingAverager const & GetSlowAverager (nAverager &slow) const
 Gets slow, reliable averager.
nAverager const & GetFastAverager (void) const
 Gets fast averager for detecting ping spikes.
nPingAverager const & GetFastAverager (nAverager &fast) const
 Gets fast averager for detecting ping spikes.

Static Public Member Functions

static void SetWeight (REAL const &weight)
 Sets the default statistical weight.
static REAL GetWeight (void)
 Gets the default statistical weight.
static void GetWeight (REAL &weight)
 Gets the default statistical weight.

Protected Member Functions

nPingAveragerSetSnailAverager (nAverager const &snail)
 Sets very slow averager.
nPingAveragerSetSlowAverager (nAverager const &slow)
 Sets slow, reliable averager.
nPingAveragerSetFastAverager (nAverager const &fast)
 Sets fast averager for detecting ping spikes.

Private Attributes

nAverager snail_
 extremely slow averager
nAverager slow_
 slow, reliable averager
nAverager fast_
 fast averager for detecting ping spikes

Static Private Attributes

static REAL weight_ = 1
 current default weight


Detailed Description

averager for pings, detects lag

Definition at line 269 of file nNetwork.h.


Constructor & Destructor Documentation

nPingAverager::nPingAverager ( void   ) 

constructor

Definition at line 3828 of file nNetwork.cpp.

03832 {

nPingAverager::~nPingAverager ( void   ) 

destructor

Definition at line 3842 of file nNetwork.cpp.


Member Function Documentation

nPingAverager::operator REAL ( void   )  const

conversion to number == GetPing()

Returns:
our best estimate for the ping

Definition at line 3911 of file nNetwork.cpp.

03915 {

REAL nPingAverager::GetPing ( void   )  const

returns the current best estimate for the ping

Returns:
our best estimate for the ping

Definition at line 3856 of file nNetwork.cpp.

Referenced by GameLoop(), nServerLag::Ping(), eTimer::ReadSync(), and sn_GetTimeout().

03860 {
03861     // collect data
03862     // determine the lowest guessed value for variance.
03863     // lag spikes should not contribute here too much.
03864     REAL variance = 1;
03865     {
03866         REAL snailVariance = this->snail_.GetDataVariance();
03867         REAL slowVariance = this->slow_.GetDataVariance();
03868         REAL fastVariance = this->fast_.GetDataVariance();
03869         variance = variance < snailVariance ? variance : snailVariance;
03870         variance = variance < slowVariance ? variance : slowVariance;
03871         variance = variance < fastVariance ? variance : fastVariance;
03872     }
03873 
03874     REAL pingSnail  = this->GetPingSnail();
03875     REAL pingSlow   = this->GetPingSlow();
03876     REAL pingFast   = this->GetPingFast();
03877 
03878     // the proposed return value: defaults to the snail ping, it flucuates the least
03879     REAL pingReturn = pingSnail;
03880 
03881     // return slow average if that differs from the snail one by at least one standard deviation
03882     if ( ( pingSlow - pingReturn ) * ( pingSlow - pingReturn ) > variance )
03883     {
03884         // but clamp it to sane values
03885         if ( pingSlow > pingReturn * 2 )
03886             pingSlow = pingReturn * 2;
03887 
03888         pingReturn = pingSlow;
03889     }
03890 
03891     // same for fast ping
03892     if ( ( pingFast - pingReturn ) * ( pingFast - pingReturn ) > variance )
03893     {
03894         if ( pingFast > pingReturn * 2 )
03895             pingFast = pingReturn * 2;
03896 
03897         pingReturn = pingFast;
03898     }
03899 

Here is the caller graph for this function:

REAL nPingAverager::GetPingSnail ( void   )  const

returns the extremely longterm average ping

Returns:
extremely longterm ping average

Definition at line 3926 of file nNetwork.cpp.

03930 {

REAL nPingAverager::GetPingSlow ( void   )  const

returns the longterm average ping

Returns:
longterm ping average

Definition at line 3941 of file nNetwork.cpp.

03945 {

REAL nPingAverager::GetPingFast ( void   )  const

returns the shortterm average ping

Returns:
shortterm ping average

Definition at line 3956 of file nNetwork.cpp.

03960 {

bool nPingAverager::IsSpiking ( void   )  const

returns whether a lag spike is currently in process

Returns:
true if unusual high fluctuations exist in the ping

Definition at line 3971 of file nNetwork.cpp.

03975 {

void nPingAverager::Timestep ( REAL  decay  ) 

lets all values decay, so they can be replaced by new ones

Parameters:
decay time since last timestep

Definition at line 3987 of file nNetwork.cpp.

Referenced by ready_handler().

03991 {
03992     snail_.Timestep( decay * .02 );

Here is the caller graph for this function:

void nPingAverager::Add ( REAL  value,
REAL  weight 
)

adds a value to the average

Parameters:
value the value to add
weight the value's statistical weight

Definition at line 4005 of file nNetwork.cpp.

04009 {
04010     // add value to both averagers
04011     snail_.Add( value, weight );

void nPingAverager::Add ( REAL  value  ) 

adds a value to the average

Parameters:
value the value to add with default weight

Definition at line 4023 of file nNetwork.cpp.

04027 {

void nPingAverager::Reset ( void   ) 

resets average to zero

Definition at line 4038 of file nNetwork.cpp.

04042 {
04043     snail_.Reset();
04044     slow_. Reset();
04045     fast_. Reset();
04046 
04047     // fill in some low weight values
04048     Add( 1, .000001 );
04049     Add( 0, .000001 );
04050 
04051     // pin snail averager close to zero

void nPingAverager::SetWeight ( REAL const &  weight  )  [inline, static]

Sets the default statistical weight.

Parameters:
weight the default statistical weight to set

Definition at line 893 of file nNetwork.h.

References weight_.

Referenced by gGame::GameLoop(), and gGame::StateUpdate().

00894 {
00895     weight_ = weight;
00896 }

Here is the caller graph for this function:

REAL nPingAverager::GetWeight ( void   )  [inline, static]

Gets the default statistical weight.

Returns:
the default statistical weight

Definition at line 863 of file nNetwork.h.

References weight_.

00864 {
00865     return weight_;
00866 }

void nPingAverager::GetWeight ( REAL weight  )  [inline, static]

Gets the default statistical weight.

Parameters:
weight the default statistical weight to fill

Definition at line 878 of file nNetwork.h.

References weight_.

00879 {
00880     weight = weight_;
00881 }

nAverager const & nPingAverager::GetSnailAverager ( void   )  const [inline]

Gets extremely slow averager.

Returns:
slow, reliable averager

Definition at line 908 of file nNetwork.h.

References snail_.

Referenced by sn_GetTimeout(), and gCycleMovement::TimestepCore().

00909 {
00910     return this->snail_;
00911 }

Here is the caller graph for this function:

nPingAverager const & nPingAverager::GetSnailAverager ( nAverager snail  )  const [inline]

Gets extremely slow averager.

Parameters:
snail very slow averager to fill
Returns:
A reference to this to allow chaining

Definition at line 924 of file nNetwork.h.

References snail_.

00925 {
00926     snail = this->snail_;
00927     return *this;
00928 }

nAverager const & nPingAverager::GetSlowAverager ( void   )  const [inline]

Gets slow, reliable averager.

Returns:
slow, reliable averager

Definition at line 956 of file nNetwork.h.

References slow_.

Referenced by GameLoop().

00957 {
00958     return this->slow_;
00959 }

Here is the caller graph for this function:

nPingAverager const & nPingAverager::GetSlowAverager ( nAverager slow  )  const [inline]

Gets slow, reliable averager.

Parameters:
slow slow, reliable averager to fill
Returns:
A reference to this to allow chaining

Definition at line 972 of file nNetwork.h.

References slow_.

00973 {
00974     slow = this->slow_;
00975     return *this;
00976 }

nAverager const & nPingAverager::GetFastAverager ( void   )  const [inline]

Gets fast averager for detecting ping spikes.

Returns:
fast averager for detecting ping spikes

Definition at line 1005 of file nNetwork.h.

References fast_.

Referenced by eTimer::ReadSync().

01006 {
01007     return this->fast_;
01008 }

Here is the caller graph for this function:

nPingAverager const & nPingAverager::GetFastAverager ( nAverager fast  )  const [inline]

Gets fast averager for detecting ping spikes.

Parameters:
fast fast averager for detecting ping spikes to fill
Returns:
A reference to this to allow chaining

Definition at line 1021 of file nNetwork.h.

References fast_.

01022 {
01023     fast = this->fast_;
01024     return *this;
01025 }

nPingAverager & nPingAverager::SetSnailAverager ( nAverager const &  snail  )  [inline, protected]

Sets very slow averager.

Parameters:
snail very slow averager to set
Returns:
A reference to this to allow chaining

Definition at line 941 of file nNetwork.h.

References snail_.

00942 {
00943     this->snail_ = snail;
00944     return *this;
00945 }

nPingAverager & nPingAverager::SetSlowAverager ( nAverager const &  slow  )  [inline, protected]

Sets slow, reliable averager.

Parameters:
slow slow, reliable averager to set
Returns:
A reference to this to allow chaining

Definition at line 989 of file nNetwork.h.

References slow_.

00990 {
00991     this->slow_ = slow;
00992     return *this;
00993 }

nPingAverager & nPingAverager::SetFastAverager ( nAverager const &  fast  )  [inline, protected]

Sets fast averager for detecting ping spikes.

Parameters:
fast fast averager for detecting ping spikes to set
Returns:
A reference to this to allow chaining

Definition at line 1038 of file nNetwork.h.

References fast_.

01039 {
01040     this->fast_ = fast;
01041     return *this;
01042 }


Member Data Documentation

nAverager nPingAverager::snail_ [private]

extremely slow averager

Definition at line 287 of file nNetwork.h.

Referenced by GetSnailAverager(), and SetSnailAverager().

nAverager nPingAverager::slow_ [private]

slow, reliable averager

Definition at line 288 of file nNetwork.h.

Referenced by GetSlowAverager(), and SetSlowAverager().

nAverager nPingAverager::fast_ [private]

fast averager for detecting ping spikes

Definition at line 289 of file nNetwork.h.

Referenced by GetFastAverager(), and SetFastAverager().

REAL nPingAverager::weight_ = 1 [static, private]

current default weight

Definition at line 290 of file nNetwork.h.

Referenced by GetWeight(), and SetWeight().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:49:18 2008 for Armagetron Advanced by  doxygen 1.5.4