[Orxonox-commit 818] r3339 - in branches/resource/src: core orxonox orxonox/gamestates orxonox/gui

rgrieder at orxonox.net rgrieder at orxonox.net
Thu Jul 23 20:04:51 CEST 2009


Author: rgrieder
Date: 2009-07-23 20:04:51 +0200 (Thu, 23 Jul 2009)
New Revision: 3339

Modified:
   branches/resource/src/core/Loader.cc
   branches/resource/src/core/Loader.h
   branches/resource/src/orxonox/LevelManager.cc
   branches/resource/src/orxonox/LevelManager.h
   branches/resource/src/orxonox/gamestates/GSMainMenu.cc
   branches/resource/src/orxonox/gui/GUIManager.cc
   branches/resource/src/orxonox/gui/GUIManager.h
Log:
Moved GUIManager::getLevelList to LevelManager because the GUIManager has nothing to do with levels.
I also had to change the way the information flows: Instead of operation on the Lua state, you tell the LevelManager to compile the list and then get the elements one by one.
The reason for this change is simple: There is no way to know from which LuaState the call came (without making an ugly hack in Tolua itself).

Modified: branches/resource/src/core/Loader.cc
===================================================================
--- branches/resource/src/core/Loader.cc	2009-07-23 12:20:51 UTC (rev 3338)
+++ branches/resource/src/core/Loader.cc	2009-07-23 18:04:51 UTC (rev 3339)
@@ -29,12 +29,10 @@
 #include "Loader.h"
 
 #include <tinyxml/ticpp.h>
-#include <boost/filesystem.hpp>
 
 #include "util/Debug.h"
 #include "util/Exception.h"
 #include "BaseObject.h"
-#include "Core.h"
 #include "Iterator.h"
 #include "ObjectList.h"
 #include "LuaBind.h"
@@ -209,24 +207,4 @@
         Loader::unload(file, mask);
         return Loader::load(file, mask);
     }
-
-    std::vector<std::string> Loader::getLevelList()
-    {
-        std::vector<std::string> levelList;
-
-        boost::filesystem::directory_iterator file(Core::getMediaPathString() + "levels");
-        boost::filesystem::directory_iterator end;
-
-        while (file != end)
-        {
-            if (!boost::filesystem::is_directory(*file) && file->string()[file->string().length()-1] != '~')
-            {
-                std::string filename = file->path().leaf();
-                if (filename.length() > 4)
-                    levelList.push_back(filename.substr(0,filename.length()-4));
-            }
-            ++file;
-        }
-        return levelList;
-    }
 }

Modified: branches/resource/src/core/Loader.h
===================================================================
--- branches/resource/src/core/Loader.h	2009-07-23 12:20:51 UTC (rev 3338)
+++ branches/resource/src/core/Loader.h	2009-07-23 18:04:51 UTC (rev 3339)
@@ -55,7 +55,6 @@
             static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask());
 
             static ClassTreeMask currentMask_s;
-            static std::vector<std::string> getLevelList();
 
         private:
             static std::vector<std::pair<const XMLFile*, ClassTreeMask> > files_s;

Modified: branches/resource/src/orxonox/LevelManager.cc
===================================================================
--- branches/resource/src/orxonox/LevelManager.cc	2009-07-23 12:20:51 UTC (rev 3338)
+++ branches/resource/src/orxonox/LevelManager.cc	2009-07-23 18:04:51 UTC (rev 3339)
@@ -29,10 +29,12 @@
 #include "LevelManager.h"
 
 #include <map>
+#include <boost/filesystem.hpp>
 
 #include "core/CommandLine.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/CoreIncludes.h"
+#include "core/Loader.h"
 #include "PlayerManager.h"
 #include "objects/Level.h"
 #include "objects/infos/HumanPlayer.h"
@@ -119,8 +121,35 @@
         ModifyConfigValue(defaultLevelName_, set, levelName);
     }
 
-    const std::string& LevelManager::getDefaultLevel()
+    const std::string& LevelManager::getDefaultLevel() const
     {
         return defaultLevelName_;
     }
+
+    std::string LevelManager::getAvailableLevelListItem(unsigned int index) const
+    {
+        if (index >= availableLevels_.size())
+            return std::string();
+        else
+            return availableLevels_[index];
+    }
+
+    void LevelManager::compileAvailableLevelList()
+    {
+        availableLevels_.clear();
+
+        boost::filesystem::directory_iterator file(Core::getMediaPathString() + "levels");
+        boost::filesystem::directory_iterator end;
+
+        while (file != end)
+        {
+            if (!boost::filesystem::is_directory(*file) && file->string()[file->string().length()-1] != '~')
+            {
+                std::string filename = file->path().leaf();
+                if (filename.length() > 4)
+                    availableLevels_.push_back(filename.substr(0,filename.length()-4));
+            }
+            ++file;
+        }
+    }
 }

Modified: branches/resource/src/orxonox/LevelManager.h
===================================================================
--- branches/resource/src/orxonox/LevelManager.h	2009-07-23 12:20:51 UTC (rev 3338)
+++ branches/resource/src/orxonox/LevelManager.h	2009-07-23 18:04:51 UTC (rev 3339)
@@ -54,7 +54,9 @@
             Level* getActiveLevel();
 
             void setDefaultLevel(const std::string& levelName); //tolua_export
-            const std::string& getDefaultLevel(); //tolua_export
+            const std::string& getDefaultLevel() const; //tolua_export
+            void compileAvailableLevelList(); //tolua_export
+            std::string getAvailableLevelListItem(unsigned int index) const; //tolua_export
 
             static LevelManager* getInstancePtr() { return singletonRef_s; }
             static LevelManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
