The data description table is a repository of definitions for a class’s data and function members that allows the engine to link, save/restore and otherwise understand the intention of those members. Failure to define these members in the table can lead to unexpected results at runtime.
Table elements are declared inside of a
END_DATADESC code block. Any number of the following macros can be placed within the table as needed, like so:
BEGIN_DATADESC( CMyClass ) DEFINE_FIELD( . . . ) END_DATADESC()
The following is a list of the most commonly used table element types.
This macro definition is used for saving and loading in the engine. Any member variable properly defined in this macro will be saved and restored automatically. The macro is declared as:
DEFINE_FIELD( variableName, variableType )
dataMemberType parameter can be any of the following types:
||No type or value (used for function parameters)|
||Any floating point value|
||A string ID (return from ALLOC_STRING)|
||Any vector, QAngle, or AngularImpulse|
||A quaternion value|
||Any integer or enum value|
||Boolean value (represented as an integer)|
||2 byte integer|
||8-bit per channel [R,G,B,A] (32-bit color)|
||class/structure based on anadditional type description|
||A special type that contains function pointers to its read/write/parse functions|
||A world coordinate value, which is fixed up across level-transitions automatically|
||A floating point time value, which is fixed up across level-transitions automatically|
||An integer tick count, which is fixed up similarly to FIELD_TIME|
||Engine string that is a model name (Must be precached)|
||Engine string that is a sound name (Must be precached)|
||A list of inputted data fields, all derived from CMultiInputVar|
||A class function pointer (Think, Use, etc.)|
||A VMatrix (Note: output coordinates are NOT worldspace)|
||A VMatrix that maps some localspace to worldspace (translation is fixed up on level-transitions)|
||matrix3x4_t that maps some localspace to worldspace (translation is fixed up on level-transitions)|
||A start and range floating point interval ( e.g., 3.2->3.6 == 3.2 and 0.4 )|
||A model index|
||A material index (using the material precache string table)|
This macro works in the same manner as
DEFINE_FIELD with regards to saving and restoring data members. It extends this functionality by also defining a reference name for the data member which links it to the keyvalue identifier defined in the FGD entry for an entity class. Once this is properly declared, the data member will be initialized to the value defined in the map upon that entity’s creation.
As an example, the following definition would link the
m_bEnabled data member to the <</i> keyvalue identifier in Hammer.
Note: The keyvalue’s identifying name is case insensitive.
This macro is used to link an output event to a named identifier used by Hammer. It is defined as:
DEFINE_OUTPUT( outputVariable, outputName )
Note: The outputEventVariable in this case must be of type COuputEvent.
This macro is used to link named inputs from Hammer to functions in the engine. This also defines the type of parameter being passed in to the function from the Entity I/O system. The macro is defined as:
parameterType can be any of the following FIELD_ types:
This macro is a shorthand version of
DEFINE_INPUTFUNC. It automatically sets the described data member to the parameter passed in from the
Input() function. This bypasses the need to create an input function whose sole purpose is to set a data member to a passed value. The macro is declared as:
DEFINE_ARRAY AND DEFINE_AUTO_ARRAY
As their names suggest, these macros deal with saving and restoring array values. The number of elements in the array must be declared when using
DEFINE_AUTO_ARRAY will cause the code to automatically determine the size of the array at runtime.
The macros are declared as:
DEFINE_ARRAY( variable, variableType, numElements )
DEFINE_AUTO_ARRAY( variable, variableType )
This macro allows custom interpretation of a variable with regards to how it is saved and restored. By passing in the reference to a handler class, the user is able to handle serialization of the data entirely.
The handler class must descend from the
CClassPtrSaveRestoreOps class; it uses the
Restore() functions for serialization.
For more information, see uses of
CClassPtrSaveRestoreOps within the code base.
Entities using a
Think() function must declare that function via this macro declaration.
Think functions must be of the type:
typedef void (*ThinkFunc)( void);
Entities using a
Use() function must declare that function via this macro declaration.
Use functions must be of the type:
typedef void (*UseFunc)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );