Managing Many Nodes

Discussion about everything. New games, 3d math, development tips...
Post Reply
Guest

Managing Many Nodes

Post by Guest »

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
nebukadnezzar
Posts: 25
Joined: Tue Dec 02, 2003 7:45 pm
Location: Germany - Bornheim

Post by nebukadnezzar »

i think the fastest way is using a sorted linked list
using quicksort and binary search.
(or use a tree instead)
Guest

Post by Guest »

So if i used a sorted linked list, i could just search through nodes beginning with the letter i wanted? is this what u mean?

btw: thanks for the quick reply
nebukadnezzar
Posts: 25
Joined: Tue Dec 02, 2003 7:45 pm
Location: Germany - Bornheim

Post by nebukadnezzar »

you could do so
but binary search means

pick the item in the middle..
if it equal to the search value abort and return the value.
if it's less take the middle of the upper half
if not the middle of the lower half
..and now recurse to the beginning ...
Guest

Post by Guest »

oh cool. i see.
thanks
rebecca

Post by rebecca »

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
Guest

Post by Guest »

perfect :D
nebukadnezzar
Posts: 25
Joined: Tue Dec 02, 2003 7:45 pm
Location: Germany - Bornheim

Post by nebukadnezzar »

is there a way to use regular expressions in a map with string as key value
Guest

Post by Guest »

hi nebukadnezzar

not directly. you have to use your own comperator class. google for std map maybe you'll find something usefull

regards
rebecca
nebukadnezzar
Posts: 25
Joined: Tue Dec 02, 2003 7:45 pm
Location: Germany - Bornheim

Post by nebukadnezzar »

i know but is there a comparator for this?
(and one where i don't need to link a big library)
at the moment i've written a comparator which compares only the first characters until it reaches the '*'.
Thats not truly regexp but it satisfies al my needs atm.
Guest

Post by Guest »

regexp from boost should be fairly small. don't know of any other

regards
rebecca
Post Reply