Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 11, 2008, 3:06:33 AM (16 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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.