RakNet  4.0
Public Types | Public Member Functions | List of all members
RakNet::Connection_RM3 Class Referenceabstract

Each remote system is represented by Connection_RM3. Used to allocate Replica3 and track which instances have been allocated. More...

#include <ReplicaManager3.h>

Public Types

enum  ConstructionMode { QUERY_REPLICA_FOR_CONSTRUCTION, QUERY_REPLICA_FOR_CONSTRUCTION_AND_DESTRUCTION, QUERY_CONNECTION_FOR_REPLICA_LIST }
 List of enumerations for how to get the list of valid objects for other systems. More...
 

Public Member Functions

virtual Replica3AllocReplica (RakNet::BitStream *allocationIdBitstream, ReplicaManager3 *replicaManager3)=0
 Class factory to create a Replica3 instance, given a user-defined identifier.
 
virtual void GetConstructedReplicas (DataStructures::List< Replica3 * > &objectsTheyDoHave)
 Get list of all replicas that are constructed for this connection.
 
bool HasReplicaConstructed (RakNet::Replica3 *replica)
 
virtual void SerializeOnDownloadStarted (RakNet::BitStream *bitStream)
 
virtual void DeserializeOnDownloadStarted (RakNet::BitStream *bitStream)
 
virtual void SerializeOnDownloadComplete (RakNet::BitStream *bitStream)
 
virtual void DeserializeOnDownloadComplete (RakNet::BitStream *bitStream)
 
SystemAddress GetSystemAddress (void) const
 
RakNetGUID GetRakNetGUID (void) const
 
bool GetDownloadWasCompleted (void) const
 
virtual bool QueryGroupDownloadMessages (void) const
 Return whether or not downloads to our system should all be processed the same tick (call to RakPeer::Receive() )
 
virtual ConstructionMode QueryConstructionMode (void) const
 Queries how to get the list of objects that exist on remote systems.
 
virtual void QueryReplicaList (DataStructures::List< Replica3 * > &newReplicasToCreate, DataStructures::List< Replica3 * > &existingReplicasToDestroy)
 Callback used when QueryConstructionMode() returns QUERY_CONNECTION_FOR_REPLICA_LIST.
 
virtual bool QuerySerializationList (DataStructures::List< Replica3 * > &replicasToSerialize)
 Override which replicas to serialize and in what order for a connection for a ReplicaManager3::Update() cycle.
 

Detailed Description

Each remote system is represented by Connection_RM3. Used to allocate Replica3 and track which instances have been allocated.

Important function: AllocReplica() - must be overridden to create an object given an identifier for that object, which you define for all objects in your game

Member Enumeration Documentation

List of enumerations for how to get the list of valid objects for other systems.

Enumerator:
QUERY_REPLICA_FOR_CONSTRUCTION 

For every object that does not exist on the remote system, call Replica3::QueryConstruction() every tick. Do not call Replica3::QueryDestruction() Do not call Connection_RM3::QueryReplicaList()

QUERY_REPLICA_FOR_CONSTRUCTION_AND_DESTRUCTION 

For every object that does not exist on the remote system, call Replica3::QueryConstruction() every tick. Based on the call, the object may be sent to the other system. For every object that does exist on the remote system, call Replica3::QueryDestruction() every tick. Based on the call, the object may be deleted on the other system. Do not call Connection_RM3::QueryReplicaList()

QUERY_CONNECTION_FOR_REPLICA_LIST 

Do not call Replica3::QueryConstruction() or Replica3::QueryDestruction() Call Connection_RM3::QueryReplicaList() to determine which objects exist on remote systems This can be faster than QUERY_REPLICA_FOR_CONSTRUCTION and QUERY_REPLICA_FOR_CONSTRUCTION_AND_DESTRUCTION for large worlds See GridSectorizer.h under /Source for code that can help with this

Member Function Documentation

virtual Replica3* RakNet::Connection_RM3::AllocReplica ( RakNet::BitStream allocationIdBitstream,
ReplicaManager3 replicaManager3 
)
pure virtual

Class factory to create a Replica3 instance, given a user-defined identifier.

Identifier is returned by Replica3::WriteAllocationID() for what type of class to create.
This is called when you download a replica from another system.
See Replica3::Dealloc for the corresponding destruction message.
Return 0 if unable to create the intended object. Note, in that case the other system will still think we have the object and will try to serialize object updates to us. Generally, you should not send objects the other system cannot create.

See Also
Replica3::WriteAllocationID(). Sample implementation:
{RakNet::RakString typeName; allocationIdBitstream->Read(typeName); if (typeName=="Soldier") return new Soldier; return 0;}
Parameters
[in]allocationIdBitstreamuser-defined bitstream uniquely identifying a game object type
[in]replicaManager3Instance of ReplicaManager3 that controls this connection
Returns
The new replica instance
virtual void RakNet::Connection_RM3::DeserializeOnDownloadComplete ( RakNet::BitStream bitStream)
inlinevirtual

Receives whatever was written in DeserializeOnDownloadComplete()

Parameters
[in]bitStreamWritten in SerializeOnDownloadComplete()
virtual void RakNet::Connection_RM3::DeserializeOnDownloadStarted ( RakNet::BitStream bitStream)
inlinevirtual

Receives whatever was written in SerializeOnDownloadStarted()

Parameters
[in]bitStreamWritten in SerializeOnDownloadStarted()
virtual void RakNet::Connection_RM3::GetConstructedReplicas ( DataStructures::List< Replica3 * > &  objectsTheyDoHave)
virtual

Get list of all replicas that are constructed for this connection.

