- Timestamp:
- Aug 24, 2009, 3:03:44 PM (15 years ago)
- Location:
- code/branches/resource3/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource3/src/core/Core.cc
r3370 r5677 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 … … 325 328 void Core::loadGraphics() 326 329 { 327 if (bGraphicsLoaded_)328 return;329 330 // Load OGRE including therender window331 scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());330 // Any exception should trigger this, even in upgradeToGraphics (see its remarks) 331 Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics); 332 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. 338 scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));341 inputManager_.reset(new InputManager(windowHnd)); 339 342 340 343 // load the CEGUI interface 341 guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow())); 342 343 // Dismiss scoped pointers 344 graphicsManager_.swap(graphicsManager); 345 inputManager_.swap(inputManager); 344 guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow())); 345 346 unloader.Dismiss(); 346 347 347 348 bGraphicsLoaded_ = true; … … 350 351 void Core::unloadGraphics() 351 352 { 352 if (!bGraphicsLoaded_)353 return;354 355 353 this->guiManager_.reset();; 356 354 this->inputManager_.reset();; 357 355 this->graphicsManager_.reset(); 356 357 // Load Ogre::Root again, but without the render system 358 try 359 { this->graphicsManager_.reset(new GraphicsManager(false)); } 360 catch (...) 361 { 362 COUT(0) << "An exception occurred during 'new GraphicsManager' while " 363 << "another exception was being handled. This will lead to undefined behaviour!" << std::endl 364 << "Terminating the program." << std::endl; 365 abort(); 366 } 358 367 359 368 bGraphicsLoaded_ = false; -
code/branches/resource3/src/core/Core.h
r3370 r5677 66 66 typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard; 67 67 friend class Singleton<Core>; 68 friend class Game; 68 69 69 70 public: … … 82 83 bool preUpdate(const Clock& time) throw(); 83 84 bool postUpdate(const Clock& time) throw(); 84 85 void loadGraphics();86 void unloadGraphics();87 85 88 86 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); … … 113 111 private: 114 112 Core(const Core&); //!< Don't use (undefined symbol) 113 114 void loadGraphics(); 115 void unloadGraphics(); 115 116 116 117 void checkDevBuild(); -
code/branches/resource3/src/core/GraphicsManager.cc
r3370 r5677 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> 40 44 41 #include <OgreConfigFile.h> 45 42 #include <OgreFrameListener.h> … … 49 46 #include <OgreRenderWindow.h> 50 47 #include <OgreRenderSystem.h> 51 #include <OgreTextureManager.h>52 48 #include <OgreViewport.h> 53 49 #include <OgreWindowEventUtilities.h> … … 68 64 namespace orxonox 69 65 { 70 using boost::shared_ptr;71 72 66 class OgreWindowEventListener : public Ogre::WindowEventListener 73 67 { … … 89 83 Non-initialising constructor. 90 84 */ 91 GraphicsManager::GraphicsManager() 92 : ogreRoot_(0) 93 , ogreLogger_(0) 85 GraphicsManager::GraphicsManager(bool bLoadRenderer) 86 : ogreWindowEventListener_(new OgreWindowEventListener()) 94 87 , renderWindow_(0) 95 88 , viewport_(0) 96 , ogreWindowEventListener_(new OgreWindowEventListener())97 89 { 98 90 RegisterObject(GraphicsManager); … … 100 92 this->setConfigValues(); 101 93 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 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 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 94 // Ogre setup procedure (creating Ogre::Root) 95 this->loadOgreRoot(); 96 // load all the required plugins for Ogre 97 this->loadOgrePlugins(); 98 // read resource declaration file 99 this->declareResources(); 100 101 if (bLoadRenderer) 102 this->upgradeToGraphics(); 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 … … 173 131 } 174 132 175 void GraphicsManager::update(const Clock& time) 176 { 177 Ogre::FrameEvent evt; 178 evt.timeSinceLastFrame = time.getDeltaTime(); 179 evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway 180 181 // don't forget to call _fireFrameStarted to OGRE to make sure 182 // everything goes smoothly 183 ogreRoot_->_fireFrameStarted(evt); 184 185 // Pump messages in all registered RenderWindows 186 // This calls the WindowEventListener objects. 187 Ogre::WindowEventUtilities::messagePump(); 188 // make sure the window stays active even when not focused 189 // (probably only necessary on windows) 190 this->renderWindow_->setActive(true); 191 192 // Time before rendering 193 uint64_t timeBeforeTick = time.getRealMicroseconds(); 194 195 // Render frame 196 ogreRoot_->_updateAllRenderTargets(); 197 198 uint64_t timeAfterTick = time.getRealMicroseconds(); 199 // Subtract the time used for rendering from the tick time counter 200 Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick); 201 202 // again, just to be sure OGRE works fine 203 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 204 } 205 206 void GraphicsManager::setCamera(Ogre::Camera* camera) 207 { 208 this->viewport_->setCamera(camera); 133 /** 134 @brief 135 Loads the renderer and creates the render window if not yet done so. 136 @remarks 137 This operation is irreversible without recreating the GraphicsManager! 138 So if it throws you HAVE to recreate the GraphicsManager!!! 139 It therefore offers almost no exception safety. 140 */ 141 void GraphicsManager::upgradeToGraphics() 142 { 143 if (renderWindow_ == NULL) 144 { 145 // Reads the ogre config and creates the render window 146 this->loadRenderer(); 147 this->initialiseResources(); 148 } 209 149 } 210 150 … … 213 153 Creates the Ogre Root object and sets up the ogre log. 214 154 */ 215 void GraphicsManager:: setupOgre()155 void GraphicsManager::loadOgreRoot() 216 156 { 217 157 COUT(3) << "Setting up Ogre..." << std::endl; … … 233 173 // create a new logManager 234 174 // Ogre::Root will detect that we've already created a Log 235 std::auto_ptr<Ogre::LogManager> logger(new Ogre::LogManager());175 ogreLogger_.reset(new Ogre::LogManager()); 236 176 COUT(4) << "Ogre LogManager created" << std::endl; 237 177 238 178 // create our own log that we can listen to 239 179 Ogre::Log *myLog; 240 myLog = logger->createLog(ogreLogFilepath.string(), true, false, false);180 myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false); 241 181 COUT(4) << "Ogre Log created" << std::endl; 242 182 … … 256 196 257 197 // Leave plugins file empty. We're going to do that part manually later 258 ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()); 259 // In case that new Root failed the logger gets destroyed because of the std::auto_ptr 260 ogreLogger_ = logger.release(); 198 ogreRoot_.reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string())); 261 199 262 200 COUT(3) << "Ogre set up done." << std::endl; … … 340 278 341 279 this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox"); 280 // Propagate the size of the new winodw 342 281 this->ogreWindowEventListener_->windowResized(renderWindow_); 343 282 344 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_); 345 346 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0); 283 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_.get()); 347 284 348 285 // create a full screen default viewport 286 // Note: This may throw when adding a viewport with an existing z-order! 287 // But in our case we only have one viewport for now anyway, therefore 288 // no ScopeGuards or anything to handle exceptions. 349 289 this->viewport_ = this->renderWindow_->addViewport(0, 0); 290 291 // add console commands 292 FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen); 293 ccPrintScreen_ = createConsoleCommand(functor1->setObject(this), "printScreen"); 294 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 350 295 } 351 296 … … 370 315 } 371 316 317 void GraphicsManager::update(const Clock& time) 318 { 319 Ogre::FrameEvent evt; 320 evt.timeSinceLastFrame = time.getDeltaTime(); 321 evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway 322 323 // don't forget to call _fireFrameStarted to OGRE to make sure 324 // everything goes smoothly 325 ogreRoot_->_fireFrameStarted(evt); 326 327 // Pump messages in all registered RenderWindows 328 // This calls the WindowEventListener objects. 329 Ogre::WindowEventUtilities::messagePump(); 330 // make sure the window stays active even when not focused 331 // (probably only necessary on windows) 332 this->renderWindow_->setActive(true); 333 334 // Time before rendering 335 uint64_t timeBeforeTick = time.getRealMicroseconds(); 336 337 // Render frame 338 ogreRoot_->_updateAllRenderTargets(); 339 340 uint64_t timeAfterTick = time.getRealMicroseconds(); 341 // Subtract the time used for rendering from the tick time counter 342 Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick); 343 344 // again, just to be sure OGRE works fine 345 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 346 } 347 348 void GraphicsManager::setCamera(Ogre::Camera* camera) 349 { 350 this->viewport_->setCamera(camera); 351 } 352 372 353 /** 373 354 @brief -
code/branches/resource3/src/core/GraphicsManager.h
r3370 r5677 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 82 void declareResources(); … … 87 92 88 93 private: 89 Ogre::Root* ogreRoot_; //!< Ogre's root 90 Ogre::LogManager* ogreLogger_; 94 scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h 95 scoped_ptr<Ogre::LogManager> ogreLogger_; 96 scoped_ptr<Ogre::Root> ogreRoot_; //!< Ogre's root 91 97 Ogre::RenderWindow* renderWindow_; //!< the one and only render window 92 98 Ogre::Viewport* viewport_; //!< default full size viewport 93 OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h94 99 95 100 // config values -
code/branches/resource3/src/orxonox/gamestates/GSLevel.cc
r3370 r5677 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.