Changeset 3366 for code/branches/resource/src/core
- Timestamp:
- Jul 29, 2009, 10:27:10 PM (15 years ago)
- Location:
- code/branches/resource/src/core
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource/src/core/Clock.h
r3196 r3366 26 26 * 27 27 */ 28 29 /**30 @file31 @brief Declaration of the Core class.32 33 The Core class is a singleton, only used to configure some variables34 in the core through the config-file.35 */36 28 37 29 #ifndef _Clock_H__ -
code/branches/resource/src/core/ConfigFileManager.cc
r3301 r3366 42 42 const char* const DEFAULT_CONFIG_FILE = "default.ini"; 43 43 44 ConfigFileManager* ConfigFileManager::singleton Ref_s = 0;44 ConfigFileManager* ConfigFileManager::singletonPtr_s = 0; 45 45 46 46 SetConsoleCommandShortcutExtern(config).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue()); … … 482 482 : mininmalFreeType_(ConfigFileType::numberOfReservedTypes) 483 483 { 484 assert(singletonRef_s == 0);485 singletonRef_s = this;486 484 } 487 485 … … 490 488 for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ) 491 489 delete (it++)->second; 492 493 assert(singletonRef_s != 0);494 singletonRef_s = 0;495 490 } 496 491 -
code/branches/resource/src/core/ConfigFileManager.h
r3196 r3366 38 38 39 39 #include "util/OrxEnum.h" 40 #include "util/Singleton.h" 40 41 41 42 namespace orxonox … … 267 268 // ConfigFileManager // 268 269 /////////////////////// 269 class _CoreExport ConfigFileManager 270 { 270 class _CoreExport ConfigFileManager : public Singleton<ConfigFileManager> 271 { 272 friend class Singleton<ConfigFileManager>; 271 273 public: 272 274 ConfigFileManager(); … … 305 307 void updateConfigValues(ConfigFileType type); 306 308 307 static ConfigFileManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }308 309 309 private: 310 310 ConfigFileManager(const ConfigFileManager&); … … 315 315 unsigned int mininmalFreeType_; 316 316 317 static ConfigFileManager* singleton Ref_s;317 static ConfigFileManager* singletonPtr_s; 318 318 }; 319 319 } -
code/branches/resource/src/core/Core.cc
r3363 r3366 83 83 { 84 84 //! Static pointer to the singleton 85 Core* Core::singleton Ref_s = 0;85 Core* Core::singletonPtr_s = 0; 86 86 87 87 SetCommandLineArgument(mediaPath, "").information("Path to the media/data files"); … … 139 139 .callback(this, &CoreConfiguration::debugLevelChanged); 140 140 141 SetConfigValue(language_, Language::get Language().defaultLanguage_)141 SetConfigValue(language_, Language::getInstance().defaultLanguage_) 142 142 .description("The language of the ingame text") 143 143 .callback(this, &CoreConfiguration::languageChanged); … … 179 179 { 180 180 // Read the translation file after the language was configured 181 Language::get Language().readTranslatedLanguageFile();181 Language::getInstance().readTranslatedLanguageFile(); 182 182 } 183 183 … … 252 252 // Cleanup guard for external console commands that don't belong to an Identifier 253 253 , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands) 254 , configuration_(new CoreConfiguration()) // Don't yet create config values! 254 255 , bDevRun_(false) 255 256 , bGraphicsLoaded_(false) 256 , configuration_(new CoreConfiguration()) // Don't yet create config values! 257 { 258 if (singletonRef_s != 0) 259 { 260 COUT(0) << "Error: The Core singleton cannot be recreated! Shutting down." << std::endl; 261 abort(); 262 } 263 Core::singletonRef_s = this; 264 257 { 265 258 // Parse command line arguments first 266 259 CommandLine::parseCommandLine(cmdLine); … … 328 321 Core::~Core() 329 322 { 330 // Don't assign singletonRef_s with NULL! Recreation is not supported331 // The is quite simply because of the pre-main code that uses heap allocation332 // And we correctly deallocate these resources in this destructor.333 323 } 334 324 -
code/branches/resource/src/core/Core.h
r3363 r3366 46 46 #include "util/OutputHandler.h" 47 47 #include "util/ScopeGuard.h" 48 #include "util/Singleton.h" 48 49 49 50 namespace orxonox … … 58 59 The class provides information about the media, config and log path. 59 60 It determines those by the use of platform specific functions. 61 @remark 62 You should only create this singleton once because it destroys the identifiers! 60 63 */ 61 class _CoreExport Core 64 class _CoreExport Core : public Singleton<Core> 62 65 { 63 66 typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard; 67 friend class Singleton<Core>; 64 68 65 69 public: … … 81 85 void loadGraphics(); 82 86 void unloadGraphics(); 83 84 static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }85 87 86 88 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); … … 136 138 bool bGraphicsLoaded_; 137 139 138 static Core* singleton Ref_s;140 static Core* singletonPtr_s; 139 141 }; 140 142 } -
code/branches/resource/src/core/GUIManager.cc
r3346 r3366 87 87 static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button); 88 88 89 GUIManager* GUIManager::singleton Ref_s = 0;89 GUIManager* GUIManager::singletonPtr_s = 0; 90 90 91 91 /** … … 105 105 , resourceProvider_(0) 106 106 { 107 assert(singletonRef_s == 0);108 singletonRef_s = this;109 110 107 using namespace CEGUI; 111 108 … … 161 158 // destroy our own tolua interfaces 162 159 LuaBind::getInstance().closeToluaInterfaces(this->luaState_); 163 164 singletonRef_s = 0;165 160 } 166 161 -
code/branches/resource/src/core/GUIManager.h
r3346 r3366 45 45 46 46 #include "util/OgreForwardRefs.h" 47 #include "util/Singleton.h" 47 48 #include "input/InputHandler.h" 48 49 … … 60 61 Those input events are then injected into CEGUI in Lua. 61 62 */ 62 class _CoreExport GUIManager : public InputHandler63 class _CoreExport GUIManager : public Singleton<GUIManager>, public InputHandler 63 64 { 65 friend class Singleton<GUIManager>; 64 66 public: 65 67 GUIManager(Ogre::RenderWindow* renderWindow); … … 73 75 void setCamera(Ogre::Camera* camera); 74 76 75 static GUIManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 76 static GUIManager* getInstancePtr() { return singletonRef_s; } 77 static GUIManager* getInstancePtr() { return singletonPtr_s; } 77 78 78 79 private: … … 99 100 lua_State* luaState_; //!< Lua state, access point to the Lua engine 100 101 101 static GUIManager* singleton Ref_s; //!< Singleton reference to GUIManager102 static GUIManager* singletonPtr_s; //!< Singleton reference to GUIManager 102 103 103 104 }; -
code/branches/resource/src/core/Game.cc
r3363 r3366 62 62 63 63 std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s; 64 Game* Game::singleton Ref_s = 0;64 Game* Game::singletonPtr_s = 0; 65 65 66 66 … … 114 114 Game::Game(const std::string& cmdLine) 115 115 { 116 if (singletonRef_s != 0)117 {118 COUT(0) << "Error: The Game singleton cannot be recreated! Shutting down." << std::endl;119 abort();120 }121 singletonRef_s = this;122 123 116 this->bAbort_ = false; 124 117 bChangingState_ = false; … … 163 156 Game::~Game() 164 157 { 165 // Don't assign singletonRef_s with NULL! Recreation is not supported166 158 } 167 159 -
code/branches/resource/src/core/Game.h
r3363 r3366 48 48 49 49 #include "util/Debug.h" 50 #include "util/Singleton.h" 50 51 51 52 /** … … 75 76 @brief 76 77 Main class responsible for running the game. 78 @remark 79 You should only create this singleton once because it owns the Core class! (see remark there) 77 80 */ 78 class _CoreExport Game 81 class _CoreExport Game : public Singleton<Game> 79 82 { 83 friend class Singleton<Game>; 80 84 typedef std::vector<shared_ptr<GameState> > GameStateVector; 81 85 typedef std::map<std::string, shared_ptr<GameState> > GameStateMap; … … 104 108 template <class T> 105 109 static bool declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bConsoleMode); 106 static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }107 110 108 111 private: … … 175 178 176 179 static std::map<std::string, GameStateInfo> gameStateDeclarations_s; 177 static Game* singleton Ref_s; //!< Pointer to the Singleton180 static Game* singletonPtr_s; //!< Pointer to the Singleton 178 181 }; 179 182 -
code/branches/resource/src/core/GraphicsManager.cc
r3349 r3366 83 83 }; 84 84 85 GraphicsManager* GraphicsManager::singleton Ref_s = 0;85 GraphicsManager* GraphicsManager::singletonPtr_s = 0; 86 86 87 87 /** … … 98 98 RegisterObject(GraphicsManager); 99 99 100 assert(singletonRef_s == 0);101 singletonRef_s = this;102 103 100 this->setConfigValues(); 104 101 … … 154 151 155 152 delete this->ogreWindowEventListener_; 156 157 assert(singletonRef_s);158 singletonRef_s = 0;159 153 } 160 154 -
code/branches/resource/src/core/GraphicsManager.h
r3346 r3366 42 42 #include <string> 43 43 #include <OgreLog.h> 44 #include "util/Singleton.h" 44 45 #include "OrxonoxClass.h" 45 46 … … 50 51 Graphics engine manager class 51 52 */ 52 class _CoreExport GraphicsManager : public OrxonoxClass, public Ogre::LogListener53 class _CoreExport GraphicsManager : public Singleton<GraphicsManager>, public OrxonoxClass, public Ogre::LogListener 53 54 { 55 friend class Singleton<GraphicsManager>; 54 56 public: 55 57 GraphicsManager(); … … 66 68 67 69 void setCamera(Ogre::Camera* camera); 68 69 inline static GraphicsManager& getInstance()70 { assert(singletonRef_s); return *singletonRef_s; }71 70 72 71 private: … … 107 106 ConsoleCommand* ccPrintScreen_; 108 107 109 static GraphicsManager* singleton Ref_s; //!< Pointer to the Singleton108 static GraphicsManager* singletonPtr_s; //!< Pointer to the Singleton 110 109 }; 111 110 } -
code/branches/resource/src/core/Language.cc
r3280 r3366 89 89 // ############################### 90 90 91 Language* Language::singleton Ref_s = 0;91 Language* Language::singletonPtr_s = 0; 92 92 93 93 /** … … 96 96 Language::Language() 97 97 { 98 assert(singletonRef_s == 0);99 singletonRef_s = this;100 101 98 this->defaultLanguage_ = "default"; 102 99 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; … … 113 110 for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it) 114 111 delete (it->second); 115 116 assert(singletonRef_s);117 singletonRef_s = 0;118 112 } 119 113 -
code/branches/resource/src/core/Language.h
r3280 r3366 37 37 Usage: 38 38 - Set the entry with the default string: 39 Language::get Language()->addEntry("label of the entry", "the string to translate");39 Language::getInstance()->addEntry("label of the entry", "the string to translate"); 40 40 41 41 - Get the localisation of the entry in the configured language: 42 std::cout << Language::get Language()->getLocalisation("name of the entry") << std::endl;42 std::cout << Language::getInstance()->getLocalisation("name of the entry") << std::endl; 43 43 */ 44 44 … … 51 51 #include <string> 52 52 #include <cassert> 53 #include "util/Singleton.h" 53 54 54 55 #define AddLanguageEntry(label, fallbackstring) \ 55 orxonox::Language::get Language().addEntry(label, fallbackstring)56 orxonox::Language::getInstance().addEntry(label, fallbackstring) 56 57 57 58 #define GetLocalisation(label) \ 58 orxonox::Language::get Language().getLocalisation(label)59 orxonox::Language::getInstance().getLocalisation(label) 59 60 60 61 … … 112 113 // ############################### 113 114 //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map. 114 class _CoreExport Language 115 class _CoreExport Language : public Singleton<Language> 115 116 { 117 friend class Singleton<Language>; 116 118 friend class CoreConfiguration; 117 119 … … 120 122 ~Language(); 121 123 122 static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; }123 124 void addEntry(const LanguageEntryLabel& label, const std::string& entry); 124 125 const std::string& getLocalisation(const LanguageEntryLabel& label) const; … … 137 138 std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels 138 139 139 static Language* singleton Ref_s;140 static Language* singletonPtr_s; 140 141 }; 141 142 } -
code/branches/resource/src/core/LuaBind.cc
r3340 r3366 43 43 namespace orxonox 44 44 { 45 LuaBind* LuaBind::singleton Ref_s = NULL;45 LuaBind* LuaBind::singletonPtr_s = NULL; 46 46 47 47 LuaBind::LuaBind() 48 48 { 49 assert(LuaBind::singletonRef_s == 0);50 LuaBind::singletonRef_s = this;51 52 49 this->includePath_ = Core::getMediaPathString(); 53 50 … … 75 72 { 76 73 this->closeToluaInterfaces(luaState_); 77 78 assert(singletonRef_s);79 LuaBind::singletonRef_s = NULL;80 74 }; 81 75 -
code/branches/resource/src/core/LuaBind.h
r3359 r3366 45 45 } 46 46 47 #include "util/Singleton.h" 48 47 49 // tolua_begin 48 50 namespace orxonox 49 51 { 50 class _CoreExport LuaBind 52 class _CoreExport LuaBind : public Singleton<LuaBind> 51 53 { 54 // tolua_end 55 friend class Singleton<LuaBind>; 52 56 53 // tolua_end54 57 struct LoadS { 55 58 const char *s; … … 61 64 ~LuaBind(); 62 65 63 inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export66 static LuaBind& getInstance() { return Singleton<LuaBind>::getInstance(); } // tolua_export 64 67 65 68 void loadFile(const std::string& filename, bool luaTags); … … 89 92 90 93 private: 91 static LuaBind* singleton Ref_s;94 static LuaBind* singletonPtr_s; 92 95 93 96 std::string luaSource_; -
code/branches/resource/src/core/Shell.cc
r3301 r3366 51 51 SetConsoleCommandShortcut(OutputHandler, debug); 52 52 53 Shell* Shell::singleton Ref_s = 0;53 Shell* Shell::singletonPtr_s = 0; 54 54 55 55 Shell::Shell() 56 56 { 57 assert(singletonRef_s == 0);58 singletonRef_s = this;59 60 57 int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell); 61 58 Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1); … … 92 89 if (this->inputBuffer_) 93 90 delete this->inputBuffer_; 94 singletonRef_s = 0;95 91 } 96 92 -
code/branches/resource/src/core/Shell.h
r3280 r3366 60 60 }; 61 61 62 class _CoreExport Shell : virtual public OrxonoxClass, public OutputBufferListener62 class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener 63 63 { 64 friend class Singleton<Shell>; 64 65 public: 65 66 Shell(); 66 67 virtual ~Shell(); 67 68 static Shell& getInstance() { assert(singletonRef_s); return *singletonRef_s; }69 68 70 69 static void clearShell(); … … 148 147 ConfigFileType commandHistoryConfigFileType_; 149 148 150 static Shell* singleton Ref_s;149 static Shell* singletonPtr_s; 151 150 }; 152 151 } -
code/branches/resource/src/core/TclBind.cc
r3360 r3366 46 46 SetConsoleCommandShortcut(TclBind, bgerror); 47 47 48 TclBind* TclBind::singleton Ref_s = 0;48 TclBind* TclBind::singletonPtr_s = 0; 49 49 50 50 TclBind::TclBind(const std::string& datapath) 51 51 { 52 assert(singletonRef_s == 0);53 singletonRef_s = this;54 52 this->interpreter_ = 0; 55 53 this->bSetTclDataPath_ = false; … … 61 59 if (this->interpreter_) 62 60 delete this->interpreter_; 63 singletonRef_s = 0;64 61 } 65 62 -
code/branches/resource/src/core/TclBind.h
r3360 r3366 34 34 #include <cassert> 35 35 #include <string> 36 #include "util/Singleton.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _CoreExport TclBind 40 class _CoreExport TclBind : public Singleton<TclBind> 40 41 { 42 friend class Singleton<TclBind>; 41 43 public: 42 44 TclBind(const std::string& datapath); 43 45 ~TclBind(); 44 45 static TclBind& getInstance() { assert(singletonRef_s); return *singletonRef_s; }46 46 47 47 static std::string tcl(const std::string& tclcode); … … 68 68 bool bSetTclDataPath_; 69 69 70 static TclBind* singleton Ref_s;70 static TclBind* singletonPtr_s; 71 71 }; 72 72 } -
code/branches/resource/src/core/TclThreadManager.cc
r3361 r3366 91 91 RegisterRootObject(TclThreadManager); 92 92 93 assert(TclThreadManager::singletonPtr_s == 0);94 TclThreadManager::singletonPtr_s = this;95 96 93 this->numInterpreterBundles_ = 0; 97 94 … … 116 113 TclThreadManager::~TclThreadManager() 117 114 { 118 TclThreadManager::singletonPtr_s = 0;119 120 115 delete this->interpreterBundlesMutex_; 121 116 // delete this->mainInterpreterMutex_; // <-- temporary disabled to avoid crash if a thread is still actively queriyng -
code/branches/resource/src/core/TclThreadManager.h
r3361 r3366 37 37 #include <string> 38 38 39 #include "util/Singleton.h" 39 40 #include "OrxonoxClass.h" 40 41 … … 43 44 namespace orxonox 44 45 { 45 class _CoreExport TclThreadManager : public OrxonoxClass46 class _CoreExport TclThreadManager : public Singleton<TclThreadManager>, public OrxonoxClass 46 47 { 48 friend class Singleton<TclThreadManager>; 47 49 friend class TclBind; 48 50 friend _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command); … … 53 55 TclThreadManager(Tcl::interpreter* interpreter); 54 56 virtual ~TclThreadManager(); 55 56 static TclThreadManager& getInstance() { assert(TclThreadManager::singletonPtr_s); return *TclThreadManager::singletonPtr_s; }57 57 58 58 static unsigned int create(); -
code/branches/resource/src/core/input/InputManager.cc
r3327 r3366 64 64 InputHandler InputHandler::EMPTY; 65 65 66 InputManager* InputManager::singleton Ref_s = 0;66 InputManager* InputManager::singletonPtr_s = 0; 67 67 68 68 //! Defines the |= operator for easier use. … … 93 93 RegisterRootObject(InputManager); 94 94 95 assert(singletonRef_s == 0);96 singletonRef_s = this;97 98 95 CCOUT(4) << "Constructing..." << std::endl; 99 96 … … 138 135 } 139 136 137 CCOUT(4) << "Construction complete." << std::endl; 140 138 internalState_ = Nothing; 141 CCOUT(4) << "Construction complete." << std::endl;142 139 } 143 140 … … 297 294 298 295 CCOUT(4) << "Destruction complete." << std::endl; 299 singletonRef_s = 0;300 296 } 301 297 -
code/branches/resource/src/core/input/InputManager.h
r3327 r3366 37 37 #include <vector> 38 38 39 #include "util/Singleton.h" 39 40 #include "core/WindowEventListener.h" 40 41 #include "InputState.h" … … 62 63 If the OIS::InputManager or the Keyboard fail, an exception is thrown. 63 64 */ 64 class _CoreExport InputManager : public WindowEventListener65 class _CoreExport InputManager : public Singleton<InputManager>, public WindowEventListener 65 66 { 67 friend class Singleton<InputManager>; 66 68 public: 67 69 //! Represents internal states of the InputManager. … … 168 170 { return this->oisInputManager_; } 169 171 170 //! Returns a reference to the singleton instance171 static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }172 173 172 private: // functions 174 173 // don't mess with a Singleton … … 211 210 std::set<InputState*> stateDestroyRequests_; //!< Requests to destroy a state 212 211 213 static InputManager* singleton Ref_s; //!< Pointer reference to the singleton212 static InputManager* singletonPtr_s; //!< Pointer reference to the singleton 214 213 }; 215 214 }
Note: See TracChangeset
for help on using the changeset viewer.