ConsoleMethod just a question
by Davide Archetti · in Torque 3D Professional · 06/01/2009 (9:49 am) · 4 replies
Sorry, I post here, because I'm using Torque3D, although this question is not striclty binded to this version of torque.
I've tried to create a new class derived from ConsoleObject, but it seems that I cannot use the ConsoleMethod define to add method to this class, indeed if you look at the define:
I whish to ask, why is it so? object shouldn't be a ConsoleObject?
How can I add method to a ConsoleObject derived class?
I've tried to create a new class derived from ConsoleObject, but it seems that I cannot use the ConsoleMethod define to add method to this class, indeed if you look at the define:
# define ConsoleMethod(className,name,returnType,minArgs,maxArgs,usage1) \
static inline returnType c##className##name(className *, S32, const char **argv); \
static returnType c##className##name##caster(SimObject *object, S32 argc, const char **argv) { \
AssertFatal( dynamic_cast<className*>( object ), "Object passed to " #name " is not a " #className "!" ); \
conmethod_return_##returnType ) c##className##name(static_cast<className*>(object),argc,argv); \
};
...you can see, in the last line that object is static_cast'ed to your className, but className is of type ConsoleObject the parent of simObject (object is a simObject*) so the static_cast will always generate an error. I whish to ask, why is it so? object shouldn't be a ConsoleObject?
How can I add method to a ConsoleObject derived class?
#2
Basically, even though the names are a bit misleading, ConsoleMethods apply only to SimObject, and classes that contain SimObject in their hierarchy.
The simple fix is to derive from SimObject instead of ConsoleObject.
06/02/2009 (9:52 pm)
You can derive directly from ConsoleObject--but not for any objects that need to utilize TorqueScript (which means that ConsoleMethod doesn't apply).Basically, even though the names are a bit misleading, ConsoleMethods apply only to SimObject, and classes that contain SimObject in their hierarchy.
The simple fix is to derive from SimObject instead of ConsoleObject.
#3
I just needed a light weight class in script for this reason I've used ConsoleObject, but if the most light weight class to use is SimObject ... I've learned a new thing also today
06/03/2009 (2:00 am)
Ok, thank you Stephen. I just needed a light weight class in script for this reason I've used ConsoleObject, but if the most light weight class to use is SimObject ... I've learned a new thing also today
#4
ConsoleObject -- provides the ability for cross-platform and remote instantiation of an object from a class (AbstractClassRep, ConcreteClassRep). Also provides for script based instantiation (but not referencing of that instantiation). The only real reason to subclass this class is for NetEvent types of things--needs to be instantiated, but not included in the simulation.
SimObject -- provides the ability to participate in the simulation (instantiated objects can be registered with the simulation, and searched via name or ID). This in turn allows the object to be referenced in TorqueScript (which is what I think you want).
NetObject -- provides access to the bitstream class, and mechanisms for using this class across a NetConnection (or subclass) for synchronizing object state across a network.
SceneObject -- provides the ability to have location within a Scene. Also has other core level scene related functionality.
GameBase -- provides the ability to process time (processTick). Also provides the ability for instantiations of the class to be control objects.
Basically, everything below GameBase is a reference implementation. ShapeBase, Player, Vehicle, etc...all are examples of how to use the top 5 classes in the hierarchy.
06/04/2009 (7:53 pm)
This is from memory, and from a long time ago (when I used to teach the Torque Boot Camps), but each of the 5 top levels of classes in the primary Torque Class Hierarchy provide specific capabilities:ConsoleObject -- provides the ability for cross-platform and remote instantiation of an object from a class (AbstractClassRep, ConcreteClassRep). Also provides for script based instantiation (but not referencing of that instantiation). The only real reason to subclass this class is for NetEvent types of things--needs to be instantiated, but not included in the simulation.
SimObject -- provides the ability to participate in the simulation (instantiated objects can be registered with the simulation, and searched via name or ID). This in turn allows the object to be referenced in TorqueScript (which is what I think you want).
NetObject -- provides access to the bitstream class, and mechanisms for using this class across a NetConnection (or subclass) for synchronizing object state across a network.
SceneObject -- provides the ability to have location within a Scene. Also has other core level scene related functionality.
GameBase -- provides the ability to process time (processTick). Also provides the ability for instantiations of the class to be control objects.
Basically, everything below GameBase is a reference implementation. ShapeBase, Player, Vehicle, etc...all are examples of how to use the top 5 classes in the hierarchy.
Associate James Ford
Sickhead Games