- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# RakNet::Replica2 Class Reference
[ReplicaManager2]

Base class for game objects that use the ReplicaManager2 system All game objects that want to use the ReplicaManager2 functionality must inherit from Replica2. Generally you will want to implement at a minimum Serialize(), Deserialize(), and SerializeConstruction(). More...

`#include <ReplicaManager2.h>`

Inheritance diagram for RakNet::Replica2:

List of all members.

## Public Member Functions
| Replica2 ()
| Constructor.
virtual | ~Replica2 ()
| Destructor.
void | SetReplicaManager (ReplicaManager2 *rm)
ReplicaManager2 * | GetReplicaManager (void) const
virtual void | SendConstruction (SystemAddress recipientAddress, SerializationType serializationType=UNDEFINED_REASON)
virtual void | SendDestruction (SystemAddress recipientAddress, SerializationType serializationType=UNDEFINED_REASON)
virtual void | SendSerialize (SystemAddress recipientAddress, SerializationType serializationType=UNDEFINED_REASON)
virtual void | SendVisibility (SystemAddress recipientAddress, SerializationType serializationType=UNDEFINED_REASON)
virtual void | BroadcastConstruction (SerializationContext *serializationContext=0)
virtual void | BroadcastSerialize (SerializationContext *serializationContext=0)
virtual void | BroadcastDestruction (SerializationContext *serializationContext=0)
virtual void | BroadcastVisibility (bool isVisible, SerializationContext *serializationContext=0)
virtual bool | SerializeConstruction (RakNet::BitStream *bitStream, SerializationContext *serializationContext)=0
virtual bool | SerializeDestruction (RakNet::BitStream *bitStream, SerializationContext *serializationContext)
virtual bool | Serialize (RakNet::BitStream *bitStream, SerializationContext *serializationContext)
virtual bool | SerializeVisibility (RakNet::BitStream *bitStream, SerializationContext *serializationContext)
virtual void | DeserializeDestruction (RakNet::BitStream *bitStream, SerializationType serializationType, SystemAddress sender, RakNetTime timestamp)
virtual void | Deserialize (RakNet::BitStream *bitStream, SerializationType serializationType, SystemAddress sender, RakNetTime timestamp)
virtual void | DeserializeVisibility (RakNet::BitStream *bitStream, SerializationType serializationType, SystemAddress sender, RakNetTime timestamp)
virtual BooleanQueryResult | QueryConstruction (Connection_RM2 *connection)
virtual BooleanQueryResult | QueryVisibility (Connection_RM2 *connection)
virtual bool | QueryIsConstructionAuthority (void) const
virtual bool | QueryIsDestructionAuthority (void) const
virtual bool | QueryIsVisibilityAuthority (void) const
virtual bool | QueryIsSerializationAuthority (void) const
virtual bool | AllowRemoteConstruction (SystemAddress sender, RakNet::BitStream *replicaData, SerializationType type, RakNetTime timestamp)
virtual void | AddAutoSerializeTimer (RakNetTime interval, SerializationType serializationType=AUTOSERIALIZE_DEFAULT, RakNetTime countdown=(RakNetTime)-1)
virtual void | ElapseAutoSerializeTimers (RakNetTime timeElapsed, bool resynchOnly)
RakNetTime | GetTimeToNextAutoSerialize (SerializationType serializationType=AUTOSERIALIZE_DEFAULT)
virtual void | BroadcastAutoSerialize (SerializationContext *serializationContext, RakNet::BitStream *serializedObject)
virtual void | CancelAutoSerializeTimer (SerializationType serializationType=AUTOSERIALIZE_DEFAULT)
virtual void | ClearAutoSerializeTimers (void)
| Remove and deallocate all previously added autoSerialize timers.
virtual void | OnAutoSerializeTimerElapsed (SerializationType serializationType, RakNet::BitStream *output, RakNet::BitStream *lastOutput, RakNetTime lastAutoSerializeCountdown, bool resynchOnly)
virtual void | ForceElapseAllAutoserializeTimers (bool resynchOnly)

