DataReplicator Class Reference
[Data Replicator Subsystem]

This class, based on the plugin system, is designed to automatically create and destroy your objects, transmit object scope, and synchronize memory. More...

#include <DataReplicator.h>

Inheritance diagram for DataReplicator:

PluginInterface List of all members.

Public Member Functions

void SetBroadcastToAll (bool value)
bool GetBroadcastToAll (void) const
void AddParticipant (PlayerID playerId)
void RemoveParticipant (PlayerID playerId)
void EnableReplication (bool value)
void SetClassFactory (ReplicatedObject *(*factoryFunc)(const char *className, RakNet::BitStream *inContext))
ReplicatedObjectReplicateObject (const char *objectName, ReplicatedObject *object, bool isObjectOwner, PacketPriority priority=HIGH_PRIORITY, PacketReliability reliability=RELIABLE_ORDERED, char orderingChannel=0, int maxUpdateFrequencyMS=0)
void DereplicateObject (ReplicatedObject *object, bool sendNotificationPacket)
 Unsynchronize an object passed to ReplicateObject.
bool ObjectInScope (ReplicatedObject *object, PlayerID target)
 Returns the last ReplicatedObject::InScope() calculation for an object.
bool IsObjectListPushComplete (PlayerID target)
 Returns if we got all remote objects pushed to us by a remote system. This only counts the first push to a new system. If a push was delayed with OBJECT_REPLICATION_PUSH_LATER this won't be true until all objects are resolved.
void SynchronizeMemory (const char *stringId, void *memory, unsigned memoryByteLength, bool isMemoryOwner, int maxUpdateFrequencyMS, ReplicatedObject *replicatedObject, PacketPriority priority=HIGH_PRIORITY, PacketReliability reliability=RELIABLE_ORDERED, char orderingChannel=0)
 Associates memory with a string identifier. Memory can either be a class that implements SynchronizedMemory, or it can be a raw pointer.
void UnsynchronizeMemory (const void *memoryPtr, bool sendNotificationPacket)
 Unsynchronizes memory that was formerly synchronized with SynchronizeMemory.
void SetMemoryContext (const void *memoryPtr, void *_context)
 Sets the memory context to be passed to each memory callback.
void InterpolateMemory (const void *memoryPtr, bool(*_interpolateCB)(void *currentValue, void *targetValue, unsigned int currentTimeMS, unsigned int timePacketSentMS, unsigned int lastCallTimeMS, void *context))
 [Optional] Set a callback for your memory pointer that will be called every tick after you get an update.
void SetMemorySerializeCB (const void *memoryPtr, void(*cbFunc)(void *source, unsigned memoryByteLength, void *context, RakNet::BitStream *bitstream, void *lastSentValue, unsigned int currentTime, unsigned int lastSendTime, PlayerID playerId, bool *includeTimestamp))
 Serializes memory to a bitstream.
void SetMemoryDeserializeCB (const void *memoryPtr, void(*cbFunc)(void *destination, unsigned memoryByteLength, void *context, RakNet::BitStream *bitstream, unsigned int timePacketSent, PlayerID playerId))
 Write to memory from a bitstream.
void SetMemoryMakeCopyCB (const void *memoryPtr, void *(*cbFunc)(void *source, unsigned memoryByteLength, void *context))
 Sets the callback to be called when we need to allocate and copy of The parameter SynchronizeMemory::memory.
void SetMemoryCopyFromCB (const void *memoryPtr, void(*cbFunc)(void *destination, void *source, unsigned memoryByteLength, void *context))
 Write one memory block to antoher.
void SetMemoryFreeMemoryCB (const void *memoryPtr, void(*cbFunc)(void *memory, unsigned memoryByteLength, void *context))
 Delete a block of memory.
void SetMemoryShouldSendUpdateCB (const void *memoryPtr, bool(*cbFunc)(void *memory, void *lastSentValue, unsigned memoryByteLength, PlayerID destinationSystem, unsigned int currentTime, unsigned int lastSendTime, void *context))
 Return true or false if we should send a memory update.
void * GetLastSentMemoryValue (const void *memoryPtr, PlayerID playerId)
 Return the last value sent for a memory block.
unsigned int GetLastSendTime (const void *memoryPtr, PlayerID playerId)
 Returns the last time this memory value was sent.
void Clear (void)
 Frees all memory and releases all participants.
