Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 12, 2008, 10:53:51 PM (16 years ago)
Author:
landauf
Message:
  • added feature to add a callback function to configvalues. they get called if the value changes. an examples is in Core.cc.
  • changed the SetConfigValue macro and the Identifier::updateConfigValues() function to work properly with inherited classes in both possible cases: 1) they overwrite the config-value or 2) they don't. an example is ParticleProjectile that defines it's own speed_ configvalue.
Location:
code/branches/core3/src/orxonox
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/orxonox/GraphicsEngine.cc

    r1591 r1596  
    9797    SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
    9898
    99     unsigned int old = this->detailLevelParticle_;
    100     SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high");
    101 
    102     if (this->detailLevelParticle_ != old)
    103       for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
    104         it->detailLevelChanged(this->detailLevelParticle_);
     99    SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high").callback(&GraphicsEngine::detailLevelParticleChanged);
     100  }
     101
     102  void GraphicsEngine::detailLevelParticleChanged()
     103  {
     104    for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
     105      it->detailLevelChanged(this->detailLevelParticle_);
    105106  }
    106107
  • code/branches/core3/src/orxonox/GraphicsEngine.h

    r1563 r1596  
    5656        public:
    5757            void setConfigValues();
     58            void detailLevelParticleChanged();
    5859            bool setup();
    5960            bool declareRessourceLocations();
  • code/branches/core3/src/orxonox/Settings.cc

    r1535 r1596  
    6868  void Settings::setConfigValues()
    6969  {
    70     SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data.");
     70    SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data.").callback(&Settings::dataPathChanged);
     71  }
     72
     73  /**
     74    @brief Callback function if the datapath has changed.
     75  */
     76  void Settings::dataPathChanged()
     77  {
    7178    if (dataPath_ != "" && dataPath_[dataPath_.size() - 1] != '/')
    7279    {
  • code/branches/core3/src/orxonox/Settings.h

    r1535 r1596  
    4848    public:
    4949      void setConfigValues();
     50      void dataPathChanged();
    5051
    5152      static const std::string& getDataPath();
  • code/branches/core3/src/orxonox/objects/ParticleProjectile.cc

    r1563 r1596  
    3232#include "SpaceShip.h"
    3333#include "core/CoreIncludes.h"
    34 
     34#include "core/ConfigValueIncludes.h"
    3535namespace orxonox
    3636{
     
    5252            this->particles_ = 0;
    5353        }
     54
     55        this->setConfigValues();
    5456    }
    5557
     
    6062    }
    6163
     64    void ParticleProjectile::setConfigValues()
     65    {
     66        SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(&ParticleProjectile::speedChanged);
     67    }
     68
     69    void ParticleProjectile::speedChanged()
     70    {
     71        Projectile::speed_s = this->speed_;
     72        if (this->owner_)
     73            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
     74    }
     75
    6276    void ParticleProjectile::changedVisibility()
    6377    {
  • code/branches/core3/src/orxonox/objects/ParticleProjectile.h

    r1558 r1596  
    4444            virtual ~ParticleProjectile();
    4545            virtual void changedVisibility();
     46            void setConfigValues();
     47            void speedChanged();
    4648
    4749        private:
  • code/branches/core3/src/orxonox/objects/Projectile.cc

    r1592 r1596  
    4444namespace orxonox
    4545{
    46     float Projectile::speed_ = 5000;
     46    float Projectile::speed_s = 5000;
    4747
    4848    Projectile::Projectile(SpaceShip* owner) : owner_(owner)
     
    7474        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
    7575        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
    76         SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second");
     76        SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(&Projectile::speedChanged);
     77    }
    7778
     79    void Projectile::speedChanged()
     80    {
     81        Projectile::speed_s = this->speed_;
    7882        if (this->owner_)
    7983            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
  • code/branches/core3/src/orxonox/objects/Projectile.h

    r1552 r1596  
    4242            virtual ~Projectile();
    4343            void setConfigValues();
     44            void speedChanged();
    4445            void destroyObject();
    4546            virtual void tick(float dt);
    4647
    4748            static float getSpeed()
    48                 { return Projectile::speed_; }
     49                { return Projectile::speed_s; }
    4950
    5051        protected:
     
    5556            std::string explosionTemplateName_;
    5657            std::string smokeTemplateName_;
    57             static float speed_;
     58        protected:
     59            static float speed_s;
     60            float speed_;
     61        private:
    5862            float lifetime_;
    5963            float damage_;
  • code/branches/core3/src/orxonox/objects/RotatingProjectile.cc

    r1584 r1596  
    6565    void RotatingProjectile::setConfigValues()
    6666    {
    67         SetConfigValue(colour_, ColourValue(1.0, 0.0, 0.0));
     67        SetConfigValue(colour_, ColourValue(1.0, 0.0, 0.0)).callback(&RotatingProjectile::colourChanged);
     68    }
    6869
     70    void RotatingProjectile::colourChanged()
     71    {
    6972        if (this->isInitialized())
    7073        {
  • code/branches/core3/src/orxonox/objects/RotatingProjectile.h

    r1558 r1596  
    1414            virtual ~RotatingProjectile();
    1515            void setConfigValues();
     16            void colourChanged();
    1617            virtual void tick(float dt);
    1718            virtual void changedVisibility();
Note: See TracChangeset for help on using the changeset viewer.