Replica Class Reference
[ReplicaManager]

The interface to derive your game's networked classes from. More...

#include <Replica.h>

Inheritance diagram for Replica:

NetworkIDGenerator List of all members.

Public Member Functions

virtual ReplicaReturnResult SendConstruction (RakNetTime currentTime, PlayerID playerId, RakNet::BitStream *outBitStream, bool *includeTimestamp)=0
virtual void SendDestruction (RakNet::BitStream *outBitStream, PlayerID playerId)=0
virtual ReplicaReturnResult ReceiveDestruction (RakNet::BitStream *inBitStream, PlayerID playerId)=0
virtual ReplicaReturnResult SendScopeChange (bool inScope, RakNet::BitStream *outBitStream, RakNetTime currentTime, PlayerID playerId)=0
virtual ReplicaReturnResult ReceiveScopeChange (RakNet::BitStream *inBitStream, PlayerID playerId)=0
virtual ReplicaReturnResult Serialize (bool *sendTimestamp, RakNet::BitStream *outBitStream, RakNetTime lastSendTime, PacketPriority *priority, PacketReliability *reliability, RakNetTime currentTime, PlayerID playerId)=0
virtual ReplicaReturnResult Deserialize (RakNet::BitStream *inBitStream, RakNetTime timestamp, RakNetTime lastDeserializeTime, PlayerID playerId)=0

Detailed Description

The interface to derive your game's networked classes from.

This is an interface of a replicated object for use in the framework of ReplicaManager You should derive from this class, implementing the functions to provide the behavior you want. If your architecture doesn't allow you to derive from this class, you can store an instance of a derived instance of this class in your base game object. In that case, use GetParent() and SetParent() and propagate the function calls up to your real classes. For an example where I do this, see Monster.h in the ReplicaManagerCS sample.


Member Function Documentation

virtual ReplicaReturnResult Replica::Deserialize RakNet::BitStream inBitStream,
RakNetTime  timestamp,
RakNetTime  lastDeserializeTime,
PlayerID  playerId
[pure virtual]
 

Called when another participant called Serialize with our system as the target

Parameters:
[in] inBitStream What was written to Serialize::outBitStream
[in] timestamp if Serialize::sendTimestamp was set to true, the time the packet was sent.
[in] lastDeserializeTime Last time you returned true from this function for this object, or 0 if never, regardless of playerId.
[in] playerId The participant that sent this message to us.

virtual ReplicaReturnResult Replica::ReceiveDestruction RakNet::BitStream inBitStream,
PlayerID  playerId
[pure virtual]
 

This function is called when SendDestruction is sent from another system. Delete your object if you want.

Parameters:
[in] inBitStream What was sent in SendDestruction::outBitStream
[in] playerId The participant that sent this message to us.
Returns:
See ReplicaReturnResult

virtual ReplicaReturnResult Replica::ReceiveScopeChange RakNet::BitStream inBitStream,
PlayerID  playerId
[pure virtual]
 

Called when when we get the SendScopeChange message. The new scope should have been encoded (by you) into inBitStream

Parameters:
[in] inBitStream What was sent in SendScopeChange::outBitStream
[in] playerId The participant that sent this message to us.
Returns:
See ReplicaReturnResult

virtual ReplicaReturnResult Replica::SendConstruction RakNetTime  currentTime,
PlayerID  playerId,
RakNet::BitStream outBitStream,
bool *  includeTimestamp
[pure virtual]
 

This function is called in the first update tick after this object is first passed to ReplicaManager::Replicate for each player, and also when a new participant joins The intent of this function is to tell another system to create an instance of this class. You can do this however you want - I recommend having each class having a string identifier which is registered with StringTable, and then using EncodeString to write the name of the class. In the callback passed to SetReceiveConstructionCB create an instance of the object based on that string.

