# RakNet::Replica3 Class Reference

Base class for your replicated objects for the ReplicaManager3 system. To use, derive your class, or a member of your class, from Replica3 Implement all pure virtual functions. More...

`#include <ReplicaManager3.h>`

Inheritance diagram for RakNet::Replica3:

List of all members.

## Public Member Functions

virtual | ~Replica3 ()
virtual void | WriteAllocationID (RakNet::BitStream *allocationIdBitstream) const =0
| Write a unique identifer for this class type The value written to allocationIdBitstream will be passed to Connection_RM3::AllocReplica() Sample implementation: {allocationIdBitstream->Write(RakNet::RakString("Soldier");}.
virtual RM3ConstructionState | QueryConstruction (RakNet::Connection_RM3 *destinationConnection, ReplicaManager3 *replicaManager3)=0

Query to see if this object should exist or be destroyed for a given remote system If ReplicaManager3::SetAutoManageConnections() is true, then this function is called by ReplicaManager3::Update() to determine if an object should exist on a given system. If an object previously existed, but no longer does, a network message will be automatically sent to destroy it Likewise, if an object did not previously exist, but now does, a network message will be automatically sent to create it.

virtual bool | QueryRemoteConstruction (RakNet::Connection_RM3 *sourceConnection)=0
| Should I allow this object to be created remotely, based solely on the sender?
virtual void | SerializeConstruction (RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *destinationConnection)=0

Write data to be sent only when the object is constructed on a remote system. SerializeConstruction is used to write out data that you need to create this object in the context of your game, such as health, score, name. Use it for data you only need to send when the object is created. After SerializeConstruction() is called, Serialize() will be called immediately thereafter. However, they are sent in different messages, so Serialize() may arrive a later frame than SerializeConstruction().

virtual bool | DeserializeConstruction (RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *sourceConnection)=0
| Read data written by Replica3::SerializeConstruction() Reads whatever data was written to constructionBitstream in Replica3::SerializeConstruction().
virtual void | SerializeDestruction (RakNet::BitStream *destructionBitstream, RakNet::Connection_RM3 *destinationConnection)=0
| Write extra data to send with the object deletion event, if desired Replica3::SerializeDestruction() will be called to write any object destruction specific data you want to send with this event. destructionBitstream can be read in DeserializeDestruction().
virtual bool | DeserializeDestruction (RakNet::BitStream *destructionBitstream, RakNet::Connection_RM3 *sourceConnection)=0
| Read data written by Replica3::SerializeDestruction() Return true to delete the object. BroadcastDestruction() will be called automatically, followed by ReplicaManager3::Dereference. Return false to not delete it. If you delete it at a later point, you are responsible for calling BroadcastDestruction() yourself.
virtual void | DeallocReplica (RakNet::Connection_RM3 *sourceConnection)=0
| Override with {delete this;} 1. Got a remote message to delete this object which passed DeserializeDestruction(), OR 2. ReplicaManager3::SetAutoManageConnections() was called autoDestroy true (which is the default setting), and a remote system that owns this object disconnected) OR 3. ReplicaManager3::PopConnection() was called with alsoDeleteCreatedReplicas as true.
virtual bool | QuerySerialization (RakNet::Connection_RM3 *destinationConnection)=0

Implement with QuerySerialization_ClientSerializable(), QuerySerialization_ServerSerializable(), or QuerySerialization_PeerToPeer() QuerySerialization() is a first pass query to check if a given object should serializable to a given system. The intent is that the user implements with one of the defaults for client, server, or peer to peer. Without this function, a careless implementation would serialize an object anytime it changed to all systems. This would give you feedback loops as the sender gets the same message back from the recipient it just sent to. If more than one system can serialize the same object then you will need to override to return true, and control the serialization result from Replica3::Serialize(). Be careful not to send back the same data to the system that just sent to you!

virtual RM3SerializationResult | Serialize (RakNet::SerializeParameters *serializeParameters)=0

Serialize our class to a bitstream User should implement this function to write the contents of this class to SerializationParamters::serializationBitstream If data only needs to be written once, you can write it to SerializeConstruction() instead for efficiency Transmitted over the network if it changed from the last time we called Serialize() Called every time the time interval to ReplicaManager3::SetAutoSerializeInterval() elapses and ReplicaManager3::Update is subsequently called.

