Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2406


Ignore:
Timestamp:
Dec 11, 2008, 3:06:33 AM (15 years ago)
Author:
landauf
Message:

Added TimeFactorListener to properly handle changes of the global time factor (makes the game faster or slower). Currently supported in Backlight, ParticleInterface and Timer, which were all critical classes I could think of (all other classes are already covered by the adjustment of dt in tick(dt)). It seems to work well, both with small values (0.1, 0.01) and great values (10, 100). Even pausing the game (0) works fine.

Location:
code/branches/objecthierarchy2/src/orxonox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc

    r2400 r2406  
    4444#include "tools/Timer.h"
    4545#include "objects/Tickable.h"
    46 #include "objects/worldentities/Backlight.h"
    47 #include "tools/ParticleInterface.h"
    4846#include "Settings.h"
    4947
    50 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 
     48#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    5149#  ifndef WIN32_LEAN_AND_MEAN
    5250#    define WIN32_LEAN_AND_MEAN
     
    231229        if (Core::isMaster())
    232230        {
    233             float change = factor / this->timeFactor_;
     231            TimeFactorListener::timefactor_s = factor;
     232
     233            for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
     234                it->changedTimeFactor(factor, this->timeFactor_);
    234235
    235236            this->timeFactor_ = factor;
    236 /*
    237             for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it != ObjectList<ParticleInterface>::end(); ++it)
    238                 it->setSpeedFactor(it->getSpeedFactor() * change);
    239 
    240             for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it != ObjectList<Backlight>::end(); ++it)
    241                 it->setTimeFactor(timeFactor_);
    242 */
    243237        }
    244238    }
     239
     240    ////////////////////////
     241    // TimeFactorListener //
     242    ////////////////////////
     243    float TimeFactorListener::timefactor_s = 1.0f;
     244
     245    TimeFactorListener::TimeFactorListener()
     246    {
     247        RegisterRootObject(TimeFactorListener);
     248    }
    245249}
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h

    r2400 r2406  
    7272        ConsoleCommand*       ccSetTimeFactor_;
    7373    };
     74
     75    class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass
     76    {
     77        friend class GSRoot;
     78
     79        public:
     80            TimeFactorListener();
     81            virtual ~TimeFactorListener() {}
     82
     83        protected:
     84            virtual void changedTimeFactor(float factor_new, float factor_old) {}
     85            inline float getTimeFactor() const
     86                { return TimeFactorListener::timefactor_s; }
     87
     88        private:
     89            static float timefactor_s;
     90    };
    7491}
    7592
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc

    r2350 r2406  
    135135        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    136136        {
    137             this->ribbonTrail_->setWidthChange(0, this->width_ * this->getWorldScale() / this->lifetime_/* * Backlight::timeFactor_s*/);
    138             this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_/* * Backlight::timeFactor_s*/);
     137            this->ribbonTrail_->setWidthChange(0, this->width_ * this->getWorldScale() / this->lifetime_ * this->getTimeFactor());
     138            this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_ * this->getTimeFactor());
    139139        }
    140140    }
     
    227227        }
    228228    }
     229
     230    void Backlight::changedTimeFactor(float factor_new, float factor_old)
     231    {
     232        this->update_lifetime();
     233    }
    229234}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h

    r2254 r2406  
    3232#include "OrxonoxPrereqs.h"
    3333#include "FadingBillboard.h"
     34#include "gamestates/GSRoot.h"
    3435
    3536namespace orxonox
    3637{
    37     class _OrxonoxExport Backlight : public FadingBillboard
     38    class _OrxonoxExport Backlight : public FadingBillboard, public TimeFactorListener
    3839    {
    3940        public:
     
    7475            virtual void changedScale();
    7576
     77        protected:
     78            virtual void changedTimeFactor(float factor_new, float factor_old);
     79
    7680        private:
    7781            virtual void startturnonoff();
  • code/branches/objecthierarchy2/src/orxonox/tools/ParticleInterface.cc

    r2171 r2406  
    5252    ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel)
    5353    {
    54         RegisterRootObject(ParticleInterface);
     54        RegisterObject(ParticleInterface);
    5555
    5656        assert(scenemanager);
     
    6969            {
    7070                this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
    71                 this->particleSystem_->setSpeedFactor(1.0f);
    72 //                this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor());
     71                this->setSpeedFactor(1.0f);
    7372            }
    7473            catch (...)
     
    224223    void ParticleInterface::setSpeedFactor(float factor)
    225224    {
    226         if (this->particleSystem_)
    227         {
    228 //            this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor);
    229             this->particleSystem_->setSpeedFactor(1.0f * factor);
    230         }
    231     }
    232     float ParticleInterface::getSpeedFactor() const
    233     {
    234         if (this->particleSystem_)
    235         {
    236 //            return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor());
    237             return (this->particleSystem_->getSpeedFactor() / 1.0f);
    238         }
    239         else
    240             return 1.0f;
     225        this->speedFactor_ = factor;
     226
     227        if (this->particleSystem_)
     228            this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor());
     229    }
     230    void ParticleInterface::changedTimeFactor(float factor_new, float factor_old)
     231    {
     232        this->setSpeedFactor(this->speedFactor_);
    241233    }
    242234
  • code/branches/objecthierarchy2/src/orxonox/tools/ParticleInterface.h

    r2087 r2406  
    3737#include "core/OrxonoxClass.h"
    3838#include "util/Math.h"
     39#include "gamestates/GSRoot.h"
    3940
    4041#define getAllEmitters() \
     
    4546namespace orxonox
    4647{
    47     class _OrxonoxExport ParticleInterface : public OrxonoxClass
     48    class _OrxonoxExport ParticleInterface : public TimeFactorListener
    4849    {
    4950        public:
     
    6970            unsigned int getNumAffectors() const;
    7071
    71             float getSpeedFactor() const;
     72            inline float getSpeedFactor() const
     73                { return this->speedFactor_; }
    7274            void setSpeedFactor(float factor);
    7375            bool getKeepParticlesInLocalSpace() const;
     
    9092                { return ParticleInterface::currentParticleInterface_s; }
    9193
     94        protected:
     95            virtual void changedTimeFactor(float factor_new, float factor_old);
     96
    9297        private:
    9398            void updateVisibility();
     
    102107            bool                      bAllowedByLOD_;
    103108            unsigned int              detaillevel_;     //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high)
     109            float                     speedFactor_;
    104110            Ogre::SceneManager*       scenemanager_;
    105111    };
  • code/branches/objecthierarchy2/src/orxonox/tools/Timer.cc

    r2087 r2406  
    9696        this->time_ = 0;
    9797
    98         RegisterRootObject(TimerBase);
     98        RegisterObject(TimerBase);
    9999    }
    100100
     
    137137        {
    138138            // If active: Decrease the timer by the duration of the last frame
    139             this->time_ -= time.getDeltaTimeMicroseconds();
     139            this->time_ -= (long long)(time.getDeltaTimeMicroseconds() * this->getTimeFactor());
    140140
    141141            if (this->time_ <= 0)
  • code/branches/objecthierarchy2/src/orxonox/tools/Timer.h

    r2171 r2406  
    6363#include "OrxonoxPrereqs.h"
    6464#include "core/OrxonoxClass.h"
     65#include "gamestates/GSRoot.h"
    6566
    6667namespace orxonox
     
    7273
    7374    //! TimerBase is the parent of the Timer class.
    74     class _OrxonoxExport TimerBase : public OrxonoxClass
     75    class _OrxonoxExport TimerBase : public TimeFactorListener
    7576    {
    7677        public:
Note: See TracChangeset for help on using the changeset viewer.