Changeset 5614
- Timestamp:
- Aug 10, 2009, 5:36:45 PM (15 years ago)
- Location:
- code/branches/resource2/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/src/core/Core.cc
r3370 r5614 313 313 // creates the class hierarchy for all classes with factories 314 314 Factory::createClassHierarchy(); 315 316 // Load OGRE excluding the renderer and the render window 317 this->graphicsManager_.reset(new GraphicsManager(false)); 315 318 } 316 319 … … 328 331 return; 329 332 330 // Load OGRE including therender window331 scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());333 // Upgrade OGRE to receive a render window 334 graphicsManager_->upgradeToGraphics(); 332 335 333 336 // The render window width and height are used to set up the mouse movement. 334 337 size_t windowHnd = 0; 335 graphicsManager ->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);338 graphicsManager_->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd); 336 339 337 340 // Calls the InputManager which sets up the input devices. … … 339 342 340 343 // load the CEGUI interface 341 guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow())); 342 343 // Dismiss scoped pointers 344 graphicsManager_.swap(graphicsManager); 344 guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow())); 345 346 // Dismiss scoped pointer 345 347 inputManager_.swap(inputManager); 346 348 … … 356 358 this->inputManager_.reset();; 357 359 this->graphicsManager_.reset(); 360 361 // Load Ogre::Root again, but without the render system 362 this->graphicsManager_.reset(new GraphicsManager(false)); 358 363 359 364 bGraphicsLoaded_ = false; -
code/branches/resource2/src/core/GraphicsManager.cc
r3370 r5614 37 37 38 38 #include <fstream> 39 #include <memory>40 39 #include <boost/filesystem.hpp> 41 #include <boost/shared_ptr.hpp> 42 43 #include <OgreCompositorManager.h> 44 #include <OgreConfigFile.h> 40 45 41 #include <OgreFrameListener.h> 46 42 #include <OgreRoot.h> … … 49 45 #include <OgreRenderWindow.h> 50 46 #include <OgreRenderSystem.h> 51 #include <OgreTextureManager.h>52 47 #include <OgreViewport.h> 53 48 #include <OgreWindowEventUtilities.h> … … 68 63 namespace orxonox 69 64 { 70 using boost::shared_ptr;71 72 65 class OgreWindowEventListener : public Ogre::WindowEventListener 73 66 { … … 89 82 Non-initialising constructor. 90 83 */ 91 GraphicsManager::GraphicsManager() 92 : ogreRoot_(0) 93 , ogreLogger_(0) 94 , renderWindow_(0) 84 GraphicsManager::GraphicsManager(bool bLoadRenderer) 85 : renderWindow_(0) 95 86 , viewport_(0) 96 87 , ogreWindowEventListener_(new OgreWindowEventListener()) … … 100 91 this->setConfigValues(); 101 92 102 // Ogre setup procedure 103 setupOgre(); 104 105 try 106 { 107 // load all the required plugins for Ogre 108 loadOgrePlugins(); 109 // read resource declaration file 110 this->declareResources(); 111 // Reads ogre config and creates the render window 93 // Ogre setup procedure (creating Ogre::Root) 94 this->loadOgreRoot(); 95 // load all the required plugins for Ogre 96 this->loadOgrePlugins(); 97 98 if (bLoadRenderer) 99 { 100 // Reads the ogre config and creates the render window 112 101 this->loadRenderer(); 113 114 // TODO: Spread this 115 this->initialiseResources(); 116 117 // add console commands 118 FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen); 119 functor1->setObject(this); 120 ccPrintScreen_ = createConsoleCommand(functor1, "printScreen"); 121 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 122 } 123 catch (...) 124 { 125 // clean up 126 delete this->ogreRoot_; 127 delete this->ogreLogger_; 128 delete this->ogreWindowEventListener_; 129 throw; 130 } 131 } 132 133 /** 134 @brief 135 Destroys all the Ogre related objects 102 } 103 } 104 105 /** 106 @brief 107 Destruction is done by the member scoped_ptrs. 136 108 */ 137 109 GraphicsManager::~GraphicsManager() 138 110 { 139 /*140 delete this->ccPrintScreen_;141 */142 143 // unload all compositors (this is only necessary because we don't yet destroy all resources!)144 Ogre::CompositorManager::getSingleton().removeAll();145 146 // Delete OGRE main control organ147 delete this->ogreRoot_;148 149 // delete the logManager (since we have created it in the first place).150 delete this->ogreLogger_;151 152 delete this->ogreWindowEventListener_;153 111 } 154 112 155 113 void GraphicsManager::setConfigValues() 156 114 { 157 SetConfigValue(resourceFile_, "resources.cfg")158 .description("Location of the resources file in the data path.");159 115 SetConfigValue(ogreConfigFile_, "ogre.cfg") 160 116 .description("Location of the Ogre config file"); … … 173 129 } 174 130 131 /** 132 @brief 133 Loads the renderer and creates the render window if not yet done so. 134 @remarks 135 This operation is irreversible without recreating the GraphicsManager! 136 */ 137 void GraphicsManager::upgradeToGraphics() 138 { 139 if (renderWindow_ == NULL) 140 { 141 this->loadRenderer(); 142 } 143 } 144 145 /** 146 @brief 147 Creates the Ogre Root object and sets up the ogre log. 148 */ 149 void GraphicsManager::loadOgreRoot() 150 { 151 COUT(3) << "Setting up Ogre..." << std::endl; 152 153 if (ogreConfigFile_ == "") 154 { 155 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl; 156 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg"); 157 } 158 if (ogreLogFile_ == "") 159 { 160 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl; 161 ModifyConfigValue(ogreLogFile_, tset, "ogre.log"); 162 } 163 164 boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_); 165 boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_); 166 167 // create a new logManager 168 // Ogre::Root will detect that we've already created a Log 169 ogreLogger_.reset(new Ogre::LogManager()); 170 COUT(4) << "Ogre LogManager created" << std::endl; 171 172 // create our own log that we can listen to 173 Ogre::Log *myLog; 174 myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false); 175 COUT(4) << "Ogre Log created" << std::endl; 176 177 myLog->setLogDetail(Ogre::LL_BOREME); 178 myLog->addListener(this); 179 180 COUT(4) << "Creating Ogre Root..." << std::endl; 181 182 // check for config file existence because Ogre displays (caught) exceptions if not 183 if (!boost::filesystem::exists(ogreConfigFilepath)) 184 { 185 // create a zero sized file 186 std::ofstream creator; 187 creator.open(ogreConfigFilepath.string().c_str()); 188 creator.close(); 189 } 190 191 // Leave plugins file empty. We're going to do that part manually later 192 ogreRoot_.reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string())); 193 194 COUT(3) << "Ogre set up done." << std::endl; 195 } 196 197 void GraphicsManager::loadOgrePlugins() 198 { 199 // just to make sure the next statement doesn't segfault 200 if (ogrePluginsFolder_ == "") 201 ogrePluginsFolder_ = "."; 202 203 boost::filesystem::path folder(ogrePluginsFolder_); 204 // Do some SubString magic to get the comma separated list of plugins 205 SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '(', ')', false, '\0'); 206 // Use backslash paths on Windows! file_string() already does that though. 207 for (unsigned int i = 0; i < plugins.size(); ++i) 208 ogreRoot_->loadPlugin((folder / plugins[i]).file_string()); 209 } 210 211 void GraphicsManager::loadRenderer() 212 { 213 CCOUT(4) << "Configuring Renderer" << std::endl; 214 215 if (!ogreRoot_->restoreConfig()) 216 if (!ogreRoot_->showConfigDialog()) 217 ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue failed."); 218 219 CCOUT(4) << "Creating render window" << std::endl; 220 221 this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox"); 222 // Propagate the size of the new winodw 223 this->ogreWindowEventListener_->windowResized(renderWindow_); 224 225 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_.get()); 226 227 // create a full screen default viewport 228 // Note: This may throw when adding a viewport with an existing z-order! 229 // But in our case we only have one viewport for now anyway, therefore 230 // no ScopeGuards or anything to handle exceptions. 231 this->viewport_ = this->renderWindow_->addViewport(0, 0); 232 233 // add console commands 234 FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen); 235 ccPrintScreen_ = createConsoleCommand(functor1->setObject(this), "printScreen"); 236 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 237 } 238 175 239 void GraphicsManager::update(const Clock& time) 176 240 { … … 207 271 { 208 272 this->viewport_->setCamera(camera); 209 }210 211 /**212 @brief213 Creates the Ogre Root object and sets up the ogre log.214 */215 void GraphicsManager::setupOgre()216 {217 COUT(3) << "Setting up Ogre..." << std::endl;218 219 if (ogreConfigFile_ == "")220 {221 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;222 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");223 }224 if (ogreLogFile_ == "")225 {226 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;227 ModifyConfigValue(ogreLogFile_, tset, "ogre.log");228 }229 230 boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);231 boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);232 233 // create a new logManager234 // Ogre::Root will detect that we've already created a Log235 std::auto_ptr<Ogre::LogManager> logger(new Ogre::LogManager());236 COUT(4) << "Ogre LogManager created" << std::endl;237 238 // create our own log that we can listen to239 Ogre::Log *myLog;240 myLog = logger->createLog(ogreLogFilepath.string(), true, false, false);241 COUT(4) << "Ogre Log created" << std::endl;242 243 myLog->setLogDetail(Ogre::LL_BOREME);244 myLog->addListener(this);245 246 COUT(4) << "Creating Ogre Root..." << std::endl;247 248 // check for config file existence because Ogre displays (caught) exceptions if not249 if (!boost::filesystem::exists(ogreConfigFilepath))250 {251 // create a zero sized file252 std::ofstream creator;253 creator.open(ogreConfigFilepath.string().c_str());254 creator.close();255 }256 257 // Leave plugins file empty. We're going to do that part manually later258 ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());259 // In case that new Root failed the logger gets destroyed because of the std::auto_ptr260 ogreLogger_ = logger.release();261 262 COUT(3) << "Ogre set up done." << std::endl;263 }264 265 void GraphicsManager::loadOgrePlugins()266 {267 // just to make sure the next statement doesn't segfault268 if (ogrePluginsFolder_ == "")269 ogrePluginsFolder_ = ".";270 271 boost::filesystem::path folder(ogrePluginsFolder_);272 // Do some SubString magic to get the comma separated list of plugins273 SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '(', ')', false, '\0');274 // Use backslash paths on Windows! file_string() already does that though.275 for (unsigned int i = 0; i < plugins.size(); ++i)276 ogreRoot_->loadPlugin((folder / plugins[i]).file_string());277 }278 279 void GraphicsManager::declareResources()280 {281 CCOUT(4) << "Declaring Resources" << std::endl;282 //TODO: Specify layout of data file and maybe use xml-loader283 //TODO: Work with ressource groups (should be generated by a special loader)284 285 if (resourceFile_ == "")286 {287 COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;288 ModifyConfigValue(resourceFile_, tset, "resources.cfg");289 }290 291 // Load resource paths from data file using configfile ressource type292 Ogre::ConfigFile cf;293 try294 {295 cf.load((Core::getMediaPath() / resourceFile_).string());296 }297 catch (...)298 {299 //COUT(1) << ex.getFullDescription() << std::endl;300 COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;301 throw;302 }303 304 // Go through all sections & settings in the file305 Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();306 307 std::string secName, typeName, archName;308 while (seci.hasMoreElements())309 {310 try311 {312 secName = seci.peekNextKey();313 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();314 Ogre::ConfigFile::SettingsMultiMap::iterator i;315 for (i = settings->begin(); i != settings->end(); ++i)316 {317 typeName = i->first; // for instance "FileSystem" or "Zip"318 archName = i->second; // name (and location) of archive319 320 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(321 (Core::getMediaPath() / archName).string(), typeName, secName);322 }323 }324 catch (Ogre::Exception& ex)325 {326 COUT(1) << ex.getFullDescription() << std::endl;327 }328 }329 }330 331 void GraphicsManager::loadRenderer()332 {333 CCOUT(4) << "Configuring Renderer" << std::endl;334 335 if (!ogreRoot_->restoreConfig())336 if (!ogreRoot_->showConfigDialog())337 ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue failed.");338 339 CCOUT(4) << "Creating render window" << std::endl;340 341 this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");342 this->ogreWindowEventListener_->windowResized(renderWindow_);343 344 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);345 346 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);347 348 // create a full screen default viewport349 this->viewport_ = this->renderWindow_->addViewport(0, 0);350 }351 352 void GraphicsManager::initialiseResources()353 {354 CCOUT(4) << "Initialising resources" << std::endl;355 //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...356 //try357 //{358 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();359 /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();360 for (unsigned int i = 0; i < str.size(); i++)361 {362 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);363 }*/364 //}365 //catch (...)366 //{367 // CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;368 // throw;369 //}370 273 } 371 274 -
code/branches/resource2/src/core/GraphicsManager.h
r3370 r5614 42 42 #include <string> 43 43 #include <OgreLog.h> 44 #include <boost/scoped_ptr.hpp> 45 44 46 #include "util/Singleton.h" 45 47 #include "OrxonoxClass.h" … … 47 49 namespace orxonox 48 50 { 51 using boost::scoped_ptr; 52 49 53 /** 50 54 @brief … … 55 59 friend class Singleton<GraphicsManager>; 56 60 public: 57 GraphicsManager( );61 GraphicsManager(bool bLoadRenderer = true); 58 62 ~GraphicsManager(); 59 63 … … 62 66 void update(const Clock& time); 63 67 64 inline Ogre::Viewport* getViewport() 65 { return this->viewport_; } 66 inline Ogre::RenderWindow* getRenderWindow() 67 { return this->renderWindow_; } 68 Ogre::Viewport* getViewport() { return this->viewport_; } 69 Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; } 70 71 void upgradeToGraphics(); 72 bool rendererLoaded() const { return renderWindow_ != NULL; } 68 73 69 74 void setCamera(Ogre::Camera* camera); … … 73 78 74 79 // OGRE initialisation 75 void setupOgre();80 void loadOgreRoot(); 76 81 void loadOgrePlugins(); 77 void declareResources();78 82 void loadRenderer(); 79 void initialiseResources();80 83 81 84 // event from Ogre::LogListener … … 87 90 88 91 private: 89 Ogre::Root* ogreRoot_; //!< Ogre's root 90 Ogre::LogManager* ogreLogger_; 92 scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h 93 scoped_ptr<Ogre::LogManager> ogreLogger_; 94 scoped_ptr<Ogre::Root> ogreRoot_; //!< Ogre's root 91 95 Ogre::RenderWindow* renderWindow_; //!< the one and only render window 92 96 Ogre::Viewport* viewport_; //!< default full size viewport 93 OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h94 97 95 98 // config values 96 std::string resourceFile_; //!< resources file name97 99 std::string ogreConfigFile_; //!< ogre config file name 98 100 std::string ogrePluginsFolder_; //!< Folder where the Ogre plugins are located -
code/branches/resource2/src/orxonox/gamestates/GSLevel.cc
r3370 r5614 29 29 30 30 #include "GSLevel.h" 31 32 #include <OgreCompositorManager.h> 31 33 32 34 #include "core/input/InputManager.h" … … 170 172 */ 171 173 174 if (GameMode::showsGraphics()) 175 { 176 // unload all compositors (this is only necessary because we don't yet destroy all resources!) 177 Ogre::CompositorManager::getSingleton().removeAll(); 178 } 172 179 173 180 // this call will delete every BaseObject!
Note: See TracChangeset
for help on using the changeset viewer.