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/objects
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 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.