virtual void OnDataOverflow (RakPeerInterface *peer, Packet *packet)
 Too much data was in a packet. User should override in a derived class to handle this. Default behavior is to assert.
virtual void OnDataUnderflow (RakPeerInterface *peer, Packet *packet)
 Not enough data was in a packet. User should override in a derived class to handle this. Default behavior is to assert.
virtual void OnInvalidPacket (RakPeerInterface *peer, Packet *packet)
 Packet data that just doesn't make sense. Default behavior is to assert.

Static Public Member Functions

static bool InterpolateFloat (float *position, float targetOrigin, float targetVelocity, unsigned int currentTimeMS, unsigned int timePacketSentMS, unsigned int lastCallTimeMS, unsigned int interpolationTimeMS, bool updatePastInterpolationTime)
 Interpolates a float using cumulative increments.
static float GetCumulativeInterpolationPercentile (unsigned int currentTimeMS, unsigned int timePacketSentMS, unsigned int lastCallTimeMS, unsigned int interpolationTimeMS)
 Returns the percentile of the remaining time that just elapsed.
static float GetLinearInterpolationPercentile (unsigned int currentTimeMS, unsigned int timePacketSentMS, unsigned int lastCallTimeMS, unsigned int interpolationTimeMS)
 Returns the percentile of the total time that just elapsed, up to the maximum of interpolationTimeMS, or 0.0f if no time is remaining.

Protected Member Functions

void OnAttach (RakPeerInterface *peer)
void OnUpdate (RakPeerInterface *peer)
int OnReceive (RakPeerInterface *peer, Packet *packet)
void OnDisconnect (RakPeerInterface *peer)
bool PropagateToGame (Packet *packet) const
void RequestObjectCreation (const char *objectName, RakNet::BitStream *context, ReplicatedObject *object, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID targetSystem)
bool SendImmediateMemoryStartRequest (BaseMemoryData *memoryData, ParticipantStruct *participantStruct)
void EncodeClassName (const char *strIn, PlayerID playerId, RakNet::BitStream *bitStream)
void OnStringMapIndex (RakPeerInterface *peer, Packet *packet)
void OnStringMapMemoryIndex (RakPeerInterface *peer, Packet *packet)
bool DecodeClassName (char *strOut, ParticipantStruct *participantStruct, RakNet::BitStream *bitStream, RakPeerInterface *peer, Packet *packet)
void DereplicateObjectInt (ReplicatedObject *object, bool sendNotificationPacket, bool remoteCall)
void AddParticipantInt (PlayerID playerId)
void AddExtendedMemoryDataToParticipant (BaseMemoryData *baseMemoryData, ParticipantStruct *participantStruct)
void AddExtendedObjectDataToParticipant (BaseObjectData *baseObjectData, ParticipantStruct *participantStruct)
void RemoveExtendedDataFromParticipant (BaseData *baseData, ParticipantStruct *participantStruct, bool isMemory, bool sendNotificationPacket)
void SendObjectStopRequest (ObjectID networkID, PlayerID target)
void SendMemoryStopRequest (char *localIdentifier, PlayerID target)
void ValidatedSend (ExtendedData *extendedData, ParticipantStruct *participant, bool isMemory, unsigned int currentTime, bool *objectPushDelayed)
BaseMemoryData * GetBaseMemoryDataByString (const char *str)
ParticipantStruct * GetParticipantByPlayerID (PlayerID playerId)
unsigned GetUnifiedMemoryCount (void *memory)
void * GetSynchronizedMemoryCopy (BaseMemoryData *baseMemoryData, void *source)
strToIndexMapType GenerateMemoryStringMappingKey (void)
BaseMemoryData * GetMemoryDataByKey (strToIndexMapType key)
BaseObjectData * GetBaseObjectByObjectID (ObjectID objectId)
BaseObjectData * GetBaseObjectByReplicatedObject (ReplicatedObject *object)
void UnsynchronizeMemoryInt (BaseMemoryData *baseMemoryData, bool sendNotificationPacket)
void OnCreationCommand (ReplicatedObject *newObject, PlayerID senderPlayerId, ObjectID objectId, PlayerID objectOwner, BaseObjectData *baseObjectData)
void AddToParticipantList (PlayerID playerId)
void RemoveFromParticipantList (PlayerID playerId, bool sendDataStopRequests, bool fromNetwork)
void RemoveAllParticipants (void)
unsigned GetParticipantIndexByPlayerID (PlayerID playerId)
ExtendedObjectData * GetExtendedObjectByReplicatedObject (ReplicatedObject *object, ParticipantStruct *participant)
ExtendedObjectData * GetExtendedObjectByObjectID (ObjectID objectId, ParticipantStruct *participant)
ExtendedMemoryData * GetExtendedMemoryByBaseMemory (BaseMemoryData *baseData, ParticipantStruct *participant)
BaseMemoryData * GetBaseMemoryDataBySynchronizedMemory (const void *memory)
void OnDataReplicateSendMemory (RakPeerInterface *peer, Packet *packet)
void OnSendReplicationPushPacket (RakPeerInterface *peer, Packet *packet)
void OnDataReplicateSendObjectScope (RakPeerInterface *peer, Packet *packet)
void OnMemoryReplicateStart (RakPeerInterface *peer, Packet *packet)
void OnDataReplicateStop (RakPeerInterface *peer, Packet *packet)
void OnNewPlayer (RakPeerInterface *peer, Packet *packet)
void OnLostPlayer (RakPeerInterface *peer, Packet *packet)
void OnObjectCreationRequest (RakPeerInterface *peer, Packet *packet)
void OnPushComplete (RakPeerInterface *peer, Packet *packet)
void OnObjectCreationRequestResponse (RakPeerInterface *peer, Packet *packet)
ReplicatedObjectCreateObject (const char *className, RakNet::BitStream *bitstream)
void AutoAssignPropertyFlags (BaseObjectData *baseObjectData, ReplicatedObject *newObject, bool isObjectOwner)
bool ParsePacket (RakPeerInterface *peer, Packet *packet)

