Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4827 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Jul 9, 2005, 12:48:50 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: state is no more singleton, but static class.
This is faster, and easier to handle, because one can just say State::getBLA() and not State::getInstance()→getBLA(); ——→>> less redundant

Location:
orxonox/trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/particles/particle_system.cc

    r4762 r4827  
    412412          //! \todo implement a faster code for the look-at Camera algorithm.
    413413
    414         const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
     414        const PNode* camera = State::getCamera();  //!< \todo MUST be different
    415415        Vector cameraPos = camera->getAbsCoor();
    416         Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
     416        Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor();
    417417        Vector view = cameraTargetPos - cameraPos;
    418418        Vector up = Vector(0, 1, 0);
  • orxonox/trunk/src/orxonox.cc

    r4822 r4827  
    4343#include "garbage_collector.h"
    4444
    45 #include "state.h"
    4645#include "event.h"
    4746#include "factory.h"
     
    9089  delete GameLoader::getInstance();
    9190  delete SoundEngine::getInstance();
    92   delete State::getInstance();
    9391  delete CDEngine::getInstance();
    9492  delete GarbageCollector::getInstance();
  • orxonox/trunk/src/story_entities/world.cc

    r4826 r4827  
    135135  if( this->worldIsInitialized)
    136136    return this->worldReference->getEntities();
    137   PRINT(1)("Someone tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n");
     137  PRINT(1)("tried to use the WorldInterface before it has been initizlized! this can result in SEGFAULTs!\n");
    138138  return NULL;
    139139}
     
    222222  //strcpy(this->worldName, name);
    223223  this->debugWorldNr = worldID;
    224   this->entities = new tList<WorldEntity>();
     224  State::setWorldEntityList(this->entities = new tList<WorldEntity>());
    225225  this->cycle = 0;
    226226
     
    244244  if (!crosshair)
    245245    crosshair = new Crosshair();
    246 
    247   /*
    248   // identifier
    249   string = grabParameter( root, "identifier");
    250   if( string == NULL || sscanf(string, "%d", &id) != 1)
    251   {
    252   PRINTF0("World is missing a proper 'identifier'\n");
    253   this->setStoryID( -1);
    254   }
    255   else setStoryID( id);
    256 
    257   // next id
    258   string = grabParameter( root, "nextid");
    259   if( string == NULL || sscanf(string, "%d", &id) != 1)
    260   {
    261   PRINTF0("World is missing a proper 'nextid'\n");
    262   this->setStoryID( -1);
    263   }
    264   else setNextStoryID( id);
    265 
    266 
    267   // path
    268   string = grabParameter( root, "path");
    269   if( string == NULL)
    270   {
    271   PRINTF0("World is missing a proper 'path'\n");
    272   this->setPath( NULL);
    273   }
    274   else
    275   {
    276   name = new char[strlen(string + 2)];
    277   strcpy( name, string);
    278   this->setPath( name);
    279   }
    280   */
    281246}
    282247
     
    304269  this->localCamera->setName ("Camera");
    305270
    306   State::getInstance()->setCamera(this->localCamera, this->localCamera->getTarget());
     271  State::setCamera(this->localCamera, this->localCamera->getTarget());
    307272
    308273  GraphicsEngine::getInstance()->displayFPS(true);
  • orxonox/trunk/src/util/state.cc

    r4597 r4827  
    2525
    2626
    27 /**
    28    \brief standard constructor
    29 */
    30 State::State ()
    31 {
    32    this->setClassID(CL_STATE, "State");
    33    this->setName("State");
    3427
    35    this->camera = NULL;
    36    this->cameraTarget = NULL;
    37 }
     28const PNode* State::camera = NULL;
     29const PNode* State::cameraTarget = NULL;
    3830
    39 /**
    40    \brief the singleton reference to this class
    41 */
    42 State* State::singletonRef = NULL;
    43 
    44 /**
    45    \brief standard deconstructor
    46 */
    47 State::~State ()
    48 {
    49   State::singletonRef = NULL;
    50 
    51 }
     31tList<WorldEntity>* State::worldEntityList = NULL;
    5232
    5333/**
     
    5636void State::setCamera(const PNode* camera, const PNode* cameraTarget)
    5737{
    58   this->camera = camera;
    59   this->cameraTarget = cameraTarget;
     38  State::camera = camera;
     39  State::cameraTarget = cameraTarget;
    6040}
  • orxonox/trunk/src/util/state.h

    r4746 r4827  
    1111// FORWARD DEFINITION
    1212class PNode;
     13class WorldEntity;
     14template<class T> class tList;
    1315
    1416//! A Singleton class, that handles some states about orxonox's objects
     
    1618
    1719 public:
    18   /** \returns a Pointer to the only object of this Class */
    19   inline static State* getInstance() { if (!singletonRef) singletonRef = new State();  return singletonRef; };
     20  // CAMERA //
     21  /** @param camera the PNode to the Camera, @param cameraTarget the PNode to the Camera's target */
     22  static void setCamera(const PNode* camera, const PNode* cameraTarget);
     23  /** @returns a Pointer to the PNode of the Camera */
     24  static inline const PNode* getCamera() { return State::camera; };
     25  /** @returns a Pointer to the CameraTarget */
     26  static inline const PNode* getCameraTarget() { return State::cameraTarget; };
    2027
    21   virtual ~State();
    22 
    23   void setCamera(const PNode* camera, const PNode* cameraTarget);
    24   /** \returns a Pointer to the PNode of the Camera */
    25   const PNode* getCamera() const { return this->camera; };
    26   /** \returns a Pointer to the CameraTarget */
    27   const PNode* getCameraTarget() const { return this->cameraTarget; };
     28  // WORLD_ENTITY_LIST //
     29  /** @param worldEntityList The World's List of WorldEntities */
     30  static inline void setWorldEntityList(tList<WorldEntity>* worldEntityList) { State::worldEntityList = worldEntityList; };
     31  /** @returns the List of WorldEntities */
     32  static inline tList<WorldEntity>* getWorldEntityList() { return State::worldEntityList; };
    2833
    2934 private:
    3035  State();
    31   static State*       singletonRef;       //!< a reference to this class
    3236
    33   const PNode*        camera;             //!< A reference to the camera
    34   const PNode*        cameraTarget;       //!< a reference to the cameraTarget
     37  static const PNode*           camera;             //!< A reference to the camera
     38  static const PNode*           cameraTarget;       //!< a reference to the cameraTarget
     39
     40  static tList<WorldEntity>*    worldEntityList;    //!< The List of the worldEntities
    3541};
    3642
  • orxonox/trunk/src/world_entities/weapons/test_gun.h

    r4758 r4827  
    1 /*! 
     1/*!
    22    \file weapon.h
    33    \brief a weapon that a player can use
     
    1212     o slowdown-factor: this is a factor d: exp(-d*x), d is element of all positive R. it determines how fast the firing-rate will slow down. if no slowdown: d=0, the bigger d is, the faster the weapon will slow down!
    1313     o energy-consumption: this determines the energy that has to be used to produce this projectile = costs per projectile
    14    
     14
    1515    Furthermore there are some other attributes, that will help to represent a firing
    1616    weapon in this world:
    1717     o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented
    1818     o shooting animation
    19      
     19
    2020*/
    2121
     
    3636  friend class World;
    3737
    38  public:
    39   TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
    40   virtual ~TestGun ();
     38  public:
     39    TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
     40    virtual ~TestGun ();
    4141
    42   virtual void activate();
    43   virtual void deactivate();
     42    virtual void activate();
     43    virtual void deactivate();
    4444
    45   virtual void fire();
    46   virtual void hit (WorldEntity* weapon, Vector* loc);
    47   virtual void destroy();
    48  
    49   virtual void tick(float time);
    50   virtual void weaponIdle();
    51   virtual void draw();
     45    virtual void fire();
     46    virtual void hit (WorldEntity* weapon, Vector* loc);
     47    virtual void destroy();
    5248
     49    virtual void tick(float time);
     50    virtual void weaponIdle();
     51    virtual void draw();
     52
     53  private:
     54    Animation3D* animation1;
     55    Animation3D* animation2;
     56    Animation3D* animation3;
     57
     58    PNode* objectComponent1;         //<! the gun is made of multiple parts, these PNodes represent their location and orientation
     59    PNode* objectComponent2;
     60    PNode* objectComponent3;
     61
     62    Vector projectileOffset;
     63    int leftRight;   // this will become an enum
    5364
    5465
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4826 r4827  
    1717#include "weapon_manager.h"
    1818#include "weapon.h"
    19 #include "stdincl.h"
    20 #include "world_entity.h"
    2119#include "vector.h"
    22 #include "model.h"
    2320#include "projectile.h"
    2421#include "list.h"
     
    3128*/
    3229Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction)
    33   : WorldEntity()
    3430{
    3531  parent->addChild(this, PNODE_ALL);
     
    3834  WorldInterface* wi = WorldInterface::getInstance();
    3935  this->worldEntities = wi->getEntityList();
    40 
    41   this->objectComponent1 = NULL;
    42   this->objectComponent2 = NULL;
    43   this->objectComponent3 = NULL;
    44 
    45   this->animation1 = NULL;
    46   this->animation2 = NULL;
    47   this->animation3 = NULL;
    4836}
    4937
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4826 r4827  
    11/*!
    22    \file weapon.h
    3     \brief a weapon that a player can use
     3    \brief a weapon that a can use
    44
    55
     
    4242// } WeaponSoundType;
    4343
     44
     45//! An enumerator defining the States of a Weapon
    4446typedef enum {
    45   W_NONE,
    46   W_SHOOT,
    47   W_RELOAD,
    48   W_ACTIVATING,
    49   W_DEACTIVATE,
    50   W_IDLE,
     47  W_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
     48  W_SHOOT         =    1,    //!< The State of the Shooting
     49  W_RELOAD        =    2,    //!< The State of the Reloading
     50  W_ACTIVATING    =    3,    //!< The State in which the weapon gets activated
     51  W_DEACTIVATING  =    4,    //!< The State in which the weapon gets deactivated
     52  W_INACTIVE      =    5,    //!< The State where the weapon is inactive (unable to shoot)
     53  W_IDLE          =    6,    //!< The State where the weapon is idle
     54
     55  W_STATES_COUNT  =    6     //!< This must match the count of the enumerations (without W_NONE)
    5156} WeaponState;
    5257
     
    5661#define    W_RIGHT       1
    5762
    58 
    59 
    60 
    61 
     63//! An abstract class, that describes weapons
     64/**
     65 * This is used as a container for all the different kinds of weapons that may exist
     66 * Animations/Sounds/etc. will be handled in the Extensions of this class.
     67 */
    6268class Weapon : public WorldEntity
    6369{
     
    8490
    8591
    86   /**
    87      \brief sets a weapons idle time
    88      \param idle time in ms
     92  /** @param idle time in ms  */
     93  inline void setWeaponIdleTime(float idleTime) { this->idleTime = idleTime; };
     94  /** @returns idle time in ms */
     95  inline float getWeaponIdleTime() const { return this->idleTime; };
     96  /** @return true if idletime is elapsed else otherwise */
     97  inline bool hasWeaponIdleTimeElapsed() const { return (this->localTime>this->idleTime)?true:false; };
    8998
    90      a weapon idle time is the time spend after a shoot until the weapon can
    91      shoot again
    92   */
    93   inline void setWeaponIdleTime(float time) { this->idleTime = time; }
    94   /**
    95      \brief gets the weapon idle time
    96      \returns idle time in ms
    97    */
    98   inline float getWeaponIdleTime() const { return this->idleTime;}
    99   /**
    100      \brief checks if the idle time is elapsed
    101      \return true if time is elapsed
    102 
    103      a weapon idle time is the time spend after a shoot until the weapon can
    104    shoot again
    105   */
    106   inline bool hasWeaponIdleTimeElapsed() const { return (this->localTime>this->idleTime)?true:false; }
    107 
    108   /**
    109      \brief fires the weapon
    110 
    111      this is called from the player.cc, when fire-button is been pushed
    112   */
     99  /** @brief fires the weapon */
    113100  virtual void fire() = 0;
    114101  virtual void hit (WorldEntity* weapon, Vector* loc);
     
    120107
    121108 protected:
    122   tList<WorldEntity>* worldEntities;
    123   float localTime;                 //<! this is the local time. important for shooting attributes like frequency
    124   float idleTime;                  //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
    125   float slowDownFactor;            //<! if the shooting frequency is a linear function of time...
     109  tList<WorldEntity>*  worldEntities;
    126110
    127   PNode* objectComponent1;         //<! the gun is made of multiple parts, these PNodes represent their location and orientation
    128   PNode* objectComponent2;
    129   PNode* objectComponent3;
     111  float                localTime;                 //<! this is the local time. important for shooting attributes like frequency
     112  float                idleTime;                  //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
     113  float                slowDownFactor;            //<! if the shooting frequency is a linear function of time...
    130114
    131   Animation3D* animation1;
    132   Animation3D* animation2;
    133   Animation3D* animation3;
    134 
    135   Vector projectileOffset;
    136   int leftRight;   // this will become an enum
    137 
    138   SoundBuffer* fireSound;
    139   SoundSource* weaponSource;
     115  SoundBuffer*         fireSound;
     116  SoundSource*         weaponSource;
    140117
    141118
    142119 private:
    143   bool enabled;                    //<! states if the weapon is enabled or not
    144   Projectile* projectile;          //<! the projectile used for this weapon
     120  bool                 enabled;                    //<! states if the weapon is enabled or not
     121  Projectile*          projectile;          //<! the projectile used for this weapon
    145122  //WeaponSound sound;
    146123};
Note: See TracChangeset for help on using the changeset viewer.