Lets say i have something like:
Code: Select all
class unit
{
public:
float vel;
vect3d pos;
irr::scene::IAnimatedMeshSceneNode* node;
unit(void);
~unit(void);
};
Thanks
Code: Select all
class unit
{
public:
float vel;
vect3d pos;
irr::scene::IAnimatedMeshSceneNode* node;
unit(void);
~unit(void);
};
Code: Select all
class unit: public irr::scene::IAnimatedMeshSceneNode{
}
Code: Select all
Index: include/ISceneNode.h
===================================================================
--- include/ISceneNode.h (revision 1278)
+++ include/ISceneNode.h (working copy)
@@ -44,7 +44,7 @@
: RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale),
Parent(0), ID(id), SceneManager(mgr), TriangleSelector(0),
AutomaticCullingState(EAC_BOX), IsVisible(true),
- DebugDataVisible(EDS_OFF), IsDebugObject(false)
+ DebugDataVisible(EDS_OFF), IsDebugObject(false), UserData(0)
{
if (parent)
parent->addChild(this);
@@ -650,6 +650,21 @@
return 0; // to be implemented by derived classes
}
+ //! Set opaque user data. This is any data that you want to associate with
+ //! this scene node. It will not be used by Irrlicht.
+ //! \param userData The data to set
+ void setUserData(void * userData)
+ {
+ UserData = userData;
+ }
+
+ //! Set opaque user data.
+ //! \return The user data that you previously provided, or 0.
+ void * getUserData(void)
+ {
+ return UserData;
+ }
+
protected:
//! A clone function for the ISceneNode members.
@@ -739,6 +754,9 @@
//! is debug object?
bool IsDebugObject;
+
+ //! Opaque user data, supplied and used by the user application.
+ void * UserData;
};
} // end namespace scene
Why don't use a Hash for this query, if you do it properly (very easy) you have O(1) query for searching.vitek wrote:You don't have to do a linear search [which is slow when you have many nodes] to find what scene node is associated with an entity.
You can use a binary search which is an order of magnitude faster than a linear search for sufficiently large data sets. Searching through an array of 10000 elements for a specific item will, on average, take 5000 compares. A binary search will take 14. It isn't constant time, but it is fast.
As an aside, if you are doing bullets and you are checking each bullet against every scene node, you are probably wasting a lot of cycles doing unnecessary intersection tests. This is likely to have more of an effect on performance than searching for the unit that maps to the node that was hit. If you partition your environment and only check bullets against nodes in the same area you will see a dramatic improvement.
As for inheritance, there is no problem with it, but often that doesn't work. The user of the library can't really inherit from CMeshSceneNode, so that isn't a possibility for them.
Travis
Last I checked, Irrlicht doesn't provide a hash map, so I didn't recommend it. The current C++ standard library doesn't provide hash containers either, so there really isn't a single portable implementation that I could refer everyone to.Why don't use a Hash for this query, if you do it properly (very easy) you have O(1) query for searching.
People do use hash maps/sets in games.By the way, you guys that have experience, why hash aren use it everywhre in video games for this kind of querys?
Yeah, I can agree with that in some ways.CuteAlien wrote:So the problems with destruction and serialization do not really matter.