]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/personality.cxx
Better encapsulation for personality
[simgear.git] / simgear / scene / model / personality.cxx
1 /**
2  * $Id$
3  */
4
5 #ifdef HAVE_CONFIG_H
6 #  include <simgear_config.h>
7 #endif
8
9 #include "personality.hxx"
10 #include "animation.hxx"
11
12 static int
13 personality_pretrav_callback(ssgEntity * entity, int mask)
14 {
15     ((SGPersonalityBranch *)entity)->_old_current = SGAnimation::current_object;
16     SGAnimation::current_object = (SGPersonalityBranch *)entity;
17     return 1;
18 }
19
20 static int
21 personality_posttrav_callback(ssgEntity * entity, int mask)
22 {
23     SGAnimation::current_object = ((SGPersonalityBranch *)entity)->_old_current;
24     ((SGPersonalityBranch *)entity)->_old_current = 0;
25     return 1;
26 }
27
28 SGPersonalityBranch::SGPersonalityBranch()
29 {
30     setTravCallback(SSG_CALLBACK_PRETRAV, personality_pretrav_callback);
31     setTravCallback(SSG_CALLBACK_POSTTRAV, personality_posttrav_callback);
32 }
33
34 void SGPersonalityBranch::setDoubleValue( double value, SGAnimation *anim, int var_id, int var_num )
35 {
36     _doubleValues[ Key( anim, var_id, var_num ) ] = value;
37 }
38
39 void SGPersonalityBranch::setIntValue( int value, SGAnimation *anim, int var_id, int var_num )
40 {
41     _intValues[ Key( anim, var_id, var_num ) ] = value;
42 }
43
44 double SGPersonalityBranch::getDoubleValue( SGAnimation *anim, int var_id, int var_num ) const
45 {
46     map<Key,double>::const_iterator it = _doubleValues.find( Key( anim, var_id, var_num ) );
47     if ( it != _doubleValues.end() ) {
48         return it->second;
49     } else {
50         return 0;
51     }
52 }
53
54 int SGPersonalityBranch::getIntValue( SGAnimation *anim, int var_id, int var_num ) const
55 {
56     map<Key,int>::const_iterator it = _intValues.find( Key( anim, var_id, var_num ) );
57     if ( it != _intValues.end() ) {
58         return it->second;
59     } else {
60         return 0;
61     }
62 }