ReplicaNet and RNLobby  1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DataBlock_Predict_Float Class Reference

#include <DataBlock_Predict_Float.h>

Inheritance diagram for DataBlock_Predict_Float:
Inheritance graph
[legend]
Collaboration diagram for DataBlock_Predict_Float:
Collaboration graph
[legend]

Classes

struct  MasterData
 
struct  ParsedData
 
struct  ReplicaData
 
struct  SessionBlock_Predict_Float
 

Public Member Functions

 RN_CLASS_MINIMAL_RTTI ()
 
 DataBlock_Predict_Float ()
 
virtual ~DataBlock_Predict_Float ()
 
virtual void Poll (DataBlockReason *reason, const bool discardOlderIncluded=false, const unsigned int discardOrder=0)
 
virtual void ParseMessage (MessageHelper *message)
 
virtual void GiveDeltaHint (void *pdata, int dataLen)
 
virtual void GiveDeltaHint (const float delta)
 
virtual void ContinuityBreak (unsigned char breakTypes)
 
virtual bool GetLastDelta (bool &continuityBreak, float &sample, SysTimeType &time, float &delta)
 
bool IsAttached (void *data)
 
void RegisterInClassPointer (float *data)
 
void SetMinError (float minerror=0.1f)
 
void SetMaxError (float maxerror=1.0f)
 
void SetMinDistance (float distance=0.1f)
 
void SetMaxDistance (float distance=1.0f)
 
void SetInterpolationFilter (float interpolation=0.1f)
 
void SetQuadratic (void)
 
void SetLinear (void)
 
void SetLagged (const float time=0.0f)
 
void SetSnapToDifference (const float difference=-1.0f)
 
void BoundaryEnable (void)
 
void BoundaryDisable (void)
 
void BoundaryWrapAround (void)
 
void BoundaryCapped (void)
 
void BoundaryLowerUpper (const float lower, const float upper)
 
void BoundaryApplyToMaster (void)
 
void BoundaryDoNotApplyToMaster (void)
 
void SetValueFloat (void)
 
void SetValueShortFloat (void)
 
void SetDeltaFloat (void)
 
void SetDeltaShortFloat (void)
 
void ReplicaContinuityBreak (const SysTimeType time, const float sample, const float delta, const bool continuityBreak, const bool ignoreTimeCheck=false, const bool clearPreviousUpdates=false)
 
void SetTimeDelta (const float timeDelta=0.0f)
 
- Public Member Functions inherited from DataBlock
virtual int GetThisClassType (void)
 
 DataBlock ()
 
virtual ~DataBlock ()
 
void SetVariableName (const char *name=0)
 
void BindReplicaNet (ReplicaNet *current)
 
void BindReplicaObject (ReplicaObject *object)
 
void SetReliableFlag (bool reliable=false)
 
bool GetReliableFlag (void) const
 
void SetCertainFlag (bool certain=false)
 
bool GetCertainFlag (void) const
 
void SetOrderedFlag (bool ordered=false)
 
bool GetOrderedFlag (void) const
 
void SetDiscardOlder (const int windowBits=0)
 
int GetDiscardOlder (void) const
 
void SetAutomaticUpdatesFlag (bool automatic=true)
 
bool GetAutomaticUpdatesFlag (void) const
 
void GiveDeltaHint (float delta)
 
void SetForceReflectionUpdate (const bool enable=false)
 
bool GetForceReflectionUpdate (void)
 
void SetReflectionMasterUpdate (const bool enable=false)
 
bool GetReflectionMasterUpdate (void)
 
virtual bool IsAllocated (void) const
 
void SetIsAllocated (const bool isAllocated=true)
 
void SetUpdateDelayMinimum (const float delay=0.0f)
 
float GetUpdateDelayMinimum (void) const
 
void SetForceSendMaximumUpdates (const int updates=0)
 
int GetForceSendMaximumUpdates (void) const
 
void SetForceSendTimeDelay (const float delay=0.0f)
 
float GetForceSendTimeDelay (void) const
 
void SetBand (const unsigned int band=0)
 
unsigned int GetBand (void) const
 
bool ShouldDiscard (MessageHelper *message)
 
virtual void OwnerChanged (const int sessionID)
 
bool GetDiscardThisUpdate (void) const
 

