Torque2D Reference
|
#include <consoleObject.h>
Classes | |
struct | Field |
Public Types | |
enum | ACRFieldTypes { StartGroupFieldType = 0xFFFFFFFD, EndGroupFieldType = 0xFFFFFFFE, DepricatedFieldType = 0xFFFFFFFF } |
typedef bool(* | SetDataNotify )(void *obj, const char *data) |
This is a function pointer typedef to support get/set callbacks for fields. More... | |
typedef const char *(* | GetDataNotify )(void *obj, const char *data) |
typedef bool(* | WriteDataNotify )(void *obj, const char *pFieldName) |
This is a function pointer typedef to support optional writing for fields. More... | |
typedef void(* | WriteCustomTamlSchema )(const AbstractClassRep *pClassRep, TiXmlElement *pParentElement) |
Allows the writing of a custom TAML schema. More... | |
typedef Vector< Field > | FieldList |
Public Member Functions | |
AbstractClassRep () | |
virtual | ~AbstractClassRep () |
S32 | getClassId (U32 netClassGroup) const |
const char * | getClassName () const |
Namespace * | getNameSpace () |
AbstractClassRep * | getNextClass () |
AbstractClassRep * | getParentClass () |
virtual AbstractClassRep * | getContainerChildClass (const bool recurse)=0 |
virtual WriteCustomTamlSchema | getCustomTamlSchema (void)=0 |
bool | isClass (AbstractClassRep *acr) |
Helper class to see if we are a given class, or a subclass thereof. More... | |
virtual ConsoleObject * | create () const =0 |
const Field * | findField (StringTableEntry fieldName) const |
AbstractClassRep * | findFieldRoot (StringTableEntry fieldName) |
AbstractClassRep * | findContainerChildRoot (AbstractClassRep *pChild) |
Static Public Member Functions | |
static void | registerClassRep (AbstractClassRep *) |
static AbstractClassRep * | findClassRep (const char *in_pClassName) |
static void | initialize () |
static void | destroyFieldValidators (AbstractClassRep::FieldList &mFieldList) |
static U32 | getClassCRC (U32 netClassGroup) |
static AbstractClassRep * | getClassList () |
Public Attributes | |
FieldList | mFieldList |
bool | mDynamicGroupExpand |
S32 | mClassGroupMask |
Mask indicating in which NetGroups this object belongs. More... | |
S32 | mClassType |
Stores the NetClass of this class. More... | |
S32 | mNetEventDir |
Stores the NetDirection of this class. More... | |
S32 | mClassId [NetClassGroupsCount] |
Stores the IDs assigned to this class for each group. More... | |
Static Public Attributes | |
static U32 | NetClassCount [NetClassGroupsCount][NetClassTypesCount] = {{0, },} |
static U32 | NetClassBitSize [NetClassGroupsCount][NetClassTypesCount] = {{0, },} |
Protected Member Functions | |
virtual void | init () const =0 |
Static Protected Member Functions | |
static ConsoleObject * | create (const char *in_pClassName) |
static ConsoleObject * | create (const U32 groupId, const U32 typeId, const U32 in_classId) |
Protected Attributes | |
const char * | mClassName |
AbstractClassRep * | nextClass |
AbstractClassRep * | parentClass |
Namespace * | mNamespace |
Static Protected Attributes | |
static AbstractClassRep ** | classTable [NetClassGroupsCount][NetClassTypesCount] |
static AbstractClassRep * | classLinkList = NULL |
static U32 | classCRC [NetClassGroupsCount] = {INITIAL_CRC_VALUE, } |
static bool | initialized = false |
Friends | |
class | ConsoleObject |
Core functionality for class manipulation.
Many of Torque's subsystems, especially network, console, and sim, require the ability to programatically instantiate classes. For instance, when objects are ghosted, the networking layer needs to be able to create an instance of the object on the client. When the console scripting language runtime encounters the "new" keyword, it has to be able to fill that request.
Since standard C++ doesn't provide a function to create a new instance of an arbitrary class at runtime, one must be created. This is what AbstractClassRep and ConcreteClassRep are all about. They allow the registration and instantiation of arbitrary classes at runtime.
In addition, ACR keeps track of the fields (registered via addField() and co.) of a class, allowing programmatic access of class fields.
Torque supports a notion of group, type, and direction for objects passed over the network. Class IDs are assigned sequentially per-group, per-type, so that, for instance, the IDs assigned to Datablocks are seperate from the IDs assigned to NetObjects or NetEvents. This can translate into significant bandwidth savings (especially since the size of the fields for transmitting these bits are determined at run-time based on the number of IDs given out.
Much like ConsoleConstructor, ACR does some preparatory work at runtime before execution is passed to main(). In actual fact, this preparatory work is done by the ConcreteClassRep template. Let's examine this more closely.
If we examine ConsoleObject, we see that two macros must be used in the definition of a properly integrated objects. From the ConsoleObject example:
What do these things actually do?
Not all that much, in fact. They expand to code something like this:
As you can see, getClassRep(), getStaticClassRep(), and getParentStaticClassRep() are just accessors to allow access to various ConcreteClassRep instances. This is where the Parent typedef comes into play as well - it lets getParentStaticClassRep() get the right class rep.
In addition, dynClassRep is declared as a member of TorqueObject, and defined later on. Much like ConsoleConstructor, ConcreteClassReps add themselves to a global linked list in their constructor.
Then, when AbstractClassRep::initialize() is called, from Con::init(), we iterate through the list and perform the following tasks:
typedef const char*(* GetDataNotify)(void *obj, const char *data) |
typedef bool(* SetDataNotify)(void *obj, const char *data) |
This is a function pointer typedef to support get/set callbacks for fields.
typedef void(* WriteCustomTamlSchema)(const AbstractClassRep *pClassRep, TiXmlElement *pParentElement) |
Allows the writing of a custom TAML schema.
typedef bool(* WriteDataNotify)(void *obj, const char *pFieldName) |
This is a function pointer typedef to support optional writing for fields.
enum ACRFieldTypes |
|
inline |
|
inlinevirtual |
|
staticprotected |
|
staticprotected |
|
pure virtual |
Implemented in ConcreteClassRep< T >.
|
static |
|
static |
AbstractClassRep * findContainerChildRoot | ( | AbstractClassRep * | pChild | ) |
const AbstractClassRep::Field * findField | ( | StringTableEntry | fieldName | ) | const |
AbstractClassRep * findFieldRoot | ( | StringTableEntry | fieldName | ) |
|
inlinestatic |
|
inline |
|
inlinestatic |
|
inline |
|
pure virtual |
Implemented in ConcreteClassRep< T >.
|
pure virtual |
Implemented in ConcreteClassRep< T >.
|
inline |
|
inline |
|
inline |
|
protectedpure virtual |
Implemented in ConcreteClassRep< T >.
|
static |
|
inline |
Helper class to see if we are a given class, or a subclass thereof.
|
static |
|
friend |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
S32 mClassGroupMask |
Mask indicating in which NetGroups this object belongs.
S32 mClassId[NetClassGroupsCount] |
Stores the IDs assigned to this class for each group.
|
protected |
S32 mClassType |
Stores the NetClass of this class.
bool mDynamicGroupExpand |
FieldList mFieldList |
|
protected |
S32 mNetEventDir |
Stores the NetDirection of this class.
|
static |
|
static |
|
protected |
|
protected |