[Orxonox-commit 459] r3036 - in trunk/src: core orxonox/gamestates

bknecht at orxonox.net bknecht at orxonox.net
Sun May 24 02:39:16 CEST 2009


Author: bknecht
Date: 2009-05-24 02:39:16 +0200 (Sun, 24 May 2009)
New Revision: 3036

Modified:
   trunk/src/core/CMakeLists.txt
   trunk/src/core/Game.cc
   trunk/src/core/Game.h
   trunk/src/orxonox/gamestates/GSLevel.cc
Log:
we do now save what level you chose last time and will preselect it for you on restart ;-). Of course you can still use --level or -l to choose your level in the old way.

Modified: trunk/src/core/CMakeLists.txt
===================================================================
--- trunk/src/core/CMakeLists.txt	2009-05-23 22:36:48 UTC (rev 3035)
+++ trunk/src/core/CMakeLists.txt	2009-05-24 00:39:16 UTC (rev 3036)
@@ -66,7 +66,7 @@
 SET(CORE_FILES ${CORE_SRC_FILES} ${CORE_HDR_FILES})
 
 GENERATE_SOURCE_GROUPS(${CORE_FILES})
-GENERATE_TOLUA_BINDINGS(Core CORE_FILES INPUTFILES LuaBind.h CommandExecutor.h)
+GENERATE_TOLUA_BINDINGS(Core CORE_FILES INPUTFILES LuaBind.h CommandExecutor.h Game.h)
 
 ADD_LIBRARY(core SHARED ${CORE_FILES})
 

Modified: trunk/src/core/Game.cc
===================================================================
--- trunk/src/core/Game.cc	2009-05-23 22:36:48 UTC (rev 3035)
+++ trunk/src/core/Game.cc	2009-05-24 00:39:16 UTC (rev 3036)
@@ -121,8 +121,25 @@
             .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
         SetConfigValue(statisticsAvgLength_, 1000000)
             .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
+        SetConfigValue(levelName_, "presentation_dm.oxw")
+            .description("Sets the preselection of the level in the main menu.");
     }
 
+    void Game::setLevel(std::string levelName)
+    {
+        ModifyConfigValue(levelName_, set, levelName);
+    }
+
+    const std::string& Game::getLevel()
+    {
+        std::string levelName;
+        CommandLine::getValue("level", &levelName);
+        if (levelName == "")
+            return levelName_;
+        else
+            return levelName;
+    }
+
     /**
     @brief
         Main loop of the orxonox game.

Modified: trunk/src/core/Game.h
===================================================================
--- trunk/src/core/Game.h	2009-05-23 22:36:48 UTC (rev 3035)
+++ trunk/src/core/Game.h	2009-05-24 00:39:16 UTC (rev 3036)
@@ -45,14 +45,19 @@
 #define AddGameState(classname, name) \
     static bool MACRO_CONCATENATE(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(name))
 
+// tolua_begin
 namespace orxonox
 {
     /**
     @brief
         Main class responsible for running the game.
     */
-    class _CoreExport Game : public OrxonoxClass
+    class _CoreExport Game
+    // tolua_end
+        : public OrxonoxClass
+    // tolua_begin
     {
+    //tolua_end
     public:
         Game(int argc, char** argv);
         ~Game();
@@ -77,8 +82,11 @@
 
         static bool addGameState(GameState* state);
         static void destroyStates();
-        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
+        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; } //tolua_export
 
+        void setLevel(std::string levelName); //tolua_export
+        const std::string& getLevel(); //tolua_export
+
     private:
         struct statisticsTickInfo
         {
@@ -113,10 +121,12 @@
         // config values
         unsigned int                    statisticsRefreshCycle_;
         unsigned int                    statisticsAvgLength_;
+        std::string                     levelName_;
 
         static std::map<std::string, GameState*> allStates_s;
         static Game* singletonRef_s;        //!< Pointer to the Singleton
+        // tolua_begin
     };
 }
-
+//tolua_end
 #endif /* _Game_H__ */

Modified: trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSLevel.cc	2009-05-23 22:36:48 UTC (rev 3035)
+++ trunk/src/orxonox/gamestates/GSLevel.cc	2009-05-24 00:39:16 UTC (rev 3036)
@@ -57,9 +57,8 @@
 {
     AddGameState(GSLevel, "level");
 
-    SetCommandLineArgument(level, "presentation_dm.oxw").shortcut("l");
+    SetCommandLineArgument(level, "").shortcut("l");
     SetConsoleCommand(GSLevel, showIngameGUI, true);
-    SetConsoleCommand(GSLevel, setLevel, true);
 
     XMLFile* GSLevel::startFile_s = NULL;
 
@@ -253,20 +252,14 @@
         // call the loader
         COUT(0) << "Loading level..." << std::endl;
         std::string levelName;
-        if (!startFile_s)
-        {
-            CommandLine::getValue("level", &levelName);
+        CommandLine::getValue("level", &levelName);
+        if (levelName == "")
+            startFile_s = new XMLFile(Core::getMediaPathString() + "levels" + '/' + Game::getInstance().getLevel());
+        else
             startFile_s = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
-        }
         Loader::open(startFile_s);
     }
 
-    void GSLevel::setLevel(std::string levelName)
-    {
-        delete GSLevel::startFile_s;
-        GSLevel::startFile_s = new XMLFile(Core::getMediaPathString() + "levels" + '/' + levelName);
-    }
-
     void GSLevel::unloadLevel()
     {
         //////////////////////////////////////////////////////////////////////////////////////////




More information about the Orxonox-commit mailing list