Protected Attributes

RakPeerInterfacerakPeer
BasicDataStructures::OrderedList<
ParticipantStruct *, PlayerID
participantList
BasicDataStructures::OrderedList<
BaseMemoryData *, strToIndexMapType > 
memoryList
BasicDataStructures::OrderedList<
BaseObjectData *, ReplicatedObject * > 
objectList
BasicDataStructures::Queue<
Packet * > 
packetQueue
BasicDataStructures::List<
char * > 
localObjectNameTable
unsigned char localCreationRequestIndex
ReplicatedObjectlocalCreationRequestTable [LOCAL_CREATION_REQUEST_TABLE_SIZE]
bool objectCreatedFromNetwork
bool ignoreReplicateObjectCalls
bool broadcastToAll
bool enableReplication
ReplicatedObject *(* objectFactoryCallback )(const char *className, RakNet::BitStream *inContext)

Static Protected Attributes

static strToIndexMapType memoryToStringMappingKey = 0

Friends

int BaseObjectDataComp (BaseObjectData *data, ReplicatedObject *key)
int BaseMemoryDataComp (BaseMemoryData *data, strToIndexMapType key)
int ExtendedMemoryDataComp (ExtendedMemoryData *data, DataReplicator::BaseData *key)
int ExtendedObjectDataComp (ExtendedObjectData *data, DataReplicator::BaseData *key)
int ParticipantStructComp (ParticipantStruct *data, PlayerID key)

Classes

struct  BaseData
struct  BaseMemoryData
struct  BaseObjectData
struct  ExtendedData
struct  ExtendedMemoryData
struct  ExtendedObjectData
struct  ParticipantStruct

Detailed Description

This class, based on the plugin system, is designed to automatically create and destroy your objects, transmit object scope, and synchronize memory.

This class is responsible for synchronizing memory and objects. It solves the problems of: 1. The concept of object scope, and relying scoping changes between systems. 2. How to send a list of all synchronized objects and memory to newly connecting systems. 3. Synchronizing object synchronization and desynchronization between systems. 4. Tracking data values sent per-system, such that you can send only value changes if desired.


Member Function Documentation

void DataReplicator::AddParticipant PlayerID  playerId  ) 
 

Adds a participant to the data replicator system. This player will from then on will get memory and object updates.

Parameters:
[in] playerId Which player you are referring to

void DataReplicator::DereplicateObject ReplicatedObject object,
bool  sendNotificationPacket
 

Unsynchronize an object passed to ReplicateObject.

This object and registered member variables will no longer be tracked by the DataReplicator system. Remote participants will get called ReplicatedObject::AcceptDereplicationRequest() If you want to delete an object you need to call this function first, or the system will crash on the next update cycle.

Parameters:
[in] object The object to unsynchronize
[in] sendNotificationPacket If you want other systems to get the AcceptDereplicationRequest event, pass true. Otherwise the object will stop being tracked locally only.

