[Orxonox-commit 1686] r6404 - in code/branches/presentation2: data data/lua src/libraries/core src/orxonox

rgrieder at orxonox.net rgrieder at orxonox.net
Wed Dec 23 19:44:50 CET 2009


Author: rgrieder
Date: 2009-12-23 19:44:49 +0100 (Wed, 23 Dec 2009)
New Revision: 6404

Added:
   code/branches/presentation2/data/DefaultResources.oxr
Removed:
   code/branches/presentation2/data/resources.oxr
Modified:
   code/branches/presentation2/data/DataInstallScript.cmake
   code/branches/presentation2/data/lua/LuaStateInit.lua
   code/branches/presentation2/src/libraries/core/GUIManager.cc
   code/branches/presentation2/src/libraries/core/GraphicsManager.cc
   code/branches/presentation2/src/libraries/core/Loader.cc
   code/branches/presentation2/src/libraries/core/LuaState.cc
   code/branches/presentation2/src/libraries/core/LuaState.h
   code/branches/presentation2/src/libraries/core/Resource.cc
   code/branches/presentation2/src/libraries/core/Resource.h
   code/branches/presentation2/src/libraries/core/XMLFile.h
   code/branches/presentation2/src/orxonox/LevelManager.cc
Log:
Simplified our resource system a bit by working with a single resource group on the user end.
However you can still declare resource groups for separate loading. But accessing the files will always look in all groups.

Modified: code/branches/presentation2/data/DataInstallScript.cmake
===================================================================
--- code/branches/presentation2/data/DataInstallScript.cmake	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/data/DataInstallScript.cmake	2009-12-23 18:44:49 UTC (rev 6404)
@@ -28,10 +28,10 @@
  #
 
 # Write some comment
-FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr "\n\n\n <!-- ---------------------------------------- -->")
-FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr     "\n <!-- Content from the external data directory -->")
-FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr     "\n <!-- ---------------------------------------- -->\n\n")
+FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr "\n\n\n <!-- ---------------------------------------- -->")
+FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr     "\n <!-- Content from the external data directory -->")
+FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr     "\n <!-- ---------------------------------------- -->\n\n")
 
 # Append the external file
 FILE(READ   @EXTERNAL_DATA_DIRECTORY@/resources.oxr _external_file)
-FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr ${_external_file})
+FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr ${_external_file})

Copied: code/branches/presentation2/data/DefaultResources.oxr (from rev 6390, code/branches/presentation2/data/resources.oxr)
===================================================================
--- code/branches/presentation2/data/DefaultResources.oxr	                        (rev 0)
+++ code/branches/presentation2/data/DefaultResources.oxr	2009-12-23 18:44:49 UTC (rev 6404)
@@ -0,0 +1,14 @@
+<ResourceCollection resourceGroup = "General" >
+    <ResourceLocation path = "levels" />
+    <ResourceLocation path = "lua" />
+    <ResourceLocation path = "overlays" />
+    <ResourceLocation path = "particle" />
+    <ResourceLocation path = "tcl" />
+</ResourceCollection>
+
+<ResourceCollection resourceGroup = "GUI" >
+    <ResourceLocation path = "gui/configs" />
+    <ResourceLocation path = "gui/layouts" />
+    <ResourceLocation path = "gui/schemes" />
+    <ResourceLocation path = "gui/scripts" />
+</ResourceCollection>

Modified: code/branches/presentation2/data/lua/LuaStateInit.lua
===================================================================
--- code/branches/presentation2/data/lua/LuaStateInit.lua	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/data/lua/LuaStateInit.lua	2009-12-23 18:44:49 UTC (rev 6404)
@@ -14,42 +14,28 @@
 end
 
 -- Redirect dofile in order to load with the resource manager