Parameters
[out]objectsTheyDoHaveDestination list. Returned in sorted ascending order, sorted on the value of the Replica3 pointer.
bool RakNet::Connection_RM3::GetDownloadWasCompleted ( void  ) const
inline
Returns
True if ID_REPLICA_MANAGER_DOWNLOAD_COMPLETE arrived for this connection
RakNetGUID RakNet::Connection_RM3::GetRakNetGUID ( void  ) const
inline
Returns
Returns the RakNetGUID passed to the constructor of this object
SystemAddress RakNet::Connection_RM3::GetSystemAddress ( void  ) const
inline
Returns
The system address passed to the constructor of this object
bool RakNet::Connection_RM3::HasReplicaConstructed ( RakNet::Replica3 replica)

Returns true if we think this remote connection has this replica constructed

Parameters
[in]replica3Which replica we are querying
Returns
True if constructed, false othewise
virtual ConstructionMode RakNet::Connection_RM3::QueryConstructionMode ( void  ) const
inlinevirtual

Queries how to get the list of objects that exist on remote systems.

The default of calling QueryConstruction for every known object is easy to use, but not efficient, especially for large worlds where many objects are outside of the player's circle of influence.
QueryDestruction is also not necessarily useful or efficient, as object destruction tends to happen in known cases, and can be accomplished by calling Replica3::BroadcastDestruction() QueryConstructionMode() allows you to specify more efficient algorithms than the default when overriden.

Returns
How to get the list of objects that exist on the remote system. You should always return the same value for a given connection
virtual bool RakNet::Connection_RM3::QueryGroupDownloadMessages ( void  ) const
inlinevirtual

Return whether or not downloads to our system should all be processed the same tick (call to RakPeer::Receive() )

Normally the system will send ID_REPLICA_MANAGER_DOWNLOAD_STARTED, ID_REPLICA_MANAGER_CONSTRUCTION for all downloaded objects, ID_REPLICA_MANAGER_SERIALIZE for each downloaded object, and lastly ID_REPLICA_MANAGER_DOWNLOAD_COMPLETE. This enables the application to show a downloading splash screen on ID_REPLICA_MANAGER_DOWNLOAD_STARTED, a progress bar, and to close the splash screen and activate all objects on ID_REPLICA_MANAGER_DOWNLOAD_COMPLETE However, if the application was not set up for this then it would result in incomplete objects spread out over time, and cause problems If you return true from QueryGroupDownloadMessages(), then these messages will be returned all in one tick, returned only when the download is complete

Note
ID_REPLICA_MANAGER_DOWNLOAD_STARTED calls the callback DeserializeOnDownloadStarted()
ID_REPLICA_MANAGER_DOWNLOAD_COMPLETE calls the callback DeserializeOnDownloadComplete()
virtual void RakNet::Connection_RM3::QueryReplicaList ( DataStructures::List< Replica3 * > &  newReplicasToCreate,
DataStructures::List< Replica3 * > &  existingReplicasToDestroy 
)
inlinevirtual

Callback used when QueryConstructionMode() returns QUERY_CONNECTION_FOR_REPLICA_LIST.

This advantage of this callback is if that there are many objects that a particular connection does not have, then we do not have to iterate through those objects calling QueryConstruction() for each of them.
BR> See GridSectorizer in the Source directory as a method to find all objects within a certain radius in a fast way.
BR>

Parameters
[out]newReplicasToCreateAnything in this list will be created on the remote system
[out]existingReplicasToDestroyAnything in this list will be destroyed on the remote system
virtual bool RakNet::Connection_RM3::QuerySerializationList ( DataStructures::List< Replica3 * > &  replicasToSerialize)
inlinevirtual

Override which replicas to serialize and in what order for a connection for a ReplicaManager3::Update() cycle.

By default, Connection_RM3 will iterate through queryToSerializeReplicaList and call QuerySerialization() on each Replica in that list queryToSerializeReplicaList is populated in the order in which ReplicaManager3::Reference() is called for those objects. If you write to to replicasToSerialize and return true, you can control in what order and for which replicas to call QuerySerialization() Example use case: We have more data to send then the bandwidth supports, so want to prioritize sends. For example enemies shooting are more important than animation effects When QuerySerializationList(), sort objects by priority, and write the list to replicasToSerialize, optionally skipping objects with a lower serialization frequency If you hit your bandwidth limit when checking SerializeParameters::bitsWrittenSoFar, you can return RM3SR_DO_NOT_SERIALIZE for all remaining items

Note
Only replicas written to replicasToSerialize are transmitted. Even if you returned RM3SR_SERIALIZED_ALWAYS a prior ReplicaManager3::Update() cycle, the replica will not be transmitted if it is not in replicasToSerialize
If you do not know what objects are candidates for serialization, you can use queryToSerializeReplicaList as a source for your filtering or sorting operations
Parameters
[in]replicasToSerializeList of replicas to call QuerySerialization() on
Returns
Return true to use replicasToSerialize (replicasToSerialize may be empty if desired). Otherwise return false.
virtual void RakNet::Connection_RM3::SerializeOnDownloadComplete ( RakNet::BitStream bitStream)
inlinevirtual

When a new connection connects, after constructing and serialization all objects, SerializeOnDownloadComplete() is called

Parameters
[out]bitStreamPassed to DeserializeOnDownloadComplete()
virtual void RakNet::Connection_RM3::SerializeOnDownloadStarted ( RakNet::BitStream bitStream)
inlinevirtual

When a new connection connects, before sending any objects, SerializeOnDownloadStarted() is called

Parameters
[out]bitStreamPassed to DeserializeOnDownloadStarted()

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