Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (17 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/gamestates/GSRoot.cc

    r2459 r2485  
    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"
     
    4041#include "core/TclBind.h"
    4142#include "core/TclThreadManager.h"
     43#include "core/LuaBind.h"
    4244#include "tools/Timer.h"
    4345#include "objects/Tickable.h"
    4446#include "Settings.h"
    4547
    46 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 
     48#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    4749#  ifndef WIN32_LEAN_AND_MEAN
    4850#    define WIN32_LEAN_AND_MEAN
     
    6668    GSRoot::GSRoot()
    6769        : RootGameState("root")
     70        , timeFactor_(1.0f)
     71        , bPaused_(false)
     72        , timeFactorPauseBackup_(1.0f)
    6873        , settings_(0)
    6974        , tclBind_(0)
     
    7378        RegisterRootObject(GSRoot);
    7479        setConfigValues();
     80
     81        this->ccSetTimeFactor_ = 0;
     82        this->ccPause_ = 0;
    7583    }
    7684
     
    8795        // creates the class hierarchy for all classes with factories
    8896        Factory::createClassHierarchy();
     97
     98        // reset game speed to normal
     99        timeFactor_ = 1.0f;
     100
     101        // Create the lua interface
     102        this->luaBind_ = new LuaBind();
    89103
    90104        // instantiate Settings class
     
    114128            setThreadAffinity((unsigned int)(limitToCPU - 1));
    115129
    116         // add console commands
    117         FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
    118         functor1->setObject(this);
    119         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit"));
    120 
    121         // add console commands
    122         FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
    123         functor2->setObject(this);
    124         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
     130        {
     131            // add console commands
     132            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame);
     133            functor->setObject(this);
     134            this->ccExit_ = createConsoleCommand(functor, "exit");
     135            CommandExecutor::addConsoleCommandShortcut(this->ccExit_);
     136        }
     137
     138        {
     139            // add console commands
     140            FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
     141            functor->setObject(this);
     142            this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
     143            CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
     144        }
     145
     146        {
     147            // time factor console command
     148            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
     149            functor->setObject(this);
     150            this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
     151            CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
     152        }
     153
     154        {
     155            // time factor console command
     156            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause);
     157            functor->setObject(this);
     158            this->ccPause_ = createConsoleCommand(functor, "pause");
     159            CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
     160        }
    125161    }
    126162
    127163    void GSRoot::leave()
    128164    {
    129         // TODO: remove and destroy console commands
     165        // destroy console commands
     166        delete this->ccExit_;
     167        delete this->ccSelectGameState_;
    130168
    131169        delete this->shell_;
     
    133171        delete this->tclBind_;
    134172
    135         delete settings_;
    136 
     173        delete this->settings_;
     174        delete this->luaBind_;
     175
     176        if (this->ccSetTimeFactor_)
     177        {
     178            delete this->ccSetTimeFactor_;
     179            this->ccSetTimeFactor_ = 0;
     180        }
     181
     182        if (this->ccPause_)
     183        {
     184            delete this->ccPause_;
     185            this->ccPause_ = 0;
     186        }
    137187    }
    138188
     
    153203        }
    154204        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    155             it->tick(leveldt);
     205            it->tick(leveldt * this->timeFactor_);
    156206        /*** HACK *** HACK ***/
    157207
     
    166216
    167217        Copyright (c) 2000-2008 Torus Knot Software Ltd
    168        
     218
    169219        OGRE is licensed under the LGPL. For more info, see OGRE license.
    170220    */
     
    173223#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
    174224        // Get the current process core mask
    175             DWORD procMask;
    176             DWORD sysMask;
     225        DWORD procMask;
     226        DWORD sysMask;
    177227#  if _MSC_VER >= 1400 && defined (_M_X64)
    178             GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
     228        GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
    179229#  else
    180             GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
     230        GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
    181231#  endif
    182232
    183             // If procMask is 0, consider there is only one core available
    184             // (using 0 as procMask will cause an infinite loop below)
    185             if (procMask == 0)
    186                     procMask = 1;
     233        // If procMask is 0, consider there is only one core available
     234        // (using 0 as procMask will cause an infinite loop below)
     235        if (procMask == 0)
     236            procMask = 1;
    187237
    188238        // if the core specified with limitToCPU is not available, take the lowest one
     
    190240            limitToCPU = 0;
    191241
    192             // Find the lowest core that this process uses and limitToCPU suggests
     242        // Find the lowest core that this process uses and limitToCPU suggests
    193243        DWORD threadMask = 1;
    194             while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
    195                     threadMask <<= 1;
    196 
    197             // Set affinity to the first core
    198             SetThreadAffinityMask(GetCurrentThread(), threadMask);
     244        while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
     245            threadMask <<= 1;
     246
     247        // Set affinity to the first core
     248        SetThreadAffinityMask(GetCurrentThread(), threadMask);
    199249#endif
    200250    }
     251
     252    /**
     253    @brief
     254        Changes the speed of Orxonox
     255    */
     256    void GSRoot::setTimeFactor(float factor)
     257    {
     258        if (Core::isMaster())
     259        {
     260            if (!this->bPaused_)
     261            {
     262                TimeFactorListener::timefactor_s = factor;
     263
     264                for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
     265                    it->changedTimeFactor(factor, this->timeFactor_);
     266
     267                this->timeFactor_ = factor;
     268            }
     269            else
     270                this->timeFactorPauseBackup_ = factor;
     271        }
     272    }
     273
     274    void GSRoot::pause()
     275    {
     276        if (Core::isMaster())
     277        {
     278            if (!this->bPaused_)
     279            {
     280                this->timeFactorPauseBackup_ = this->timeFactor_;
     281                this->setTimeFactor(0.0f);
     282                this->bPaused_ = true;
     283            }
     284            else
     285            {
     286                this->bPaused_ = false;
     287                this->setTimeFactor(this->timeFactorPauseBackup_);
     288            }
     289        }
     290    }
     291
     292    ////////////////////////
     293    // TimeFactorListener //
     294    ////////////////////////
     295    float TimeFactorListener::timefactor_s = 1.0f;
     296
     297    TimeFactorListener::TimeFactorListener()
     298    {
     299        RegisterRootObject(TimeFactorListener);
     300    }
    201301}
Note: See TracChangeset for help on using the changeset viewer.