[Orxonox-commit 112] r2807 - in branches/gui/src: core orxonox orxonox/gamestates

rgrieder at orxonox.net rgrieder at orxonox.net
Thu Mar 19 18:11:00 CET 2009


Author: rgrieder
Date: 2009-03-19 17:11:00 +0000 (Thu, 19 Mar 2009)
New Revision: 2807

Modified:
   branches/gui/src/core/Core.cc
   branches/gui/src/core/Core.h
   branches/gui/src/orxonox/Game.cc
   branches/gui/src/orxonox/Game.h
   branches/gui/src/orxonox/gamestates/GSClient.cc
Log:
Moved global game clock to Core. Use getGameClock() for a const reference to an object that can tell you the time since the game was started or since the last capture() (which is usually once a frame).

Modified: branches/gui/src/core/Core.cc
===================================================================
--- branches/gui/src/core/Core.cc	2009-03-19 17:07:18 UTC (rev 2806)
+++ branches/gui/src/core/Core.cc	2009-03-19 17:11:00 UTC (rev 2807)
@@ -93,17 +93,19 @@
     SetCommandLineArgument(settingsFile, "orxonox.ini");
     SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu");
 
-    /**
-        @brief Constructor: Registers the object and sets the config-values.
-        @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel()
-    */
-    Core::Core(int argc, char** argv)
+    Core::Core()
     {
         RegisterRootObject(Core);
 
         assert(Core::singletonRef_s == 0);
         Core::singletonRef_s = this;
+    }
 
+    Clock* Core::initialise(int argc, char** argv)
+    {
+        // Set up a basic clock to keep time
+        this->gameClock_ = new Clock();
+
         // Parse command line arguments fist
         try
         {
@@ -172,6 +174,9 @@
         Factory::createClassHierarchy();
         
         this->loaded_ = true;
+
+        // Return non const pointer to the game's clock for the main loop
+        return this->gameClock_;
     }
 
     /**
@@ -194,6 +199,8 @@
         // Also delete external console command that don't belong to an Identifier
         CommandExecutor::destroyExternalCommands();
 
+        delete this->gameClock_;
+
         assert(Core::singletonRef_s);
         Core::singletonRef_s = 0;
     }

Modified: branches/gui/src/core/Core.h
===================================================================
--- branches/gui/src/core/Core.h	2009-03-19 17:07:18 UTC (rev 2806)
+++ branches/gui/src/core/Core.h	2009-03-19 17:11:00 UTC (rev 2807)
@@ -60,11 +60,12 @@
     class _CoreExport Core : public OrxonoxClass
     {
         public:
-            Core(int argc, char** argv);
+            Core();
             ~Core();
+
+            Clock* initialise(int argc, char** argv);
             void setConfigValues();
 
-            bool isLoaded() { return this->loaded_; }
             void update(const Clock& time);
 
             static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
@@ -74,6 +75,8 @@
             static const std::string& getLanguage();
             static void  resetLanguage();
 
+            static const Clock& getGameClock() { return *getInstance().gameClock_; }
+
             static void tsetMediaPath(const std::string& path)
             { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); }
             static const boost::filesystem::path& getMediaPath();
@@ -119,6 +122,8 @@
             TclBind*              tclBind_;
             TclThreadManager*     tclThreadManager_;
 
+            Clock*                gameClock_;
+
             int softDebugLevel_;                            //!< The debug level
             int softDebugLevelConsole_;                     //!< The debug level for the console
             int softDebugLevelLogfile_;                     //!< The debug level for the logfile

Modified: branches/gui/src/orxonox/Game.cc
===================================================================
--- branches/gui/src/orxonox/Game.cc	2009-03-19 17:07:18 UTC (rev 2806)
+++ branches/gui/src/orxonox/Game.cc	2009-03-19 17:11:00 UTC (rev 2807)
@@ -88,12 +88,8 @@
 
         this->abort_ = false;
 
-        this->core_ = new orxonox::Core(argc, argv);
-        if (!this->core_->isLoaded())
-        {
-            COUT(0) << "Core was not fully loaded, probably an exception occurred during consruction. Aborting" << std::endl;
-            abort();
-        }
+        this->core_ = new orxonox::Core();
+        this->gameClock_ = this->core_->initialise(argc, argv);
     }
 
     /**
@@ -141,10 +137,6 @@
         root.addChild(&ioConsole);
         root.addChild(&dedicated);
 
-
-        // start global orxonox time
-        Clock clock;
-
         root.activate();
 
         // get initial state from command line
@@ -152,9 +144,9 @@
 
         while (!this->abort_)
         {
-            clock.capture();
+            this->gameClock_->capture();
 
-            root.tick(clock);
+            root.tick(*this->gameClock_);
 
             if (root.stateRequest_ != "")
                 root.gotoState(root.stateRequest_);

Modified: branches/gui/src/orxonox/Game.h
===================================================================
--- branches/gui/src/orxonox/Game.h	2009-03-19 17:07:18 UTC (rev 2806)
+++ branches/gui/src/orxonox/Game.h	2009-03-19 17:11:00 UTC (rev 2807)
@@ -60,6 +60,7 @@
         Game(Game&); // don't mess with singletons
 
         Core* core_;
+        Clock* gameClock_;
 
         bool abort_;
 

Modified: branches/gui/src/orxonox/gamestates/GSClient.cc
===================================================================
--- branches/gui/src/orxonox/gamestates/GSClient.cc	2009-03-19 17:07:18 UTC (rev 2806)
+++ branches/gui/src/orxonox/gamestates/GSClient.cc	2009-03-19 17:11:00 UTC (rev 2807)
@@ -60,8 +60,7 @@
 
         GSLevel::enter();
 
-        // TODO: Get Clock from Game or GameStateManager, but with 0 delta time
-        client_->update(Clock());
+        client_->update(Core::getGameClock());
     }
 
     void GSClient::leave()




More information about the Orxonox-commit mailing list