virtual void | Deserialize (RakNet::BitStream *serializationBitstream, RakNetTime timeStamp, RakNet::Connection_RM3 *sourceConnection)=0
| Read what was written in Serialize() Reads the contents of the class from SerializationParamters::serializationBitstream Called whenever Serialize() is called with different data from the last send.
virtual void | SerializeConstructionRequestAccepted (RakNet::BitStream *serializationBitstream, RakNet::Connection_RM3 *requestingConnection)
virtual void | DeserializeConstructionRequestAccepted (RakNet::BitStream *serializationBitstream, RakNet::Connection_RM3 *acceptingConnection)
virtual void | SerializeConstructionRequestRejected (RakNet::BitStream *serializationBitstream, RakNet::Connection_RM3 *requestingConnection)
virtual void | DeserializeConstructionRequestRejected (RakNet::BitStream *serializationBitstream, RakNet::Connection_RM3 *rejectingConnection)
virtual void | PostDeserializeConstruction (RakNet::Connection_RM3 *sourceConnection)
virtual void | PreDestruction (RakNet::Connection_RM3 *sourceConnection)
RakNetGUID | GetCreatingSystemGUID (void) const
virtual void | BroadcastDestruction (void)
virtual RM3ConstructionState | QueryConstruction_ClientConstruction (RakNet::Connection_RM3 *destinationConnection)
| Default call for QueryConstruction(). Allow clients to create this object.
virtual bool | QueryRemoteConstruction_ClientConstruction (RakNet::Connection_RM3 *sourceConnection)
| Default call for QueryConstruction(). Allow clients to create this object.
virtual RM3ConstructionState | QueryConstruction_ServerConstruction (RakNet::Connection_RM3 *destinationConnection)
| Default call for QueryConstruction(). Allow the server to create this object, but not the client.
virtual bool | QueryRemoteConstruction_ServerConstruction (RakNet::Connection_RM3 *sourceConnection)
| Default call for QueryConstruction(). Allow the server to create this object, but not the client.
virtual RM3ConstructionState | QueryConstruction_PeerToPeer (RakNet::Connection_RM3 *destinationConnection)
| Default call for QueryConstruction(). Peer to peer - creating system sends the object to all other systems. No relaying.
virtual bool | QueryRemoteConstruction_PeerToPeer (RakNet::Connection_RM3 *sourceConnection)
| Default call for QueryConstruction(). Peer to peer - creating system sends the object to all other systems. No relaying.
virtual bool | QuerySerialization_ClientSerializable (RakNet::Connection_RM3 *destinationConnection)
| Default call for QuerySerialization(). Use if the values you are serializing are generated by the client that owns the object. The serialization will be relayed through the server to the other clients.
virtual bool | QuerySerialization_ServerSerializable (RakNet::Connection_RM3 *destinationConnection)
| Default call for QuerySerialization(). Use if the values you are serializing are generated only by the server. The serialization will be sent to all clients, but the clients will not send back to the server.
virtual bool | QuerySerialization_PeerToPeer (RakNet::Connection_RM3 *destinationConnection)
| Default call for QuerySerialization(). Use if the values you are serializing are on a peer to peer network. The peer that owns the object will send to all. Remote peers will not send.
void | SwapIdenticalSerializationPointers (void)

## Public Attributes

RakNetGUID | creatingSystemGUID
RakNetGUID | deletingSystemGUID
| GUID of the system that caused the item to send a deletion command over the network.

## Detailed Description

Base class for your replicated objects for the ReplicaManager3 system. To use, derive your class, or a member of your class, from Replica3 Implement all pure virtual functions.

## Constructor & Destructor Documentation

Replica3::~Replica3 | ( |  | ) | `[virtual]`

Before deleting a local instance of Replica3, call Replica3::BroadcastDestruction() for the deletion notification to go out on the network. It is not necessary to call ReplicaManager3::Dereference(), as this happens automatically in the destructor

## Member Function Documentation

void Replica3::BroadcastDestruction | ( | void |  | ) | `[virtual]`

Call to send a network message to delete this object on other systems Call it before deleting the object

virtual void RakNet::Replica3::DeallocReplica | ( | RakNet::Connection_RM3 * | sourceConnection | ) | `[pure virtual]`

Override with {delete this;} 1. Got a remote message to delete this object which passed DeserializeDestruction(), OR 2. ReplicaManager3::SetAutoManageConnections() was called autoDestroy true (which is the default setting), and a remote system that owns this object disconnected) OR 3. ReplicaManager3::PopConnection() was called with alsoDeleteCreatedReplicas as true.

Override with {delete this;} to actually delete the object (and any other processing you wish). If you don't want to delete the object, just do nothing, however, the system will not know this so you are responsible for deleting it yoruself later. destructionBitstream may be 0 if the object was deleted locally

virtual void RakNet::Replica3::Deserialize | ( | RakNet::BitStream * | serializationBitstream,
|  | RakNetTime | timeStamp,
|  | RakNet::Connection_RM3 * | sourceConnection |
| ) |  |  | `[pure virtual]`

Read what was written in Serialize() Reads the contents of the class from SerializationParamters::serializationBitstream Called whenever Serialize() is called with different data from the last send.

