Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 6, 2009, 1:59:00 AM (15 years ago)
Author:
landauf
Message:

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r2797 r2896  
    3232#include "util/Exception.h"
    3333#include "util/Debug.h"
    34 #include "core/Core.h"
    35 #include "core/Factory.h"
    36 #include "core/ConfigValueIncludes.h"
    37 #include "core/CoreIncludes.h"
     34#include "core/Clock.h"
     35#include "core/Game.h"
     36#include "core/GameMode.h"
     37#include "core/CommandLine.h"
    3838#include "core/ConsoleCommand.h"
    39 #include "core/CommandLine.h"
    40 #include "core/Shell.h"
    41 #include "core/TclBind.h"
    42 #include "core/TclThreadManager.h"
    43 #include "core/LuaBind.h"
     39#include "tools/TimeFactorListener.h"
    4440#include "tools/Timer.h"
    4541#include "objects/Tickable.h"
    4642
    47 #ifdef ORXONOX_PLATFORM_WINDOWS
    48 #  ifndef WIN32_LEAN_AND_MEAN
    49 #    define WIN32_LEAN_AND_MEAN
    50 #  endif
    51 #  ifndef NOMINMAX
    52 #    define NOMINMAX // required to stop windows.h screwing up std::min definition
    53 #  endif
    54 #  include "windows.h"
    55 #endif
    56 
    5743namespace orxonox
    5844{
    59     SetCommandLineArgument(limitToCPU, 1).information("0: off | #cpu");
    60 
    61     GSRoot::GSRoot()
    62         : RootGameState("root")
     45    AddGameState(GSRoot, "root");
     46    SetCommandLineSwitch(console);
     47    // Shortcuts for easy direct loading
     48    SetCommandLineSwitch(server);
     49    SetCommandLineSwitch(client);
     50    SetCommandLineSwitch(dedicated);
     51    SetCommandLineSwitch(standalone);
     52
     53    GSRoot::GSRoot(const std::string& name)
     54        : GameState(name)
    6355        , timeFactor_(1.0f)
    6456        , bPaused_(false)
    6557        , timeFactorPauseBackup_(1.0f)
    66         , tclBind_(0)
    67         , tclThreadManager_(0)
    68         , shell_(0)
    69     {
    70         RegisterRootObject(GSRoot);
    71         setConfigValues();
    72 
     58    {
    7359        this->ccSetTimeFactor_ = 0;
    7460        this->ccPause_ = 0;
     
    7965    }
    8066
    81     void GSRoot::setConfigValues()
    82     {
    83         SetConfigValue(statisticsRefreshCycle_, 250000)
    84             .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    85         SetConfigValue(statisticsAvgLength_, 1000000)
    86             .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    87     }
    88 
    89     void GSRoot::enter()
    90     {
    91         // creates the class hierarchy for all classes with factories
    92         Factory::createClassHierarchy();
    93 
     67    void GSRoot::activate()
     68    {
    9469        // reset game speed to normal
    95         timeFactor_ = 1.0f;
    96 
    97         // reset frame counter
    98         this->statisticsStartTime_ = 0;
    99         this->statisticsTickTimes_.clear();
    100         this->periodTickTime_ = 0;
    101         this->avgFPS_ = 0.0f;
    102         this->avgTickTime_ = 0.0f;
    103 
    104         // Create the lua interface
    105         this->luaBind_ = new LuaBind();
    106 
    107         // initialise TCL
    108         this->tclBind_ = new TclBind(Core::getMediaPathString());
    109         this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
    110 
    111         // create a shell
    112         this->shell_ = new Shell();
    113 
    114         // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
    115         // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
    116         // the timer though).
    117         int limitToCPU = CommandLine::getValue("limitToCPU");
    118         if (limitToCPU > 0)
    119             setThreadAffinity((unsigned int)(limitToCPU - 1));
    120 
    121         {
    122             // add console commands
    123             FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame);
    124             functor->setObject(this);
    125             this->ccExit_ = createConsoleCommand(functor, "exit");
    126             CommandExecutor::addConsoleCommandShortcut(this->ccExit_);
    127         }
    128 
    129         {
    130             // add console commands
    131             FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
    132             functor->setObject(this);
    133             this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
    134             CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
    135         }
     70        this->timeFactor_ = 1.0f;
    13671
    13772        {
     
    15085            CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
    15186        }
    152     }
    153 
    154     void GSRoot::leave()
    155     {
    156         // destroy console commands
    157         delete this->ccExit_;
    158         delete this->ccSelectGameState_;
    159 
    160         delete this->shell_;
    161         delete this->tclThreadManager_;
    162         delete this->tclBind_;
    163 
    164         delete this->luaBind_;
    165 
     87
     88        // Load level directly?
     89        bool loadLevel = false;
     90        if (CommandLine::getValue("standalone").getBool())
     91        {
     92            Game::getInstance().requestStates("graphics, standalone, level");
     93            loadLevel = true;
     94        }
     95        if (CommandLine::getValue("server").getBool())
     96        {
     97            Game::getInstance().requestStates("graphics, server, level");
     98            loadLevel = true;
     99        }
     100        if (CommandLine::getValue("client").getBool())
     101        {
     102            Game::getInstance().requestStates("graphics, client, level");
     103            loadLevel = true;
     104        }
     105        if (CommandLine::getValue("dedicated").getBool())
     106        {
     107            Game::getInstance().requestStates("dedicated, level");
     108            loadLevel = true;
     109        }
     110       
     111        // Determine where to start otherwise
     112        if (!loadLevel && !CommandLine::getValue("console").getBool())
     113        {
     114            // Also load graphics
     115            Game::getInstance().requestState("graphics");
     116        }
     117    }
     118
     119    void GSRoot::deactivate()
     120    {
    166121        if (this->ccSetTimeFactor_)
    167122        {
     
    177132    }
    178133
    179     void GSRoot::ticked(const Clock& time)
    180     {
     134    void GSRoot::update(const Clock& time)
     135    {
     136        if (this->getActivity().topState)
     137        {
     138            // This state can not 'survive' on its own.
     139            // Load a user interface therefore
     140            Game::getInstance().requestState("ioConsole");
     141        }
     142
    181143        uint64_t timeBeforeTick = time.getRealMicroseconds();
    182 
    183         TclThreadManager::getInstance().tick(time.getDeltaTime());
    184144
    185145        for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it)
     
    200160        uint64_t timeAfterTick = time.getRealMicroseconds();
    201161
    202         // STATISTICS
    203         assert(timeAfterTick - timeBeforeTick >= 0 );
    204         statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick};
    205         statisticsTickTimes_.push_back(tickInfo);
    206         assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength);
    207         this->periodTickTime_ += tickInfo.tickLength;
    208 
    209         // Ticks GSGraphics or GSDedicated
    210         this->tickChild(time);
    211 
    212         if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
    213         {
    214             std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    215             assert(it != this->statisticsTickTimes_.end());
    216             int64_t lastTime = timeAfterTick - statisticsAvgLength_;
    217             if ((int64_t)it->tickTime < lastTime)
    218             {
    219                 do
    220                 {
    221                     assert(this->periodTickTime_ > it->tickLength);
    222                     this->periodTickTime_ -= it->tickLength;
    223                     ++it;
    224                     assert(it != this->statisticsTickTimes_.end());
    225                 } while ((int64_t)it->tickTime < lastTime);
    226                 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
    227             }
    228 
    229             uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
    230             this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
    231             this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
    232 
    233             statisticsStartTime_ = timeAfterTick;
    234         }
    235 
    236     }
    237 
    238     /**
    239     @note
    240         The code of this function has been copied and adjusted from OGRE, an open source graphics engine.
    241             (Object-oriented Graphics Rendering Engine)
    242         For the latest info, see http://www.ogre3d.org/
    243 
    244         Copyright (c) 2000-2008 Torus Knot Software Ltd
    245 
    246         OGRE is licensed under the LGPL. For more info, see OGRE license.
    247     */
    248     void GSRoot::setThreadAffinity(unsigned int limitToCPU)
    249     {
    250 #ifdef ORXONOX_PLATFORM_WINDOWS
    251         // Get the current process core mask
    252         DWORD procMask;
    253         DWORD sysMask;
    254 #  if _MSC_VER >= 1400 && defined (_M_X64)
    255         GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
    256 #  else
    257         GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
    258 #  endif
    259 
    260         // If procMask is 0, consider there is only one core available
    261         // (using 0 as procMask will cause an infinite loop below)
    262         if (procMask == 0)
    263             procMask = 1;
    264 
    265         // if the core specified with limitToCPU is not available, take the lowest one
    266         if (!(procMask & (1 << limitToCPU)))
    267             limitToCPU = 0;
    268 
    269         // Find the lowest core that this process uses and limitToCPU suggests
    270         DWORD threadMask = 1;
    271         while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
    272             threadMask <<= 1;
    273 
    274         // Set affinity to the first core
    275         SetThreadAffinityMask(GetCurrentThread(), threadMask);
    276 #endif
     162        // Also add our tick time
     163        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    277164    }
    278165
     
    283170    void GSRoot::setTimeFactor(float factor)
    284171    {
    285         if (Core::isMaster())
     172        if (GameMode::isMaster())
    286173        {
    287174            if (!this->bPaused_)
     
    301188    void GSRoot::pause()
    302189    {
    303         if (Core::isMaster())
     190        if (GameMode::isMaster())
    304191        {
    305192            if (!this->bPaused_)
     
    316203        }
    317204    }
    318 
    319     ////////////////////////
    320     // TimeFactorListener //
    321     ////////////////////////
    322     float TimeFactorListener::timefactor_s = 1.0f;
    323 
    324     TimeFactorListener::TimeFactorListener()
    325     {
    326         RegisterRootObject(TimeFactorListener);
    327     }
    328205}
Note: See TracChangeset for help on using the changeset viewer.