Changeset 8423
- Timestamp:
- May 9, 2011, 5:06:49 AM (14 years ago)
- Location:
- code/trunk/src/libraries
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/Core.cc
r8366 r8423 90 90 91 91 Core::Core(const std::string& cmdLine) 92 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands) 93 : identifierDestroyer_(Identifier::destroyAllIdentifiers) 94 // Cleanup guard for external console commands that don't belong to an Identifier 95 , consoleCommandDestroyer_(ConsoleCommand::destroyAll) 92 : pathConfig_(NULL) 93 , dynLibManager_(NULL) 94 , signalHandler_(NULL) 95 , configFileManager_(NULL) 96 , languageInstance_(NULL) 97 , ioConsole_(NULL) 98 , tclBind_(NULL) 99 , tclThreadManager_(NULL) 100 , rootScope_(NULL) 101 , graphicsManager_(NULL) 102 , inputManager_(NULL) 103 , guiManager_(NULL) 104 , graphicsScope_(NULL) 96 105 , bGraphicsLoaded_(false) 97 106 , bStartIOConsole_(true) … … 99 108 , ogreConfigTimestamp_(0) 100 109 , bDevMode_(false) 110 , destructionHelper_(this) 101 111 { 102 112 // Set the hard coded fixed paths 103 this->pathConfig_ .reset(new PathConfig());113 this->pathConfig_ = new PathConfig(); 104 114 105 115 // Create a new dynamic library manager 106 this->dynLibManager_ .reset(new DynLibManager());116 this->dynLibManager_ = new DynLibManager(); 107 117 108 118 // Load modules … … 128 138 // create a signal handler (only active for Linux) 129 139 // This call is placed as soon as possible, but after the directories are set 130 this->signalHandler_ .reset(new SignalHandler());140 this->signalHandler_ = new SignalHandler(); 131 141 this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log"); 132 142 … … 147 157 148 158 // Manage ini files and set the default settings file (usually orxonox.ini) 149 this->configFileManager_ .reset(new ConfigFileManager());159 this->configFileManager_ = new ConfigFileManager(); 150 160 this->configFileManager_->setFilename(ConfigFileType::Settings, 151 161 CommandLineParser::getValue("settingsFile").getString()); 152 162 153 163 // Required as well for the config values 154 this->languageInstance_ .reset(new Language());164 this->languageInstance_ = new Language(); 155 165 156 166 // Do this soon after the ConfigFileManager has been created to open up the 157 167 // possibility to configure everything below here 158 ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true);168 RegisterRootObject(Core); 159 169 this->setConfigValues(); 160 170 … … 166 176 } 167 177 if (this->bStartIOConsole_) 168 this->ioConsole_ .reset(new IOConsole());178 this->ioConsole_ = new IOConsole(); 169 179 #endif 170 180 … … 173 183 174 184 // Load OGRE excluding the renderer and the render window 175 this->graphicsManager_ .reset(new GraphicsManager(false));185 this->graphicsManager_ = new GraphicsManager(false); 176 186 177 187 // initialise Tcl 178 this->tclBind_ .reset(new TclBind(PathConfig::getDataPathString()));179 this->tclThreadManager_ .reset(new TclThreadManager(tclBind_->getTclInterpreter()));188 this->tclBind_ = new TclBind(PathConfig::getDataPathString()); 189 this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter()); 180 190 181 191 // Create singletons that always exist (in other libraries) 182 this->rootScope_ .reset(new Scope<ScopeID::Root>());192 this->rootScope_ = new Scope<ScopeID::Root>(); 183 193 184 194 // Generate documentation instead of normal run? … … 198 208 } 199 209 200 /** 201 @brief 202 All destruction code is handled by scoped_ptrs and ScopeGuards. 203 */ 204 Core::~Core() 210 void Core::destroy() 205 211 { 206 212 // Remove us from the object lists again to avoid problems when destroying them 207 213 this->unregisterObject(); 214 215 safeObjectDelete(&graphicsScope_); 216 safeObjectDelete(&guiManager_); 217 safeObjectDelete(&inputManager_); 218 safeObjectDelete(&graphicsManager_); 219 safeObjectDelete(&rootScope_); 220 safeObjectDelete(&tclThreadManager_); 221 safeObjectDelete(&tclBind_); 222 safeObjectDelete(&ioConsole_); 223 safeObjectDelete(&languageInstance_); 224 safeObjectDelete(&configFileManager_); 225 ConsoleCommand::destroyAll(); 226 Identifier::destroyAllIdentifiers(); 227 safeObjectDelete(&signalHandler_); 228 safeObjectDelete(&dynLibManager_); 229 safeObjectDelete(&pathConfig_); 208 230 } 209 231 … … 285 307 286 308 // Calls the InputManager which sets up the input devices. 287 inputManager_ .reset(new InputManager());309 inputManager_ = new InputManager(); 288 310 289 311 // Load the CEGUI interface 290 guiManager_ .reset(new GUIManager(inputManager_->getMousePosition()));312 guiManager_ = new GUIManager(inputManager_->getMousePosition()); 291 313 292 314 bGraphicsLoaded_ = true; … … 297 319 298 320 // Create singletons associated with graphics (in other libraries) 299 graphicsScope_ .reset(new Scope<ScopeID::Graphics>());321 graphicsScope_ = new Scope<ScopeID::Graphics>(); 300 322 301 323 unloader.Dismiss(); … … 304 326 void Core::unloadGraphics() 305 327 { 306 this->graphicsScope_.reset();307 this->guiManager_.reset();308 this->inputManager_.reset();309 this->graphicsManager_.reset();328 safeObjectDelete(&graphicsScope_); 329 safeObjectDelete(&guiManager_); 330 safeObjectDelete(&inputManager_); 331 safeObjectDelete(&graphicsManager_); 310 332 311 333 // Load Ogre::Root again, but without the render system 312 334 try 313 { this->graphicsManager_ .reset(new GraphicsManager(false)); }335 { this->graphicsManager_ = new GraphicsManager(false); } 314 336 catch (...) 315 337 { -
code/trunk/src/libraries/core/Core.h
r8366 r8423 45 45 46 46 #include <string> 47 #include <boost/scoped_ptr.hpp>48 47 #include <loki/ScopeGuard.h> 49 48 49 #include "util/DestructionHelper.h" 50 50 #include "util/Singleton.h" 51 51 #include "OrxonoxClass.h" … … 61 61 class _CoreExport Core : public Singleton<Core>, public OrxonoxClass 62 62 { 63 typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;64 63 friend class Singleton<Core>; 65 64 friend class Game; … … 74 73 */ 75 74 Core(const std::string& cmdLine); 76 ~Core(); 75 76 /// Leave empty and use destroy() instead 77 ~Core() {} 78 /// Destructor that also executes when the object fails to construct 79 void destroy(); 77 80 78 81 void setConfigValues(); … … 108 111 109 112 void setThreadAffinity(int limitToCPU); 110 // MANAGED SINGLETONS/OBJECTS 111 // Mind the order for the destruction! 112 scoped_ptr<PathConfig> pathConfig_; 113 scoped_ptr<DynLibManager> dynLibManager_; 114 scoped_ptr<SignalHandler> signalHandler_; 115 SimpleScopeGuard identifierDestroyer_; 116 SimpleScopeGuard consoleCommandDestroyer_; 117 scoped_ptr<ConfigFileManager> configFileManager_; 118 scoped_ptr<Language> languageInstance_; 119 scoped_ptr<IOConsole> ioConsole_; 120 scoped_ptr<TclBind> tclBind_; 121 scoped_ptr<TclThreadManager> tclThreadManager_; 122 scoped_ptr<Scope<ScopeID::Root> > rootScope_; 113 114 PathConfig* pathConfig_; 115 DynLibManager* dynLibManager_; 116 SignalHandler* signalHandler_; 117 ConfigFileManager* configFileManager_; 118 Language* languageInstance_; 119 IOConsole* ioConsole_; 120 TclBind* tclBind_; 121 TclThreadManager* tclThreadManager_; 122 Scope<ScopeID::Root>* rootScope_; 123 123 // graphical 124 scoped_ptr<GraphicsManager> graphicsManager_;//!< Interface to OGRE125 scoped_ptr<InputManager> inputManager_;//!< Interface to OIS126 scoped_ptr<GUIManager> guiManager_;//!< Interface to GUI127 scoped_ptr<Scope<ScopeID::Graphics> >graphicsScope_;124 GraphicsManager* graphicsManager_; //!< Interface to OGRE 125 InputManager* inputManager_; //!< Interface to OIS 126 GUIManager* guiManager_; //!< Interface to GUI 127 Scope<ScopeID::Graphics>* graphicsScope_; 128 128 129 bool 130 int 131 std::string 132 bool 133 bool 134 long long 135 long long 136 bool 129 bool bGraphicsLoaded_; 130 int softDebugLevelLogFile_; //!< The debug level for the log file (belongs to OutputHandler) 131 std::string language_; //!< The language 132 bool bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called 133 bool bStartIOConsole_; //!< Set to false if you don't want to use the IOConsole 134 long long lastLevelTimestamp_; ///< Timestamp when the last level was started 135 long long ogreConfigTimestamp_; ///< Timestamp wehen the ogre config level was modified 136 bool bDevMode_; //!< Developers bit. If set to false, some options are not available as to not confuse the normal user. 137 137 138 static Core* singletonPtr_s; 138 /// Helper object that executes the surrogate destructor destroy() 139 DestructionHelper<Core> destructionHelper_; 140 141 static Core* singletonPtr_s; 139 142 }; 140 143 } -
code/trunk/src/libraries/core/GUIManager.cc
r8419 r8423 162 162 */ 163 163 GUIManager::GUIManager(const std::pair<int, int>& mousePosition) 164 : destroyer_(*this, &GUIManager::cleanup) 165 , guiRenderer_(NULL) 164 : guiRenderer_(NULL) 166 165 , resourceProvider_(NULL) 167 166 #ifndef ORXONOX_OLD_CEGUI … … 177 176 , menuRootWindow_(NULL) 178 177 , camera_(NULL) 178 , destructionHelper_(this) 179 179 { 180 180 RegisterRootObject(GUIManager); … … 258 258 } 259 259 260 void GUIManager:: cleanup()260 void GUIManager::destroy() 261 261 { 262 262 using namespace CEGUI; 263 263 264 264 #ifdef ORXONOX_OLD_CEGUI 265 delete guiSystem_;266 delete guiRenderer_;267 delete scriptModule_;265 safeObjectDelete(&guiSystem_); 266 safeObjectDelete(&guiRenderer_); 267 safeObjectDelete(&scriptModule_); 268 268 #else 269 269 System::destroy(); … … 272 272 OgreRenderer::destroy(*guiRenderer_); 273 273 LuaScriptModule::destroy(*scriptModule_); 274 delete ceguiLogger_;275 delete rqListener_;276 #endif 277 delete luaState_;274 safeObjectDelete(&ceguiLogger_); 275 safeObjectDelete(&rqListener_); 276 #endif 277 safeObjectDelete(&luaState_); 278 278 } 279 279 … … 285 285 void GUIManager::changedGUIScheme(void) 286 286 { 287 288 287 } 289 288 -
code/trunk/src/libraries/core/GUIManager.h
r8411 r8423 44 44 #include <CEGUIVersion.h> 45 45 #include <boost/shared_ptr.hpp> 46 #include <loki/ScopeGuard.h>47 46 47 #include "util/DestructionHelper.h" 48 48 #include "util/OgreForwardRefs.h" 49 49 #include "util/TriBool.h" … … 83 83 public: 84 84 GUIManager(const std::pair<int, int>& mousePosition); 85 85 86 //! Leave empty and use cleanup() instead 86 87 ~GUIManager() {} 88 /// Destructor that also executes when object fails to construct 89 void destroy(); 87 90 88 91 void setConfigValues(void); … … 134 137 GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class) 135 138 136 /// Destructor that also executes when object fails to construct137 void cleanup();138 139 139 void executeCode(const std::string& str); 140 140 … … 156 156 virtual void windowResized(unsigned int newWidth, unsigned int newHeight); 157 157 virtual void windowFocusChanged(bool bFocus); 158 159 /// Surrogate for the destructor160 Loki::ObjScopeGuardImpl0<GUIManager, void (GUIManager::*)()> destroyer_;161 158 162 159 #ifdef ORXONOX_OLD_CEGUI … … 180 177 Ogre::Camera* camera_; //!< Camera used to render the scene with the GUI 181 178 179 /// Helper object that executes the surrogate destructor destroy() 180 DestructionHelper<GUIManager> destructionHelper_; 181 182 182 static GUIManager* singletonPtr_s; //!< Singleton reference to GUIManager 183 183 -
code/trunk/src/libraries/core/Game.cc
r8351 r8423 78 78 79 79 Game::Game(const std::string& cmdLine) 80 // Destroy factories before the Core!81 : gsFactoryDestroyer_(Game::GameStateFactory::getFactories(), &std::map<std::string, shared_ptr<GameStateFactory> >::clear)82 {83 this->bAbort_ = false;84 bChangingState_ = false;85 80 : gameClock_(NULL) 81 , core_(NULL) 82 , bChangingState_(false) 83 , bAbort_(false) 84 , destructionHelper_(this) 85 { 86 86 #ifdef ORXONOX_PLATFORM_WINDOWS 87 87 minimumSleepTime_ = 1000/*us*/; … … 103 103 104 104 // Set up a basic clock to keep time 105 this->gameClock_ .reset(new Clock());105 this->gameClock_ = new Clock(); 106 106 107 107 // Create the Core 108 this->core_ .reset(new Core(cmdLine));108 this->core_ = new Core(cmdLine); 109 109 110 110 // Do this after the Core creation! … … 127 127 } 128 128 129 /** 130 @brief 131 All destruction code is handled by scoped_ptrs and SimpleScopeGuards. 132 */ 133 Game::~Game() 129 void Game::destroy() 134 130 { 135 131 // Remove us from the object lists again to avoid problems when destroying them 136 132 this->unregisterObject(); 133 134 assert(loadedStates_.size() <= 1); // Just empty root GameState 135 // Destroy all GameStates (shared_ptrs take care of actual destruction) 136 constructedStates_.clear(); 137 138 GameStateFactory::getFactories().clear(); 139 safeObjectDelete(&core_); 140 safeObjectDelete(&gameClock_); 137 141 } 138 142 -
code/trunk/src/libraries/core/Game.h
r8418 r8423 45 45 #include <vector> 46 46 #include <boost/shared_ptr.hpp> 47 #include <boost/scoped_ptr.hpp>48 47 #include <boost/preprocessor/cat.hpp> 49 #include <loki/ScopeGuard.h>50 48 51 49 #include "util/Debug.h" 50 #include "util/DestructionHelper.h" 52 51 #include "util/Singleton.h" 53 52 #include "OrxonoxClass.h" … … 56 55 @brief 57 56 Adds a new GameState to the Game. The second parameter is the name as string 58 and every following param ter is a constructor argument (which is usually non existent)57 and every following parameter is a constructor argument (which is usually non existent) 59 58 */ 60 59 #define DeclareGameState(className, stateName, bIgnoreTickTime, bGraphicsMode) \ … … 92 91 public: 93 92 Game(const std::string& cmdLine); 94 ~Game(); 93 94 //! Leave empty and use cleanup() instead 95 ~Game() {} 96 /// Destructor that also executes when object fails to construct 97 void destroy(); 95 98 96 99 void setConfigValues(); … … 138 141 { return shared_ptr<GameState>(new T(info)); } 139 142 }; 140 // For the factory destruction141 typedef Loki::ObjScopeGuardImpl0<std::map<std::string, shared_ptr<GameStateFactory> >, void (std::map<std::string, shared_ptr<GameStateFactory> >::*)()> ObjScopeGuard;142 143 143 144 struct StatisticsTickInfo … … 166 167 void resetChangingState() { this->bChangingState_ = false; } 167 168 168 scoped_ptr<Clock> gameClock_; 169 scoped_ptr<Core> core_; 170 ObjScopeGuard gsFactoryDestroyer_; 169 Clock* gameClock_; 170 Core* core_; 171 171 172 172 GameStateMap constructedStates_; … … 194 194 unsigned int fpsLimit_; 195 195 196 /// Helper object that executes the surrogate destructor destroy() 197 DestructionHelper<Game> destructionHelper_; 198 196 199 static std::map<std::string, GameStateInfo> gameStateDeclarations_s; 197 200 static Game* singletonPtr_s; //!< Pointer to the Singleton -
code/trunk/src/libraries/core/GraphicsManager.cc
r8366 r8423 94 94 GraphicsManager* GraphicsManager::singletonPtr_s = 0; 95 95 96 /**97 @brief98 Non-initialising constructor.99 */100 96 GraphicsManager::GraphicsManager(bool bLoadRenderer) 101 97 : ogreWindowEventListener_(new OgreWindowEventListener()) … … 104 100 , lastFrameStartTime_(0.0f) 105 101 , lastFrameEndTime_(0.0f) 102 , destructionHelper_(this) 106 103 { 107 104 RegisterObject(GraphicsManager); … … 134 131 } 135 132 136 /** 137 @brief 138 Destruction is done by the member scoped_ptrs. 139 */ 140 GraphicsManager::~GraphicsManager() 133 void GraphicsManager::destroy() 141 134 { 142 135 Loader::unload(debugOverlay_.get()); 143 136 144 Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_ .get());137 Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_); 145 138 ModifyConsoleCommand(__CC_printScreen_name).resetFunction(); 146 139 ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).resetFunction(); … … 151 144 Loader::unload(resources_.get()); 152 145 Loader::unload(extResources_.get()); 146 147 safeObjectDelete(&ogreRoot_); 148 safeObjectDelete(&ogreLogger_); 149 safeObjectDelete(&ogreWindowEventListener_); 153 150 } 154 151 … … 218 215 // create a new logManager 219 216 // Ogre::Root will detect that we've already created a Log 220 ogreLogger_ .reset(new Ogre::LogManager());217 ogreLogger_ = new Ogre::LogManager(); 221 218 COUT(4) << "Ogre LogManager created" << std::endl; 222 219 … … 241 238 242 239 // Leave plugins file empty. We're going to do that part manually later 243 ogreRoot_ .reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()));240 ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()); 244 241 245 242 COUT(3) << "Ogre set up done." << std::endl; … … 300 297 this->ogreWindowEventListener_->windowResized(renderWindow_); 301 298 302 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_ .get());299 Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_); 303 300 304 301 // create a full screen default viewport -
code/trunk/src/libraries/core/GraphicsManager.h
r8351 r8423 48 48 #include <string> 49 49 #include <OgreLog.h> 50 #include <boost/scoped_ptr.hpp>51 50 #include <boost/shared_ptr.hpp> 52 51 52 #include "util/DestructionHelper.h" 53 53 #include "util/Singleton.h" 54 54 #include "OrxonoxClass.h" … … 68 68 public: 69 69 GraphicsManager(bool bLoadRenderer = true); 70 ~GraphicsManager(); 70 71 //! Leave empty and use cleanup() instead 72 ~GraphicsManager() {} 73 /// Destructor that also executes when object fails to construct 74 void destroy(); 71 75 72 76 void setConfigValues(); … … 113 117 std::string setVSync(bool vsync); 114 118 115 scoped_ptr<OgreWindowEventListener>ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h116 scoped_ptr<Ogre::LogManager>ogreLogger_;117 scoped_ptr<Ogre::Root>ogreRoot_; //!< Ogre's root119 OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h 120 Ogre::LogManager* ogreLogger_; 121 Ogre::Root* ogreRoot_; //!< Ogre's root 118 122 Ogre::RenderWindow* renderWindow_; //!< the one and only render window 119 123 Ogre::Viewport* viewport_; //!< default full size viewport … … 134 138 int ogreLogLevelCritical_; //!< Corresponding Orxonox debug level for LL_CRITICAL 135 139 140 /// Helper object that executes the surrogate destructor destroy() 141 DestructionHelper<GraphicsManager> destructionHelper_; 142 136 143 static GraphicsManager* singletonPtr_s; //!< Pointer to the Singleton 137 144 // tolua_begin
Note: See TracChangeset
for help on using the changeset viewer.