Objects
From PX Documentation
Contents |
Overview
Netdog Objects map directly to the entity model of your game. Network objects store all relevant data about your in-game objects, and provide mechanisms for updating and synchronization across all clients and servers within the game topology. The basics of object use are creation of the object type, creation of the object itself, and installation of the object callback function.
Objects can then be manipulated using a series of update functions as listed below.
Creating New Objects
The first step for creating a new object is to create an object type to associate the object with.
int NDInstallObjectType(int objectType,
int objectSize,
const char *typeName = NULL,
NDObjectCallback createObjectCB = NULL,
NDValidationCallback createObjectValidationCB = NULL,
NDObjectCallback deleteObjectCB = NULL,
NDValidationCallback deleteObjectValidationCB = NULL,
NDObjectCallback updateObjectCB = NULL,
NDValidationCallback updateObjectValidationCB = NULL,
int channelID = -1);
The arguments for this type creation are:
- objectType is the variable for the new object type
- objectSize is the size of the object
- typeName is the textual description of the object type
- createObjectCB is a function to handle object creation
- createObjectValidationCB is a function to handle object creation validation (see Callback Functions)
- deleteObjectCB is a function to handle object deletion
- deleteObjectValidationCB is a function to handle object deletion validation
- updateObjectCB is a function to handle object updates
- updateObjectValidationCB is a function to handle object update validation
- channelID is the channel ID of the channel to which the object is assigned (as applicable)
Then, create the specific object that corresponds with in-game objects, and map it to an object type.
int NDCreateObject(int type,
void* obj = NULL,
int channelID = -1);
This function takes the following arguments:
- type is the object type as defined in NDInstallObjectType
- obj is the object serialization if applicable
- channelID is the channel ID of the channel to which the object is assigned (as applicable)
This object can be deleted using the following function
int NDDeleteObject(int objectID,
int channelID = -1);
Where:
- objectID is the unique identifier of the object
- channelID is the channel ID of the channel to which the object is assigned (as applicable)
Other Pure Object Model Functions
int NDBeginObjectUpdate(int channelID = -1);
Where:
- channelID is the channel ID of the channel to which the object is assigned (as applicable)
int NDEndObjectUpdate(int channelID = -1);
Where:
- channelID is the channel ID of the channel to which the object is assigned (as applicable)
int NDUpdateObjectField(int objectID,
int fieldID,
int fieldType,
int channelID = -1);
Where:
- objectID is the unique identifier of the object
- fieldID is the unique identifier of the field
- fieldType is the predefined type of field
- channelID is the channel ID of the channel to which the object is assigned (as applicable)
int NDRegisterField(int objectType,
int fieldID,
int fieldType,
int size,
int offset,
int flags,
NDOFieldChangedCallback callback,
char* fieldName,
int channelID = -1);
Where:
- objectType is the predefined type for the object
- fieldID is the unique identifier for the field
- fieldType is the predefined type for the field
- size is the size of the field in bytes
- offset is the position of the field within data structure
- flags is not yet implemented, always set to 0
- callback is the function that will handle field changes (see Callback Functions)
- fieldname is a string representation of the field
- channelID is the channel ID of the channel to which the object is assigned (as applicable)
Retrieving Objects
The following three functions are used to retrieve objects by either Object ID, Object Type, or both (for an extra level of type-checking), respectively. Objects, once retrieved, can be used by gamers or manipulated and updated into the existing world.
NDOGetByID returns the type of the retrieved object in the type pointer.
void* NDOGetByID(int id,
int* type = NULL,
int channelID = -1);
void* NDOGetByType(int objectType,
int local = 0,
int instanceNum = 0,
int channelID = -1);
void* NDOGetByTypeID(int type,
int id,
int channelID = -1);
const char* NDOGetTypeName(int type);
Other Object Functions
NDOGetNumObjects returns the number of objects within a specific channel (provided by channelID)
int NDOGetNumObjects(int channelID = -1);
See also: Object Driven Model Tutorial
