Changeset 3254 for code/branches/core4/src/orxonox
- Timestamp:
- Jun 29, 2009, 10:01:38 PM (15 years ago)
- Location:
- code/branches/core4/src/orxonox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/orxonox/GraphicsManager.cc
r3250 r3254 38 38 #include <fstream> 39 39 #include <boost/filesystem.hpp> 40 #include <boost/shared_ptr.hpp> 40 41 41 42 #include <OgreCompositorManager.h> … … 70 71 namespace orxonox 71 72 { 73 using boost::shared_ptr; 74 72 75 class _OrxonoxExport OgreWindowEventListener : public Ogre::WindowEventListener 73 76 { … … 89 92 , renderWindow_(0) 90 93 , viewport_(0) 91 , ogreWindowEventListener_( 0)94 , ogreWindowEventListener_(new OgreWindowEventListener()) 92 95 { 93 96 RegisterObject(GraphicsManager); … … 96 99 singletonRef_s = this; 97 100 98 this->loaded_ = false;99 100 101 this->setConfigValues(); 101 } 102 103 void GraphicsManager::initialise() 104 { 102 105 103 // Ogre setup procedure 106 104 setupOgre(); 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 112 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 this->loaded_ = true; 105 106 try 107 { 108 // load all the required plugins for Ogre 109 loadOgrePlugins(); 110 // read resource declaration file 111 this->declareResources(); 112 // Reads ogre config and creates the render window 113 this->loadRenderer(); 114 115 // TODO: Spread this 116 this->initialiseResources(); 117 118 // add console commands 119 FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen); 120 functor1->setObject(this); 121 ccPrintScreen_ = createConsoleCommand(functor1, "printScreen"); 122 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 123 } 124 catch (...) 125 { 126 // clean up 127 delete this->ogreRoot_; 128 delete this->ogreLogger_; 129 delete this->ogreWindowEventListener_; 130 throw; 131 } 124 132 } 125 133 … … 130 138 GraphicsManager::~GraphicsManager() 131 139 { 132 if (this->loaded_) 133 { 134 delete this->ccPrintScreen_; 135 136 if (this->ogreWindowEventListener_) 137 { 138 // remove our WindowEventListener first to avoid bad calls after the window has been destroyed 139 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this->ogreWindowEventListener_); 140 delete this->ogreWindowEventListener_; 141 } 142 143 // destroy render window 144 // Ogre::RenderSystem* renderer = this->ogreRoot_->getRenderSystem(); 145 // renderer->destroyRenderWindow("Orxonox"); 146 147 // HACK! This fixes an exit crash 148 Map::hackDestroyMap(); 149 150 // unload all compositors 151 Ogre::CompositorManager::getSingleton().removeAll(); 152 153 // Delete OGRE main control organ 154 delete this->ogreRoot_; 155 156 // delete the ogre log and the logManager (since we have created it in the first place). 157 this->ogreLogger_->getDefaultLog()->removeListener(this); 158 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 159 delete this->ogreLogger_; 160 } 140 /* 141 delete this->ccPrintScreen_; 142 */ 143 144 // HACK! This fixes an exit crash 145 Map::hackDestroyMap(); 146 // unload all compositors (this is only necessary because we don't yet destroy all resources!) 147 Ogre::CompositorManager::getSingleton().removeAll(); 148 149 // Delete OGRE main control organ 150 delete this->ogreRoot_; 151 152 // delete the logManager (since we have created it in the first place). 153 delete this->ogreLogger_; 154 155 delete this->ogreWindowEventListener_; 161 156 162 157 assert(singletonRef_s); … … 194 189 void GraphicsManager::update(const Clock& time) 195 190 { 196 if (this->loaded_) 197 { 198 Ogre::FrameEvent evt; 199 evt.timeSinceLastFrame = time.getDeltaTime(); 200 evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway 201 202 // don't forget to call _fireFrameStarted to OGRE to make sure 203 // everything goes smoothly 204 ogreRoot_->_fireFrameStarted(evt); 205 206 // Pump messages in all registered RenderWindows 207 // This calls the WindowEventListener objects. 208 Ogre::WindowEventUtilities::messagePump(); 209 // make sure the window stays active even when not focused 210 // (probably only necessary on windows) 211 this->renderWindow_->setActive(true); 212 213 // render 214 ogreRoot_->_updateAllRenderTargets(); 215 216 // again, just to be sure OGRE works fine 217 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 218 } 191 Ogre::FrameEvent evt; 192 evt.timeSinceLastFrame = time.getDeltaTime(); 193 evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway 194 195 // don't forget to call _fireFrameStarted to OGRE to make sure 196 // everything goes smoothly 197 ogreRoot_->_fireFrameStarted(evt); 198 199 // Pump messages in all registered RenderWindows 200 // This calls the WindowEventListener objects. 201 Ogre::WindowEventUtilities::messagePump(); 202 // make sure the window stays active even when not focused 203 // (probably only necessary on windows) 204 this->renderWindow_->setActive(true); 205 206 // render 207 ogreRoot_->_updateAllRenderTargets(); 208 209 // again, just to be sure OGRE works fine 210 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 219 211 } 220 212 … … 248 240 // create a new logManager 249 241 // Ogre::Root will detect that we've already created a Log 250 ogreLogger_ = new Ogre::LogManager();242 std::auto_ptr<Ogre::LogManager> logger(new Ogre::LogManager()); 251 243 COUT(4) << "Ogre LogManager created" << std::endl; 252 244 253 245 // create our own log that we can listen to 254 246 Ogre::Log *myLog; 255 myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);247 myLog = logger->createLog(ogreLogFilepath.string(), true, false, false); 256 248 COUT(4) << "Ogre Log created" << std::endl; 257 249 … … 272 264 // Leave plugins file empty. We're going to do that part manually later 273 265 ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()); 266 // In case that new Root failed the logger gets destroyed because of the std::auto_ptr 267 ogreLogger_ = logger.release(); 274 268 275 269 COUT(3) << "Ogre set up done." << std::endl; … … 348 342 if (!ogreRoot_->restoreConfig()) 349 343 if (!ogreRoot_->showConfigDialog()) 350 ThrowException(InitialisationFailed, " Could not show Ogre configuration dialogue.");344 ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue failed."); 351 345 352 346 CCOUT(4) << "Creating render window" << std::endl; … … 354 348 this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox"); 355 349 356 this->ogreWindowEventListener_ = new OgreWindowEventListener();357 350 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_); 358 351 -
code/branches/core4/src/orxonox/GraphicsManager.h
r3196 r3254 57 57 58 58 void setConfigValues(); 59 void initialise();60 59 61 60 void update(const Clock& time); … … 93 92 94 93 private: 95 bool loaded_;96 97 94 Ogre::Root* ogreRoot_; //!< Ogre's root 98 95 Ogre::LogManager* ogreLogger_; 99 96 Ogre::RenderWindow* renderWindow_; //!< the one and only render window 100 97 Ogre::Viewport* viewport_; //!< default full size viewport 101 OgreWindowEventListener* ogreWindowEventListener_; 98 OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h 102 99 103 100 // config values -
code/branches/core4/src/orxonox/gamestates/GSGraphics.cc
r3243 r3254 108 108 setConfigValues(); 109 109 110 // initialise graphics manager. Doesn't load the render window yet!110 // Load OGRE including the render window 111 111 this->graphicsManager_ = new GraphicsManager(); 112 this->graphicsManager_->initialise();113 112 114 113 // load debug overlay
Note: See TracChangeset
for help on using the changeset viewer.