[Orxonox-commit 937] r5660 - in code/branches/resource2/src: core orxonox

rgrieder at orxonox.net rgrieder at orxonox.net
Tue Aug 18 12:06:41 CEST 2009


Author: rgrieder
Date: 2009-08-18 12:06:41 +0200 (Tue, 18 Aug 2009)
New Revision: 5660

Modified:
   code/branches/resource2/src/core/GraphicsManager.cc
   code/branches/resource2/src/core/Loader.cc
   code/branches/resource2/src/core/LuaState.cc
   code/branches/resource2/src/core/XMLFile.h
   code/branches/resource2/src/orxonox/LevelManager.cc
Log:
Added bLuaSupport_ to XMLFile so we can load the resource locations without lua. And therefore LuaState can access its init script via resources.
Also fixed a problem in the LevelManager with level loading.

Modified: code/branches/resource2/src/core/GraphicsManager.cc
===================================================================
--- code/branches/resource2/src/core/GraphicsManager.cc	2009-08-18 09:41:56 UTC (rev 5659)
+++ code/branches/resource2/src/core/GraphicsManager.cc	2009-08-18 10:06:41 UTC (rev 5660)
@@ -102,6 +102,7 @@
         Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getDataPathString(), "FileSystem", "dataRoot", false);
         // Load resources
         resources_.reset(new XMLFile("resources.oxr", "dataRoot"));
+        resources_->setLuaSupport(false);
         Loader::open(resources_.get());
 
         // Only for development runs
@@ -109,6 +110,7 @@
         {
             Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getExternalDataPathString(), "FileSystem", "externalDataRoot", false);
             extResources_.reset(new XMLFile("resources.oxr", "externalDataRoot"));
+            extResources_->setLuaSupport(false);
             Loader::open(extResources_.get());
         }
 

Modified: code/branches/resource2/src/core/Loader.cc
===================================================================
--- code/branches/resource2/src/core/Loader.cc	2009-08-18 09:41:56 UTC (rev 5659)
+++ code/branches/resource2/src/core/Loader.cc	2009-08-18 10:06:41 UTC (rev 5660)
@@ -121,11 +121,25 @@
 
         Loader::currentMask_s = file->getMask() * mask;
 
-        // Use the LuaState to replace the XML tags (calls our function)
-        scoped_ptr<LuaState> luaState(new LuaState());
-        luaState->setIncludeParser(&Loader::replaceLuaTags);
-        luaState->includeFile(file->getFilename(), file->getResourceGroup(), false);
-        //luaState->doString(luaInput);
+        std::string xmlInput;
+        if (file->getLuaSupport())
+        {
+            // Use the LuaState to replace the XML tags (calls our function)
+            scoped_ptr<LuaState> luaState(new LuaState());
+            luaState->setIncludeParser(&Loader::replaceLuaTags);
+            luaState->includeFile(file->getFilename(), file->getResourceGroup(), false);
+            xmlInput = luaState->getOutput().str();
+        }
+        else
+        {
+            shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename(), file->getResourceGroup());
+            if (info == NULL)
+            {
+                COUT(1) << "Error: Could not find XML file '" << file->getFilename() << "'." << std::endl;
+                return false;
+            }
+            xmlInput = Resource::open(file->getFilename(), file->getResourceGroup())->getAsString();
+        }
 
         try
         {
@@ -133,7 +147,7 @@
             COUT(3) << "Mask: " << Loader::currentMask_s << std::endl;
 
             ticpp::Document xmlfile(file->getFilename());
-            xmlfile.Parse(luaState->getOutput().str(), true);
+            xmlfile.Parse(xmlInput, true);
 
             ticpp::Element rootElement;
             rootElement.SetAttribute("name", "root");

Modified: code/branches/resource2/src/core/LuaState.cc
===================================================================
--- code/branches/resource2/src/core/LuaState.cc	2009-08-18 09:41:56 UTC (rev 5659)
+++ code/branches/resource2/src/core/LuaState.cc	2009-08-18 10:06:41 UTC (rev 5660)
@@ -78,8 +78,7 @@
         lua_setglobal(luaState_, "luaState");
 
         // Parse init script
-        // Note: We have to use a hard coded path because the script is required for the resource loading
-        this->doString("dofile(\"" + Core::getDataPathString() + "lua/LuaStateInit.lua\")");
+        this->doFile("LuaStateInit.lua");
     }
 
     LuaState::~LuaState()

Modified: code/branches/resource2/src/core/XMLFile.h
===================================================================
--- code/branches/resource2/src/core/XMLFile.h	2009-08-18 09:41:56 UTC (rev 5659)
+++ code/branches/resource2/src/core/XMLFile.h	2009-08-18 10:06:41 UTC (rev 5660)
@@ -49,14 +49,18 @@
                 , mask_(mask)
             { }
 
+            void setLuaSupport(bool val) { bLuaSupport_ = val; }
+
             const std::string& getFilename() const { return this->filename_; }
             const std::string& getResourceGroup() const { return this->group_; }
             const ClassTreeMask& getMask() const { return this->mask_; }
+            bool getLuaSupport() const { return this->bLuaSupport_; }
 
         private:
             std::string filename_;
             std::string group_;
             ClassTreeMask mask_;
+            bool bLuaSupport_;
     };
 }
 

Modified: code/branches/resource2/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/resource2/src/orxonox/LevelManager.cc	2009-08-18 09:41:56 UTC (rev 5659)
+++ code/branches/resource2/src/orxonox/LevelManager.cc	2009-08-18 10:06:41 UTC (rev 5660)
@@ -141,6 +141,10 @@
             if (it->find("old/") == 0)
                 it = availableLevels_.erase(it);
             else
+            {
+                size_t pos = it->find(".oxw");
+                *it = it->substr(0, pos);
                 ++it;
+            }
     }
 }




More information about the Orxonox-commit mailing list