C4 Engine Terathon Software C4 Engine API Documentation

• Message Manager

API Links
Developer Links

MessageMgr::SetPlayerConstructor

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

void SetPlayerConstructor(PlayerConstructProc *proc, void *data = nullptr);

Parameters
proc A pointer to the player construction function.
data A user-defined pointer that is passed to the player construction function.
Description
When the Message Manager needs to construct a new Player object, it first checks to see if a player constructor function has been installed. If so, then it calls the player construction function, allowing the application to construct an object of a type that is a subclass of the Player class. Initially, there is no player constructor function, so the Message Manager just constructs the Player base class.

The SetPlayerConstructor 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 proc parameter should point to a function with the following signature.

typedef Player *PlayerConstructProc(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 data parameter of the SetPlayerConstructor function. Ordinarily, this callback should simply construct a new object having type that is a subclass of Player and return it.

The current player constructor can be uninstalled by calling the SetPlayerConstructor function with a value of nullptr for the proc parameter.
See Also

Player