Game Development Community

Simset in C

by Demolishun · in Torque Game Engine · 01/25/2007 (9:17 pm) · 2 replies

I am working on a GUI object that needs to access SimObjects from C++ with dynamic data. I am reading the code for simsets and it looks like it will do what I want. However, I cannot quite figure out a few details:

First how smart is SimObjectPtr if I do this?:
SimObjectPtr<SimSet> mCellList;

Will the static_cast prevent non SimSet based objects from being referenced by this pointer?

Also, if I do something similar with SimObject can I access completely dynamic script variables?

Thanks,
Frank Carney

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67


#1
01/25/2007 (11:43 pm)
> Will the static_cast prevent non SimSet based objects from being referenced by this pointer?

no, but dynamic_cast will. - altho note you don't need a SimObjectPtr for that; a regular pointer will do. As i understand things, the main (only?) advantage of using SimObjectPtr is that when the object being pointed to is deleted, the pointer automatically goes to NULL without involving the whole onDeleteNotify() mechanism.


> Also, if I do something similar with SimObject can I access completely dynamic script variables?

i believe so. you certainly can access global variables created in script via Con::getBoolVar() or whatever, and there must be something similar for member variables. - I'd advise checking out the source to the consoleMethod "dump()", as that guy iterates thru the dynamic fields.
however, if you're going to be accessing the variable frequently, like more than once per frame or more, i suspect that Con::getBoolVar() might not be the most performant thing in the world. - if you want to add performant variables dynamically, i think you'd want to use a setter() and getter() instead.
#2
01/26/2007 (4:47 pm)
It looks like SimObjectPtr will ensure I can do NULL checks to make sure I have a valid object. It uses static_cast to reference objects in its operator= functions.

I think for performance I am going to create a SimObject based object that has the variables I need. It seems fairly trivial to access those through script using InitPersistFields.

I am trying to make an object that is quick for creation and destruction, but can be accessed via script for debugging. There is nothing like just using tree() in the console to what is going on.

I started reading through the setter and getter code for simobject last night and it looked as though it would get the variable regardless of whether it is static or dynamic. That is nice.

Thanks