C4 Engine
C4 Engine API Documentation

MessageMgr::SetPlayerCreator

Defined in:  C4Messages.h
Sets the creator callback function for Player objects.
Prototype

void SetPlayerCreator(PlayerCreatorCallback *callback, void *cookie = nullptr);

Parameters
callback A pointer to the player creator callback function.
cookie The cookie that is passed to the callback function.
Description
When the Message Manager needs to create a new Player object, it first checks to see if a player creator callback function has been installed. If so, then it calls the callback function, allowing the application to create an object of a type that is a subclass of the Player class. Initially, there is no player creator callback function, so the Message Manager just creates an object whose type is the Player base class.

The SetPlayerCreator function should be called by an application's startup code when it wants to use a subclass of the Player class to represent players in a game. The callback parameter should point to a function with the following signature.

typedef Player *PlayerCreatorCallback(PlayerKey, void *);

The player key that is passed in the first parameter should be passed to the constructor for the Player base class. The second parameter is set to the value specified by the cookie parameter of the SetPlayerCreator function. Ordinarily, this callback function should simply construct a new object having type that is a subclass of Player and return it.

The current player creator callback function can be uninstalled by calling the SetPlayerCreator function with a value of nullptr for the callback parameter.
See Also

Player