## Detailed Description

Base class for game objects that use the ReplicaManager2 system All game objects that want to use the ReplicaManager2 functionality must inherit from Replica2. Generally you will want to implement at a minimum Serialize(), Deserialize(), and SerializeConstruction().

## Member Function Documentation

void Replica2::SetReplicaManager | ( | ReplicaManager2 * | rm | ) |

Sets the replica manager to use with this Replica. Will also set the NetworkIDManager associated with RakPeerInterface::SetNetworkIDManager() Call this before using any of the functions below!

Parameters:

  `[in]` | rm | A pointer to your instance of ReplicaManager 2

ReplicaManager2 * Replica2::GetReplicaManager | ( | void |  | ) | const

Returns what was passed to SetReplicaManager(), or 0 if no value ever passed

Returns:
  Registered instance of ReplicaManager2

void Replica2::SendConstruction | ( | SystemAddress | recipientAddress,
|  | SerializationType | serializationType = `UNDEFINED_REASON` |
| ) |  |  | `[virtual]`

Construct this object on other systems Triggers a call to SerializeConstruction()

Note:
  If using peer-to-peer, don't forget to set NetworkID::peerToPeerMode=true and comment out NETWORK_ID_USE_PTR_TABLE in NetworkIDManager.h

Parameters:

  `[in]` | recipientAddress | Which system to send to
  `[in]` | serializationType | What type of command this is. Use UNDEFINED_REASON to have a type chosen automatically

void Replica2::SendDestruction | ( | SystemAddress | recipientAddress,
|  | SerializationType | serializationType = `UNDEFINED_REASON` |
| ) |  |  | `[virtual]`

Destroy this object on other systems Triggers a call to SerializeDestruction()

Parameters:

  `[in]` | recipientAddress | Which system to send to
  `[in]` | serializationType | What type of command this is. Use UNDEFINED_REASON to have a type chosen automatically

void Replica2::SendSerialize | ( | SystemAddress | recipientAddress,
|  | SerializationType | serializationType = `UNDEFINED_REASON` |
| ) |  |  | `[virtual]`

Serialize this object to another system Triggers a call to Serialize()

Parameters:

  `[in]` | recipientAddress | Which system to send to
  `[in]` | serializationType | What type of command this is. Use UNDEFINED_REASON to have a type chosen automatically

void Replica2::SendVisibility | ( | SystemAddress | recipientAddress,
|  | SerializationType | serializationType = `UNDEFINED_REASON` |
| ) |  |  | `[virtual]`

Update the visibility of this object on another system Triggers a call to SerializeVisibility()

Parameters:

  `[in]` | recipientAddress | Which system to send to
  `[in]` | serializationType | What type of command this is. Use UNDEFINED_REASON to have a type chosen automatically

void Replica2::BroadcastConstruction | ( | SerializationContext * | serializationContext = `0` | ) | `[virtual]`

Construct this object on other systems

Parameters:

  `[in]` | serializationContext | Which system to send to, an input timestamp, and the SerializationType. 0 to use defaults, no timestamp.

void Replica2::BroadcastSerialize | ( | SerializationContext * | serializationContext = `0` | ) | `[virtual]`

Serialize this object to all current connections Triggers a call to SerializeConstruction() for each connection (you can serialize differently per connection).

Parameters:

  `[in]` | serializationContext | Which system to send to, an input timestamp, and the SerializationType. 0 to use defaults, no timestamp.

void Replica2::BroadcastDestruction | ( | SerializationContext * | serializationContext = `0` | ) | `[virtual]`

Destroy this object on all current connections Triggers a call to SerializeDestruction() for each connection (you can serialize differently per connection).

Parameters:

  `[in]` | serializationContext | Which system to send to, an input timestamp, and the SerializationType. 0 to use defaults, no timestamp.