--- Note: The function does not behave exactly like LuaState::doFile because the
---       default argument here for the group is not "General" but
---       "NoResourceGroupProvided". This resolves to the resource group used to
---       do the current file.
-doFile = function(filename, resourceGroup)
-  local bSearchOtherPaths = (resourceGroup == nil) or false
-  resourceGroup = resourceGroup or "NoResourceGroupProvided"
-  luaState:doFile(filename, resourceGroup, bSearchOtherPaths)
+doFile = function(filename)
+  luaState:doFile(filename)
   -- Required because the C++ function cannot return whatever might be on the stack
-  return LuaStateReturnValue
+  return LuaStateReturnValue -- C-injected global variable
 end
 original_dofile = dofile
 dofile = doFile
 
 -- Create includeFile function that preparses the file according
 -- to a function provided to the LuaState constructor (in C++)
--- Note: See the same notes as for doFile
-include = function(filename, resourceGroup)
-  local bSearchOtherPaths = (resourceGroup == nil) or false
-  resourceGroup = resourceGroup or "NoResourceGroupProvided"
-  luaState:includeFile(filename, resourceGroup, bSearchOtherPaths)
+include = function(filename)
+  luaState:includeFile(filename)
   -- Required because the C++ function cannot return whatever might be on the stack
-  return LuaStateReturnValue
+  return LuaStateReturnValue -- C-injected global variable
 end
 
 -- Replace require function with almost similar behaviour
--- The difference is that you need to provide a resource group
--- Default value there is the current one (if present) or else "General"
--- But the loaded modules are then stored with only with the name (where name has no .lua extension)
--- CAUTION: That also means that you need to take care of conflicting filenames among groups
--- Furthermore the moduleName parameters is appended with the .lua extension when looking for the file
+-- The loaded modules are then stored with their names (where name has no .lua extension)
+-- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file
 old_require = require
-require = function(moduleName, resourceGroup)
-  local bSearchOtherPaths = (resourceGroup == nil) or false
-  resourceGroup = resourceGroup or "NoResourceGroupProvided"
-  if not luaState:fileExists(moduleName .. ".lua", resourceGroup, bSearchOtherPaths) then
+require = function(moduleName)
+  if not luaState:fileExists(moduleName .. ".lua") then
     return nil
   end
   if not _LOADED then
@@ -59,7 +45,7 @@
     -- save old value
     _REQUIREDNAME_OLD = _REQUIREDNAME
     _REQUIREDNAME = moduleName
-    luaState:doFile(moduleName .. ".lua", resourceGroup, bSearchOtherPaths)
+    luaState:doFile(moduleName .. ".lua")
     _LOADED[moduleName] = LuaStateReturnValue or true
     -- restore old value
     _REQUIREDNAME = _REQUIREDNAME_OLD

Deleted: code/branches/presentation2/data/resources.oxr
===================================================================
--- code/branches/presentation2/data/resources.oxr	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/data/resources.oxr	2009-12-23 18:44:49 UTC (rev 6404)
@@ -1,14 +0,0 @@
-<ResourceCollection resourceGroup = "General" >
-    <ResourceLocation path = "levels" />
-    <ResourceLocation path = "lua" />
-    <ResourceLocation path = "overlays" />
-    <ResourceLocation path = "particle" />
-    <ResourceLocation path = "tcl" />
-</ResourceCollection>
-
-<ResourceCollection resourceGroup = "GUI" >
-    <ResourceLocation path = "gui/configs" />
-    <ResourceLocation path = "gui/layouts" />
-    <ResourceLocation path = "gui/schemes" />
-    <ResourceLocation path = "gui/scripts" />
-</ResourceCollection>

Modified: code/branches/presentation2/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/GUIManager.cc	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/GUIManager.cc	2009-12-23 18:44:49 UTC (rev 6404)
@@ -124,7 +124,7 @@
 
         // setup scripting
         luaState_.reset(new LuaState());
-        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
+        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua");
         // This is necessary to ensure that input events also use the right resource info when triggering lua functions
         luaState_->setDefaultResourceInfo(this->rootFileInfo_);
         scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState()));
