#include <ReplicaManager2.h>
Public Member Functions | ||||
ReplicaManager2 () | ||||
Constructor. | ||||
virtual | ~ReplicaManager2 () | |||
Destructor. | ||||
void | SetConnectionFactory (Connection_RM2Factory *factory) | |||
void | SetDefaultOrderingChannel (char def) | |||
| ||||
void | SetDefaultPacketPriority (PacketPriority def) | |||
| ||||
void | SetDefaultPacketReliability (PacketReliability def) | |||
| ||||
void | SetAutoUpdateScope (bool construction, bool visibility) | |||
void | SetAutoAddNewConnections (bool autoAdd) | |||
bool | AddNewConnection (SystemAddress systemAddress) | |||
bool | RemoveConnection (SystemAddress systemAddress) | |||
void | SetDoReplicaAutoSerializeUpdate (bool autoUpdate) | |||
void | SendConstruction (Replica2 *replica, BitStream *replicaData, SystemAddress recipient, RakNetTime timestamp, bool sendMessage, DataStructures::OrderedList< SystemAddress, SystemAddress > &exclusionList, unsigned char localClientId, SerializationType type=SEND_CONSTRUCTION_GENERIC_TO_SYSTEM, PacketPriority priority=NUMBER_OF_PRIORITIES, PacketReliability reliability=NUMBER_OF_RELIABILITIES, char orderingChannel=-1) | |||
void | SendDestruction (Replica2 *replica, BitStream *replicaData, SystemAddress recipient, RakNetTime timestamp, bool sendMessage, DataStructures::OrderedList< SystemAddress, SystemAddress > &exclusionList, SerializationType type=SEND_DESTRUCTION_GENERIC_TO_SYSTEM, PacketPriority priority=NUMBER_OF_PRIORITIES, PacketReliability reliability=NUMBER_OF_RELIABILITIES, char orderingChannel=-1) | |||
void | SendSerialize (Replica2 *replica, BitStream *replicaData, SystemAddress recipient, RakNetTime timestamp, DataStructures::OrderedList< SystemAddress, SystemAddress > &exclusionList, SerializationType type=SEND_SERIALIZATION_GENERIC_TO_SYSTEM, PacketPriority priority=NUMBER_OF_PRIORITIES, PacketReliability reliability=NUMBER_OF_RELIABILITIES, char orderingChannel=-1) | |||
void | SendVisibility (Replica2 *replica, BitStream *replicaData, SystemAddress recipient, RakNetTime timestamp, DataStructures::OrderedList< SystemAddress, SystemAddress > &exclusionList, SerializationType type=SEND_VISIBILITY_TRUE_TO_SYSTEM, PacketPriority priority=NUMBER_OF_PRIORITIES, PacketReliability reliability=NUMBER_OF_RELIABILITIES, char orderingChannel=-1) | |||
unsigned | GetReplicaCount (void) const | |||
Replica2 * | GetReplicaAtIndex (unsigned index) | |||
unsigned | GetConnectionCount (void) const | |||
Connection_RM2 * | GetConnectionAtIndex (unsigned index) const | |||
Connection_RM2 * | GetConnectionBySystemAddress (SystemAddress systemAddress) const | |||
unsigned int | GetConnectionIndexBySystemAddress (SystemAddress systemAddress) const | |||
void | RecalculateVisibility (Replica2 *replica) | |||
void | GetConnectionsWithReplicaConstructed (Replica2 *replica, DataStructures::OrderedList< SystemAddress, Connection_RM2 *, ReplicaManager2::Connection_RM2CompBySystemAddress > &output) | |||
void | GetConnectionsWithSerializeVisibility (Replica2 *replica, DataStructures::OrderedList< SystemAddress, Connection_RM2 *, ReplicaManager2::Connection_RM2CompBySystemAddress > &output) | |||
RakPeerInterface * | GetRakPeer (void) const | |||
void | Reference (Replica2 *replica, bool *newReference) | |||
void | Dereference (Replica2 *replica) | |||
Protected Member Functions | ||||
void | OnAttach (RakPeerInterface *peer) | |||
PluginReceiveResult | OnReceive (RakPeerInterface *peer, Packet *packet) | |||
void | OnCloseConnection (RakPeerInterface *peer, SystemAddress systemAddress) | |||
void | OnShutdown (RakPeerInterface *peer) | |||
void | Update (RakPeerInterface *peer) |
Quick start: 1. Create a class that derives from Connection_RM2, implementing the Construct() function. Construct() is a factory function that should return instances of your game objects, given a user-defined identifier. 2. Create a class that derives from Connection_RM2Factory, implementing AllocConnection() and DeallocConnection() to return instances of the class from step 1. 3. Attach ReplicaManager2 as a plugin 4. Call ReplicaManager2::SetConnectionFactory with an instance of the class from step 2. 5. For each of your game classes that use this system, derive from Replica2 and implement SerializeConstruction(), Serialize(), Deserialize(). The output of SerializeConstruction() is sent to Connection_RM2::Construct() 6. When these classes are allocated, call Replica2::SetReplicaManager() with the instance of ReplicaManager2 class created in step 3 (this could be done automatically in the constructor) 7. Creation: Use Replica2::SendConstruction() to create the object remotely, Replica2::SendDestruction() to delete the object remotely. 8. Scoping: Override Replica2::QueryVisibility() and Replica2::QueryConstruction() to return BQR_YES or BQR_NO if an object should be visible and in scope to a given connection. Defaults to BQR_ALWAYS 9. Automatic serialization: Call Replica2::AddAutoSerializeTimer() to automatically call Replica2::Serialize() at intervals, compare this to the last value, and broadcast out the object when the serialized variables change.
This system is a server or peer: Call NetworkIDManager::SetIsNetworkIDAuthority(true).
This system is a client: Call NetworkIDManager::SetIsNetworkIDAuthority(false).
If peer to peer, set NetworkID::peerToPeerMode=true, and comment out NETWORK_ID_USE_PTR_TABLE in NetworkIDManager.h
void ReplicaManager2::SetConnectionFactory | ( | Connection_RM2Factory * | factory | ) |
Sets the factory class used to allocate connection objects
[in] | factory | A pointer to an instance of a class that derives from Connection_RM2Factory. This pointer it saved and not copied, so the object should remain in memory. |
void ReplicaManager2::SetAutoUpdateScope | ( | bool | construction, | |
bool | visibility | |||
) |
Auto scope will track the prior construction and serialization visibility of each registered Replica2 class, for each connection. Per-tick, as the visibility or construction status of a replica changes, it will be constructed, destroyed, or the visibility will change as appropriate.
[in] | construction | If true, Connection_RM2::SetConstructionByReplicaQuery will be called once per PluginInterface::Update tick. This will call Replica2::QueryConstruction to return if an object should be exist on a particular connection |
[in] | visibility | If true, Connection_RM2::SetConstructionSerializationByReplicaQuery will be called once per PluginInterface::Update tick. This will call Replica2::QuerySerialization to return if an object should be visible to a particular connection or not. |
void ReplicaManager2::SetAutoAddNewConnections | ( | bool | autoAdd | ) |
Autoadd will cause a Connection_RM2 instance to be allocated for every connection. Defaults to true. Set this to false if you have connections which do not participate in the game (master server, etc).
[in] | autoAdd | If true, all incoming connections are added as ReplicaManager2 connections. |
bool ReplicaManager2::AddNewConnection | ( | SystemAddress | systemAddress | ) |
If SetAutoAddNewConnections() is false, you need to add connections manually connections are also created implicitly if needed
[in] | systemAddress | The address of the new system |
bool ReplicaManager2::RemoveConnection | ( | SystemAddress | systemAddress | ) |
Remove an existing connection. Also done automatically on ID_DISCONNECTION_NOTIFICATION and ID_CONNECTION_LOST
[in] | systemAddress | The address of the system to remove the connection for |
void ReplicaManager2::SetDoReplicaAutoSerializeUpdate | ( | bool | autoUpdate | ) |
If true, autoserialize timers added with Replica2::AddAutoSerializeTimer() will automatically decrement. If false, you must call Replica2::ElapseAutoSerializeTimers() manually. Defaults to true
[in] | autoUpdate | True to automatically call ElapseAutoSerializeTimers(). Set to false if you need to control these timers. |
void ReplicaManager2::SendConstruction | ( | Replica2 * | replica, | |
BitStream * | replicaData, | |||
SystemAddress | recipient, | |||
RakNetTime | timestamp, | |||
bool | sendMessage, | |||
DataStructures::OrderedList< SystemAddress, SystemAddress > & | exclusionList, | |||
unsigned char | localClientId, | |||
SerializationType | type = SEND_CONSTRUCTION_GENERIC_TO_SYSTEM , |
|||
PacketPriority | priority = NUMBER_OF_PRIORITIES , |
|||
PacketReliability | reliability = NUMBER_OF_RELIABILITIES , |
|||
char | orderingChannel = -1 | |||
) |
Sends a construction command to one or more systems, which will be relayed throughout the network. Recipient(s) will allocate the connection via Connection_RM2Factory::AllocConnection() if it does not already exist. Will trigger a call on the remote system(s) to Connection_RM2::Construct()
This is a low level function. Beginners may wish to use Replica2::SendConstruction() or Replica2::BroadcastConstruction(). You can also override Replica2::QueryConstruction()
[in] | replica | The class to construct remotely |
[in] | replicaData | User-defined serialized data representing how to construct the class. Could be the name of the class, a unique identifier, or other methods |
[in] | recipient | Which system to send to. Use UNASSIGNED_SYSTEM_ADDRESS to send to all previously created connections. Connection_RM2Factory::AllocConnection will be called if this connection has not been previously used. |
[in] | timestamp | Timestamp to send with the message. Use 0 to not send a timestamp if you don't need it. |
[in] | sendMessage | True to actually send a network message. False to only register that the object exists on the remote system, useful for objects created outside ReplicaManager2, or objects that already existed in the world. |
[in] | exclusionList | Which systems to not send to. This list is carried with the messsage, and appended to at each node in the connection graph. This is used to prevent infinite cyclical sends. |
[in] | localClientId | If replica->QueryIsConstructionAuthority()==false, this number will be sent with SEND_CONSTRUCTION_REQUEST_TO_SERVER to the recipient. SEND_CONSTRUCTION_REPLY_ACCEPTED_TO_CLIENT or SEND_CONSTRUCTION_REPLY_DENIED_TO_CLIENT will be returned, and this number will be used to look up the local object in Replica2::clientPtrArray |
[in] | type | What kind of serialization operation this is. Use one of the pre-defined types, or create your own. This will be returned in type in Connection_RM2::Construct() |
[in] | priority | PacketPriority to send with. Use NUMBER_OF_PRIORITIES to use the default defined by SetDefaultPacketPriority(). |
[in] | reliability | PacketReliability to send with. Use NUMBER_OF_RELIABILITIES to use the default defined by SetDefaultPacketReliability(); |
[in] | orderingChannel | ordering channel to send on. Use -1 to use the default defined by SetDefaultOrderingChannel() |
void ReplicaManager2::SendDestruction | ( | Replica2 * | replica, | |
BitStream * | replicaData, | |||
SystemAddress | recipient, | |||
RakNetTime | timestamp, | |||
bool | sendMessage, | |||
DataStructures::OrderedList< SystemAddress, SystemAddress > & | exclusionList, | |||
SerializationType | type = SEND_DESTRUCTION_GENERIC_TO_SYSTEM , |
|||
PacketPriority | priority = NUMBER_OF_PRIORITIES , |
|||
PacketReliability | reliability = NUMBER_OF_RELIABILITIES , |
|||
char | orderingChannel = -1 | |||
) |
Sends a destruction command to one or more systems, which will be relayed throughout the network. Recipient(s) will allocate the connection via Connection_RM2Factory::AllocConnection() if it does not already exist. Will trigger a call on the remote system(s) to Replica2::ReceiveDestruction() which in turn calls Replica2::DeserializeDestruction() with the value passed in replicaData Note: This is a low level function. Beginners may wish to use Replica2::SendDestruction() or Replica2::BroadcastDestruction().
[in] | replica | The class to destroy remotely |
[in] | replicaData | User-defined serialized data. Passed to Replica2::ReceiveDestruction() |
[in] | recipient | Which system to send to. Use UNASSIGNED_SYSTEM_ADDRESS to send to all previously created connections. Connection_RM2Factory::AllocConnection will be called if this connection has not been previously used. |
[in] | timestamp | Timestamp to send with the message. Use 0 to not send a timestamp if you don't need it. |
[in] | sendMessage | True to actually send a network message. False to only register that the object no longer exists on the remote system. |
[in] | exclusionList | Which systems to not send to. This list is carried with the messsage, and appended to at each node in the connection graph. This is used to prevent infinite cyclical sends. |
[in] | type | What kind of serialization operation this is. Use one of the pre-defined types, or create your own. This will be returned in type in Connection_RM2::Construct() |
[in] | priority | PacketPriority to send with. Use NUMBER_OF_PRIORITIES to use the default defined by SetDefaultPacketPriority(). |
[in] | reliability | PacketReliability to send with. Use NUMBER_OF_RELIABILITIES to use the default defined by SetDefaultPacketReliability(); |
[in] | orderingChannel | ordering channel to send on. Use -1 to use the default defined by SetDefaultOrderingChannel() |
Call SetConnectionFactory() with a derived instance of Connection_RM2Factory.
void ReplicaManager2::SendSerialize | ( | Replica2 * | replica, | |
BitStream * | replicaData, | |||
SystemAddress | recipient, | |||
RakNetTime | timestamp, | |||
DataStructures::OrderedList< SystemAddress, SystemAddress > & | exclusionList, | |||
SerializationType | type = SEND_SERIALIZATION_GENERIC_TO_SYSTEM , |
|||
PacketPriority | priority = NUMBER_OF_PRIORITIES , |
|||
PacketReliability | reliability = NUMBER_OF_RELIABILITIES , |
|||
char | orderingChannel = -1 | |||
) |
Sends a serialized object to one or more systems, which will be relayed throughout the network. Recipient(s) will allocate the connection via Connection_RM2Factory::AllocConnection() if it does not already exist. Will trigger a call on the remote system(s) to Replica2::ReceiveSerialization() which in turn calls Replica2::Deserialize() with the value passed in replicaData Note: This is a low level function. Beginners may wish to use Replica2::SendSerialize() or Replica2::BroadcastSerialize().
[in] | replica | The class to serialize |
[in] | replicaData | User-defined serialized data. Passed to Replica2::ReceiveSerialization() |
[in] | recipient | Which system to send to. Use UNASSIGNED_SYSTEM_ADDRESS to send to all previously created connections. Connection_RM2Factory::AllocConnection will be called if this connection has not been previously used. |
[in] | timestamp | Timestamp to send with the message. Use 0 to not send a timestamp if you don't need it. |
[in] | exclusionList | Which systems to not send to. This list is carried with the messsage, and appended to at each node in the connection graph. This is used to prevent infinite cyclical sends. |
[in] | type | What kind of serialization operation this is. Use one of the pre-defined types, or create your own. This will be returned in type in Connection_RM2::Construct() |
[in] | priority | PacketPriority to send with. Use NUMBER_OF_PRIORITIES to use the default defined by SetDefaultPacketPriority(). |
[in] | reliability | PacketReliability to send with. Use NUMBER_OF_RELIABILITIES to use the default defined by SetDefaultPacketReliability(); |
[in] | orderingChannel | ordering channel to send on. Use -1 to use the default defined by SetDefaultOrderingChannel() |
Call SetConnectionFactory() with a derived instance of Connection_RM2Factory.
void ReplicaManager2::SendVisibility | ( | Replica2 * | replica, | |
BitStream * | replicaData, | |||
SystemAddress | recipient, | |||
RakNetTime | timestamp, | |||
DataStructures::OrderedList< SystemAddress, SystemAddress > & | exclusionList, | |||
SerializationType | type = SEND_VISIBILITY_TRUE_TO_SYSTEM , |
|||
PacketPriority | priority = NUMBER_OF_PRIORITIES , |
|||
PacketReliability | reliability = NUMBER_OF_RELIABILITIES , |
|||
char | orderingChannel = -1 | |||
) |
Sets the visibility status of an object. which will be relayed throughout the network. Objects that are not visible should be hidden in the game world, and will not send AutoSerialize updates Recipient(s) will allocate the connection via Connection_RM2Factory::AllocConnection() if it does not already exist. Will trigger a call on the remote system(s) to Connection_RM2::ReceiveVisibility() Note: This is a low level function. Beginners may wish to use Connection_RM2::SendVisibility() or override Replica2::QueryVisibility()
[in] | objectList | The objects to send to the system. |
[in] | replicaData | User-defined serialized data. Read in Connection_RM2::ReceiveVisibility() |
[in] | recipient | Which system to send to. Use UNASSIGNED_SYSTEM_ADDRESS to send to all previously created connections. Connection_RM2Factory::AllocConnection will be called if this connection has not been previously used. |
[in] | timestamp | Timestamp to send with the message. Use 0 to not send a timestamp if you don't need it. |
[in] | sendMessage | True to actually send a network message. False to only register that the objects exist on the remote system |
[in] | type | What kind of serialization operation this is. Use one of the pre-defined types, or create your own. This will be returned in type in Connection_RM2::Construct() |
[in] | priority | PacketPriority to send with. Use NUMBER_OF_PRIORITIES to use the default defined by SetDefaultPacketPriority(). |
[in] | reliability | PacketReliability to send with. Use NUMBER_OF_RELIABILITIES to use the default defined by SetDefaultPacketReliability(); |
[in] | orderingChannel | ordering channel to send on. Use -1 to use the default defined by SetDefaultOrderingChannel() |
Call SetConnectionFactory() with a derived instance of Connection_RM2Factory.
unsigned ReplicaManager2::GetReplicaCount | ( | void | ) | const |
Returns how many Replica2 instances are registered. Replica2 instances are automatically registered when used, and unregistered when calling Deref (which is automatically done in the destructor). Used for GetReplicaAtIndex if you want to perform some object on all registered Replica objects.
Replica2 * ReplicaManager2::GetReplicaAtIndex | ( | unsigned | index | ) |
Returns a previously registered Replica2 *, from index 0 to GetReplicaCount()-1. Replica2* objects are returned in the order they were registered.
[in] | index | An index, from 0 to GetReplicaCount()-1. |
unsigned ReplicaManager2::GetConnectionCount | ( | void | ) | const |
Returns the number of registered connections. Connections are registered implicitly when used. Connections are unregistered on disconnect.
Connection_RM2 * ReplicaManager2::GetConnectionAtIndex | ( | unsigned | index | ) | const |
Returns a connection pointer previously implicitly added.
[in] | index | An index, from 0 to GetConnectionCount()-1. |
Connection_RM2 * ReplicaManager2::GetConnectionBySystemAddress | ( | SystemAddress | systemAddress | ) | const |
Returns a connection pointer previously implicitly added.
[in] | systemAddress | The system address of the connection to return |
unsigned int ReplicaManager2::GetConnectionIndexBySystemAddress | ( | SystemAddress | systemAddress | ) | const |
Returns the index of a connection, by SystemAddress
[in] | systemAddress | The system address of the connection index to return |
void ReplicaManager2::RecalculateVisibility | ( | Replica2 * | replica | ) |
Call this when Replica2::QueryVisibility() or Replica2::QueryConstructionVisibility() changes from BQR_ALWAYS or BQR_NEVER to BQR_YES or BQR_NO Otherwise these two conditions are assumed to never change
[in] | Which | replica to update |
void ReplicaManager2::GetConnectionsWithReplicaConstructed | ( | Replica2 * | replica, | |
DataStructures::OrderedList< SystemAddress, Connection_RM2 *, ReplicaManager2::Connection_RM2CompBySystemAddress > & | output | |||
) |
Given a replica instance, return all connections that are believed to have this replica instantiated.
[in] | replica | Which replica is being refered to |
[out] | output | List of connections, ordered by system address |
void ReplicaManager2::GetConnectionsWithSerializeVisibility | ( | Replica2 * | replica, | |
DataStructures::OrderedList< SystemAddress, Connection_RM2 *, ReplicaManager2::Connection_RM2CompBySystemAddress > & | output | |||
) |
Given a replica instance, return all connections that are believed to have this replica visible
[in] | replica | Which replica is being refered to |
[out] | output | List of connections, ordered by system address |
RakPeerInterface * ReplicaManager2::GetRakPeer | ( | void | ) | const |
Gets the instance of RakPeerInterface that this plugin was attached to
void ReplicaManager2::Reference | ( | Replica2 * | replica, | |
bool * | newReference | |||
) |
Internally starts tracking this replica
void ReplicaManager2::Dereference | ( | Replica2 * | replica | ) |
Stops tracking this replica. Call before deleting the Replica. Done automatically in ~Replica()
void ReplicaManager2::OnAttach | ( | RakPeerInterface * | peer | ) | [protected, virtual] |
Called when the interface is attached
[in] | peer | the instance of RakPeer that is calling Receive |
Reimplemented from PluginInterface.
PluginReceiveResult ReplicaManager2::OnReceive | ( | RakPeerInterface * | peer, | |
Packet * | packet | |||
) | [protected, virtual] |
OnReceive is called for every packet.
[in] | peer | the instance of RakPeer that is calling Receive |
[in] | packet | the packet that is being returned to the user |
Reimplemented from PluginInterface.
void ReplicaManager2::OnCloseConnection | ( | RakPeerInterface * | peer, | |
SystemAddress | systemAddress | |||
) | [protected, virtual] |
Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system
[in] | peer | the instance of RakPeer that is calling Receive |
[in] | systemAddress | The system whose connection was closed |
Reimplemented from PluginInterface.
void ReplicaManager2::OnShutdown | ( | RakPeerInterface * | peer | ) | [protected, virtual] |
Called when RakPeer is shutdown
[in] | peer | the instance of RakPeer that is calling Receive |
Reimplemented from PluginInterface.
void ReplicaManager2::Update | ( | RakPeerInterface * | peer | ) | [protected, virtual] |
Update is called every time a packet is checked for .
[in] | peer | - the instance of RakPeer that is calling Receive |
Reimplemented from PluginInterface.