Static Public Member Functions

static DataBlock_Predict_FloatRegister (float *data)
 
static bool BoundaryApplyToValue (ReplicaObject *object, float &value)
 

Protected Member Functions

float ApplyBoundaryToValue (const float value) const
 
int AddDataBlockData (DynamicMessageHelper *message, const float sample, const SysTimeType time, const float delta)
 
void FreeSessionBlocks (void)
 
float CalculateReplicaValue (DataBlockReason *reason)
 
- Protected Member Functions inherited from DataBlock
void SetID (int id)
 
const char * GetROName (ReplicaObject *from=0)
 
void EmitBaseDebugInfo (const char *name, const char *className, DataBlockReason *reason)
 
void EmitBaseDebugInfoUpdates (const char *name, const char *className, DataBlockReason *reason)
 
std::string GetVariableName (void)
 

Protected Attributes

float * mData
 
bool mContinuityBreak
 
bool mIsDistanceBased
 
float mMinDistance
 
float mMaxDistance
 
float mMinError
 
bool mIsQuadratic
 
bool mGotData
 
bool mImplementTeleport
 
bool mDoPrep
 
float mTestData
 
float mMaxError
 
float mInterpolationFilter
 
RegistryManagerMap< int,
SessionBlock_Predict_Float
mPerSessionData
 
ReplicaData mReplicaData
 
MasterData mMasterData
 
bool mDoneMasterPoll
 
std::map< SysTimeType, ParsedDatamParsedByTime
 
float mLagged
 
SysTimeType mFirstLaggedTime
 
float mSnapToDifference
 
bool mBoundaryEnable
 
bool mBoundaryIsWrap
 
float mBoundaryLower
 
float mBoundaryUpper
 
bool mBoundaryWriteBack
 
SysTimeType mLastGoodDataTime
 
bool mShortValue
 
bool mShortDelta
 
float mTimeDelta
 
- Protected Attributes inherited from DataBlock
short mID
 
ReplicaNetmBoundReplicaNet
 
ReplicaObjectmBoundObject
 
bool mReliable
 
bool mCertain
 
bool mOrdered
 
bool mAutomaticUpdates
 
bool mIsAllocated
 
bool mDebugOn
 
char * mDebugText
 
float mUpdateDelayMinimum
 
int mForceSendMaximumUpdates
 
float mForceSendTimeDelay
 
char * mVariableName
 
unsigned int mBand
 
int mDiscardOlder
 
unsigned int mDiscardOlderMidPoint
 
unsigned int mDiscardOlderEndPoint
 
size_t mDiscardOlderRealSize
 
unsigned int mLocalisedOrderingSent
 
unsigned int mLocalisedOrderingReceived
 
bool mDiscardThisUpdate
 
bool mForceReflectionUpdate
 
bool mReflectionMasterUpdate
 

Additional Inherited Members

- Public Types inherited from DataBlock
enum  ContinuityBreakTypes { kStop = 1, kSuddenChange = 2, kTeleport = 4 }
 

Detailed Description

This DataBlock derived class tries to perform data prediction on float variable types.
This class operates on three levels.
1) It constantly checks the data value and notes down changes based on what it thinks are continuity changes using the extrapolation model for the master side.
2) Each {value,delta and time} update sent to a replica object is stored and using this information the extrapolation/interpolation is checked against what the current value is doing. If the extrapolation is too far off based on the input tolerance values then the master copy of the extrapolation data is used to calculate a new more accurate prediction model.
3) The replica version of this class receives {value,delta and time} updates and extrapolates these. When performing extrapolation/interpolation the contents of the class member variable is read and the interpolation filter is used to smooth the update from the contents to the network value. When a continuity break is received the interpolation filter is ignored.
The DataBlock type can also vary the accuracy of the tolerance used dependent on the calculated distance to the observer object for a session. If there is no observer or the distance couldn't be calculated (kReplicaObject_InfiniteDistance is returned by CalculateDistanceToObject) then the minimum tolerance is used.
This DataBlock does allow the Ordered() flag to be set, however it has little use since this DataBlock will automatically reject old updates.

Constructor & Destructor Documentation

The ctor performs some basic initialisation

virtual ~DataBlock_Predict_Float ( )
virtual

The dtor makes sure everything is tidy

