Changeset 2194 in orxonox.OLD for orxonox/branches/chris/src
- Timestamp:
- Jul 18, 2004, 12:03:57 PM (20 years ago)
- Location:
- orxonox/branches/chris/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/chris/src/player.cc
r2192 r2194 22 22 using namespace std; 23 23 24 // initialize the pointers used for is_a identification 25 bool (*Player::basefunc)(char*) = WorldEntity::is_a; 26 char *Player::is = "Player"; 24 27 25 28 Player::Player(bool isFree) : WorldEntity(isFree) … … 88 91 glEnd(); 89 92 93 printf("Player is a Player: %d\n", is_a("Player")); 94 printf("Player is a WorldEntity: %d\n", is_a("WorldEntity")); 95 printf("Player is a Banana: %d\n", is_a("Banana")); 90 96 printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z); 91 97 } … … 128 134 } 129 135 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 136 bool Player::is_a(char* name) 137 { 138 if( !strcmp( name, is)) return true; 139 else return basefunc (name); 140 } -
orxonox/branches/chris/src/player.h
r2192 r2194 18 18 ~Player (); 19 19 20 static bool is_a(char* name); 21 20 22 virtual void post_spawn (); 21 23 virtual void tick (float time); … … 24 26 virtual void collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags); 25 27 virtual void command (Command* cmd); 26 28 27 29 virtual void draw (); 28 30 virtual void get_lookat (Location* locbuf); … … 31 33 32 34 private: 35 static bool (*basefunc)(char*); 36 static char *is; 37 33 38 bool bUp, bDown, bLeft, bRight, bAscend, bDescend; 34 39 bool bFire; -
orxonox/branches/chris/src/world_entity.cc
r2192 r2194 23 23 24 24 using namespace std; 25 26 // initialize the pointers used for is_a identification 27 bool (*WorldEntity::basefunc)(char*) = WorldEntity::is_none; 28 char *WorldEntity::is = "WorldEntity"; 25 29 26 30 /** … … 183 187 */ 184 188 void WorldEntity::left_world () {} 189 190 /** 191 \brief this method can be used to determine what type of WorldEntity a particular pointer represents at runtime 192 \param name: a string specifying the type (use the name of the class) 193 \return true if the entity is in fact of that type or a derivation thereof false if the entity is not related to the specifiead type 194 195 Since this funtion is declared static, it has to be redeclaed and reimplemented in every derivation of WorldEntity, but since it is written 196 very generally you just have to copy paste this function and initialize the two static is_a variables (basefunc and is) correctly. 197 Note that these have to be redeclared as well or you will get a compiler error. 198 */ 199 bool WorldEntity::is_a (char* name) 200 { 201 if( !strcmp( name, is)) return true; 202 else return basefunc (name); 203 } 204 205 /** 206 \brief basefunc of WorldEntity 207 \param name: not relevant 208 \return false 209 210 dummy is_a() implementation that returns false only 211 */ 212 bool WorldEntity::is_none (char* name) 213 { 214 return false; 215 } -
orxonox/branches/chris/src/world_entity.h
r2192 r2194 25 25 26 26 bool isFree (); 27 28 static bool is_a(char* name); 27 29 28 30 //void addAbility(Ability* ability); … … 35 37 virtual void collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags); 36 38 virtual void command (Command* cmd); 37 39 38 40 virtual void draw (); 39 41 virtual void get_lookat (Location* locbuf); 40 42 41 43 virtual void left_world (); 42 44 43 45 private: 46 static bool is_none (char* name); 47 static bool (*basefunc)(char*); 48 static char *is; 49 44 50 const bool bFree; 45 51 bool bCollide;
Note: See TracChangeset
for help on using the changeset viewer.