Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2194 in orxonox.OLD for orxonox/branches/chris


Ignore:
Timestamp:
Jul 18, 2004, 12:03:57 PM (20 years ago)
Author:
chris
Message:

orxonox/branches/chris: Implemented is_a() query for WorldEntities

Location:
orxonox/branches/chris/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/chris/src/player.cc

    r2192 r2194  
    2222using namespace std;
    2323
     24// initialize the pointers used for is_a identification
     25bool (*Player::basefunc)(char*) = WorldEntity::is_a;
     26char *Player::is = "Player";
    2427
    2528Player::Player(bool isFree) : WorldEntity(isFree)
     
    8891        glEnd();
    8992       
     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"));
    9096        printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
    9197}
     
    128134}
    129135
    130 
    131 
    132 
    133 
    134 
    135 
    136 
    137 
    138 
    139 
    140 
    141 
    142 
    143 
    144 
    145 
    146 
     136bool 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  
    1818  ~Player ();
    1919
     20        static bool is_a(char* name);
     21
    2022        virtual void post_spawn ();
    2123  virtual void tick (float time);
     
    2426  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
    2527        virtual void command (Command* cmd);
    26  
     28   
    2729  virtual void draw ();
    2830  virtual void get_lookat (Location* locbuf);
     
    3133
    3234 private:
     35        static bool (*basefunc)(char*);
     36  static char *is;
     37
    3338        bool bUp, bDown, bLeft, bRight, bAscend, bDescend;
    3439        bool bFire;
  • orxonox/branches/chris/src/world_entity.cc

    r2192 r2194  
    2323
    2424using namespace std;
     25
     26// initialize the pointers used for is_a identification
     27bool (*WorldEntity::basefunc)(char*) = WorldEntity::is_none;
     28char *WorldEntity::is = "WorldEntity";
    2529
    2630/**
     
    183187*/
    184188void 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*/
     199bool 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*/
     212bool WorldEntity::is_none (char* name)
     213{
     214        return false;
     215}
  • orxonox/branches/chris/src/world_entity.h

    r2192 r2194  
    2525
    2626        bool isFree ();
     27
     28        static bool is_a(char* name);
    2729       
    2830  //void addAbility(Ability* ability);
     
    3537  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
    3638        virtual void command (Command* cmd);
    37  
     39   
    3840  virtual void draw ();
    3941  virtual void get_lookat (Location* locbuf);
    4042
    4143        virtual void left_world ();
    42 
     44       
    4345 private:
     46        static bool is_none (char* name);       
     47        static bool (*basefunc)(char*);
     48        static char *is;
     49 
    4450  const bool bFree;     
    4551  bool bCollide;
Note: See TracChangeset for help on using the changeset viewer.