@@ -141,7 +141,7 @@
         guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
 
         // Initialise the basic Lua code
-        this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
+        this->luaState_->doFile("InitialiseGUI.lua");
 
         // Align CEGUI mouse with OIS mouse
         guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);

Modified: code/branches/presentation2/src/libraries/core/GraphicsManager.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/GraphicsManager.cc	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/GraphicsManager.cc	2009-12-23 18:44:49 UTC (rev 6404)
@@ -99,17 +99,17 @@
         this->loadOgreRoot();
 
         // At first, add the root paths of the data directories as resource locations
-        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getDataPathString(), "FileSystem", "dataRoot", false);
+        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getDataPathString(), "FileSystem");
         // Load resources
-        resources_.reset(new XMLFile("resources.oxr", "dataRoot"));
+        resources_.reset(new XMLFile("DefaultResources.oxr"));
         resources_->setLuaSupport(false);
         Loader::open(resources_.get());
 
         // Only for development runs
         if (PathConfig::isDevelopmentRun())
         {
-            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem", "externalDataRoot", false);
-            extResources_.reset(new XMLFile("resources.oxr", "externalDataRoot"));
+            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem");
+            extResources_.reset(new XMLFile("resources.oxr"));
             extResources_->setLuaSupport(false);
             Loader::open(extResources_.get());
         }
@@ -394,22 +394,33 @@
         Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
     {
         int orxonoxLevel;
-        switch (lml)
+        std::string introduction;
+        // Do not show caught OGRE exceptions in front
+        if (message.find("OGRE_EXCEPTION"))
         {
-        case Ogre::LML_TRIVIAL:
-            orxonoxLevel = this->ogreLogLevelTrivial_;
-            break;
-        case Ogre::LML_NORMAL:
-            orxonoxLevel = this->ogreLogLevelNormal_;
-            break;
-        case Ogre::LML_CRITICAL:
-            orxonoxLevel = this->ogreLogLevelCritical_;
-            break;
-        default:
-            orxonoxLevel = 0;
+            orxonoxLevel = OutputLevel::Debug;
+            introduction = "Ogre, caught exception: ";
         }
+        else
+        {
+            switch (lml)
+            {
+            case Ogre::LML_TRIVIAL:
+                orxonoxLevel = this->ogreLogLevelTrivial_;
+                break;
+            case Ogre::LML_NORMAL:
+                orxonoxLevel = this->ogreLogLevelNormal_;
+                break;
+            case Ogre::LML_CRITICAL:
+                orxonoxLevel = this->ogreLogLevelCritical_;
+                break;
+            default:
+                orxonoxLevel = 0;
+            }
+            introduction = "Ogre: ";
+        }
         OutputHandler::getOutStream(orxonoxLevel)
-            << "Ogre: " << message << std::endl;
+            << introduction << message << std::endl;
     }
 
     size_t GraphicsManager::getRenderWindowHandle()

Modified: code/branches/presentation2/src/libraries/core/Loader.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/Loader.cc	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/Loader.cc	2009-12-23 18:44:49 UTC (rev 6404)
@@ -127,18 +127,18 @@
             // 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->includeFile(file->getFilename());
             xmlInput = luaState->getOutput().str();
         }
         else
         {
-            shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename(), file->getResourceGroup());
+            shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename());
             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();
+            xmlInput = Resource::open(file->getFilename())->getAsString();
         }
 
         try

Modified: code/branches/presentation2/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/LuaState.cc	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/LuaState.cc	2009-12-23 18:44:49 UTC (rev 6404)
@@ -85,34 +85,23 @@
         lua_close(luaState_);
     }
 
