#include <DataReplicator.h>
Inheritance diagram for DataReplicator:
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)) |
ReplicatedObject * | ReplicateObject (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) |
ReplicatedObject * | CreateObject (const char *className, RakNet::BitStream *bitstream) |
void | AutoAssignPropertyFlags (BaseObjectData *baseObjectData, ReplicatedObject *newObject, bool isObjectOwner) |
bool | ParsePacket (RakPeerInterface *peer, Packet *packet) |
Protected Attributes | |
RakPeerInterface * | rakPeer |
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 |
ReplicatedObject * | localCreationRequestTable [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 |
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.
|
Adds a participant to the data replicator system. This player will from then on will get memory and object updates.
|
|
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.
|
|
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.
|
|
Returns the value passed to SetBroadcastToAll, or the default of false
|
|
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
|
|
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.
|
|
Return the last value sent for a memory block. Returns the lastSentValue parameter passed to the SetMemoryShouldSendUpdateCB() callback for a given playerId
|
|
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.
|
|
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.
|
|
[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.
|
|
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.
|
|
Returns the last ReplicatedObject::InScope() calculation for an object.
|
|
Called when the interface is attached
Reimplemented from PluginInterface. |
|
Called when RakPeer is shutdown
Reimplemented from PluginInterface. |
|
OnReceive is called for every packet.
Reimplemented from PluginInterface. |
|
OnUpdate is called every time a packet is checked for .
Reimplemented from PluginInterface. |
|
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
Reimplemented from PluginInterface. |
|
Removes a participant from the data replicator system
|
|
This function causes an object that inherits from ReplicatedObject to send creation, destruction, and scope updates to all participants.
|
|
With BroadcastToAll true, all players that connect will have AddParticipant called on their playerId. Defaults to false
|
|
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.
|
|
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
|
|
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().
|
|
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.
|
|
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
///
|
|
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.
|
|
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
|
|
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
///
|
|
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.
|
|
Unsynchronizes memory that was formerly synchronized with SynchronizeMemory.
|