Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

moved setTimeFactor to GSRoot because tickables are currently ticked there

Location:
code/branches/objecthierarchy2/src/orxonox/gamestates
Files:
4 edited

Legend:

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

    r2396 r2400  
    4141#include "core/CoreIncludes.h"
    4242#include "core/Core.h"
    43 //#include "objects/Backlight.h"
    4443#include "objects/Tickable.h"
    4544#include "objects/Radar.h"
    46 //#include "tools/ParticleInterface.h"
    4745#include "CameraManager.h"
    4846#include "LevelManager.h"
     
    5654    GSLevel::GSLevel()
    5755//        : GameState<GSGraphics>(name)
    58         : timeFactor_(1.0f)
    59         , keyBinder_(0)
     56        : keyBinder_(0)
    6057        , inputState_(0)
    6158        , radar_(0)
     
    6865        this->ccKeybind_ = 0;
    6966        this->ccTkeybind_ = 0;
    70         this->ccSetTimeFactor_ = 0;
    7167
    7268        setConfigValues();
     
    107103            // create the global LevelManager
    108104            this->levelManager_ = new LevelManager();
    109 
    110             // reset game speed to normal
    111             timeFactor_ = 1.0f;
    112105
    113106            this->loadLevel();
     
    134127            InputManager::getInstance().requestEnterState("game");
    135128        }
    136 
    137         if (Core::isMaster())
    138         {
    139             // time factor console command
    140             FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
    141             functor->setObject(this);
    142             ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
    143             CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
    144         }
    145129    }
    146130
     
    152136            delete this->ccKeybind_;
    153137            this->ccKeybind_ = 0;
    154         }
    155         if (this->ccSetTimeFactor_)
    156         {
    157             delete this->ccSetTimeFactor_;
    158             this->ccSetTimeFactor_ = 0;
    159138        }
    160139        if (this->ccTkeybind_)
     
    218197        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    219198        //    it->tick(time.getDeltaTime() * this->timeFactor_);
    220     }
    221 
    222     /**
    223     @brief
    224         Changes the speed of Orxonox
    225     */
    226     void GSLevel::setTimeFactor(float factor)
    227     {
    228 /*
    229         float change = factor / this->timeFactor_;
    230 */
    231         this->timeFactor_ = factor;
    232 /*
    233         for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
    234             it->setSpeedFactor(it->getSpeedFactor() * change);
    235 
    236         for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it)
    237             it->setTimeFactor(timeFactor_);
    238 */
    239199    }
    240200
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h

    r2344 r2400  
    4444        ~GSLevel();
    4545
    46         // this has to be public because proteced triggers a bug in msvc
    47         // when taking the function address.
    48         void setTimeFactor(float factor);
    49         float getTimeFactor() { return this->timeFactor_; }
    50 
    5146    protected:
    5247        void enter(Ogre::Viewport* viewport);
     
    5651        void loadLevel();
    5752        void unloadLevel();
    58 
    59         float timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
    6053
    6154        // console commands
     
    8073        ConsoleCommand*       ccKeybind_;
    8174        ConsoleCommand*       ccTkeybind_;
    82         ConsoleCommand*       ccSetTimeFactor_;
    8375
    8476    private:
  • 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}
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h

    r2344 r2400  
    4747        { requestState("root"); }
    4848
     49        // this has to be public because proteced triggers a bug in msvc
     50        // when taking the function address.
     51        void setTimeFactor(float factor);
     52        float getTimeFactor() { return this->timeFactor_; }
     53
    4954    private:
    5055        void enter();
     
    5560        void setThreadAffinity(unsigned int limitToCPU);
    5661
     62        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
    5763        Settings*             settings_;
    5864        TclBind*              tclBind_;
     
    6470        ConsoleCommand*       ccExit_;
    6571        ConsoleCommand*       ccSelectGameState_;
     72        ConsoleCommand*       ccSetTimeFactor_;
    6673    };
    6774}
Note: See TracChangeset for help on using the changeset viewer.