void DataReplicator::EnableReplication bool  value  ) 
 

Normally when a player is added as a participant, (either by calling AddParticipant or having BroadcastToAll as true) they willimmediately get object creation requests. However, this is often inappropriate since that player may be loading or not yet in a playable modeCall this function with false to queue up all packets and not process them until this function is called with true.Defaults to true.

Parameters:
[in] value false to queue replication, true (default) to immediately process replication

bool DataReplicator::GetBroadcastToAll void   )  const
 

Returns the value passed to SetBroadcastToAll, or the default of false

Returns:
true or false

float DataReplicator::GetCumulativeInterpolationPercentile unsigned int  currentTimeMS,
unsigned int  timePacketSentMS,
unsigned int  lastCallTimeMS,
unsigned int  interpolationTimeMS
[static]
 

Returns the percentile of the remaining time that just elapsed.

For example, if you interpolate over 10 seconds, 5 seconds has already passed, and this function was called 2.5 seconds later, you just used 50% of the remaining time. The function will return .5, so for example if you are interpolating position, you move halfway towards the destination. This is very useful for interpolation as it tells you the percentile of the remaining distance/angle/time to move towards the target. The percentile is capped to the total interpolation time

Parameters:
[in] currentTimeMS The current time
[in] timePacketSentMS The time we started moving position
[in] lastUpdateTime The last time we updated position towards the target
[in] interpolationTime How long to interpolate for (how long it takes to reach the destination)
Returns:
1.0f means all the remaining interpolation time has been used. 0.0 means don't interpolate at all.

unsigned int DataReplicator::GetLastSendTime const void *  memoryPtr,
PlayerID  playerId
 

Returns the last time this memory value was sent.

This function is useful for linking sends, since the time returned from this function will be equal to the currentTime parameter in the memory serialize callback for all serializations that occur during the same update. For example, if you are processing the memory block "position" and want to always send position if you also send "controls" then you should check the last time whichever one was first registered was sent inside the callback for the one registered later. If the times are equal then you would go ahead and allow the send in the SetMemoryShouldSendUpdateCB callback.

Parameters:
[in] memoryPtr The pointer returned from the SetMemoryMakeCopyCB() callback.
[in] playerId Specifies which player's memory copy copy we are referring to
Returns:
The last time a send was done for memoryPtr for the player playerId. Returns 0 if no sends were ever done, or this memory block is not found.

void * DataReplicator::GetLastSentMemoryValue const void *  memoryPtr,
PlayerID  playerId
 

Return the last value sent for a memory block.

Returns the lastSentValue parameter passed to the SetMemoryShouldSendUpdateCB() callback for a given playerId

Parameters:
[in] memoryPtr The pointer returned from the SetMemoryMakeCopyCB() callback.
[in] playerId Specifies which player's memory copy copy we are referring to
Returns:
Either a pointer to a SynchronizedMemory object or a pointer to a copy of some raw data, or 0 if that memory block or player is not registered

float DataReplicator::GetLinearInterpolationPercentile unsigned int  currentTimeMS,
unsigned int  timePacketSentMS,
unsigned int  lastCallTimeMS,
unsigned int  interpolationTimeMS
[static]
 

Returns the percentile of the total time that just elapsed, up to the maximum of interpolationTimeMS, or 0.0f if no time is remaining.

If you interpolate over 10 seconds and 6 seconds have passed then this function would return .6. On your next call, if another 2 seconds have passed, this function would return .2. This is capped to the total interpolation time, so if on the final call 4 seconds have passed, for a total of 12 seconds, only the last 2 seconds would count, and the function would return .2.

Parameters:
[in] currentTimeMS The current time
[in] timePacketSentMS The time we started moving position
[in] lastUpdateTime The last time we updated position towards the target
[in] interpolationTime How long to interpolate for (how long it takes to reach the destination)
Returns:
0.0f means interpolation is complete. Otherwise returns the amount to interpolate.

bool DataReplicator::InterpolateFloat float *  position,
float  targetOrigin,
float  targetVelocity,
unsigned int  currentTimeMS,
unsigned int  timePacketSentMS,
unsigned int  lastCallTimeMS,
unsigned int  interpolationTimeMS,
bool  updatePastInterpolationTime
[static]
 

Interpolates a float using cumulative increments.

