Changeset 6404 for code/branches/presentation2/src/libraries
- Timestamp:
- Dec 23, 2009, 7:44:49 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/core
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/GUIManager.cc
r6387 r6404 125 125 // setup scripting 126 126 luaState_.reset(new LuaState()); 127 rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua" , "GUI");127 rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua"); 128 128 // This is necessary to ensure that input events also use the right resource info when triggering lua functions 129 129 luaState_->setDefaultResourceInfo(this->rootFileInfo_); … … 142 142 143 143 // Initialise the basic Lua code 144 this->luaState_->doFile("InitialiseGUI.lua" , "GUI", false);144 this->luaState_->doFile("InitialiseGUI.lua"); 145 145 146 146 // Align CEGUI mouse with OIS mouse -
code/branches/presentation2/src/libraries/core/GraphicsManager.cc
r6394 r6404 100 100 101 101 // 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"); 103 103 // Load resources 104 resources_.reset(new XMLFile(" resources.oxr", "dataRoot"));104 resources_.reset(new XMLFile("DefaultResources.oxr")); 105 105 resources_->setLuaSupport(false); 106 106 Loader::open(resources_.get()); … … 109 109 if (PathConfig::isDevelopmentRun()) 110 110 { 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")); 113 113 extResources_->setLuaSupport(false); 114 114 Loader::open(extResources_.get()); … … 395 395 { 396 396 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: "; 410 421 } 411 422 OutputHandler::getOutStream(orxonoxLevel) 412 << "Ogre: "<< message << std::endl;423 << introduction << message << std::endl; 413 424 } 414 425 -
code/branches/presentation2/src/libraries/core/Loader.cc
r6400 r6404 128 128 scoped_ptr<LuaState> luaState(new LuaState()); 129 129 luaState->setIncludeParser(&Loader::replaceLuaTags); 130 luaState->includeFile(file->getFilename() , file->getResourceGroup(), false);130 luaState->includeFile(file->getFilename()); 131 131 xmlInput = luaState->getOutput().str(); 132 132 } 133 133 else 134 134 { 135 shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename() , file->getResourceGroup());135 shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename()); 136 136 if (info == NULL) 137 137 { … … 139 139 return false; 140 140 } 141 xmlInput = Resource::open(file->getFilename() , file->getResourceGroup())->getAsString();141 xmlInput = Resource::open(file->getFilename())->getAsString(); 142 142 } 143 143 -
code/branches/presentation2/src/libraries/core/LuaState.cc
r6281 r6404 86 86 } 87 87 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); 105 95 return sourceInfo; 106 96 } 107 97 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); 111 101 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; 116 105 } 117 106 … … 128 117 } 129 118 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); 133 122 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; 138 126 } 139 127 … … 185 173 } 186 174 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); 190 178 if (info == NULL) 191 179 return false; -
code/branches/presentation2/src/libraries/core/LuaState.h
r6281 r6404 71 71 ~LuaState(); 72 72 73 void doFile(const std::string& filename , const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export73 void doFile(const std::string& filename); // tolua_export 74 74 void doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>()); 75 75 76 void includeFile(const std::string& filename , const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export76 void includeFile(const std::string& filename); // tolua_export 77 77 void includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>()); 78 78 79 79 void luaPrint(const std::string& str); // tolua_export 80 80 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_export81 bool fileExists(const std::string& filename); // tolua_export 82 82 83 83 const std::stringstream& getOutput() const { return output_; } … … 98 98 99 99 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); 101 101 102 102 #if LUA_VERSION_NUM != 501 -
code/branches/presentation2/src/libraries/core/Resource.cc
r5781 r6404 34 34 std::string Resource::DEFAULT_GROUP(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 35 35 36 DataStreamPtr Resource::open(const std::string& name , const std::string& group, bool bSearchGroupsIfNotFound)36 DataStreamPtr Resource::open(const std::string& name) 37 37 { 38 return Ogre::ResourceGroupManager::getSingleton().openResource(name, group, bSearchGroupsIfNotFound); 38 return Ogre::ResourceGroupManager::getSingleton().openResource(name, 39 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true); 39 40 } 40 41 41 DataStreamListPtr Resource::openMulti(const std::string& pattern , const std::string& group)42 DataStreamListPtr Resource::openMulti(const std::string& pattern) 42 43 { 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; 44 52 } 45 53 46 bool Resource::exists(const std::string& name , const std::string& group)54 bool Resource::exists(const std::string& name) 47 55 { 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 } 49 65 } 50 66 51 shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name , const std::string& group)67 shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name) 52 68 { 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 } 53 78 Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name); 54 79 for (std::vector<Ogre::FileInfo>::const_iterator it = infos->begin(); it != infos->end(); ++it) … … 67 92 return shared_ptr<ResourceInfo>(); 68 93 } 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 } 69 106 } -
code/branches/presentation2/src/libraries/core/Resource.h
r6388 r6404 34 34 #include <boost/shared_ptr.hpp> 35 35 #include <OgreDataStream.h> 36 #include <OgreStringVector.h> 36 37 37 38 namespace orxonox … … 40 41 using Ogre::DataStreamList; 41 42 using Ogre::DataStreamListPtr; 43 using Ogre::StringVector; 44 using Ogre::StringVectorPtr; 42 45 43 46 //! Stores basic information about a Resource from Ogre … … 56 59 }; 57 60 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. 61 63 */ 62 64 class _CoreExport Resource … … 72 74 Even if resource locations are added recursively, you 73 75 must provide a fully qualified name to this method. 74 @param groupName75 The name of the resource group; this determines which76 locations are searched.77 @param searchGroupsIfNotFound78 If true, if the resource is not found in79 the group specified, other groups will be searched.80 76 @return 81 77 Shared pointer to data stream containing the data. Will be 82 78 destroyed automatically when no longer referenced. 83 79 */ 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); 87 81 88 82 //! 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) 91 84 { 92 return open(fileInfo->filename , fileInfo->group, bSearchGroupsIfNotFound);85 return open(fileInfo->filename); 93 86 } 94 87 … … 102 95 added recursively, subdirectories will be searched too so this 103 96 does not need to be fully qualified. 104 @param groupName105 The resource group; this determines which locations106 are searched.107 97 @return 108 98 Shared pointer to a data stream list , will be 109 99 destroyed automatically when no longer referenced 110 100 */ 111 static DataStreamListPtr openMulti(const std::string& pattern , const std::string& group = Resource::DEFAULT_GROUP);101 static DataStreamListPtr openMulti(const std::string& pattern); 112 102 113 103 /** 114 Find out if the named file exists in a group.104 Find out if the named file exists. 115 105 @param filename 116 106 Fully qualified name of the file to test for 117 @param group118 The name of the resource group119 107 */ 120 static bool exists(const std::string& name , const std::string& group = Resource::DEFAULT_GROUP);108 static bool exists(const std::string& name); 121 109 122 110 /** 123 Get struct with information about group,path and size.111 Get struct with information about path and size. 124 112 @param filename 125 113 Fully qualified name of the file to test for 126 @param group127 The name of the resource group128 114 */ 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); 130 125 131 126 //! Name of the default resource group (usually "General") -
code/branches/presentation2/src/libraries/core/XMLFile.h
r5781 r6404 40 40 { 41 41 public: 42 XMLFile(const std::string& filename , const std::string& resourceGroup = "General")42 XMLFile(const std::string& filename) 43 43 : filename_(filename) 44 , group_(resourceGroup)45 44 , bLuaSupport_(true) 46 45 { } 47 XMLFile(const ClassTreeMask& mask, const std::string& filename , const std::string& resourceGroup = "General")46 XMLFile(const ClassTreeMask& mask, const std::string& filename) 48 47 : filename_(filename) 49 , group_(resourceGroup)50 48 , mask_(mask) 51 49 , bLuaSupport_(true) … … 55 53 56 54 const std::string& getFilename() const { return this->filename_; } 57 const std::string& getResourceGroup() const { return this->group_; }58 55 const ClassTreeMask& getMask() const { return this->mask_; } 59 56 bool getLuaSupport() const { return this->bLuaSupport_; } … … 61 58 private: 62 59 std::string filename_; 63 std::string group_;64 60 ClassTreeMask mask_; 65 61 bool bLuaSupport_; // Default is true
Note: See TracChangeset
for help on using the changeset viewer.