typedef std::map<String, AnimationState> AnimationStateSet;
What's that ?? what return that ? how can i access animationState object from animationstateset ?
std::map
-
:wumpus:
- OGRE Retired Team Member

- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
http://www.sgi.com/tech/stl/Map.html
Nuff said, it is a dictionary that can look up AnimationState objects by name (String).
You can use the find method to look up a key in a Map, like
Nuff said, it is a dictionary that can look up AnimationState objects by name (String).
You can use the find method to look up a key in a Map, like
Code: Select all
AnimationStateSet::iterator found = set.find("SwimSwimHungry");
if(found != set.end())
{
// The animation state has been found, do something with it
}
-
haffax
- OGRE Retired Moderator

- Posts: 4823
- Joined: Fri Jun 18, 2004 1:40 pm
- Location: Berlin, Germany
- x 8
Welcome to the complex world of the STL.
A very good STL reference can be found here.
A std::map is set of key-value pairs. So in the case of your map the key type is String and the value type is AnimationState. There are several ways to access elements in the container.
One way:
This is the easiest way, but there are a few properties that you must be aware of. Look into the dokumentation for details.
Another way is through iterators:
You can't possibly learn STL in one day. You should look out for a tutorial or some such.
A std::map is set of key-value pairs. So in the case of your map the key type is String and the value type is AnimationState. There are several ways to access elements in the container.
One way:
Code: Select all
AnimationState state = myAnimationStateSet["walkloop"];
Another way is through iterators:
Code: Select all
// set iterator to first element in map
AnimationStateSet::iterator it = myAnimationStateSet.begin();
// while loop for all elements in the map.
while(it != myAnimationStateSet.end())
{
String key = it->first;
String state = it->second;
//do something with them
.....
++it; // set iterator to the next element
}
-
:wumpus:
- OGRE Retired Team Member

- Posts: 3067
- Joined: Tue Feb 10, 2004 12:53 pm
- Location: The Netherlands
- x 1
Don't do this! Use find(). It generates more code than find() as it creates "walkloop" in cases it did not exist yet (initializing it to default values), which is usually not what you want anyway. This is one of the traps that makes STL outright dangerous to people new to it. Only use the [] syntax to set values:tanis wrote:Code: Select all
AnimationState state = myAnimationStateSet["walkloop"];
Code: Select all
myAnimationStateSet["walkloop"] = AnimationState(param, param2, ...);