A static math function that interpolates a value between the current position and the final position, given the starting time, current time, and last update time. The parameters here match the parameters in the callback to InterpolateMemory. All the parameters match the InterpolateMemory callback, so this is an easy way to do linear interpolation on a float.

Parameters:
[in] position Pointer to the float you want to interpolate. Both an in and an out parameter.
[in] targetOrigin The origin of the destination you want to reach, not counting velocity
[in] targetVelocity The velocity of the destination, or 0 if the destination is not moving
[in] currentTimeMS The current time
[in] timePacketSentMS The time we started moving position
[in] lastUpdateTime The last time we updated position towards the target
[in] interpolationTime How long to interpolate for (how long it takes to reach the destination)
[in] updatePastInterpolationTime After reaching the target, should we continue to interpolate to stay at the location of the moving target? Only meaninful if targetVelocity is nonzero
Returns:
True if we no longer need to interpolate. Otherwise false.

void DataReplicator::InterpolateMemory const void *  memoryPtr,
bool(*)(void *currentValue, void *targetValue, unsigned int currentTimeMS, unsigned int timePacketSentMS, unsigned int lastCallTimeMS, void *context)  _interpolateCB
 

[Optional] Set a callback for your memory pointer that will be called every tick after you get an update.

The intended use of this function is to interpolate the memory that is given to you between the currentValue and the targetValue This memory is treated as a special case for updates, such that you can interpolate a value without causing a send every tick. Instead, interpolation continues until the value changes from something other than interpolation, at which point an update gets sent.

Parameters:
[in] _interpolateCB REQUIRED callback. In it, you should adjust currentValue to be closer or equal to destinationValue. Return true if you are done interpolating and this function will stop getting called until the next update arrives.
Returns:
True if you are done interpolating, false otherwise.

bool DataReplicator::IsObjectListPushComplete PlayerID  target  ) 
 

Returns if we got all remote objects pushed to us by a remote system. This only counts the first push to a new system. If a push was delayed with OBJECT_REPLICATION_PUSH_LATER this won't be true until all objects are resolved.

Parameters:
[in] target Who pushed to us.
Returns:
True if all objects were pushed to us, false otherwise

bool DataReplicator::ObjectInScope ReplicatedObject object,
PlayerID  target
 

Returns the last ReplicatedObject::InScope() calculation for an object.

Parameters:
[in] object The object we are referencing
[in] target Who the object is in scope in relation to
Returns:
If the locally registered object is in scope on this remote system

void DataReplicator::OnAttach RakPeerInterface peer  )  [protected, virtual]
 

Called when the interface is attached

Parameters:
[in] peer the instance of RakPeer that is calling Receive

Reimplemented from PluginInterface.

void DataReplicator::OnDisconnect RakPeerInterface peer  )  [protected, virtual]
 

Called when RakPeer is shutdown

Parameters:
[in] peer the instance of RakPeer that is calling Receive

Reimplemented from PluginInterface.

int DataReplicator::OnReceive RakPeerInterface peer,
Packet packet
[protected, virtual]
 

OnReceive is called for every packet.

Parameters:
[in] peer the instance of RakPeer that is calling Receive
[in] packet the packet that is being returned to the user
Returns:
2 to absorb but do not deallocate the packet, 1 to absorb and automatically deallocate the packet, 0 to allow the packet to propagate to another handler, or to the game

Reimplemented from PluginInterface.

void DataReplicator::OnUpdate RakPeerInterface peer  )  [protected, virtual]
 

OnUpdate is called every time a packet is checked for .

Parameters:
[in] peer - the instance of RakPeer that is calling Receive

Reimplemented from PluginInterface.

bool DataReplicator::PropagateToGame Packet packet  )  const [protected, virtual]
 

PropagateToGame tells RakPeer if a particular packet should be sent to the game or notIf you create a custom packet ID just for this handler you would not want to propagate it to the game, for example

Parameters:
[in] id The first byte of the packet in question
Return values:
true (default) Allow a packet to propagate to the game
Returns:
false Only let the packet be sent to message handlers

Reimplemented from PluginInterface.

void DataReplicator::RemoveParticipant PlayerID  playerId  ) 
 

Removes a participant from the data replicator system

Parameters:
[in] playerId Which player you are referring to

ReplicatedObject * DataReplicator::ReplicateObject const char *  objectName,
ReplicatedObject object,
bool  isObjectOwner,
PacketPriority  priority = HIGH_PRIORITY,
PacketReliability  reliability = RELIABLE_ORDERED,
char  orderingChannel = 0,
int  maxUpdateFrequencyMS = 0
 

