Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6404


Ignore:
Timestamp:
Dec 23, 2009, 7:44:49 PM (15 years ago)
Author:
rgrieder
Message:

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.

Location:
code/branches/presentation2
Files:
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/data/DataInstallScript.cmake

    r5781 r6404  
    2929
    3030# Write some comment
    31 FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr "\n\n\n <!-- ---------------------------------------- -->")
    32 FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr     "\n <!-- Content from the external data directory -->")
    33 FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr     "\n <!-- ---------------------------------------- -->\n\n")
     31FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr "\n\n\n <!-- ---------------------------------------- -->")
     32FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr     "\n <!-- Content from the external data directory -->")
     33FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr     "\n <!-- ---------------------------------------- -->\n\n")
    3434
    3535# Append the external file
    3636FILE(READ   @EXTERNAL_DATA_DIRECTORY@/resources.oxr _external_file)
    37 FILE(APPEND @DATA_INSTALL_DIRECTORY@/resources.oxr ${_external_file})
     37FILE(APPEND @DATA_INSTALL_DIRECTORY@/DefaultResources.oxr ${_external_file})
  • code/branches/presentation2/data/lua/LuaStateInit.lua

    r6403 r6404  
    1515
    1616-- Redirect dofile in order to load with the resource manager
    17 -- Note: The function does not behave exactly like LuaState::doFile because the
    18 --       default argument here for the group is not "General" but
    19 --       "NoResourceGroupProvided". This resolves to the resource group used to
    20 --       do the current file.
    21 doFile = function(filename, resourceGroup)
    22   local bSearchOtherPaths = (resourceGroup == nil) or false
    23   resourceGroup = resourceGroup or "NoResourceGroupProvided"
    24   luaState:doFile(filename, resourceGroup, bSearchOtherPaths)
     17doFile = function(filename)
     18  luaState:doFile(filename)
    2519  -- Required because the C++ function cannot return whatever might be on the stack
    26   return LuaStateReturnValue
     20  return LuaStateReturnValue -- C-injected global variable
    2721end
    2822original_dofile = dofile
     
    3125-- Create includeFile function that preparses the file according
    3226-- to a function provided to the LuaState constructor (in C++)
    33 -- Note: See the same notes as for doFile
    34 include = function(filename, resourceGroup)
    35   local bSearchOtherPaths = (resourceGroup == nil) or false
    36   resourceGroup = resourceGroup or "NoResourceGroupProvided"
    37   luaState:includeFile(filename, resourceGroup, bSearchOtherPaths)
     27include = function(filename)
     28  luaState:includeFile(filename)
    3829  -- Required because the C++ function cannot return whatever might be on the stack
    39   return LuaStateReturnValue
     30  return LuaStateReturnValue -- C-injected global variable
    4031end
    4132
    4233-- Replace require function with almost similar behaviour
    43 -- The difference is that you need to provide a resource group
    44 -- Default value there is the current one (if present) or else "General"
    45 -- But the loaded modules are then stored with only with the name (where name has no .lua extension)
    46 -- CAUTION: That also means that you need to take care of conflicting filenames among groups
    47 -- Furthermore the moduleName parameters is appended with the .lua extension when looking for the file
     34-- The loaded modules are then stored with their names (where name has no .lua extension)
     35-- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file
    4836old_require = require
    49 require = function(moduleName, resourceGroup)
    50   local bSearchOtherPaths = (resourceGroup == nil) or false
    51   resourceGroup = resourceGroup or "NoResourceGroupProvided"
    52   if not luaState:fileExists(moduleName .. ".lua", resourceGroup, bSearchOtherPaths) then
     37require = function(moduleName)
     38  if not luaState:fileExists(moduleName .. ".lua") then
    5339    return nil
    5440  end
     
    6046    _REQUIREDNAME_OLD = _REQUIREDNAME
    6147    _REQUIREDNAME = moduleName
    62     luaState:doFile(moduleName .. ".lua", resourceGroup, bSearchOtherPaths)
     48    luaState:doFile(moduleName .. ".lua")
    6349    _LOADED[moduleName] = LuaStateReturnValue or true
    6450    -- restore old value
  • code/branches/presentation2/src/libraries/core/GUIManager.cc

    r6387 r6404  
    125125        // setup scripting
    126126        luaState_.reset(new LuaState());
    127         rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
     127        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua");
    128128        // This is necessary to ensure that input events also use the right resource info when triggering lua functions
    129129        luaState_->setDefaultResourceInfo(this->rootFileInfo_);
     
    142142
    143143        // Initialise the basic Lua code
    144         this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
     144        this->luaState_->doFile("InitialiseGUI.lua");
    145145
    146146        // Align CEGUI mouse with OIS mouse
  • code/branches/presentation2/src/libraries/core/GraphicsManager.cc

    r6394 r6404  
    100100
    101101        // At first, add the root paths of the data directories as resource locations
    102         Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getDataPathString(), "FileSystem", "dataRoot", false);
     102        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getDataPathString(), "FileSystem");
    103103        // Load resources
    104         resources_.reset(new XMLFile("resources.oxr", "dataRoot"));
     104        resources_.reset(new XMLFile("DefaultResources.oxr"));
    105105        resources_->setLuaSupport(false);
    106106        Loader::open(resources_.get());
     
    109109        if (PathConfig::isDevelopmentRun())
    110110        {
    111             Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem", "externalDataRoot", false);
    112             extResources_.reset(new XMLFile("resources.oxr", "externalDataRoot"));
     111            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem");
     112            extResources_.reset(new XMLFile("resources.oxr"));
    113113            extResources_->setLuaSupport(false);
    114114            Loader::open(extResources_.get());
     
    395395    {
    396396        int orxonoxLevel;
    397         switch (lml)
    398         {
    399         case Ogre::LML_TRIVIAL:
    400             orxonoxLevel = this->ogreLogLevelTrivial_;
    401             break;
    402         case Ogre::LML_NORMAL:
    403             orxonoxLevel = this->ogreLogLevelNormal_;
    404             break;
    405         case Ogre::LML_CRITICAL:
    406             orxonoxLevel = this->ogreLogLevelCritical_;
    407             break;
    408         default:
    409             orxonoxLevel = 0;
     397        std::string introduction;
     398        // Do not show caught OGRE exceptions in front
     399        if (message.find("OGRE_EXCEPTION"))
     400        {
     401            orxonoxLevel = OutputLevel::Debug;
     402            introduction = "Ogre, caught exception: ";
     403        }
     404        else
     405        {
     406            switch (lml)
     407            {
     408            case Ogre::LML_TRIVIAL:
     409                orxonoxLevel = this->ogreLogLevelTrivial_;
     410                break;
     411            case Ogre::LML_NORMAL:
     412                orxonoxLevel = this->ogreLogLevelNormal_;
     413                break;
     414            case Ogre::LML_CRITICAL:
     415                orxonoxLevel = this->ogreLogLevelCritical_;
     416                break;
     417            default:
     418                orxonoxLevel = 0;
     419            }
     420            introduction = "Ogre: ";
    410421        }
    411422        OutputHandler::getOutStream(orxonoxLevel)
    412             << "Ogre: " << message << std::endl;
     423            << introduction << message << std::endl;
    413424    }
    414425
  • code/branches/presentation2/src/libraries/core/Loader.cc

    r6400 r6404  
    128128            scoped_ptr<LuaState> luaState(new LuaState());
    129129            luaState->setIncludeParser(&Loader::replaceLuaTags);
    130             luaState->includeFile(file->getFilename(), file->getResourceGroup(), false);
     130            luaState->includeFile(file->getFilename());
    131131            xmlInput = luaState->getOutput().str();
    132132        }
    133133        else
    134134        {
    135             shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename(), file->getResourceGroup());
     135            shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename());
    136136            if (info == NULL)
    137137            {
     
    139139                return false;
    140140            }
    141             xmlInput = Resource::open(file->getFilename(), file->getResourceGroup())->getAsString();
     141            xmlInput = Resource::open(file->getFilename())->getAsString();
    142142        }
    143143
  • code/branches/presentation2/src/libraries/core/LuaState.cc

    r6281 r6404  
    8686    }
    8787
    88     shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
    89     {
    90         shared_ptr<ResourceInfo> sourceInfo;
    91         if (resourceGroup != "NoResourceGroupProvided")
    92             sourceInfo = Resource::getInfo(filename, resourceGroup);
    93 
    94         // Continue search if not explicitly forbidden
    95         if (bSearchOtherPaths && sourceInfo == NULL)
    96         {
    97             // Call might be relative to the file currently being processed
    98             sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group);
    99             if (sourceInfo == NULL)
    100             {
    101                 // Maybe find something in the same group but in the root path
    102                 sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);
    103             }
    104         }
     88    shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename)
     89    {
     90        // Look in the current directory first
     91        shared_ptr<ResourceInfo> sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename);
     92        // Continue search in root directories
     93        if (sourceInfo == NULL && !sourceFileInfo_->path.empty())
     94            sourceInfo = Resource::getInfo(filename);
    10595        return sourceInfo;
    10696    }
    10797
    108     void LuaState::includeFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
    109     {
    110         shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
     98    void LuaState::includeFile(const std::string& filename)
     99    {
     100        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
    111101        if (sourceInfo != NULL)
    112             this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
    113         else
    114             COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '"
    115                     << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
     102            this->includeString(Resource::open(sourceInfo)->getAsString(), sourceInfo);
     103        else
     104            COUT(2) << "LuaState: Cannot include file '" << filename << "'." << std::endl;
    116105    }
    117106
     
    128117    }
    129118
    130     void LuaState::doFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
    131     {
    132         shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
     119    void LuaState::doFile(const std::string& filename)
     120    {
     121        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename);
    133122        if (sourceInfo != NULL)
    134             this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
    135         else
    136             COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '"
    137                 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
     123            this->doString(Resource::open(sourceInfo)->getAsString(), sourceInfo);
     124        else
     125            COUT(2) << "LuaState: Cannot do file '" << filename << "'." << std::endl;
    138126    }
    139127
     
    185173    }
    186174
    187     bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
    188     {
    189         shared_ptr<ResourceInfo> info =  this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
     175    bool LuaState::fileExists(const std::string& filename)
     176    {
     177        shared_ptr<ResourceInfo> info = this->getFileInfo(filename);
    190178        if (info == NULL)
    191179            return false;
  • code/branches/presentation2/src/libraries/core/LuaState.h

    r6281 r6404  
    7171        ~LuaState();
    7272
    73         void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
     73        void doFile(const std::string& filename); // tolua_export
    7474        void doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
    7575
    76         void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
     76        void includeFile(const std::string& filename); // tolua_export
    7777        void includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
    7878
    7979        void luaPrint(const std::string& str); // tolua_export
    8080        void luaLog(unsigned int level, const std::string& message); // tolua_export
    81         bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
     81        bool fileExists(const std::string& filename); // tolua_export
    8282
    8383        const std::stringstream& getOutput() const { return output_; }
     
    9898
    9999    private:
    100         shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths);
     100        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename);
    101101
    102102#if LUA_VERSION_NUM != 501
  • code/branches/presentation2/src/libraries/core/Resource.cc

    r5781 r6404  
    3434    std::string Resource::DEFAULT_GROUP(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    3535
    36     DataStreamPtr Resource::open(const std::string& name, const std::string& group, bool bSearchGroupsIfNotFound)
     36    DataStreamPtr Resource::open(const std::string& name)
    3737    {
    38         return Ogre::ResourceGroupManager::getSingleton().openResource(name, group, bSearchGroupsIfNotFound);
     38        return Ogre::ResourceGroupManager::getSingleton().openResource(name,
     39            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
    3940    }
    4041
    41     DataStreamListPtr Resource::openMulti(const std::string& pattern, const std::string& group)
     42    DataStreamListPtr Resource::openMulti(const std::string& pattern)
    4243    {
    43         return Ogre::ResourceGroupManager::getSingleton().openResources(pattern, group);
     44        DataStreamListPtr resources(new Ogre::DataStreamList());
     45        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
     46        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
     47        {
     48            DataStreamListPtr temp = Ogre::ResourceGroupManager::getSingleton().openResources(pattern, *it);
     49            resources->insert(resources->end(), temp->begin(), temp->end());
     50        }
     51        return resources;
    4452    }
    4553
    46     bool Resource::exists(const std::string& name, const std::string& group)
     54    bool Resource::exists(const std::string& name)
    4755    {
    48         return Ogre::ResourceGroupManager::getSingleton().resourceExists(group, name);
     56        try
     57        {
     58            Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
     59            return true;
     60        }
     61        catch (const Ogre::Exception&)
     62        {
     63            return false;
     64        }
    4965    }
    5066
    51     shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name, const std::string& group)
     67    shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name)
    5268    {
     69        std::string group;
     70        try
     71        {
     72            group = Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
     73        }
     74        catch (const Ogre::Exception&)
     75        {
     76            return shared_ptr<ResourceInfo>();
     77        }
    5378        Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name);
    5479        for (std::vector<Ogre::FileInfo>::const_iterator it = infos->begin(); it != infos->end(); ++it)
     
    6792        return shared_ptr<ResourceInfo>();
    6893    }
     94
     95    StringVectorPtr Resource::findResourceNames(const std::string& pattern)
     96    {
     97        StringVectorPtr resourceNames(new Ogre::StringVector());
     98        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
     99        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
     100        {
     101            StringVectorPtr temp = Ogre::ResourceGroupManager::getSingleton().findResourceNames(*it, pattern);
     102            resourceNames->insert(resourceNames->end(), temp->begin(), temp->end());
     103        }
     104        return resourceNames;
     105    }
    69106}
  • code/branches/presentation2/src/libraries/core/Resource.h

    r6388 r6404  
    3434#include <boost/shared_ptr.hpp>
    3535#include <OgreDataStream.h>
     36#include <OgreStringVector.h>
    3637
    3738namespace orxonox
     
    4041    using Ogre::DataStreamList;
    4142    using Ogre::DataStreamListPtr;
     43    using Ogre::StringVector;
     44    using Ogre::StringVectorPtr;
    4245
    4346    //! Stores basic information about a Resource from Ogre
     
    5659    };
    5760
    58     /**
    59     @brief
    60         Provides simple functions to easily access the Ogre::ResourceGroupManager
     61    /** Provides simple functions to easily access the Ogre::ResourceGroupManager.
     62        The wrapper functions also avoid having to deal with resource groups.
    6163    */
    6264    class _CoreExport Resource
     
    7274            Even if resource locations are added recursively, you
    7375            must provide a fully qualified name to this method.
    74         @param groupName
    75             The name of the resource group; this determines which
    76             locations are searched.
    77         @param searchGroupsIfNotFound
    78             If true, if the resource is not found in
    79             the group specified, other groups will be searched.
    8076        @return
    8177            Shared pointer to data stream containing the data. Will be
    8278            destroyed automatically when no longer referenced.
    8379        */
    84         static DataStreamPtr open(const std::string& name,
    85             const std::string& group = Resource::DEFAULT_GROUP,
    86             bool bSearchGroupsIfNotFound = false);
     80        static DataStreamPtr open(const std::string& name);
    8781
    8882        //! Similar to open(string, string, bool), but with a fileInfo struct
    89         static DataStreamPtr open(shared_ptr<ResourceInfo> fileInfo,
    90             bool bSearchGroupsIfNotFound = false)
     83        static DataStreamPtr open(shared_ptr<ResourceInfo> fileInfo)
    9184        {
    92             return open(fileInfo->filename, fileInfo->group, bSearchGroupsIfNotFound);
     85            return open(fileInfo->filename);
    9386        }
    9487
     
    10295            added recursively, subdirectories will be searched too so this
    10396            does not need to be fully qualified.
    104         @param groupName
    105             The resource group; this determines which locations
    106             are searched.
    10797        @return
    10898            Shared pointer to a data stream list , will be
    10999            destroyed automatically when no longer referenced
    110100        */
    111         static DataStreamListPtr openMulti(const std::string& pattern, const std::string& group = Resource::DEFAULT_GROUP);
     101        static DataStreamListPtr openMulti(const std::string& pattern);
    112102
    113103        /**
    114             Find out if the named file exists in a group.
     104            Find out if the named file exists.
    115105        @param filename
    116106            Fully qualified name of the file to test for
    117         @param group
    118             The name of the resource group
    119107        */
    120         static bool exists(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
     108        static bool exists(const std::string& name);
    121109
    122110        /**
    123             Get struct with information about group, path and size.
     111            Get struct with information about path and size.
    124112        @param filename
    125113            Fully qualified name of the file to test for
    126         @param group
    127             The name of the resource group
    128114        */
    129         static shared_ptr<ResourceInfo> getInfo(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
     115        static shared_ptr<ResourceInfo> getInfo(const std::string& name);
     116
     117        /**
     118            Retrieves a list with all resources matching a certain pattern.
     119        @param pattern
     120            The pattern to look for. If resource locations have been
     121            added recursively, subdirectories will be searched too so this
     122            does not need to be fully qualified.
     123        */
     124        static StringVectorPtr findResourceNames(const std::string& pattern);
    130125
    131126        //! Name of the default resource group (usually "General")
  • code/branches/presentation2/src/libraries/core/XMLFile.h

    r5781 r6404  
    4040    {
    4141        public:
    42             XMLFile(const std::string& filename, const std::string& resourceGroup = "General")
     42            XMLFile(const std::string& filename)
    4343                : filename_(filename)
    44                 , group_(resourceGroup)
    4544                , bLuaSupport_(true)
    4645            { }
    47             XMLFile(const ClassTreeMask& mask, const std::string& filename, const std::string& resourceGroup = "General")
     46            XMLFile(const ClassTreeMask& mask, const std::string& filename)
    4847                : filename_(filename)
    49                 , group_(resourceGroup)
    5048                , mask_(mask)
    5149                , bLuaSupport_(true)
     
    5553
    5654            const std::string& getFilename() const { return this->filename_; }
    57             const std::string& getResourceGroup() const { return this->group_; }
    5855            const ClassTreeMask& getMask() const { return this->mask_; }
    5956            bool getLuaSupport() const { return this->bLuaSupport_; }
     
    6158        private:
    6259            std::string filename_;
    63             std::string group_;
    6460            ClassTreeMask mask_;
    6561            bool bLuaSupport_; // Default is true
  • code/branches/presentation2/src/orxonox/LevelManager.cc

    r6394 r6404  
    3030
    3131#include <map>
    32 #include <OgreResourceGroupManager.h>
    3332
    3433#include "core/CommandLineParser.h"
     
    3635#include "core/CoreIncludes.h"
    3736#include "core/Loader.h"
     37#include "core/Resource.h"
    3838#include "core/ScopedSingletonManager.h"
    3939#include "PlayerManager.h"
     
    132132    void LevelManager::compileAvailableLevelList()
    133133    {
    134         availableLevels_.clear();
    135 
    136         availableLevels_ = *Ogre::ResourceGroupManager::getSingleton().findResourceNames(
    137             Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "*.oxw");
    138 
     134        availableLevels_ = *Resource::findResourceNames("*.oxw");
    139135        for (std::vector<std::string>::iterator it = availableLevels_.begin(); it != availableLevels_.end();)
    140136            if (it->find("old/") == 0)
Note: See TracChangeset for help on using the changeset viewer.