Porting using Ogre::Any [Patch]

shanefarris

11-11-2009 23:15:13

I just got the latest Ogre from trunk and it looks like we need to replace UserDefinedObject with Ogre::Any. I was going to do that myself maybe tonight, or in the next few days. What is the best way to give you my updates? I am assuming I don't have write access to the svn repo, and I have never made a patch using svn. I can figure that out though, but I can't patch everything because I've had to make some changes to the code so it would fit my project, so I'm not sure it that complicates anything or not.

Is this code change something that you would like me to submit?

shanefarris

12-11-2009 20:37:36

I went ahead an created a patch. I did a quick smoke test with some boxes falling, colliding and bouncing on a hightmap, but if anyone sees an error let me know. Also my version of OgreOde has been modified to fit my engine, so I took the changes and made them in a text editor against the svn code, so let me know if there are any issues with that. The changes are simple enough though so looking at the patch you should get a pretty good idea of whats going on.

If you're like me and are new to patching, here is a quick article on creating and applying an svn patch:
http://ariejan.net/2007/07/03/how-to-cr ... ubversion/


Index: include/OgreOdeBody.h
===================================================================
--- include/OgreOdeBody.h (revision 2756)
+++ include/OgreOdeBody.h (working copy)
@@ -138,7 +138,7 @@
It extends the OGRE UserDefinedObject to allow reverse links from Ogre::Entity.
It extends the OGRE MovableObject to allow scene node attachment.
*/
- class _OgreOdeExport Body : public Ogre::MovableObject, public Ogre::UserDefinedObject
+ class _OgreOdeExport Body : public Ogre::MovableObject
{
friend class Joint;
friend class World;
Index: include/OgreOdeGeometry.h
===================================================================
--- include/OgreOdeGeometry.h (revision 2756)
+++ include/OgreOdeGeometry.h (working copy)
@@ -18,7 +18,7 @@
Note that this class does not override the UserDefinedObject's getTypeId method
because this class is abstract.
*/
- class _OgreOdeExport Geometry : public Ogre::UserDefinedObject, public Ogre::MovableObject
+ class _OgreOdeExport Geometry : public Ogre::MovableObject
{
friend class Space;
friend class World;
@@ -81,9 +81,6 @@
void setUserData(size_t user_data){_user_data = user_data;}
size_t getUserData() const {return _user_data;}

- void setUserObject(UserDefinedObject* object){_user_object = object;}
- UserDefinedObject* getUserObject(){return _user_object;}
-
virtual size_t getID() const ;
virtual void notify(Body* body);

@@ -174,7 +171,6 @@

static int _geometry_count;
size_t _user_data;
- UserDefinedObject* _user_object;
World *_world;

};
Index: loader/src/OgreOdeDotLoader.cpp
===================================================================
--- loader/src/OgreOdeDotLoader.cpp (revision 2756)
+++ loader/src/OgreOdeDotLoader.cpp (working copy)
@@ -206,7 +206,7 @@

vGeom->setPosition(boxCenter);
vehicle->setGeometry(vGeom);
- vGeom->setUserObject(vehicle);
+ vGeom->setUserAny(Ogre::Any(vehicle));
}
vehicle->setTransformGeometry(new TransformGeometry(_world, vehicle->getSpace()));
vehicle->getTransformGeometry()->setEncapsulatedGeometry(vehicle->getGeometry());
Index: prefab/include/OgreOdePrefabObject.h
===================================================================
--- prefab/include/OgreOdePrefabObject.h (revision 2756)
+++ prefab/include/OgreOdePrefabObject.h (working copy)
@@ -6,7 +6,7 @@
namespace OgreOde_Prefab
{

- class _OgreOdeExport_Prefab Object : public Ogre::UserDefinedObject
+ class _OgreOdeExport_Prefab Object
{
public:
Object(ObjectType type, OgreOde::World *world):
Index: prefab/src/OgreOdeRagdoll.cpp
===================================================================
--- prefab/src/OgreOdeRagdoll.cpp (revision 2756)
+++ prefab/src/OgreOdeRagdoll.cpp (working copy)
@@ -331,7 +331,7 @@
if (physical_bone->_geometry)
{
physical_bone->_geometry->setBody(physical_bone->_body);
- physical_bone->_geometry->setUserObject(this);
+ physical_bone->_geometry->setUserAny(Ogre::Any(this));
}

if (physical_bone->_body)
Index: prefab/src/OgreOdeVehicle.cpp
===================================================================
--- prefab/src/OgreOdeVehicle.cpp (revision 2756)
+++ prefab/src/OgreOdeVehicle.cpp (working copy)
@@ -42,7 +42,7 @@

_geometry = new SphereGeometry(_radius, _world, space);
_geometry->setBody(_body);
- _geometry->setUserObject(this);
+ _geometry->setUserAny(Ogre::Any(this));

_joint = new SuspensionJoint(_world);
_joint->attach(vehicle->getBody(),_body);
@@ -251,7 +251,7 @@
_geometry = new BoxGeometry(box, _world, space ? space : _world->getDefaultSpace());
else
_geometry = geometry;
- _geometry->setUserObject(this);
+ _geometry->setUserAny(Ogre::Any(this));

_transform = new TransformGeometry(_world, _space);
_transform->setEncapsulatedGeometry(_geometry);
@@ -292,7 +292,7 @@
_node->attachObject(_body);

if (_geometry)
- _geometry->setUserObject(this);
+ _geometry->setUserAny(Ogre::Any(this));

}
//------------------------------------------------------------------------------------------------
@@ -638,7 +638,7 @@
{
Geometry *geom = contact->getFirstGeometry();

- Object* pObject = (Object*) geom->getUserObject();
+ Object* pObject = any_cast<Object*>(geom->getUserAny());
if (pObject &&
(pObject->getObjectType() == OgreOde_Prefab::ObjectType_Wheel))
{
@@ -648,7 +648,7 @@
else
{
geom = contact->getSecondGeometry();
- pObject = (Object*) geom->getUserObject();
+ pObject = any_cast<Object*>(geom->getUserAny());
if (pObject && (pObject->getObjectType() == OgreOde_Prefab::ObjectType_Wheel))
{
((OgreOde_Prefab::Vehicle::Wheel*)pObject)->setupTyreContact(contact);
Index: src/OgreOdeBody.cpp
===================================================================
--- src/OgreOdeBody.cpp (revision 2756)
+++ src/OgreOdeBody.cpp (working copy)
@@ -113,7 +113,7 @@
_historyResize(_world->getHistorySize());
// Tie the physical body to the movable
// used when getting physical out of Movables.
- this->setUserObject (this);
+ this->setUserAny(Ogre::Any(this));

}
//-----------------------------------------------------------------------
Index: src/OgreOdeGeometry.cpp
===================================================================
--- src/OgreOdeGeometry.cpp (revision 2756)
+++ src/OgreOdeGeometry.cpp (working copy)
@@ -18,7 +18,6 @@

//------------------------------------------------------------------------------------------------
Geometry::Geometry(World *world, Space* space):
- UserDefinedObject(),
_contact_high_water_mark (0),
_last_contact_num(0),
_max_contacts (32),
@@ -28,7 +27,6 @@
_debug_obj (0),
_debug_node (0),
_user_data (0),
- _user_object (0),
_geom (0),
_world(world)
{
Index: src/OgreOdeSpace.cpp
===================================================================
--- src/OgreOdeSpace.cpp (revision 2756)
+++ src/OgreOdeSpace.cpp (working copy)
@@ -270,7 +270,7 @@

Body *body1, *body2;
Geometry *geom;
- Ogre::UserDefinedObject *uo1, *uo2;
+ Ogre::Any uo1, uo2;

// Movables to Movables
Ogre::SceneQueryMovableIntersectionList::iterator it, itend;
@@ -284,26 +284,26 @@
*/

// Get user defined objects (generic in OGRE)
- uo1 = it->first->getUserObject();
- uo2 = it->second->getUserObject();
+ uo1 = it->first->getUserAny();
+ uo2 = it->second->getUserAny();

// Only perform collision if we have UserDefinedObject links
- if (uo1 && uo2)
+ if (!uo1.isEmpty() && !uo2.isEmpty())
{
bool isBody1 = false;
- if (uo1->getTypeName () == "Body")
+ if (uo1.getType () == typeid(Body))
isBody1 = true;

bool isBody2 = false;
- if (uo2->getTypeName () == "Body")
+ if (uo2.getType () == typeid(Body))
isBody2 = true;
if (isBody1 || isBody2)
{
if (isBody2 && isBody1)
{
// Both are dynamic object
- body1 = static_cast<Body*>(uo1);
- body2 = static_cast<Body*>(uo2);
+ body1 = any_cast<Body*>(uo1);
+ body2 = any_cast<Body*>(uo2);

// Do detailed collision test
body1->collide (data, body2);
@@ -313,13 +313,13 @@
// Both are dynamic object
if (isBody1)
{
- body1 = static_cast<Body*> (uo1);
- geom = static_cast<Geometry*> (uo2);
+ body1 = any_cast<Body*> (uo1);
+ geom = any_cast<Geometry*> (uo2);
}
else
{
- geom = static_cast<Geometry*> (uo1);
- body1 = static_cast<Body*> (uo2);
+ geom = any_cast<Geometry*> (uo1);
+ body1 = any_cast<Body*> (uo2);
}

// Do detailed collision test
@@ -343,15 +343,15 @@
wf = wit->second;

// Get user defined objects (generic in OGRE)
- uo1 = mo->getUserObject();
+ uo1 = mo->getUserAny();
// Only perform collision if we have UserDefinedObject link
// otherwise ...
- if (uo1)
+ if (!uo1.isEmpty())
{
// Cast to ApplicationObject
- if (uo1->getTypeName () == "Body")
+ if (uo1.getType () == typeid(Body))
{
- body1 = static_cast<Body*>(uo1);
+ body1 = any_cast<Body*>(uo1);
body1->collidePlaneBounds(data, wf);
}
// else // static objects don't collide against Scene Geometry

tuan kuranes

13-11-2009 08:33:02

Thanks for the contribution.

Before we can add that to the SVN, it would be better to add some #define handling the non 1.7 case, so that user sticking with 1.6 can still compile.

Please use ogreaddons sourceforge patch tracking system, that helps storing/retrieving them, and post the link in the forums here.

shanefarris

13-11-2009 15:07:34

I'll check out the tracking system today, but I thought that Ogre::Any has been in Ogre for awhile including in 1.6, is this not the case?

tuan kuranes

16-11-2009 08:43:34

thought that Ogre::Any has been in Ogre for awhile including in 1.6, is this not the case?
ok, then.