This function causes an object that inherits from ReplicatedObject to send creation, destruction, and scope updates to all participants.

Parameters:
[in] objectName The name of the class to create. If object is 0, objectName must be filled in. This name will be sent to your class factory.
[in] object A pointer to the object if you already created it, or 0 if the object was not created yet and you want it to be created.
[in] isObjectOwner Do we own this object? If we do, then when we disconnect all other systems will get a call to ReplicatedObject::AcceptDereplicationRequest
[in] priority Same as the parameter in RakPeer::Send
[in] reliability Same as the parameter in RakPeer::Send
[in] orderingChannel Same as the parameter in RakPeer::Send
[in] maxUpdateFrequencyMS How often, at most, to test for scope changes and potentially send push notifications to other participants. Pass 0 to check every call to RakPeer::Update.
Returns:
The object passed to the function, or the newly created object if no object was passed.

void DataReplicator::SetBroadcastToAll bool  value  ) 
 

With BroadcastToAll true, all players that connect will have AddParticipant called on their playerId. Defaults to false

Parameters:
[in] value True or false, to broadcast to all or not.

void DataReplicator::SetClassFactory ReplicatedObject *(*)(const char *className, RakNet::BitStream *inContext)  factoryFunc  ) 
 

Using object functions requires a callback that is able to create instances derivations of ReplicatedObject by class name. You can implement this through a switch / case or something more sophisticated if you wish. It is mandatory to call this functionif you want to automatically create objects through this system.

Parameters:
[in] factoryFunc The callback.

void DataReplicator::SetMemoryContext const void *  memoryPtr,
void *  _context
 

Sets the memory context to be passed to each memory callback.

This can be anything you want and is simply a pointer that is passed around for you. The intended use for this is to pass the ReplicatedObject that contains this member variable so you can process events on memory updates.Defaults to 0

Parameters:
[in] memoryPtr The pointer to associate this context with
[in] _context the data to associate

void DataReplicator::SetMemoryCopyFromCB const void *  memoryPtr,
void(*)(void *destination, void *source, unsigned memoryByteLength, void *context)  cbFunc
 

Write one memory block to antoher.

Sets the callback to be called when we need to only copy The parameter SynchronizeMemory::memory. Otherwise identical to SetMemoryMakeCopyCB().

Parameters:
[in] memoryPtr Which memory to associate this callback with
[in] cbFunc Function pointer to the callback
[in] destination A block of memory - whatever structure and size was returned by SetMemoryMakeCopyCB(), that needs a copy of source. This is used to track lastSentValue for SetMemorySerializeCB as well as the pre-interpolation value to track if something other than interpolation changed this memory.
[in] source The parameter SynchronizeMemory::memory.
[in] memoryByteLength The parameter SynchronizeMemory::memoryByteLength. Isn't necessarily the size of source or destination - the real allocated size of those pointers depends on what you returned from the SetMemoryMakeCopyCB() callback.
[in] context The parameter SetMemoryContext::_context, or 0 if that function was not called.

void DataReplicator::SetMemoryDeserializeCB const void *  memoryPtr,
void(*)(void *destination, unsigned memoryByteLength, void *context, RakNet::BitStream *bitstream, unsigned int timePacketSent, PlayerID playerId)  cbFunc
 

Write to memory from a bitstream.

The callback passed to this function is called when we get an update from the callback passed to SetMemorySerializeCB(). Whatever was written to the parameter bitstream in SetMemorySerializeCB() will be in the bitstream in the callback. If you want to do processing or events based on getting an update for a memory block, this is the place to do it. The default behavior is to copy the data in bitstream to memoryPtr.

Parameters:
[in] memoryPtr Which memory to associate this callback with
[in] cbFunc Function pointer to the callback
[in] destination The parameter SynchronizeMemory::memory.
[in] memoryByteLength The parameter SynchronizeMemory::memoryByteLength.
[in] context The parameter SetMemoryContext::_context, or 0 if that function was not called.
[in] bitstream The data passed to the parameter bitstream in SetMemorySerializeCB.
[in] timePacketSent If includeTimestamp was set to true in the SetMemorySerializeCB callback, then this is when the packet was sent. Otherwise it is the time the time we got the packet.
[in] playerId The player that we got bitstream from.

void DataReplicator::SetMemoryFreeMemoryCB const void *  memoryPtr,
void(*)(void *memory, unsigned memoryByteLength, void *context)  cbFunc
 