Parameters:

  `[in]` | serializationBitstream | Bitstream passed to Serialize()
  `[in]` | timeStamp | 0 if unused, else contains the time the message originated on the remote system
  `[in]` | sourceConnection | Which system sent to us

virtual bool RakNet::Replica3::DeserializeConstruction | ( | RakNet::BitStream * | constructionBitstream,
|  | RakNet::Connection_RM3 * | sourceConnection |
| ) |  |  | `[pure virtual]`

Read data written by Replica3::SerializeConstruction() Reads whatever data was written to constructionBitstream in Replica3::SerializeConstruction().

Parameters:

  `[out]` | constructionBitstream | Bitstream written to in Replica3::SerializeConstruction()
  `[in]` | sourceConnection | System that sent us this network message.

Returns:
  true to accept construction of the object. false to reject, in which case the object will be deleted via Replica3::DeallocReplica()

virtual void RakNet::Replica3::DeserializeConstructionRequestAccepted | ( | RakNet::BitStream * | serializationBitstream,
|  | RakNet::Connection_RM3 * | acceptingConnection |
| ) |  |  | `[inline, virtual]`

Receive the result of SerializeConstructionRequestAccepted

Parameters:

  `[in]` | serializationBitstream | Source bitstream to read from
  `[in]` | acceptingConnection | Which system sent to us

virtual void RakNet::Replica3::DeserializeConstructionRequestRejected | ( | RakNet::BitStream * | serializationBitstream,
|  | RakNet::Connection_RM3 * | rejectingConnection |
| ) |  |  | `[inline, virtual]`

Receive the result of DeserializeConstructionRequestRejected

Parameters:

  `[in]` | serializationBitstream | Source bitstream to read from
  `[in]` | requestingConnection | Which system sent to us

RakNetGUID Replica3::GetCreatingSystemGUID | ( | void |  | ) | const

creatingSystemGUID is set the first time Reference() is called, or if we get the object from another system

Returns:
  System that originally created this object

virtual void RakNet::Replica3::PostDeserializeConstruction | ( | RakNet::Connection_RM3 * | sourceConnection | ) | `[inline, virtual]`

Called after DeserializeConstruction completes for the object successfully Override to trigger some sort of event when you know the object has completed deserialization.

Parameters:

  `[in]` | sourceConnection | System that sent us this network message.

virtual void RakNet::Replica3::PreDestruction | ( | RakNet::Connection_RM3 * | sourceConnection | ) | `[inline, virtual]`

Called after DeserializeDestruction completes for the object successfully, but obviously before the object is deleted Also called in PopConnection() if alsoDeleteCreatedReplicas is true Override to trigger some sort of event when you know the object has completed destruction.

Parameters:

  `[in]` | sourceConnection | System that sent us this network message.

virtual RM3ConstructionState RakNet::Replica3::QueryConstruction | ( | RakNet::Connection_RM3 * | destinationConnection,
|  | ReplicaManager3 * | replicaManager3 |
| ) |  |  | `[pure virtual]`

Query to see if this object should exist or be destroyed for a given remote system If ReplicaManager3::SetAutoManageConnections() is true, then this function is called by ReplicaManager3::Update() to determine if an object should exist on a given system. If an object previously existed, but no longer does, a network message will be automatically sent to destroy it Likewise, if an object did not previously exist, but now does, a network message will be automatically sent to create it.

Note:
  Defaults are provided: QueryConstruction_PeerToPeer(), QueryConstruction_ServerConstruction(), QueryConstruction_ClientConstruction(). Return one of these functions for a working default for the relevant topology.

Parameters:

  `[in]` | destinationConnection | Which system we will send to
  `[in]` | replicaManager3 | Plugin instance for this Replica3

Returns:
  What action to take

virtual bool RakNet::Replica3::QueryRemoteConstruction | ( | RakNet::Connection_RM3 * | sourceConnection | ) | `[pure virtual]`

Should I allow this object to be created remotely, based solely on the sender?

Note:
  Defaults are provided: QueryRemoteConstruction_PeerToPeer(), QueryRemoteConstruction_ServerConstruction(), QueryRemoteConstruction_ClientConstruction(). Return one of these functions for a working default for the relevant topology.

Parameters:

  `[in]` | sourceConnection | Which system sent us the object creation request message.

Returns:
  True to allow the object to pass onto DeserializeConstruction() (where it may also be rejected), false to immediately reject the remote construction request

virtual bool RakNet::Replica3::QuerySerialization | ( | RakNet::Connection_RM3 * | destinationConnection | ) | `[pure virtual]`

Implement with QuerySerialization_ClientSerializable(), QuerySerialization_ServerSerializable(), or QuerySerialization_PeerToPeer() QuerySerialization() is a first pass query to check if a given object should serializable to a given system. The intent is that the user implements with one of the defaults for client, server, or peer to peer. Without this function, a careless implementation would serialize an object anytime it changed to all systems. This would give you feedback loops as the sender gets the same message back from the recipient it just sent to. If more than one system can serialize the same object then you will need to override to return true, and control the serialization result from Replica3::Serialize(). Be careful not to send back the same data to the system that just sent to you!

