Managing Many Nodes
Managing Many Nodes
In my level i have player models spawn according to the settings in an xml file. so the number of them is always changing. one of the options in the xml file is to give each node a name. how can i manage them all?. i want to be able to access a particular one, when i knoe only its name.
i though i could use a linked list, but does this mean that every time i want to access a node i have to search through every node in the list to find it?
is there any faster, more efficient way of doing this? thanks
i though i could use a linked list, but does this mean that every time i want to access a node i have to search through every node in the list to find it?
is there any faster, more efficient way of doing this? thanks
-
- Posts: 25
- Joined: Tue Dec 02, 2003 7:45 pm
- Location: Germany - Bornheim
-
- Posts: 25
- Joined: Tue Dec 02, 2003 7:45 pm
- Location: Germany - Bornheim
hi
i use the map of the standard template library for this.
heres how you do it:
#include <map>
typedef std::map<std::string, irr::scene::ISceneNode*> NodeMap
NodeMap nodes;
// insert, make sure name is unique!!!!
void insertNode(const char* name, irr::scene::ISceneNode* node)
{
nodes[name]=node;
}
// lookup
irr::scene::ISceneNode* getNode(const char* name)
{
return nodes[name];
}
// remove
void removeNode(const char* name)
{
NodeMap::iterator iter=nodes.find(name);
if(iter!=nodes.end())
{
irr::scene::ISceneNode* node=(*iter).second;
node.remove();
nodes.erase(iter);
}
}
regards
rebecca
i use the map of the standard template library for this.
heres how you do it:
#include <map>
typedef std::map<std::string, irr::scene::ISceneNode*> NodeMap
NodeMap nodes;
// insert, make sure name is unique!!!!
void insertNode(const char* name, irr::scene::ISceneNode* node)
{
nodes[name]=node;
}
// lookup
irr::scene::ISceneNode* getNode(const char* name)
{
return nodes[name];
}
// remove
void removeNode(const char* name)
{
NodeMap::iterator iter=nodes.find(name);
if(iter!=nodes.end())
{
irr::scene::ISceneNode* node=(*iter).second;
node.remove();
nodes.erase(iter);
}
}
regards
rebecca
-
- Posts: 25
- Joined: Tue Dec 02, 2003 7:45 pm
- Location: Germany - Bornheim
-
- Posts: 25
- Joined: Tue Dec 02, 2003 7:45 pm
- Location: Germany - Bornheim