Delete a block of memory.

Set the callback to be called when the system no longer needs a copy of allocated memory. This occurs on shutdown, and when a participant is dropped such that the last sent value to that participant (if non-unified memory), or when the last reference to a block of sent memory (for unified memory) is no longer needed Defaults to

        /// 
You can leave this at the default unless you did complex allocation in the SetMemoryMakeCopyCB() callback
Parameters:
[in] memoryPtr Which memory to associate this callback with
[in] cbFunc Function pointer to the callback
[in] memory The pointer to delete
[in] memoryByteLength The parameter SynchronizeMemory::memoryByteLength. Isn't necessarily the size of source or destination - the real allocated size of those pointers depends on what you returned from the SetMemoryMakeCopyCB() callback.
[in] context The parameter SetMemoryContext::_context, or 0 if that function was not called.

void DataReplicator::SetMemoryMakeCopyCB const void *  memoryPtr,
void *(*)(void *source, unsigned memoryByteLength, void *context)  cbFunc
 

Sets the callback to be called when we need to allocate and copy of The parameter SynchronizeMemory::memory.

Whatever you return will be passed to lastSentValue in the callback for SetMemorySerializeCB and source in the callback for SetMemoryCopyFromCB.

Note:
You aren't restricted to exactly copying source as the system does not use what you return - it only passes it to those functions.For example, if you are pointing to a structure that contains pointers, to make a copy of the last sent value you don't want to copy the pointers - you want to allocate memory to hold the values of those pointers.This is used to track lastSentValue for SetMemorySerializeCB() as well as the pre-interpolation value to track if something other than interpolation changed this memory. Defaults to doing a simple char* allocation with a memcpy
Parameters:
[in] memoryPtr Which memory to associate this callback with
[in] cbFunc Function pointer to the callback
[in] destination The parameter SynchronizeMemory::memory.
[in] memoryByteLength The parameter SynchronizeMemory::memoryByteLength.
[in] context The parameter SetMemoryContext::_context, or 0 if that function was not called.

void DataReplicator::SetMemorySerializeCB const void *  memoryPtr,
void(*)(void *source, unsigned memoryByteLength, void *context, RakNet::BitStream *bitstream, void *lastSentValue, unsigned int currentTime, unsigned int lastSendTime, PlayerID playerId, bool *includeTimestamp)  cbFunc
 

Serializes memory to a bitstream.

This callback is responsible for sending a bitstream to a remote system, that can represent a change in value to the data pointed to by the source pointer. Whatever you write to the bitstream will be received by the callback passed to SetMemoryDeserializeCB.Note that while the intended purpose is to serialize the data pointed to by source, you can send anything you want and whatever you send will arrive in the deserialize callback. This callback is only called if the callback passed to SetMemoryShouldSendUpdateCB returns true. The last sent value and last sent time is given to you in case you want to use delta compression.If you want to trigger events to occur or to save values everytime you send to a particular system this is the place to do it. The default behavior is to do a bitstream write from source of length memoryByteLength

Parameters:
[in] memoryPtr Which memory to associate this callback with
[in] cbFunc Function pointer to the callback
[in] source The parameter SynchronizeMemory::memory.
[in] memoryByteLength The parameter SynchronizeMemory::memoryByteLength.
[in] context The parameter SetMemoryContext::_context, or 0 if that function was not called.
[in] bitstream This bitstream will be sent to playerId when this function returns. The intended usage is to serialize memoryPtr to this bitstream, but you can do whatever you want.
[in] lastSentValue When this function returns, the callback passed to either SetMemoryMakeCopyCB or SetMemoryCopyFromCB to make a copy of source. This essentially tracks the last value sent to playerId.
[in] currentTime The time RakPeer::Receive was called that triggered the update to the DataReplicator system. This should be close to the current value of RakNet::GetTime and can be used to avoid calling that slow function.
[in] lastSendTime The last time that this function was called for this playerId. Matches the prior value of currentTime.
[in] playerId The player that we are sending bitStream to.
[in] includeTimestamp If you set this pointer to true, then a timestamp will be included in the packet and will be reflected in the timePacketSent parameter of the callback from SetMemoryDeserializeCB. Defaults to false.

void DataReplicator::SetMemoryShouldSendUpdateCB const void *  memoryPtr,
bool(*)(void *memory, void *lastSentValue, unsigned memoryByteLength, PlayerID destinationSystem, unsigned int currentTime, unsigned int lastSendTime, void *context)  cbFunc
 

