Changeset 8351 for code/trunk/src/libraries/core/GraphicsManager.cc
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/GraphicsManager.cc
r8079 r8351 30 30 #include "GraphicsManager.h" 31 31 32 #include <cstdlib> 32 33 #include <fstream> 33 34 #include <sstream> … … 35 36 #include <boost/shared_array.hpp> 36 37 37 #include <OgreArchiveFactory.h>38 #include <OgreArchiveManager.h>39 38 #include <OgreFrameListener.h> 40 39 #include <OgreRoot.h> … … 60 59 #include "GUIManager.h" 61 60 #include "Loader.h" 62 #include "MemoryArchive.h"63 61 #include "PathConfig.h" 64 62 #include "ViewportEventListener.h" … … 102 100 GraphicsManager::GraphicsManager(bool bLoadRenderer) 103 101 : ogreWindowEventListener_(new OgreWindowEventListener()) 104 #if OGRE_VERSION < 0x010600105 , memoryArchiveFactory_(new MemoryArchiveFactory())106 #endif107 102 , renderWindow_(0) 108 103 , viewport_(0) … … 126 121 // Only for development runs 127 122 if (PathConfig::isDevelopmentRun()) 128 {129 123 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem"); 130 extResources_.reset(new XMLFile("resources.oxr")); 131 extResources_->setLuaSupport(false);132 Loader::open(extResources_.get());133 }124 125 extResources_.reset(new XMLFile("resources.oxr")); 126 extResources_->setLuaSupport(false); 127 Loader::open(extResources_.get()); 134 128 135 129 if (bLoadRenderer) … … 156 150 // Undeclare the resources 157 151 Loader::unload(resources_.get()); 158 if (PathConfig::isDevelopmentRun()) 159 Loader::unload(extResources_.get()); 152 Loader::unload(extResources_.get()); 160 153 } 161 154 … … 164 157 SetConfigValue(ogreConfigFile_, "ogre.cfg") 165 158 .description("Location of the Ogre config file"); 166 SetConfigValue(ogrePluginsDirectory_, specialConfig::ogrePluginsDirectory)167 .description("Folder where the Ogre plugins are located.");168 159 SetConfigValue(ogrePlugins_, specialConfig::ogrePlugins) 169 160 .description("Comma separated list of all plugins to load."); … … 196 187 this->loadRenderer(); 197 188 198 #if OGRE_VERSION < 0x010600199 // WORKAROUND: There is an incompatibility for particle scripts when trying200 // to support both Ogre 1.4 and 1.6. The hacky solution is to create201 // scripts for the 1.6 version and then remove the inserted "particle_system"202 // keyword. But we need to supply these new scripts as well, which is why203 // there is an extra Ogre::Archive dealing with it in the memory.204 using namespace Ogre;205 ArchiveManager::getSingleton().addArchiveFactory(memoryArchiveFactory_.get());206 const StringVector& groups = ResourceGroupManager::getSingleton().getResourceGroups();207 // Travers all groups208 for (StringVector::const_iterator itGroup = groups.begin(); itGroup != groups.end(); ++itGroup)209 {210 FileInfoListPtr files = ResourceGroupManager::getSingleton().findResourceFileInfo(*itGroup, "*.particle");211 for (FileInfoList::const_iterator itFile = files->begin(); itFile != files->end(); ++itFile)212 {213 // open file214 Ogre::DataStreamPtr input = ResourceGroupManager::getSingleton().openResource(itFile->filename, *itGroup, false);215 std::stringstream output;216 // Parse file and replace "particle_system" with nothing217 while (!input->eof())218 {219 std::string line = input->getLine();220 size_t pos = line.find("particle_system");221 if (pos != std::string::npos)222 {223 // 15 is the length of "particle_system"224 line.replace(pos, 15, "");225 }226 output << line << std::endl;227 }228 // Add file to the memory archive229 shared_array<char> data(new char[output.str().size()]);230 // Debug optimisations231 const std::string& outputStr = output.str();232 char* rawData = data.get();233 for (unsigned i = 0; i < outputStr.size(); ++i)234 rawData[i] = outputStr[i];235 MemoryArchive::addFile("particle_scripts_ogre_1.4_" + *itGroup, itFile->filename, data, output.str().size());236 }237 if (!files->empty())238 {239 // Declare the files, but using a new group240 ResourceGroupManager::getSingleton().addResourceLocation("particle_scripts_ogre_1.4_" + *itGroup,241 "Memory", "particle_scripts_ogre_1.4_" + *itGroup);242 }243 }244 #endif245 246 189 // Initialise all resources (do this AFTER the renderer has been loaded!) 247 190 // Note: You can only do this once! Ogre will check whether a resource group has … … 305 248 void GraphicsManager::loadOgrePlugins() 306 249 { 307 // just to make sure the next statement doesn't segfault 308 if (ogrePluginsDirectory_.empty()) 309 ogrePluginsDirectory_ = '.'; 310 311 boost::filesystem::path folder(ogrePluginsDirectory_); 250 // Plugin path can have many different locations... 251 std::string pluginPath = specialConfig::ogrePluginsDirectory; 252 #ifdef DEPENDENCY_PACKAGE_ENABLE 253 if (!PathConfig::isDevelopmentRun()) 254 { 255 # if defined(ORXONOX_PLATFORM_WINDOWS) 256 pluginPath = PathConfig::getExecutablePathString(); 257 # elif defined(ORXONOX_PLATFORM_APPLE) 258 // TODO: Where are the plugins being installed to? 259 pluginPath = PathConfig::getExecutablePathString(); 260 # endif 261 } 262 #endif 263 264 #ifdef ORXONOX_PLATFORM_WINDOWS 265 // Add OGRE plugin path to the environment. That way one plugin could 266 // also depend on another without problems on Windows 267 const char* currentPATH = getenv("PATH"); 268 std::string newPATH = pluginPath; 269 if (currentPATH != NULL) 270 newPATH = std::string(currentPATH) + ';' + newPATH; 271 putenv(const_cast<char*>(("PATH=" + newPATH).c_str())); 272 #endif 273 312 274 // Do some SubString magic to get the comma separated list of plugins 313 275 SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '{', '}', false, '\0'); 314 // Use backslash paths on Windows! file_string() already does that though.315 276 for (unsigned int i = 0; i < plugins.size(); ++i) 316 ogreRoot_->loadPlugin( (folder / plugins[i]).file_string());277 ogreRoot_->loadPlugin(pluginPath + '/' + plugins[i]); 317 278 } 318 279
Note: See TracChangeset
for help on using the changeset viewer.