Note:
If you return true from IsNetworkIDAuthority, which you should do for a server or peer, I recommend encoding the value returned by GetNetworkID() into your bitstream and calling SetNetworkID with that value in your SetReceiveConstructionCB callback.

Dereplicate, SetScope, and SignalSerializeNeeded all rely on being able to call GET_OBJECT_FROM_ID which requires that SetNetworkID be called on that object.

SendConstruction is called once for every new player that connects and every existing player when an object is passed to Replicate.

Parameters:
[in] currentTime The current time that would be returned by RakNet::GetTime(). That's a slow call I do already, so you can use the parameter instead of having to call it yourself.
[in] playerId The participant to send to.
[out] outBitStream The data you want to write in the message. If you do not write to outBitStream and return true, then no send call will occur and the system will consider this object as not created on that remote system.
[out] includeTimestamp Set to true to include a timestamp with the message. This will be reflected in the timestamp parameter of the callback. Defaults to false.
Returns:
See ReplicaReturnResult

virtual void Replica::SendDestruction RakNet::BitStream outBitStream,
PlayerID  playerId
[pure virtual]
 

The purpose of the function is to send a packet containing the data in outBitStream to playerId telling that system that Dereplicate was called. In the code, this is called in the update cycle after you call ReplicaManager::Destruct(). Then, if you write to outBitStream, a message is sent to that participant. This is the one send you cannot delay because objects may be deleted and we can't read into them past this.

Parameters:
[out] outBitStream The data to send. If you do not write to outBitStream, then no send call will occur
[in] playerId The participant to send to.

virtual ReplicaReturnResult Replica::SendScopeChange bool  inScope,
RakNet::BitStream outBitStream,
RakNetTime  currentTime,
PlayerID  playerId
[pure virtual]
 

Called when ReplicaManager::SetScope is called with a different value than what it currently has. It is up to you to write inScope to outBitStream. Not doing so, and returning true, means you want to cancel the scope change call. If inScope is true, you return true, and data is written to outBitStream, then Serialize will be called automatically This is a convenience feature, since there's almost no case where an object would go in scope but not be serialized

Parameters:
[in] inScope The new scope that will be sent to ReceiveScopeChange that originally came from SetScope
[out] outBitStream The data to send. If you do not write to outBitStream and return true, then no send will occur and the object will keep its existing scope
[in] currentTime The current time that would be returned by RakNet::GetTime(). That's a slow call I do already, so you can use the parameter instead of having to call it yourself.
[in] playerId The participant to send to.
Returns:
See ReplicaReturnResult

virtual ReplicaReturnResult Replica::Serialize bool *  sendTimestamp,
RakNet::BitStream outBitStream,
RakNetTime  lastSendTime,
PacketPriority priority,
PacketReliability reliability,
RakNetTime  currentTime,
PlayerID  playerId
[pure virtual]
 

Called when ReplicaManager::SignalSerializeNeeded is called with this object as the parameter. The system will ensure that Serialize only occurs for participants that have this object constructed and in scope The intent of this function is to serialize all your class member variables for remote transmission.

Parameters:
[out] sendTimestamp Set to true to include a timestamp with the message. This will be reflected in the timestamp parameter Deserialize. Defaults to false.
[out] outBitStream The data you want to write in the message. If you do not write to outBitStream and return true, then no send will occur for this participant.
[in] lastSendTime The last time Serialize returned true and outBitStream was written to. 0 if this is the first time the function has ever been called for this playerId
[in] priority Passed to RakPeer::Send for the send call.
[in] reliability Passed to RakPeer::Send for the send call.
[in] currentTime The current time that would be returned by RakNet::GetTime(). That's a slow call I do already, so you can use the parameter instead of having to call it yourself.
[in] playerId The participant we are sending to.
Returns:
See ReplicaReturnResult


The documentation for this class was generated from the following file:
Generated on Sat Oct 14 08:37:39 2006 for RakNet by  doxygen 1.4.6-NO