-    shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename)
     {
-        shared_ptr<ResourceInfo> sourceInfo;
-        if (resourceGroup != "NoResourceGroupProvided")
-            sourceInfo = Resource::getInfo(filename, resourceGroup);
-
-        // Continue search if not explicitly forbidden
-        if (bSearchOtherPaths && sourceInfo == NULL)
-        {
-            // Call might be relative to the file currently being processed
-            sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group);
-            if (sourceInfo == NULL)
-            {
-                // Maybe find something in the same group but in the root path
-                sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);
-            }
-        }
+        // Look in the current directory first
+        shared_ptr<ResourceInfo> sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename);
+        // Continue search in root directories
+        if (sourceInfo == NULL && !sourceFileInfo_->path.empty())
+            sourceInfo = Resource::getInfo(filename);
         return sourceInfo;
     }
 
-    void LuaState::includeFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    void LuaState::includeFile(const std::string& filename)
     {
-        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
         if (sourceInfo != NULL)
-            this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
+            this->includeString(Resource::open(sourceInfo)->getAsString(), sourceInfo);
         else
-            COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '"
-                    << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
+            COUT(2) << "LuaState: Cannot include file '" << filename << "'." << std::endl;
     }
 
     void LuaState::includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo)
@@ -127,14 +116,13 @@
         this->doString(luaInput, sourceFileInfo);
     }
 
-    void LuaState::doFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    void LuaState::doFile(const std::string& filename)
     {
-        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
         if (sourceInfo != NULL)
-            this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
+            this->doString(Resource::open(sourceInfo)->getAsString(), sourceInfo);
         else
-            COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '"
-                << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
+            COUT(2) << "LuaState: Cannot do file '" << filename << "'." << std::endl;
     }
 
     void LuaState::doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo)
@@ -184,9 +172,9 @@
         OutputHandler::getOutStream(level) << message << std::endl;
     }
 
-    bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    bool LuaState::fileExists(const std::string& filename)
     {
-        shared_ptr<ResourceInfo> info =  this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+        shared_ptr<ResourceInfo> info = this->getFileInfo(filename);
         if (info == NULL)
             return false;
         else

Modified: code/branches/presentation2/src/libraries/core/LuaState.h
===================================================================
--- code/branches/presentation2/src/libraries/core/LuaState.h	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/LuaState.h	2009-12-23 18:44:49 UTC (rev 6404)
@@ -70,15 +70,15 @@
         LuaState();
         ~LuaState();
 
-        void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
+        void doFile(const std::string& filename); // tolua_export
         void doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
 
-        void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
+        void includeFile(const std::string& filename); // tolua_export
         void includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
 
         void luaPrint(const std::string& str); // tolua_export
         void luaLog(unsigned int level, const std::string& message); // tolua_export
-        bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
+        bool fileExists(const std::string& filename); // tolua_export
 
         const std::stringstream& getOutput() const { return output_; }
         void clearOutput() { output_.clear(); } // tolua_export
@@ -97,7 +97,7 @@
         static void closeToluaInterfaces(lua_State* state);
 
     private:
-        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths);
+        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename);
 
 #if LUA_VERSION_NUM != 501
         struct LoadS

