Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 28, 2008, 8:30:25 PM (16 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
Location:
code/branches/gui/src/core
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/CorePrereqs.h

    r1672 r1674  
    162162
    163163  // game states
    164   class BaseGameState;
    165164  class GameState;
    166165  class RootGameState;
  • code/branches/gui/src/core/GameState.cc

    r1672 r1674  
    3434
    3535#include "GameState.h"
    36 #include <cassert>
    3736#include "Debug.h"
    3837#include "Exception.h"
     
    359358        This method is not virtual! You cannot override it therefore.
    360359    */
    361     void GameState::tick(float dt, uint64_t time)
     360    void GameState::tick(const Clock& time)
    362361    {
    363362        this->operation_.running = true;
    364         this->ticked(dt, time);
     363        this->ticked(time);
    365364        this->operation_.running = false;
    366365    }
  • code/branches/gui/src/core/GameState.h

    r1672 r1674  
    4242#include <map>
    4343#include "util/Integers.h"
     44#include "Clock.h"
    4445
    4546namespace orxonox
     
    100101        virtual void enter() = 0;
    101102        virtual void leave() = 0;
    102         virtual void ticked(float dt, uint64_t time) = 0;
     103        virtual void ticked(const Clock& time) = 0;
    103104
    104105        GameState* getActiveChild() { return this->activeChild_; }
    105106
    106         void tickChild(float dt, uint64_t time) { if (this->getActiveChild()) this->getActiveChild()->tick(dt, time); }
     107        void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    107108
    108109    private:
     
    113114        void grandchildRemoved(GameState* grandchild);
    114115
    115         void tick(float dt, uint64_t time);
     116        void tick(const Clock& time);
    116117        void activate();
    117118        void deactivate();
  • code/branches/gui/src/core/RootGameState.cc

    r1673 r1674  
    2929#include "RootGameState.h"
    3030
    31 #include <OgreTimer.h>
    32 #include "util/Integers.h"
     31#include "Clock.h"
    3332#include "Debug.h"
    3433#include "Exception.h"
     
    9594            if (current)
    9695            {
    97                 //OrxAssert(dynamic_cast<GameState*>(current),
    98                 //    "RootGameState: There was a RootGameState in the subtree of Root");
    99                 //GameState* currentGS = static_cast<GameState*>(current);
    100                 //currentGS->makeTransition(this, request);
    10196                current->makeTransition(0, request);
    10297            }
     
    141136        gotoState(initialState);
    142137
    143         Ogre::Timer timer;
    144         uint64_t storedTime = 0;
    145         unsigned long lastTimersTime = 1;
    146         timer.reset();
     138        Clock clock;
    147139        while (this->activeChild_)
    148140        {
    149             // get current time
    150             unsigned long timersTime = timer.getMicroseconds();
    151             uint64_t realTime = storedTime + timersTime;
    152             float dt = (float)(timersTime - lastTimersTime)/1000000.0f;
    153             if (timersTime > 7000000)
    154             {
    155                 // Under worst condition, the ogre timer will overflow right after 7 seconds
    156                 storedTime += timersTime;
    157                 lastTimersTime = 0;
    158                 timer.reset();
    159             }
    160             else
    161             {
    162                 lastTimersTime = timersTime;
    163             }
     141            clock.capture();
    164142
    165             this->tick(dt, realTime);
     143            this->tick(clock);
    166144
    167145            if (this->stateRequest_ != "")
  • code/branches/gui/src/core/RootGameState.h

    r1672 r1674  
    3131
    3232#include "CorePrereqs.h"
    33 #include <OgrePrerequisites.h>
    3433#include "GameState.h"
    3534
     
    3837    class _CoreExport RootGameState : public GameState
    3938    {
    40         //friend class GameState;
    41 
    4239    public:
    4340        RootGameState(const std::string& name);
     
    4643        void requestState(const std::string& name);
    4744        void start();
    48 
    49     protected:
    50         //virtual void ticked(float dt) = 0;
    51         //virtual void enter() = 0;
    52         //virtual void leave() = 0;
    5345
    5446    private:
Note: See TracChangeset for help on using the changeset viewer.