@@ -65,6 +67,7 @@
             void activateNextLevel();
 
             std::list<Level*> levels_s;
+            std::vector<std::string> availableLevels_;
 
             // config values
             std::string defaultLevelName_;

Modified: branches/resource/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- branches/resource/src/orxonox/gamestates/GSMainMenu.cc	2009-07-23 12:20:51 UTC (rev 3338)
+++ branches/resource/src/orxonox/gamestates/GSMainMenu.cc	2009-07-23 18:04:51 UTC (rev 3339)
@@ -66,7 +66,7 @@
         this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
 
         // show main menu
-        GUIManager::getInstance().showGUI("mainmenu_3");
+        GUIManager::getInstance().showGUI("mainmenu_4");
         GUIManager::getInstance().setCamera(this->camera_);
         GraphicsManager::getInstance().setCamera(this->camera_);
 

Modified: branches/resource/src/orxonox/gui/GUIManager.cc
===================================================================
--- branches/resource/src/orxonox/gui/GUIManager.cc	2009-07-23 12:20:51 UTC (rev 3338)
+++ branches/resource/src/orxonox/gui/GUIManager.cc	2009-07-23 18:04:51 UTC (rev 3339)
@@ -60,7 +60,6 @@
 #include "core/Clock.h"
 #include "ToluaBindCore.h"
 #include "ToluaBindOrxonox.h"
-#include "core/Loader.h"
 
 namespace orxonox
 {
@@ -87,6 +86,7 @@
     };
 
     static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
+
     GUIManager* GUIManager::singletonRef_s = 0;
 
     /**
@@ -156,7 +156,7 @@
     @brief
         Destructor of the GUIManager
 
-        Basically shuts down CEGUI and destroys the Lua engine and afterwards the interface to the Ogre engine.
+        Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules.
     */
     GUIManager::~GUIManager()
     {
@@ -173,32 +173,17 @@
     @brief
         Calls main Lua script
     @todo
-        Replace loadGUI.lua with loadGUI_2.lua after merging this back to trunk.
-        However CEGUI is able to execute a startup script. We could maybe put this call in this startup code.
-
         This function calls the main Lua script for our GUI.
 
         Additionally we set the datapath variable in Lua. This is needed so Lua can access the data used for the GUI.
     */
     void GUIManager::loadLuaCode()
     {
-        try
-        {
-            // set datapath for GUI data
-            lua_pushfstring(this->scriptModule_->getLuaState(), Core::getMediaPathString().c_str());
-            lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
-            // call main Lua script
-            this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");
-        }
-        catch (CEGUI::Exception& ex)
-        {
-#if CEGUI_VERSION_MINOR < 6
-            throw GeneralException(ex.getMessage().c_str());
-#else
-            throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
-                ex.getFileName().c_str(), ex.getName().c_str());
-#endif
-        }
+        // set datapath for GUI data
+        lua_pushfstring(this->scriptModule_->getLuaState(), Core::getMediaPathString().c_str());
+        lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
+        // call main Lua script
+        this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");
     }
 
     /**
@@ -218,27 +203,6 @@
     }
 
     /**
-
-    */
-    void GUIManager::getLevelList()
-    {
-        lua_State* L = this->scriptModule_->getLuaState();
-        lua_newtable(L);
-
-        std::vector<std::string> list = Loader::getLevelList();
-
-        int j = 1;
-        for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); i++)
-        {
-            lua_pushnumber(L,j);
-            lua_pushstring(L,i->c_str());
-            lua_settable(L,-3);
-            j++;
-        }
-        lua_setglobal(L, "levellist");
-    }
-
-    /**
     @brief
         Tells the GUIManager which SceneManager to use
     @param camera

Modified: branches/resource/src/orxonox/gui/GUIManager.h
===================================================================
--- branches/resource/src/orxonox/gui/GUIManager.h	2009-07-23 12:20:51 UTC (rev 3338)
+++ branches/resource/src/orxonox/gui/GUIManager.h	2009-07-23 18:04:51 UTC (rev 3339)
@@ -46,7 +46,6 @@
 #include "util/OgreForwardRefs.h"
 #include "core/input/InputHandler.h"
 
-// tolua_begin
 namespace orxonox
 {
     /**
@@ -60,12 +59,8 @@
         Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler.
         Those input events are then injected into CEGUI in Lua.
     */
-    class _OrxonoxExport GUIManager
-// tolua_end
-        : public InputHandler
-// tolua_begin
+    class _OrxonoxExport GUIManager : public InputHandler
     {
-// tolua_end
     public:
         GUIManager(Ogre::RenderWindow* renderWindow);
         ~GUIManager();
@@ -77,13 +72,11 @@
 
         void setCamera(Ogre::Camera* camera);
 
-        static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
+        static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
         static GUIManager* getInstancePtr() { return singletonRef_s; }
 
-        void getLevelList(); //tolua_export
-
     private:
-        GUIManager(const GUIManager& instance);                 //!< private constructor (this is a singleton class)
+        GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
 
         void loadLuaCode();
 
@@ -107,7 +100,7 @@
 
         static GUIManager*       singletonRef_s;    //!< Singleton reference to GUIManager
 
-    }; // tolua_export
-} // tolua_export
+    };
+}
 
 #endif /* _GUIManager_H__ */




More information about the Orxonox-commit mailing list