void Replica2::BroadcastVisibility | ( | bool | isVisible,
|  | SerializationContext * | serializationContext = `0` |
| ) |  |  | `[virtual]`

Update the visibility state of this object on all other systems Use SEND_VISIBILITY_TRUE_TO_SYSTEM or SEND_VISIBILITY_FALSE_TO_SYSTEM in serializationContext::serializationType Triggers a call to SerializeVisibility() for each connection (you can serialize differently per connection).

Parameters:

  `[in]` | serializationContext | Which system to send to, an input timestamp, and the SerializationType. 0 to use defaults, no timestamp, true visibility

virtual bool RakNet::Replica2::SerializeConstruction | ( | RakNet::BitStream * | bitStream,
|  | SerializationContext * | serializationContext |
| ) |  |  | `[pure virtual]`

CALLBACK: Override in order to write to bitStream data identifying this class for the class factory. Will be received by Connection_RM2::Construct() to create an instance of this class.

Parameters:

  `[out]` | bitStream | Data used to identify this class, along with any data you also want to send when constructing the class
  `[in]` | serializationContext | serializationType passed to Replica2::SendConstruction(), along with destination system, and a timestamp you can write to.

Returns:
  Return false to cancel the construction, true to process

bool Replica2::SerializeDestruction | ( | RakNet::BitStream * | bitStream,
|  | SerializationContext * | serializationContext |
| ) |  |  | `[virtual]`

CALLBACK: Override in order to write to bitStream data to send along with destruction requests. Will be received by DeserializeDestruction()

Parameters:

  `[out]` | bitStream | Data to send
  `[in]` | serializationContext | Describes which system we are sending to, and a timestamp as an out parameter

Returns:
  Return false to cancel the operation, true to process

bool Replica2::Serialize | ( | RakNet::BitStream * | bitStream,
|  | SerializationContext * | serializationContext |
| ) |  |  | `[virtual]`

CALLBACK: Override in order to write to bitStream data to send as regular class serialization, for normal per-tick data. Will be received by Deserialize()

Parameters:

  `[out]` | bitStream | Data to send
  `[in]` | serializationContext | Describes which system we are sending to, and a timestamp as an out parameter

Returns:
  Return false to cancel the operation, true to process

bool Replica2::SerializeVisibility | ( | RakNet::BitStream * | bitStream,
|  | SerializationContext * | serializationContext |
| ) |  |  | `[virtual]`

CALLBACK: Override in order to write to bitStream data to send along with visibility changes. Will be received by DeserializeVisibility()

Parameters:

  `[out]` | bitStream | Data to send
  `[in]` | serializationContext | Describes which system we are sending to, and a timestamp as an out parameter

Returns:
  Return false to cancel the operation, true to process

void Replica2::DeserializeDestruction | ( | RakNet::BitStream * | bitStream,
|  | SerializationType | serializationType,
|  | SystemAddress | sender,
|  | RakNetTime | timestamp |
| ) |  |  | `[virtual]`

CALLBACK: Receives data written by SerializeDestruction()

Parameters:

  `[in]` | bitStream | Data sent
  `[in]` | serializationType | SerializationContext::serializationType
  `[in]` | sender | Which system sent this message to us
  `[in]` | timestamp | If a timestamp was written, will be whatever was written adjusted to the local system time. 0 if not used.

void Replica2::Deserialize | ( | RakNet::BitStream * | bitStream,
|  | SerializationType | serializationType,
|  | SystemAddress | sender,
|  | RakNetTime | timestamp |
| ) |  |  | `[virtual]`

CALLBACK: Receives data written by Serialize()

Parameters:

  `[in]` | bitStream | Data sent
  `[in]` | serializationType | SerializationContext::serializationType
  `[in]` | sender | Which system sent this message to us
  `[in]` | timestamp | If a timestamp was written, will be whatever was written adjusted to the local system time. 0 if not used.

