[Orxonox-commit 412] r2996 - in branches/netp3/src: core orxonox/gamestates

rgrieder at orxonox.net rgrieder at orxonox.net
Wed May 20 16:13:26 CEST 2009


Author: rgrieder
Date: 2009-05-20 16:13:26 +0200 (Wed, 20 May 2009)
New Revision: 2996

Modified:
   branches/netp3/src/core/Game.cc
   branches/netp3/src/core/Game.h
   branches/netp3/src/core/GameState.cc
   branches/netp3/src/core/GameState.h
   branches/netp3/src/orxonox/gamestates/GSGraphics.cc
   branches/netp3/src/orxonox/gamestates/GSGraphics.h
   branches/netp3/src/orxonox/gamestates/GSRoot.cc
   branches/netp3/src/orxonox/gamestates/GSRoot.h
Log:
Fixed tick-time issue: Not all tick times were being taken into account.
As of now, only GSRoot and GSGraphics manage the tick times themselves (marked with "AddGameState(GSRoot, "root", false)")

Modified: branches/netp3/src/core/Game.cc
===================================================================
--- branches/netp3/src/core/Game.cc	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/core/Game.cc	2009-05-20 14:13:26 UTC (rev 2996)
@@ -167,8 +167,18 @@
             this->core_->update(*this->gameClock_);
             for (std::vector<GameState*>::const_iterator it = this->activeStates_.begin();
                 it != this->activeStates_.end(); ++it)
+            {
+                // Add tick time for most of the states
+                uint64_t timeBeforeTick;
+                if ((*it)->getCountTickTime())
+                    timeBeforeTick = this->gameClock_->getRealMicroseconds();
+                
                 (*it)->update(*this->gameClock_);
 
+                if ((*it)->getCountTickTime())
+                    this->addTickTime(this->gameClock_->getRealMicroseconds() - timeBeforeTick);
+            }
+
             // STATISTICS
             if (this->periodTime_ > statisticsRefreshCycle_)
             {

Modified: branches/netp3/src/core/Game.h
===================================================================
--- branches/netp3/src/core/Game.h	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/core/Game.h	2009-05-20 14:13:26 UTC (rev 2996)
@@ -42,8 +42,13 @@
 #include <vector>
 #include "OrxonoxClass.h"
 
-#define AddGameState(classname, name) \
-    static bool MACRO_CONCATENATE(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(name))
+/**
+ at def
+    Adds a new GameState to the Game. The second parameter is the name as string
+    and every following paramter is a constructor argument (which is usually non existent)
+*/
+#define AddGameState(classname, ...) \
+    static bool MACRO_CONCATENATE(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(__VA_ARGS__))
 
 namespace orxonox
 {

Modified: branches/netp3/src/core/GameState.cc
===================================================================
--- branches/netp3/src/core/GameState.cc	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/core/GameState.cc	2009-05-20 14:13:26 UTC (rev 2996)
@@ -44,8 +44,9 @@
     @brief
         Constructor only initialises variables and sets the name permanently.
     */
-    GameState::GameState(const std::string& name)
+    GameState::GameState(const std::string& name, bool countTickTime)
         : name_(name)
+        , bCountTickTime_(countTickTime)
         , parent_(0)
     {
         this->activity_.activating   = false;

Modified: branches/netp3/src/core/GameState.h
===================================================================
--- branches/netp3/src/core/GameState.h	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/core/GameState.h	2009-05-20 14:13:26 UTC (rev 2996)
@@ -77,13 +77,15 @@
         };
 
     public:
-        GameState(const std::string& name);
+        GameState(const std::string& name, bool countTicktime = true);
         virtual ~GameState();
 
         const std::string& getName() const { return name_; }
-        State getActivity() const    { return this->activity_; }
-        GameState* getParent() const       { return this->parent_; }
+        State getActivity()          const { return this->activity_; }
+        GameState* getParent()       const { return this->parent_; }
 
+        bool getCountTickTime()      const { return this->bCountTickTime_; }
+
         void addChild(GameState* state);
         void removeChild(GameState* state);
 
@@ -101,6 +103,7 @@
 
         const std::string                        name_;
         State                                    activity_;
+        const bool                               bCountTickTime_;
         GameState*                               parent_;
         std::map<std::string, GameState*>        children_;
     };

Modified: branches/netp3/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- branches/netp3/src/orxonox/gamestates/GSGraphics.cc	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/orxonox/gamestates/GSGraphics.cc	2009-05-20 14:13:26 UTC (rev 2996)
@@ -56,10 +56,10 @@
 
 namespace orxonox
 {
-    AddGameState(GSGraphics, "graphics");
+    AddGameState(GSGraphics, "graphics", false);
 
-    GSGraphics::GSGraphics(const std::string& name)
-        : GameState(name)
+    GSGraphics::GSGraphics(const std::string& name, bool countTickTime)
+        : GameState(name, countTickTime)
         , inputManager_(0)
         , console_(0)
         , guiManager_(0)
@@ -212,15 +212,16 @@
 
         uint64_t timeBeforeTick = time.getRealMicroseconds();
 
-        this->inputManager_->update(time);        // tick console
+        this->inputManager_->update(time);
         this->console_->update(time);
-        this->guiManager_->update(time);
 
         uint64_t timeAfterTick = time.getRealMicroseconds();
 
         // Also add our tick time
         Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
 
+        // Process gui events
+        this->guiManager_->update(time);
         // Render
         this->graphicsManager_->update(time);
     }

Modified: branches/netp3/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- branches/netp3/src/orxonox/gamestates/GSGraphics.h	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/orxonox/gamestates/GSGraphics.h	2009-05-20 14:13:26 UTC (rev 2996)
@@ -50,7 +50,7 @@
     class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
     {
     public:
-        GSGraphics(const std::string& name);
+        GSGraphics(const std::string& name, bool countTickTime);
         ~GSGraphics();
         void setConfigValues();
 

Modified: branches/netp3/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- branches/netp3/src/orxonox/gamestates/GSRoot.cc	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/orxonox/gamestates/GSRoot.cc	2009-05-20 14:13:26 UTC (rev 2996)
@@ -42,7 +42,7 @@
 
 namespace orxonox
 {
-    AddGameState(GSRoot, "root");
+    AddGameState(GSRoot, "root", false);
     SetCommandLineSwitch(console);
     // Shortcuts for easy direct loading
     SetCommandLineSwitch(server);
@@ -50,8 +50,8 @@
     SetCommandLineSwitch(dedicated);
     SetCommandLineSwitch(standalone);
 
-    GSRoot::GSRoot(const std::string& name)
-        : GameState(name)
+    GSRoot::GSRoot(const std::string& name, bool countTickTime)
+        : GameState(name, countTickTime)
         , timeFactor_(1.0f)
         , bPaused_(false)
         , timeFactorPauseBackup_(1.0f)

Modified: branches/netp3/src/orxonox/gamestates/GSRoot.h
===================================================================
--- branches/netp3/src/orxonox/gamestates/GSRoot.h	2009-05-20 14:10:02 UTC (rev 2995)
+++ branches/netp3/src/orxonox/gamestates/GSRoot.h	2009-05-20 14:13:26 UTC (rev 2996)
@@ -38,7 +38,7 @@
     class _OrxonoxExport GSRoot : public GameState
     {
     public:
-        GSRoot(const std::string& name);
+        GSRoot(const std::string& name, bool countTickTime);
         ~GSRoot();
 
         void activate();




More information about the Orxonox-commit mailing list