![]() TGE Version 1.5.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AbstractClassRep Class Reference#include <consoleObject.h>
Inheritance diagram for AbstractClassRep: ![]() Detailed DescriptionCore functionality for class manipulation.
Introduction (or, Why AbstractClassRep?)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.
NetClasses and Class IDsTorque 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.AbstractClassRep InternalsMuch 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:
// This is from inside the class definition... DECLARE_CONOBJECT(TorqueObject); // And this is from outside the class definition... IMPLEMENT_CONOBJECT(TorqueObject); What do these things actually do? Not all that much, in fact. They expand to code something like this:
// This is from inside the class definition... static ConcreteClassRep<TorqueObject> dynClassRep; static AbstractClassRep* getParentStaticClassRep(); static AbstractClassRep* getStaticClassRep(); virtual AbstractClassRep* getClassRep() const;
// And this is from outside the class definition... AbstractClassRep* TorqueObject::getClassRep() const { return &TorqueObject::dynClassRep; } AbstractClassRep* TorqueObject::getStaticClassRep() { return &dynClassRep; } AbstractClassRep* TorqueObject::getParentStaticClassRep() { return Parent::getStaticClassRep(); } ConcreteClassRep<TorqueObject> TorqueObject::dynClassRep("TorqueObject", 0, -1, 0); 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:
Member Typedef Documentation
This is a function pointer typedef to support get/set callbacks for fields.
Member Enumeration Documentation
Constructor & Destructor Documentation
Member Function Documentation
Helper class to see if we are a given class, or a subclass thereof.
Implemented in ConcreteClassRep< T >.
Implemented in ConcreteClassRep< T >.
Friends And Related Function Documentation
Field DocumentationMask indicating in which NetGroups this object belongs.
Stores the NetClass of this class.
Stores the NetDirection of this class.
Stores the IDs assigned to this class for each group.
|