Returns:
  True to allow calling Replica3::Serialize() for this connection, false to not call.

virtual RM3SerializationResult RakNet::Replica3::Serialize | ( | RakNet::SerializeParameters * | serializeParameters | ) | `[pure virtual]`

Serialize our class to a bitstream User should implement this function to write the contents of this class to SerializationParamters::serializationBitstream If data only needs to be written once, you can write it to SerializeConstruction() instead for efficiency Transmitted over the network if it changed from the last time we called Serialize() Called every time the time interval to ReplicaManager3::SetAutoSerializeInterval() elapses and ReplicaManager3::Update is subsequently called.

Parameters:

  | in/out] | serializeParameters Parameters controlling the serialization, including destination bitstream to write to

Returns:
  Whether to serialize, and if so, how to optimize the results

virtual void RakNet::Replica3::SerializeConstruction | ( | RakNet::BitStream * | constructionBitstream,
|  | RakNet::Connection_RM3 * | destinationConnection |
| ) |  |  | `[pure virtual]`

Write data to be sent only when the object is constructed on a remote system. SerializeConstruction is used to write out data that you need to create this object in the context of your game, such as health, score, name. Use it for data you only need to send when the object is created. After SerializeConstruction() is called, Serialize() will be called immediately thereafter. However, they are sent in different messages, so Serialize() may arrive a later frame than SerializeConstruction().

Note:
  The object's NetworkID and allocation id are handled by the system automatically, you do not need to write these values.

Parameters:

  `[out]` | constructionBitstream | Destination bitstream to write your data to
  `[in]` | destinationConnection | System that will receive this network message.

virtual void RakNet::Replica3::SerializeConstructionRequestAccepted | ( | RakNet::BitStream * | serializationBitstream,
|  | RakNet::Connection_RM3 * | requestingConnection |
| ) |  |  | `[inline, virtual]`

If a system creates an object and NetworkIDManager::IsNetworkIDAuthority() returns false, then the object cannot locally assign NetworkID, which means that the object cannot be used over the network The object will call SerializeConstruction() and sent over the network with a temporary id. When the object is created by a system where NetworkIDManager::IsNetworkIDAuthority() returns true, SerializeConstructionRequestAccepted() will be called with the opportunity to write additional data if desired. The sender will then receive serializationBitstream in DeserializeConstructionRequestAccepted(), after the NetworkID has been assigned. This is not pure virtual, because it is not often used and is not necessary for the system to work.

Parameters:

  `[out]` | serializationBitstream | Destination bitstream to write to
  `[in]` | requestingConnection | Which system sent to us

virtual void RakNet::Replica3::SerializeConstructionRequestRejected | ( | RakNet::BitStream * | serializationBitstream,
|  | RakNet::Connection_RM3 * | requestingConnection |
| ) |  |  | `[inline, virtual]`

Same as SerializeConstructionRequestAccepted(), but the client construction request was rejected

Parameters:

  `[out]` | serializationBitstream | Destination bitstream to write to
  `[in]` | requestingConnection | Which system sent to us

virtual void RakNet::Replica3::SerializeDestruction | ( | RakNet::BitStream * | destructionBitstream,
|  | RakNet::Connection_RM3 * | destinationConnection |
| ) |  |  | `[pure virtual]`

Write extra data to send with the object deletion event, if desired Replica3::SerializeDestruction() will be called to write any object destruction specific data you want to send with this event. destructionBitstream can be read in DeserializeDestruction().

Parameters:

  `[out]` | destructionBitstream | Bitstream for you to write to
  `[in]` | destinationConnection | System that will receive this network message.

void Replica3::SwapIdenticalSerializationPointers | ( | void |  | ) |

------------- All internal after here ------------------

virtual void RakNet::Replica3::WriteAllocationID | ( | RakNet::BitStream * | allocationIdBitstream | ) | const`[pure virtual]`

Write a unique identifer for this class type The value written to allocationIdBitstream will be passed to Connection_RM3::AllocReplica() Sample implementation: {allocationIdBitstream->Write(RakNet::RakString("Soldier");}.

Parameters:

  `[out]` | allocationIdBitstream | Bitstream for the user to write to, to identify this class

## Member Data Documentation

RakNetGUID RakNet::Replica3::creatingSystemGUID

GUID of the system that first called Reference() on this object. Transmitted automatically when the object is constructed

The documentation for this class was generated from the following files:

- C:/RakNet/Source/ReplicaManager3.h
- C:/RakNet/Source/ReplicaManager3.cpp