void Replica2::DeserializeVisibility | ( | RakNet::BitStream * | bitStream,
|  | SerializationType | serializationType,
|  | SystemAddress | sender,
|  | RakNetTime | timestamp |
| ) |  |  | `[virtual]`

CALLBACK: Receives data written by SerializeVisibility()

Parameters:

  `[in]` | bitStream | Data sent
  `[in]` | serializationType | SerializationContext::serializationType
  `[in]` | sender | Which system sent this message to us
  `[in]` | timestamp | If a timestamp was written, will be whatever was written adjusted to the local system time. 0 if not used.

BooleanQueryResult Replica2::QueryConstruction | ( | Connection_RM2 * | connection | ) | `[virtual]`

CALLBACK: For a given connection, should this object exist? Checked every Update cycle if ReplicaManager2::SetAutoUpdateScope() parameter construction is true Defaults to BQR_ALWAYS

Parameters:

  `[in]` | connection | Which connection we are referring to. 0 means unknown, in which case the system is checking for BQR_ALWAYS or BQR_NEVER as an optimization.

Returns:
  BQR_NO and the object will be destroyed. BQR_YES and the object will be created. BQR_ALWAYS is YES for all connections, and is optimized to only be checked once.

BooleanQueryResult Replica2::QueryVisibility | ( | Connection_RM2 * | connection | ) | `[virtual]`

CALLBACK: For a given connection, should this object be visible (updatable?) Checked every Update cycle if ReplicaManager2::SetAutoUpdateScope() parameter serializationVisiblity is true Defaults to BQR_ALWAYS

Parameters:

  `[in]` | connection | Which connection we are referring to. 0 means unknown, in which case the system is checking for BQR_ALWAYS or BQR_NEVER as an optimization.

Returns:
  BQR_NO or BQR_YES and as this value changes per connection, you will get a call to DeserializeVisibility().

bool Replica2::QueryIsConstructionAuthority | ( | void |  | ) | const`[virtual]`

CALLBACK: Does this system have control over construction of this object? While not strictly required, it is best to have this consistently return true for only one system. Otherwise systems may fight and override each other. Defaults to NetworkIDManager::IsNetworkIDAuthority();

Returns:
  True if an authority over this operation, for this object instance

bool Replica2::QueryIsDestructionAuthority | ( | void |  | ) | const`[virtual]`

CALLBACK: Does this system have control over deletion of this object? While not strictly required, it is best to have this consistently return true for only one system. Otherwise systems may fight and override each other. Defaults to NetworkIDManager::IsNetworkIDAuthority();

Returns:
  True if an authority over this operation, for this object instance

bool Replica2::QueryIsVisibilityAuthority | ( | void |  | ) | const`[virtual]`

CALLBACK: Does this system have control over visibility of this object? While not strictly required, it is best to have this consistently return true for only one system. Otherwise systems may fight and override each other. Defaults to NetworkIDManager::IsNetworkIDAuthority();

Returns:
  True if an authority over this operation, for this object instance

bool Replica2::QueryIsSerializationAuthority | ( | void |  | ) | const`[virtual]`

CALLBACK: Does this system have control over serialization of object members of this object? It is reasonable to have this be true for more than one system, but you would want to serialize different variables so those systems do not conflict. Defaults to NetworkIDManager::IsNetworkIDAuthority();

Returns:
  True if an authority over this operation, for this object instance

bool Replica2::AllowRemoteConstruction | ( | SystemAddress | sender,
|  | RakNet::BitStream * | replicaData,
|  | SerializationType | type,
|  | RakNetTime | timestamp |
| ) |  |  | `[virtual]`

CALLBACK: If QueryIsConstructionAuthority() is false for a remote system, should that system be able to create this kind of object?

Parameters:

  `[in]` | sender | Which system sent this message to us? Also happens to be the system that is requesting to create an object
  `[in]` | replicaData | Construction data used to create this object
  `[in]` | type | Which type of serialization operation was performed
  `[in]` | timestamp | Written timestamp with the packet. 0 if not used.