Member Function Documentation

void BoundaryApplyToMaster ( void  )

If the boundary value checking is enabled this will also write-back the boundary check to the master's client value. This write-back will happen the next time this DataBlock is polled. The default is for this value write-back to be disabled.

static bool BoundaryApplyToValue ( ReplicaObject object,
float &  value 
)
static

Utility function to apply the boundary checking rules configured for a Predict_Float DataBlock to a variable. The variable must be registered with ReplicaNet as DataBlock_Predict_Float.

Returns
True is returned if the variable was registered and false if not registered.
void BoundaryCapped ( void  )

Use this keyword to set the boundary checks to use a capped value.

void BoundaryDisable ( void  )

Disables any boundary checking code.

void BoundaryDoNotApplyToMaster ( void  )
void BoundaryEnable ( void  )

Enable the boundary value checking code. This allows the DataBlock to have wrap around values (for example 0 <= angle < 360) or values that are capped. The upper and lower boundary and wrap around or capped are set by the other Boundary prefixed functions. The default is for this feature to be disabled. If enabled on a master then the user value will not be modified however the internal value used will be capped/wrapped before applying any update filtering. If enabled on a client then the user value will be capped/wrapped.

void BoundaryLowerUpper ( const float  lower,
const float  upper 
)

Where lower <= value < upper for wrapped checks and lower <= value <= upper for capped checks.

void BoundaryWrapAround ( void  )

Use this keyword to set the boundary checks to use a wrap around value.

virtual void ContinuityBreak ( unsigned char  breakTypes)
virtual

This is used by a master ReplicaObject to set a continuity break for the data block and provides useful information to any extrapolation algorithms.

Parameters
breakTypesThe break types to use for this break. For example : DataBlock::kSuddenChange | DataBlock::kTeleport

Reimplemented from DataBlock.

virtual bool GetLastDelta ( bool &  continuityBreak,
float &  sample,
SysTimeType &  time,
float &  delta 
)
virtual

Gets the last delta for this DataBlock. Depending on the ReplicaObject replica or master state this is either the last received delta update or the most accurate calculated delta update.

Returns
Returns true if the delta information has been updated. If false the input values have not been changed.
virtual void GiveDeltaHint ( void *  pdata,
int  dataLen 
)
virtual

This is a feedback function used by a master ReplicaObject that enables an application to give a delta hint to a DataBlock. The delta should be expressed in units of change per second.

Parameters
pdatathe pointer to the data type to give a hint for
dataLemthe length of the data type

Reimplemented from DataBlock.

bool IsAttached ( void *  data)
virtual

Given a data pointer this function identifies if this data block is attached to the pointer.

Returns
Returns true if the data pointer is attached to this data block.

Reimplemented from DataBlock.

virtual void ParseMessage ( MessageHelper message)
virtual

This parses a message for the derived class of this data block. If this virtual method is implemented by a derived class the parent method should be called. Implementation note: The same amount of data added to the message during the Poll() must equal the length of data retrieved during this function. Care must be taken when implementing functionality such as GetDiscardOlder() to preserve the length of data. Processing for this function may occur during the thread context of ReplicaNet so processing time used by this function should be kept to a minimum to avoid performance issues.

Parameters
messageThe current message buffer that contains the packet data

Reimplemented from DataBlock.

virtual void Poll ( DataBlockReason reason,
const bool  discardOlderIncluded = false,
const unsigned int  discardOrder = 0 
)
virtual

A poll function that is called by ReplicaNet to check for updates to this particular data block. If this virtual method is implemented by a derived class the parent method should be called before a data packet is created. Processing for this function may occur during the thread context of ReplicaNet so processing time used by this function should be kept to a minimum to avoid performance issues.

Parameters
reasonthe reason code that is passed in to this class to enable a response to be calculated
discardOlderIncludedWhen true and using SetDiscardOlder() this gives a hint to the DataBlock that the derived class has filled in a valid value for discardOrder. The default value is false and the DataBlock will use a global discard order seqeunce.
discardOrderWhen using SetDiscardOlder() and discardOlderIncluded is true this must contain a valid order sequence number for the update. The sequence should be unique for each target sessionID for the update. Since the sequence number is local for each target sessionID the window size for SetDiscardOlder() can be smaller.

