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>
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) |
virtual void | OnConstructionComplete (RakNet::BitStream *replicaData, SystemAddress sender, SerializationType type, ReplicaManager2 *replicaManager, RakNetTime timestamp, NetworkID networkId, bool networkIDCollision) |
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::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
- Note:
- The same data is sent to all participants when the autoserialize timer completes. If the data sent depends on the system to be sent to, do not use autoserialize. This is an optimization to save memory.
- 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 |
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.
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() |
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. |
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. |
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::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 |
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 |
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. |
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. |
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. |
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. |
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
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.
A timer has elapsed. Compare the last value sent to the current value, and if different, send the new value
A call to Connection_RM2 Construct() has completed and the object is now internally referenced
- Parameters:
-
[in] | replicaData | Whatever was written bitStream in Replica2::SerializeConstruction() |
[in] | type | Whatever was written serializationType in Replica2::SerializeConstruction() |
[in] | replicaManager | ReplicaManager2 instance that created this class. |
[in] | timestamp | timestamp sent with Replica2::SerializeConstruction(), 0 for none. |
[in] | networkId | NetworkID that will be assigned automatically to the new object after this function returns |
[in] | networkIDCollision | True if the network ID that should be assigned to this object is already in use. Usuallly this is because the object already exists, and you should just read your data and return 0. |
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
- Note:
- This query is NOT used for ReplicaManager2::BroadcastConstruction() or SendConstruction(), which forces the operation to occur. If you DO want to use the query, use ReplicaManager2::Reference() and the next time RakPeer::Receive() is called it will occur.
- 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.
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::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::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
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
- Note:
- This query is NOT used for ReplicaManager2::BroadcastVisibility() or SendVisibility(), which forces the operation to occur. If you DO want to use the query, use ReplicaManager2::Reference() and the next time RakPeer::Receive() is called it will occur.
- 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().
Construct this object on other systems Triggers a call to SerializeConstruction()
- Note:
- If using peer-to-peer, NETWORK_ID_SUPPORTS_PEER_TO_PEER should be defined in RakNetDefines.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 |
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 |
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 |
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 |
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
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
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
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
The documentation for this class was generated from the following files: