Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 28, 2008, 8:30:25 PM (17 years ago)
Author:
rgrieder
Message:
  • Wrote Clock() class: It starts an internal clock when GSRoot starts and gets handed to all GameState ticks as reference. You can then either query the ticked time or the real time (for instance for statistical measurements)
  • general clean up in all the game states
File:
1 edited

Legend:

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

    r1672 r1674  
    3030#include "GSRoot.h"
    3131
    32 #include "util/SubString.h"
     32//#include "util/SubString.h"
    3333#include "core/Factory.h"
    3434#include "core/ConfigFileManager.h"
     
    3939#include "core/Exception.h"
    4040#include "core/TclBind.h"
    41 #include "core/Core.h"
    42 #include "core/CommandLine.h"
    4341#include "core/TclThreadManager.h"
    4442#include "GraphicsEngine.h"
    4543#include "Settings.h"
     44
     45#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     46#  ifndef WIN32_LEAN_AND_MEAN
     47#    define WIN32_LEAN_AND_MEAN
     48#  endif
     49#  include "windows.h"
     50
     51   //Get around Windows hackery
     52#  ifdef max
     53#    undef max
     54#  endif
     55#  ifdef min
     56#    undef min
     57#  endif
     58#endif
    4659
    4760namespace orxonox
     
    119132        graphicsEngine_->setup();       // creates ogre root and other essentials
    120133
     134        // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
     135        // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
     136        // the timer though).
     137        setThreadAffinity();
     138
    121139        // add console commands
    122140        FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
     
    138156    }
    139157
    140     void GSRoot::ticked(float dt, uint64_t time)
    141     {
    142         TclThreadManager::getInstance().tick(dt);
    143 
    144         this->tickChild(dt, time);
     158    void GSRoot::ticked(const Clock& time)
     159    {
     160        TclThreadManager::getInstance().tick(time.getDeltaTime());
     161
     162        this->tickChild(time);
     163    }
     164
     165    /**
     166    @note
     167        The code of this function has been copied from OGRE, an open source graphics engine.
     168            (Object-oriented Graphics Rendering Engine)
     169        For the latest info, see http://www.ogre3d.org/
     170
     171        Copyright (c) 2000-2008 Torus Knot Software Ltd
     172       
     173        OGRE is licensed under the LGPL. For more info, see ogre license info.
     174    */
     175    void GSRoot::setThreadAffinity()
     176    {
     177#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     178        // Get the current process core mask
     179            DWORD procMask;
     180            DWORD sysMask;
     181#if _MSC_VER >= 1400 && defined (_M_X64)
     182            GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
     183#else
     184            GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
     185#endif
     186
     187            // If procMask is 0, consider there is only one core available
     188            // (using 0 as procMask will cause an infinite loop below)
     189            if (procMask == 0)
     190                    procMask = 1;
     191
     192            // Find the lowest core that this process uses
     193        DWORD threadMask = 1;
     194            while ((threadMask & procMask) == 0)
     195                    threadMask <<= 1;
     196
     197            // Set affinity to the first core
     198            SetThreadAffinityMask(GetCurrentThread(), threadMask);
     199#endif
    145200    }
    146201}
Note: See TracChangeset for help on using the changeset viewer.