Reimplemented from DataBlock.

static DataBlock_Predict_Float* Register ( float *  data)
static

This registers the memory area with this data block type and returns a new pointer

Parameters
datathe start of the memory to check
Returns
Returns a pointer that can be used to attach to a ReplicaObject
void RegisterInClassPointer ( float *  data)
inline

This registers the memory area with this data block type. This is used when the memory is in datablocks that are allocated as part of a bigger class.

Parameters
datathe start of the memory to check
void ReplicaContinuityBreak ( const SysTimeType  time,
const float  sample,
const float  delta,
const bool  continuityBreak,
const bool  ignoreTimeCheck = false,
const bool  clearPreviousUpdates = false 
)

Sets the local replica extrapolation/interpolation, thus causing a local replica continuity break until an update arrives from the network.

Parameters
timeThe network time for the update.
sampleThe data value.
deltaThe delta value applied to the data per second.
continuityBreakIf true this indicates the value should be applied to the prediction calculation directly without an interpolation filter, for example a teleport continuity break uses this.
ignoreTimeCheckIgnores the time check allowing an older network update to be applied to the prediction calculation.
clearPreviousUpdatesWhen true and using lagged updates (using SetLagged) this clears any previously received but pending updates.
void SetDeltaFloat ( void  )

Set this DataBlock to use full 32 bit floating point values when propagating the value. This is the default option.

void SetDeltaShortFloat ( void  )

Set this DataBlock to use short 16 bit floating point values when propagating the value.

void SetInterpolationFilter ( float  interpolation = 0.1f)

This sets the interpolation filter factor to use when extrapolating this variable type
0 < interpolation <= 1.0f
1.0f Is very hard interpolation and 0.1f is very soft. 0.1f Is the default.

Parameters
interpolationthe interpolation to use
void SetLagged ( const float  time = 0.0f)

Allows this replica DataBlock to use interpolation for a period specified by time. This has the effect of permanently lagging the changes made to the variable attached to this DataBlock. This option uses some extra memory to store updates until they can be actioned. This function can be used at any time. Each replica DataBlock can use a different time value. With ReplicaObjects that change owner there may be a pause in updates visible until the new master continues the movement and sends updates. NOTE: If a reflection object ID is set and matches the current session ID the lagged value will be ignored to avoid the update to replicas being lagged twice.

Parameters
timeThe time is seconds, so using SetLagged(0.2f) will cause all changes in this variable to appear to be 0.2 seconds behind the master object. Using a value less than or equal to 0.0f will disable this feature.
void SetLinear ( void  )
inline

For distance based interpolation this makes the calculation based on a linear formula. The default is linear.

void SetMaxDistance ( float  distance = 1.0f)

Sets the maximum distance start point for the maximum error to take effect

Parameters
thedistance
void SetMaxError ( float  maxerror = 1.0f)

This sets the maximum error that is tolerated for this variable type

Parameters
maxerrorthe maximum error to tolerate
void SetMinDistance ( float  distance = 0.1f)

Sets the minimum distance start point for the minimum error to take effect

Parameters
thedistance
void SetMinError ( float  minerror = 0.1f)

This sets the minimum error that is tolerated for this variable type

Parameters
minerrorthe minimum error to tolerate
void SetQuadratic ( void  )
inline

For distance based interpolation this makes the calculation based on a quadratic formula. The default is linear.

void SetSnapToDifference ( const float  difference = -1.0f)

Allows this replica DataBlock to snap to the extrapolated value if the difference is greater than the configured difference. For a replica DataBlock if the difference between this DataBlock and the extrapolated value is greater than the configured amount then the extrapolated value is applied without any interpolation filter. This option can be changed as often as required and can be configured differently for each peer.

Parameters
differenceThe default value is -1.0f meaning this feature is disabled. Any value greater than or equal to 0.0f will enable this feature.
void SetTimeDelta ( const float  timeDelta = 0.0f)

Sets the amount of time the extrapolation will calculate into the future.

Parameters
timeDeltaThe time in seconds.
void SetValueFloat ( void  )

Set this DataBlock to use full 32 bit floating point values when propagating the value. This is the default option.

void SetValueShortFloat ( void  )

Set this DataBlock to use short 16 bit floating point values when propagating the value.