Modified: code/branches/presentation2/src/libraries/core/Resource.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/Resource.cc	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/Resource.cc	2009-12-23 18:44:49 UTC (rev 6404)
@@ -33,23 +33,48 @@
 {
     std::string Resource::DEFAULT_GROUP(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
 
-    DataStreamPtr Resource::open(const std::string& name, const std::string& group, bool bSearchGroupsIfNotFound)
+    DataStreamPtr Resource::open(const std::string& name)
     {
-        return Ogre::ResourceGroupManager::getSingleton().openResource(name, group, bSearchGroupsIfNotFound);
+        return Ogre::ResourceGroupManager::getSingleton().openResource(name,
+            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
     }
 
-    DataStreamListPtr Resource::openMulti(const std::string& pattern, const std::string& group)
+    DataStreamListPtr Resource::openMulti(const std::string& pattern)
     {
-        return Ogre::ResourceGroupManager::getSingleton().openResources(pattern, group);
+        DataStreamListPtr resources(new Ogre::DataStreamList());
+        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
+        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
+        {
+            DataStreamListPtr temp = Ogre::ResourceGroupManager::getSingleton().openResources(pattern, *it);
+            resources->insert(resources->end(), temp->begin(), temp->end());
+        }
+        return resources;
     }
 
-    bool Resource::exists(const std::string& name, const std::string& group)
+    bool Resource::exists(const std::string& name)
     {
-        return Ogre::ResourceGroupManager::getSingleton().resourceExists(group, name);
+        try
+        {
+            Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
+            return true;
+        }
+        catch (const Ogre::Exception&)
+        {
+            return false;
+        }
     }
 
-    shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name, const std::string& group)
+    shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name)
     {
+        std::string group;
+        try
+        {
+            group = Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
+        }
+        catch (const Ogre::Exception&)
+        {
+            return shared_ptr<ResourceInfo>();
+        }
         Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name);
         for (std::vector<Ogre::FileInfo>::const_iterator it = infos->begin(); it != infos->end(); ++it)
         {
@@ -66,4 +91,16 @@
         }
         return shared_ptr<ResourceInfo>();
     }
+
+    StringVectorPtr Resource::findResourceNames(const std::string& pattern)
+    {
+        StringVectorPtr resourceNames(new Ogre::StringVector());
+        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
+        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
+        {
+            StringVectorPtr temp = Ogre::ResourceGroupManager::getSingleton().findResourceNames(*it, pattern);
+            resourceNames->insert(resourceNames->end(), temp->begin(), temp->end());
+        }
+        return resourceNames;
+    }
 }

Modified: code/branches/presentation2/src/libraries/core/Resource.h
===================================================================
--- code/branches/presentation2/src/libraries/core/Resource.h	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/Resource.h	2009-12-23 18:44:49 UTC (rev 6404)
@@ -33,12 +33,15 @@
 
 #include <boost/shared_ptr.hpp>
 #include <OgreDataStream.h>
+#include <OgreStringVector.h>
 
 namespace orxonox
 {
     // Import the Ogre::DataStreamList
     using Ogre::DataStreamList;
     using Ogre::DataStreamListPtr;
+    using Ogre::StringVector;
+    using Ogre::StringVectorPtr;
 
     //! Stores basic information about a Resource from Ogre
     struct ResourceInfo
@@ -55,9 +58,8 @@
         size_t size;
     };
 
