ReplicaNet and RNLobby
1
|
#include <DataBlock_Predict_Float.h>
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) |
![]() | |
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_Float * | Register (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) |
![]() | |
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, ParsedData > | mParsedByTime |
float | mLagged |
SysTimeType | mFirstLaggedTime |
float | mSnapToDifference |
bool | mBoundaryEnable |
bool | mBoundaryIsWrap |
float | mBoundaryLower |
float | mBoundaryUpper |
bool | mBoundaryWriteBack |
SysTimeType | mLastGoodDataTime |
bool | mShortValue |
bool | mShortDelta |
float | mTimeDelta |
![]() | |
short | mID |
ReplicaNet * | mBoundReplicaNet |
ReplicaObject * | mBoundObject |
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 | |
![]() | |
enum | ContinuityBreakTypes { kStop = 1, kSuddenChange = 2, kTeleport = 4 } |
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.
The ctor performs some basic initialisation
|
virtual |
The dtor makes sure everything is tidy
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 |
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.
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 | ) |
Disables BoundaryApplyToMaster().
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 |
This is used by a master ReplicaObject to set a continuity break for the data block and provides useful information to any extrapolation algorithms.
breakTypes | The break types to use for this break. For example : DataBlock::kSuddenChange | DataBlock::kTeleport |
Reimplemented from DataBlock.
|
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.
|
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.
pdata | the pointer to the data type to give a hint for |
dataLem | the length of the data type |
Reimplemented from DataBlock.
|
virtual |
Given a data pointer this function identifies if this data block is attached to the pointer.
Reimplemented from DataBlock.
|
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.
message | The current message buffer that contains the packet data |
Reimplemented from DataBlock.
|
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.
reason | the reason code that is passed in to this class to enable a response to be calculated |
discardOlderIncluded | When 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. |
discardOrder | When 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 |
This registers the memory area with this data block type and returns a new pointer
data | the start of the memory to check |
|
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.
data | the 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.
time | The network time for the update. |
sample | The data value. |
delta | The delta value applied to the data per second. |
continuityBreak | If 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. |
ignoreTimeCheck | Ignores the time check allowing an older network update to be applied to the prediction calculation. |
clearPreviousUpdates | When 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.
interpolation | the 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.
time | The 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. |
|
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
the | distance |
void SetMaxError | ( | float | maxerror = 1.0f | ) |
This sets the maximum error that is tolerated for this variable type
maxerror | the maximum error to tolerate |
void SetMinDistance | ( | float | distance = 0.1f | ) |
Sets the minimum distance start point for the minimum error to take effect
the | distance |
void SetMinError | ( | float | minerror = 0.1f | ) |
This sets the minimum error that is tolerated for this variable type
minerror | the minimum error to tolerate |
|
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.
difference | The 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.
timeDelta | The 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.