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 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 update objects as they change over time
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.
ReplicaManager3 is designed to be a generic, overridable plugin that handles as many of these details as possible automatically. ReplicaManager3 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, and to automatically serialize your objects when the serialized member data changes.
Quick start:
- Derive from Connection_RM3 and implement Connection_RM3::AllocReplica(). This is a factory function where given an identifier for a class (such as name) return an instance of that class. Should be able to return any networked object in your game.
- Derive from ReplicaManager3 and implement AllocConnection() and DeallocConnection() to return the class you created in step 1.
- Derive your networked game objects from Replica3. All pure virtuals have to be implemented, however defaults are provided for Replica3::QueryConstruction() and Replica3::QueryRemoteConstruction() depending on your network architecture.
- When a new game object is created on the local system, pass it to ReplicaManager3::Reference().
- When a game object is destroyed on the local system, and you want other systems to know about it, call Replica3::BroadcastDestruction()
- Attach ReplicaManager3 as a plugin
For a full list of functions with detailed documentation on each parameter, see ReplicaManager3.h.
The primary sample is located at Samples\ReplicaManager3.
|