Returns:
  True to allow remote construction of this object. If true, we will reply with SEND_CONSTRUCTION_REPLY_ACCEPTED_TO_CLIENT and the network ID will be set on the requester.

void Replica2::AddAutoSerializeTimer | ( | RakNetTime | interval,
|  | SerializationType | serializationType = `AUTOSERIALIZE_DEFAULT`,
|  | RakNetTime | countdown = `(RakNetTime)-1` |
| ) |  |  | `[virtual]`

Adds a timer that will elapse every countdown milliseconds, calling Serialize with AUTOSERIALIZE_DEFAULT or whatever value was passed to serializationType Every time this timer elapses, the value returned from Serialize() will be compared to the last value returned by Serialize(). If different, SendSerialize() will be called automatically. It is possible to create your own AUTOSERIALIZE enumerations and thus control which parts of the object is serialized Use CancelAutoSerializeTimer() or ClearAutoSerializeTimers() to stop the timer. If this timer already exists, it will simply override the existing countdown This timer will automatically repeat every countdown milliseconds

Parameters:

  `[in]` | interval | Time in milliseconds between autoserialize ticks. Use 0 to process immediately, and every tick
  `[in]` | serializationType | User-defined identifier for what type of serialization operation to perform. Returned in Deserialize() as the serializationType parameter.
  `[in]` | countdown | Amount of time before doing the next autoserialize. Defaults to interval

void Replica2::ElapseAutoSerializeTimers | ( | RakNetTime | timeElapsed,
|  | bool | resynchOnly |
| ) |  |  | `[virtual]`

Elapse time for all timers added with AddAutoSerializeTimer() Only necessary to call this if you call Replica2::SetDoReplicaAutoSerializeUpdate(false) (which defaults to true)

Parameters:

  `[in]` | timeElapsed | How many milliseconds have elapsed since the last call
  `[in]` | resynchOnly | True to only update what was considered the last send, without actually doing a send.

RakNetTime Replica2::GetTimeToNextAutoSerialize | ( | SerializationType | serializationType = `AUTOSERIALIZE_DEFAULT` | ) |

Returns how many milliseconds are remaining until the next autoserialize update

Parameters:

  `[in]` | serializationType | User-defined identifier for what type of serialization operation to perform. Returned in Deserialize() as the serializationType parameter.

Returns:
  How many milliseconds are remaining until the next autoserialize update. Returns -1 if no such autoserialization timer is in place.

void Replica2::BroadcastAutoSerialize | ( | SerializationContext * | serializationContext,
|  | RakNet::BitStream * | serializedObject |
| ) |  |  | `[virtual]`

Do the actual send call when needed to support autoSerialize If you want to do different types of send calls (UNRELIABLE for example) override this function.

Parameters:

  `[in]` | serializationContext | Describes the recipient, sender. serializationContext::timestamp is an [out] parameter which if you write to, will be send along with the message
  `[in]` | serializedObject | Data to pass to ReplicaManager2::SendSerialize()

void Replica2::CancelAutoSerializeTimer | ( | SerializationType | serializationType = `AUTOSERIALIZE_DEFAULT` | ) | `[virtual]`

Stop calling an autoSerialize timer previously setup with AddAutoSerializeTimer()

Parameters:

  `[in]` | serializationType | Corresponding value passed to serializationType

void Replica2::OnAutoSerializeTimerElapsed | ( | SerializationType | serializationType,
|  | RakNet::BitStream * | output,
|  | RakNet::BitStream * | lastOutput,
|  | RakNetTime | lastAutoSerializeCountdown,
|  | bool | resynchOnly |
| ) |  |  | `[virtual]`

A timer has elapsed. Compare the last value sent to the current value, and if different, send the new value

void Replica2::ForceElapseAllAutoserializeTimers | ( | bool | resynchOnly | ) | `[virtual]`

Immediately elapse all autoserialize timers Used internally when a Deserialize() event occurs, so that the deserialize does not trigger an autoserialize itself

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

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