Jenkins Software

Replica Manager 2 Plugin Interface Implementation

Replica Manager 2 (Depreciated) Implementation Overview

Any game that has objects that are created and destroyed while the game is in progress, almost all non-trivial games, faces a minimum of 3 problems:

  • How to broadcast existing game objects to new players
  • How to broadcast new game objects to existing players
  • How to broadcast deleted game objects to existing players

Additional potential problems, depending on complexity and optimization

  • How to only send object updates to players that can see those objects
  • How to create and destroy objects dynamically as the player moves around the world
  • How to allow the client to create objects locally when this is necessary right away for programming or graphical reasons (such as shooting a bullet).
  • How to indicate to a player when they are done downloading all game objects and can start playing

The solution to most of these problems is usually straightforward, yet still requires a significant amount of work and debugging, with several dozen lines of code per object.

ReplicaManager2 is designed to be a generic, overridable plugin that handles as many of these details as possible automatically. ReplicaManager2 automatically creates and destroys objects, downloads the world to new players, manages players, and automatically serializes as needed. It also includes the advanced ability to automatically relay messages, to automatically serialize your objects when the serialized member data changes, and to automatically handle object scope based on a boolean callback indicating if a particular system can see a particular object.

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.

For a full list of functions with detailed documentation on each parameter, see ReplicaManager2.h.

The primary sample is located at Samples\ReplicaManager2. There is also a 3D sample, Ogre3DInterpDemo

See Also

Index
ReplicaManager3
PluginInterface
Ogre3DInterpDemo