Return true or false if we should send a memory update.

Set the callback to be called when the system needs to know if we should send another update to a remote system. Generally you will compare memory and lastSentValue and return true if they are different and enough time has passed between currentTime and lastSendTime/ Defaults to

        /// 
Parameters:
[in] memoryPtr Which memory to associate this callback with
[in] cbFunc Function pointer to the callback
[in] lastSentValue The pointer returned from the SetMemoryMakeCopyCB() callback.
[in] memory The parameter SynchronizeMemory::memory.
[in] memoryByteLength The parameter SynchronizeMemory::memoryByteLength. Isn't necessarily the size of source or destination - the real allocated size of those pointers depends on what you returned from the SetMemoryMakeCopyCB() callback.
[in] destinationSystem The player that we are considering sending to
[in] currentTime The time RakPeer::Receive was called that triggered the update to the DataReplicator system. This should be close to the current value of RakNet::GetTime and can be used to avoid calling that slow function.
[in] lastSendTime The last time that this function was called for this playerId. Matches the prior value of currentTime.
[in] context The parameter SetMemoryContext::_context, or 0 if that function was not called.

void DataReplicator::SynchronizeMemory const char *  stringId,
void *  memory,
unsigned  memoryByteLength,
bool  isMemoryOwner,
int  maxUpdateFrequencyMS,
ReplicatedObject replicatedObject,
PacketPriority  priority = HIGH_PRIORITY,
PacketReliability  reliability = RELIABLE_ORDERED,
char  orderingChannel = 0
 

Associates memory with a string identifier. Memory can either be a class that implements SynchronizedMemory, or it can be a raw pointer.

The best place to register memory is in ReplicatedObject::OnReplication, since this is called exactly once on every system when an object is registered. You can call this more than once for the same pointer if you want to change the parameters used. Memory will be updated in the same order you call SynchronizeMemory on it.

Note:
Clients (IsNetworkIDAuthority()==false) cannot update memory they own if they do not also own the object.

Servers (IsNetworkIDAuthority()==true) can always update memory, even if they do not own that memory.

Parameters:
[in] stringId Identifier for this memory. The set {stringId, ReplicatedObjectId} must form a unique pair. It is easiest just to pass the variable name.
[in] memory A pointer to a memory block that is passed around as the memoryPtr parameter to all the SetMemory*CB callbacks. The default behaviors assume this is a pointer to the memory you want copied and will perform memcpy on it. If you overwrite all the callbacks, you can pass anything you want.
[in] memoryByteLength The byte length of the data pointed to by memory. This is only used by the default callbacks for SetMemoryCopyFromCB, SetMemoryMakeCopyCB(), SetMemoryDeserializeCB, and SetMemorySerializeCB. If you set these callbacks yourself you can pass anything you want.
[in] isMemoryOwner Are we the owner of the memory? If you own the memory, that means you are the main source of updates for this memory. Among other things, you will send the actual value for interpolation sends while other systems will send the extrapolated value.
[in] maxUpdateFrequencyMS How often, at most, to test for changes and potentially send packets. Pass 0 to check every call to RakPeer::Update. Unless you use the default behavior for SetMemorySerializeCB, I recommend you pass 0 and if you don't want to send just return false from the callback.
[in] replicatedObject If this memory is a member variable of an object that derives from or has a parent class of ReplicatedObject, then pass it here. Pass 0 if this memory is not a member variable of an object (i.e. a global variable).
[in] priority Same as the parameter in RakPeer::Send
[in] reliability Same as the parameter in RakPeer::Send
[in] orderingChannel Same as the parameter in RakPeer::Send

void DataReplicator::UnsynchronizeMemory const void *  memoryPtr,
bool  sendNotificationPacket
 

Unsynchronizes memory that was formerly synchronized with SynchronizeMemory.

Parameters:
[in] memoryPtr Pointer to the memory, NOT the stringId, that was passed to SynchronizeMemory
[in] memory Pointer to the memory, NOT the stringId, that was passed to SynchronizeMemory
[in] sendNotificationPacket Tell the other system we are unsynchronizing this object? You should do this if you are deleting the object and want that deletion to transmit over the network.


The documentation for this class was generated from the following files:
Generated on Mon Mar 20 20:32:55 2006 for RakNet by  doxygen 1.4.6-NO