NetworkIDGenerator Class Reference

Unique shared ids for each object instance. More...

#include <NetworkIDGenerator.h>

Inheritance diagram for NetworkIDGenerator:

ReplicatedObject List of all members.

Public Member Functions

 NetworkIDGenerator ()
 Constructor. ObjectIDs, if IsNetworkIDAuthority() is true, are created here.
virtual ~NetworkIDGenerator ()
 Destructor. Used ObjectIDs, if any, are freed here.
virtual ObjectID GetNetworkID (void)
virtual void SetNetworkID (ObjectID id)
virtual void SetParent (void *_parent)
virtual void * GetParent (void) const
virtual bool IsNetworkIDAuthority (void) const =0
virtual bool RequiresSetParent (void) const

Static Public Member Functions

static ObjectID GetStaticNetworkID (void)
static void SetStaticNetworkID (ObjectID i)
static void * GET_BASE_OBJECT_FROM_ID (ObjectID x)
 If you use a parent, returns this instance rather than the parent object.
static void * GET_OBJECT_FROM_ID (ObjectID x)
 Returns the parent object, or this instance if you don't use a parent.

Static Public Attributes

static BasicDataStructures::AVLBalancedBinarySearchTree<
ObjectIDNode > 
IDTree
 This AVL tree holds the pointer to ObjectID mappings.

Protected Member Functions

void GenerateID (void)
 Internal function to generate an ID when needed. This is deferred until needed and is not called from the constructor.

Protected Attributes

ObjectID objectID
 The network ID of this object.
bool serverAssignedID
 Store whether or not its a server assigned ID.
void * parent
 The parent set by SetParent().
bool callGenerationCode
 This is crap but is necessary because virtual functions don't work in the constructor.

Static Private Attributes

static ObjectID staticItemID = 0

Detailed Description

Unique shared ids for each object instance.

A class you can derive from to make it easier to represent every networked object with an integer. This way you can refer to objects over the network. One system should return true for IsNetworkIDAuthority() and the rest should return false. When an object needs to be created, have the the one system create the object. Then have that system send a message to all other systems, and include the value returned from GetNetworkID() in that packet. All other systems should then create the same class of object, and call SetNetworkID() on that class with the ObjectID in the packet.

See also:
the manual for more information on this.


Member Function Documentation

ObjectID NetworkIDGenerator::GetNetworkID void   )  [virtual]
 

Returns the ObjectID that you can use to refer to this object over the network.

Return values:
UNASSIGNED_OBJECT_ID UNASSIGNED_OBJECT_ID is returned IsNetworkIDAuthority() is false and SetNetworkID() was not previously called. This is also returned if you call this function in the constructor.
0-65534 Any other value is a valid ObjectID. ObjectIDs start at 0 and go to 65534, wrapping at that point.

void * NetworkIDGenerator::GetParent void   )  const [virtual]
 

Return what was passed to SetParent

Returns:
The value passed to SetParent, or 0 if it was never called.

ObjectID NetworkIDGenerator::GetStaticNetworkID void   )  [static]
 

These function is only meant to be used when saving games as you should save the HIGHEST value staticItemID has achieved upon save and reload it upon load. Save AFTER you've created all the items derived from this class you are going to create.

Returns:
the HIGHEST Object Id currently used

virtual bool NetworkIDGenerator::IsNetworkIDAuthority void   )  const [pure virtual]
 

For every group of systems, one system needs to be responsible for creating unique IDs for all objects created on all systems. This way, systems can send that id in packets to refer to objects (you can't send pointers because the memory allocations may be different). In a client/server enviroment, the system that creates unique IDs would be the server. return true if this system is responsible for creating unique IDs (probably the server), return true. Otherwise return false.

Implemented in ReplicatedObject.

bool NetworkIDGenerator::RequiresSetParent void   )  const [virtual]
 

Overload this function and return true if you require that SetParent is called before this object is used. You should do this if you want this to be a member object of another class rather than derive from this class.

void NetworkIDGenerator::SetNetworkID ObjectID  id  )  [virtual]
 

Sets the ObjectID for this instance. Usually this is called by the clients and determined from the servers. However, if you save multiplayer games you would likely use This on load as well.

void NetworkIDGenerator::SetParent void *  _parent  )  [virtual]
 

Your class does not have to derive from NetworkIDGenerator, although that is the easiest way to implement this. If you want this to be a member object of another class, rather than inherit, then call SetParent() with a pointer to the parent class instance. GET_OBJECT_FROM_ID will then return the parent rather than this instance.

void NetworkIDGenerator::SetStaticNetworkID ObjectID  i  )  [static]
 

These function is only meant to be used when loading games. Load BEFORE you create any new objects that are not SetIDed based on the save data.

Parameters:
[in] i the highest number of NetworkIDGenerator reached.


The documentation for this class was generated from the following files:
Generated on Mon Mar 20 20:32:55 2006 for RakNet by  doxygen 1.4.6-NO