-    /**
-    @brief
-        Provides simple functions to easily access the Ogre::ResourceGroupManager
+    /** Provides simple functions to easily access the Ogre::ResourceGroupManager.
+        The wrapper functions also avoid having to deal with resource groups.
     */
     class _CoreExport Resource
     {
@@ -71,25 +73,16 @@
             The name of the resource to locate.
             Even if resource locations are added recursively, you
             must provide a fully qualified name to this method.
-        @param groupName
-            The name of the resource group; this determines which
-            locations are searched.
-        @param searchGroupsIfNotFound
-            If true, if the resource is not found in
-            the group specified, other groups will be searched.
         @return
             Shared pointer to data stream containing the data. Will be
             destroyed automatically when no longer referenced.
         */
-        static DataStreamPtr open(const std::string& name,
-            const std::string& group = Resource::DEFAULT_GROUP,
-            bool bSearchGroupsIfNotFound = false);
+        static DataStreamPtr open(const std::string& name);
 
         //! Similar to open(string, string, bool), but with a fileInfo struct
-        static DataStreamPtr open(shared_ptr<ResourceInfo> fileInfo,
-            bool bSearchGroupsIfNotFound = false)
+        static DataStreamPtr open(shared_ptr<ResourceInfo> fileInfo)
         {
-            return open(fileInfo->filename, fileInfo->group, bSearchGroupsIfNotFound);
+            return open(fileInfo->filename);
         }
 
         /**
@@ -101,33 +94,35 @@
             The pattern to look for. If resource locations have been
             added recursively, subdirectories will be searched too so this
             does not need to be fully qualified.
-        @param groupName
-            The resource group; this determines which locations
-            are searched.
         @return
             Shared pointer to a data stream list , will be
             destroyed automatically when no longer referenced
         */
-        static DataStreamListPtr openMulti(const std::string& pattern, const std::string& group = Resource::DEFAULT_GROUP);
+        static DataStreamListPtr openMulti(const std::string& pattern);
 
         /**
-            Find out if the named file exists in a group.
+            Find out if the named file exists.
         @param filename
             Fully qualified name of the file to test for
-        @param group
-            The name of the resource group
         */
-        static bool exists(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
+        static bool exists(const std::string& name);
 
         /**
-            Get struct with information about group, path and size.
+            Get struct with information about path and size.
         @param filename
             Fully qualified name of the file to test for
-        @param group
-            The name of the resource group
         */
-        static shared_ptr<ResourceInfo> getInfo(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
+        static shared_ptr<ResourceInfo> getInfo(const std::string& name);
 
+        /**
+            Retrieves a list with all resources matching a certain pattern.
+        @param pattern
+            The pattern to look for. If resource locations have been
+            added recursively, subdirectories will be searched too so this
+            does not need to be fully qualified.
+        */
+        static StringVectorPtr findResourceNames(const std::string& pattern);
+
         //! Name of the default resource group (usually "General")
         static std::string DEFAULT_GROUP;
 

Modified: code/branches/presentation2/src/libraries/core/XMLFile.h
===================================================================
--- code/branches/presentation2/src/libraries/core/XMLFile.h	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/libraries/core/XMLFile.h	2009-12-23 18:44:49 UTC (rev 6404)
@@ -39,14 +39,12 @@
     class _CoreExport XMLFile
     {
         public:
-            XMLFile(const std::string& filename, const std::string& resourceGroup = "General")
+            XMLFile(const std::string& filename)
                 : filename_(filename)
-                , group_(resourceGroup)
                 , bLuaSupport_(true)
             { }
-            XMLFile(const ClassTreeMask& mask, const std::string& filename, const std::string& resourceGroup = "General")
+            XMLFile(const ClassTreeMask& mask, const std::string& filename)
                 : filename_(filename)
-                , group_(resourceGroup)
                 , mask_(mask)
                 , bLuaSupport_(true)
             { }
@@ -54,13 +52,11 @@
             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_; // Default is true
     };

Modified: code/branches/presentation2/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/presentation2/src/orxonox/LevelManager.cc	2009-12-22 22:20:19 UTC (rev 6403)
+++ code/branches/presentation2/src/orxonox/LevelManager.cc	2009-12-23 18:44:49 UTC (rev 6404)
@@ -29,12 +29,12 @@
 #include "LevelManager.h"
 
 #include <map>
-#include <OgreResourceGroupManager.h>
 
 #include "core/CommandLineParser.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/CoreIncludes.h"
 #include "core/Loader.h"
+#include "core/Resource.h"
 #include "core/ScopedSingletonManager.h"
 #include "PlayerManager.h"
 #include "Level.h"
@@ -131,11 +131,7 @@
 
     void LevelManager::compileAvailableLevelList()
     {
-        availableLevels_.clear();
-
-        availableLevels_ = *Ogre::ResourceGroupManager::getSingleton().findResourceNames(
-            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "*.oxw");
-
+        availableLevels_ = *Resource::findResourceNames("*.oxw");
         for (std::vector<std::string>::iterator it = availableLevels_.begin(); it != availableLevels_.end();)
             if (it->find("old/") == 0)
                 it = availableLevels_.erase(it);




More information about the Orxonox-commit mailing list