Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2008, 10:08:37 PM (15 years ago)
Author:
landauf
Message:

moved setTimeFactor to GSRoot because tickables are currently ticked there

File:
1 edited

Legend:

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

    r2344 r2400  
    3232#include "util/Exception.h"
    3333#include "util/Debug.h"
     34#include "core/Core.h"
    3435#include "core/Factory.h"
    3536#include "core/ConfigValueIncludes.h"
     
    4344#include "tools/Timer.h"
    4445#include "objects/Tickable.h"
     46#include "objects/worldentities/Backlight.h"
     47#include "tools/ParticleInterface.h"
    4548#include "Settings.h"
    4649
     
    6770    GSRoot::GSRoot()
    6871        : RootGameState("root")
     72        , timeFactor_(1.0f)
    6973        , settings_(0)
    7074        , tclBind_(0)
     
    7478        RegisterRootObject(GSRoot);
    7579        setConfigValues();
     80
     81        this->ccSetTimeFactor_ = 0;
    7682    }
    7783
     
    8894        // creates the class hierarchy for all classes with factories
    8995        Factory::createClassHierarchy();
     96
     97        // reset game speed to normal
     98        timeFactor_ = 1.0f;
    9099
    91100        // Create the lua interface
     
    129138        ccSelectGameState_ = createConsoleCommand(functor2, "selectGameState");
    130139        CommandExecutor::addConsoleCommandShortcut(ccSelectGameState_);
     140
     141        // time factor console command
     142        FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
     143        functor->setObject(this);
     144        ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
     145        CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
    131146    }
    132147
     
    143158        delete this->settings_;
    144159        delete this->luaBind_;
     160
     161        if (this->ccSetTimeFactor_)
     162        {
     163            delete this->ccSetTimeFactor_;
     164            this->ccSetTimeFactor_ = 0;
     165        }
    145166    }
    146167
     
    155176        // Call the Tickable objects
    156177        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    157             it->tick(time.getDeltaTime());
     178            it->tick(time.getDeltaTime() * this->timeFactor_);
    158179        /*** HACK *** HACK ***/
    159180
     
    168189
    169190        Copyright (c) 2000-2008 Torus Knot Software Ltd
    170        
     191
    171192        OGRE is licensed under the LGPL. For more info, see OGRE license.
    172193    */
     
    175196#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    176197        // Get the current process core mask
    177             DWORD procMask;
    178             DWORD sysMask;
     198        DWORD procMask;
     199        DWORD sysMask;
    179200#  if _MSC_VER >= 1400 && defined (_M_X64)
    180             GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
     201        GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
    181202#  else
    182             GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
    183 #  endif
    184 
    185             // If procMask is 0, consider there is only one core available
    186             // (using 0 as procMask will cause an infinite loop below)
    187             if (procMask == 0)
    188                     procMask = 1;
     203        GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
     204#  endif
     205
     206        // If procMask is 0, consider there is only one core available
     207        // (using 0 as procMask will cause an infinite loop below)
     208        if (procMask == 0)
     209            procMask = 1;
    189210
    190211        // if the core specified with limitToCPU is not available, take the lowest one
     
    192213            limitToCPU = 0;
    193214
    194             // Find the lowest core that this process uses and limitToCPU suggests
     215        // Find the lowest core that this process uses and limitToCPU suggests
    195216        DWORD threadMask = 1;
    196             while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
    197                     threadMask <<= 1;
    198 
    199             // Set affinity to the first core
    200             SetThreadAffinityMask(GetCurrentThread(), threadMask);
     217        while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
     218            threadMask <<= 1;
     219
     220        // Set affinity to the first core
     221        SetThreadAffinityMask(GetCurrentThread(), threadMask);
    201222#endif
    202223    }
     224
     225    /**
     226    @brief
     227        Changes the speed of Orxonox
     228    */
     229    void GSRoot::setTimeFactor(float factor)
     230    {
     231        if (Core::isMaster())
     232        {
     233            float change = factor / this->timeFactor_;
     234
     235            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*/
     243        }
     244    }
    203245}
Note: See TracChangeset for help on using the changeset viewer.