Page 1 of 1

UserData field for MovableObject

Posted: Fri Mar 21, 2008 6:25 pm
by KungFooMasta
This idea comes from PhysX.

Often times entities are part of a higher level class used in our applications. (GameObject) Currently there is no easy way to obtain a GameObject from a MovableObject. What we need is a simple member:

Code: Select all

void* MovableObject::userData
We could either have this be public and directly accessible, or add get/set functions to wrap it. This is very easy to add in, and does not force us to name our MovableObject instance to match the name of our GameObject. In fact, if you have 2 MovableObjects with the same name you will get an exception.

Please add this in. :)

Re: UserData field for MovableObject

Posted: Fri Mar 21, 2008 6:27 pm
by nullsquared
KungFooMasta wrote:This idea comes from PhysX.

Often times entities are part of a higher level class used in our applications. (GameObject) Currently there is no easy way to obtain a GameObject from a MovableObject. What we need is a simple member:

Code: Select all

void* MovableObject::userData
We could either have this be public and directly accessible, or add get/set functions to wrap it. This is very easy to add in, and does not force us to name our MovableObject instance to match the name of our GameObject. In fact, if you have 2 MovableObjects with the same name you will get an exception.

Please add this in. :)
http://www.ogre3d.org/docs/api/html/cla ... dingBoxa34

Code: Select all

struct GameObject: public Ogre::UserDefinedObject {
// foo
};
someMovableObject->setUserObject(myGameObject);
-or-
http://www.ogre3d.org/docs/api/html/cla ... dingBoxa36

Code: Select all

someMovableObject->setUserAny(Ogre::Any(myGameObject));
Just not both - the value itself is shared.

Posted: Fri Mar 21, 2008 6:30 pm
by KungFooMasta
I was just looking at the API and found the same thing! :)

I guess I would derive a class from UserDefinedObject to include a GameObject*, and then cast it to get access.

Posted: Fri Mar 21, 2008 6:31 pm
by nullsquared
KungFooMasta wrote:I was just looking at the API and found the same thing! :)

I guess I would derive a class from UserDefinedObject to include a GameObject*, and then cast it to get access.
Just use an Ogre::Any.

Posted: Fri Mar 21, 2008 6:32 pm
by CABAListic
You don't even need to derive anymore. The Any object is a templated wrapper around any type, so you can store whatever you want. It's basically a save variant to a void* pointer.

Posted: Fri Mar 21, 2008 6:46 pm
by KungFooMasta
Awesome! Thanks for the input, Ogre community ftw!