Changeset 5658 for code/branches/resource2/src
- Timestamp:
- Aug 18, 2009, 11:14:25 AM (15 years ago)
- Location:
- code/branches/resource2/src/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/src/core/Core.cc
r5655 r5658 303 303 void Core::loadGraphics() 304 304 { 305 if (bGraphicsLoaded_)306 return;305 // Any exception should trigger this, even in upgradeToGraphics (see its remarks) 306 Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics); 307 307 308 308 // Upgrade OGRE to receive a render window … … 314 314 315 315 // Calls the InputManager which sets up the input devices. 316 scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));316 inputManager_.reset(new InputManager(windowHnd)); 317 317 318 318 // load the CEGUI interface 319 319 guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow())); 320 320 321 // Dismiss scoped pointer 322 inputManager_.swap(inputManager); 321 unloader.Dismiss(); 323 322 324 323 bGraphicsLoaded_ = true; … … 327 326 void Core::unloadGraphics() 328 327 { 329 if (!bGraphicsLoaded_)330 return;331 332 328 this->guiManager_.reset();; 333 329 this->inputManager_.reset();; … … 637 633 } 638 634 639 bool Core::preUpdate(const Clock& time) throw() 640 { 641 std::string exceptionMessage; 642 try 643 { 644 if (this->bGraphicsLoaded_) 645 { 646 // process input events 647 this->inputManager_->update(time); 648 // process gui events 649 this->guiManager_->update(time); 650 } 651 // process thread commands 652 this->tclThreadManager_->update(time); 653 } 654 catch (const std::exception& ex) 655 { exceptionMessage = ex.what(); } 656 catch (...) 657 { exceptionMessage = "Unknown exception"; } 658 if (!exceptionMessage.empty()) 659 { 660 COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl; 661 COUT(0) << "This should really never happen! Closing the program." << std::endl; 662 return false; 663 } 664 return true; 665 } 666 667 bool Core::postUpdate(const Clock& time) throw() 668 { 669 std::string exceptionMessage; 670 try 671 { 672 if (this->bGraphicsLoaded_) 673 { 674 // Render (doesn't throw) 675 this->graphicsManager_->update(time); 676 } 677 } 678 catch (const std::exception& ex) 679 { exceptionMessage = ex.what(); } 680 catch (...) 681 { exceptionMessage = "Unknown exception"; } 682 if (!exceptionMessage.empty()) 683 { 684 COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl; 685 COUT(0) << "This should really never happen! Closing the program." << std::endl; 686 return false; 687 } 688 return true; 635 void Core::preUpdate(const Clock& time) 636 { 637 if (this->bGraphicsLoaded_) 638 { 639 // process input events 640 this->inputManager_->update(time); 641 // process gui events 642 this->guiManager_->update(time); 643 } 644 // process thread commands 645 this->tclThreadManager_->update(time); 646 } 647 648 void Core::postUpdate(const Clock& time) 649 { 650 if (this->bGraphicsLoaded_) 651 { 652 // Render (doesn't throw) 653 this->graphicsManager_->update(time); 654 } 689 655 } 690 656 } -
code/branches/resource2/src/core/Core.h
r5654 r5658 65 65 typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard; 66 66 friend class Singleton<Core>; 67 friend class Game; 67 68 68 69 public: … … 78 79 79 80 void setConfigValues(); 80 81 bool preUpdate(const Clock& time) throw();82 bool postUpdate(const Clock& time) throw();83 84 void loadGraphics();85 void unloadGraphics();86 81 87 82 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); … … 117 112 Core(const Core&); //!< Don't use (undefined symbol) 118 113 114 void preUpdate(const Clock& time); 115 void postUpdate(const Clock& time); 116 117 void loadGraphics(); 118 void unloadGraphics(); 119 119 120 void checkDevBuild(); 120 121 void setExecutablePath(); -
code/branches/resource2/src/core/GUIManager.cc
r5654 r5658 109 109 COUT(3) << "Initialising CEGUI." << std::endl; 110 110 111 try 112 { 113 // Note: No SceneManager specified yet 114 guiRenderer_.reset(new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000)); 115 resourceProvider_ = guiRenderer_->createResourceProvider(); 116 resourceProvider_->setDefaultResourceGroup("GUI"); 117 118 // setup scripting 119 scriptModule_.reset(new LuaScriptModule()); 120 luaState_ = scriptModule_->getLuaState(); 121 122 // Create our own logger to specify the filepath 123 std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger()); 124 ceguiLogger->setLogFilename(Core::getLogPathString() + "cegui.log"); 125 // set the log level according to ours (translate by subtracting 1) 126 ceguiLogger->setLoggingLevel( 127 static_cast<LoggingLevel>(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1)); 128 this->ceguiLogger_ = ceguiLogger.release(); 129 130 // create the CEGUI system singleton 131 guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get())); 132 133 // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place 134 LuaState::openToluaInterfaces(this->luaState_); 135 136 // initialise the basic lua code 137 this->loadLuaCode(); 138 } 139 catch (CEGUI::Exception& ex) 140 { 141 #if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6 142 throw GeneralException(ex.getMessage().c_str()); 143 #else 144 throw GeneralException(ex.getMessage().c_str(), ex.getLine(), 145 ex.getFileName().c_str(), ex.getName().c_str()); 146 #endif 147 } 111 // Note: No SceneManager specified yet 112 guiRenderer_.reset(new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000)); 113 resourceProvider_ = guiRenderer_->createResourceProvider(); 114 resourceProvider_->setDefaultResourceGroup("GUI"); 115 116 // setup scripting 117 scriptModule_.reset(new LuaScriptModule()); 118 luaState_ = scriptModule_->getLuaState(); 119 120 // Create our own logger to specify the filepath 121 std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger()); 122 ceguiLogger->setLogFilename(Core::getLogPathString() + "cegui.log"); 123 // set the log level according to ours (translate by subtracting 1) 124 ceguiLogger->setLoggingLevel( 125 static_cast<LoggingLevel>(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1)); 126 this->ceguiLogger_ = ceguiLogger.release(); 127 128 // create the CEGUI system singleton 129 guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get())); 130 131 // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place 132 LuaState::openToluaInterfaces(this->luaState_); 133 134 // initialise the basic lua code 135 this->loadLuaCode(); 148 136 } 149 137 -
code/branches/resource2/src/core/Game.cc
r5651 r5658 37 37 #include <exception> 38 38 #include <boost/weak_ptr.hpp> 39 #include <CEGUIExceptions.h> 39 40 40 41 #include "util/Debug.h" … … 197 198 198 199 // Core preUpdate (doesn't throw) 199 if (!this->core_->preUpdate(*this->gameClock_)) 200 { 200 try 201 { this->core_->preUpdate(*this->gameClock_); } 202 catch (...) 203 { 204 COUT(0) << "An exception occurred in the Core preUpdate: " << Game::getExceptionMessage() << std::endl; 205 COUT(0) << "This should really never happen! Closing the program." << std::endl; 201 206 this->stop(); 202 207 break; … … 207 212 208 213 // Core postUpdate (doesn't throw) 209 if (!this->core_->postUpdate(*this->gameClock_)) 210 { 214 try 215 { this->core_->postUpdate(*this->gameClock_); } 216 catch (...) 217 { 218 COUT(0) << "An exception occurred in the Core postUpdate: " << Game::getExceptionMessage() << std::endl; 219 COUT(0) << "This should really never happen! Closing the program." << std::endl; 211 220 this->stop(); 212 221 break; … … 241 250 this->loadState(requestedStateNode->name_); 242 251 } 243 catch ( const std::exception& ex)252 catch (...) 244 253 { 245 COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << ex.what() << std::endl;254 COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << Game::getExceptionMessage() << std::endl; 246 255 // All scheduled operations have now been rendered inert --> flush them and issue a warning 247 256 if (this->requestedStateNodes_.size() > 1) 248 COUT( 1) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl;257 COUT(4) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl; 249 258 this->requestedStateNodes_.clear(); 250 259 break; … … 262 271 it != this->loadedStates_.end(); ++it) 263 272 { 264 std::string exceptionMessage;265 273 try 266 274 { … … 273 281 this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick)); 274 282 } 275 catch (const std::exception& ex)276 { exceptionMessage = ex.what(); }277 283 catch (...) 278 { exceptionMessage = "Unknown exception"; } 279 if (!exceptionMessage.empty()) 280 { 281 COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << exceptionMessage << std::endl; 284 { 285 COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << Game::getExceptionMessage() << std::endl; 282 286 COUT(1) << "This should really never happen!" << std::endl; 283 287 COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl; … … 585 589 state->deactivate(); 586 590 } 591 catch (...) 592 { 593 COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << Game::getExceptionMessage() << std::endl; 594 COUT(2) << " There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl; 595 } 596 // Check if graphics is still required 597 if (!bAbort_) 598 { 599 bool graphicsRequired = false; 600 for (unsigned i = 0; i < loadedStates_.size(); ++i) 601 graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode; 602 if (!graphicsRequired) 603 this->unloadGraphics(); 604 } 605 this->bChangingState_ = false; 606 } 607 608 /*static*/ std::string Game::getExceptionMessage() 609 { 610 std::string exceptionMessage; 611 try 612 { 613 // rethrow 614 throw; 615 } 587 616 catch (const std::exception& ex) 588 617 { 589 COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << ex.what() << std::endl; 590 COUT(2) << " There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl; 591 } 592 // Check if graphics is still required 593 bool graphicsRequired = false; 594 for (unsigned i = 0; i < loadedStates_.size(); ++i) 595 graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode; 596 if (!graphicsRequired) 597 this->unloadGraphics(); 598 this->bChangingState_ = false; 618 return ex.what(); 619 } 620 catch (const CEGUI::Exception& ex) 621 { 622 #if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6 623 return GeneralException(ex.getMessage().c_str()).getDescription(); 624 #else 625 return GeneralException(ex.getMessage().c_str(), ex.getLine(), 626 ex.getFileName().c_str(), ex.getName().c_str()).getDescription(); 627 #endif 628 } 629 catch (...) 630 { 631 return "Unknown exception"; 632 } 599 633 } 600 634 -
code/branches/resource2/src/core/Game.h
r5651 r5658 151 151 // ScopeGuard helper function 152 152 void resetChangingState() { this->bChangingState_ = false; } 153 /** 154 @brief 155 Retrieves information from an exception caught with "..." 156 @remarks 157 Never ever call this function without an exception in the stack! 158 */ 159 static std::string getExceptionMessage(); 153 160 154 161 scoped_ptr<Clock> gameClock_; -
code/branches/resource2/src/core/GraphicsManager.cc
r5657 r5658 152 152 @remarks 153 153 This operation is irreversible without recreating the GraphicsManager! 154 So if it throws you HAVE to recreate the GraphicsManager!!! 155 It therefore offers almost no exception safety. 154 156 */ 155 157 void GraphicsManager::upgradeToGraphics()
Note: See TracChangeset
for help on using the changeset viewer.