Changeset 3366 for code/branches
- Timestamp:
- Jul 29, 2009, 10:27:10 PM (15 years ago)
- Location:
- code/branches/resource/src
- Files:
-
- 45 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 } -
code/branches/resource/src/orxonox/CameraManager.cc
r3346 r3366 42 42 namespace orxonox 43 43 { 44 CameraManager* CameraManager::singleton Ref_s = 0;44 CameraManager* CameraManager::singletonPtr_s = 0; 45 45 46 46 CameraManager::CameraManager(Ogre::Viewport* viewport) 47 47 : viewport_(viewport) 48 48 { 49 assert(singletonRef_s == 0);50 singletonRef_s = this;51 52 49 this->fallbackCamera_ = 0; 53 50 } … … 55 52 CameraManager::~CameraManager() 56 53 { 57 assert(singletonRef_s != 0);58 singletonRef_s = 0;59 60 54 if (this->fallbackCamera_) 61 55 this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_); -
code/branches/resource/src/orxonox/CameraManager.h
r3196 r3366 41 41 #include <list> 42 42 #include "util/OgreForwardRefs.h" 43 #include "util/Singleton.h" 43 44 44 45 namespace orxonox 45 46 { 46 class _OrxonoxExport CameraManager 47 class _OrxonoxExport CameraManager : public Singleton<CameraManager> 47 48 { 49 friend class Singleton<CameraManager>; 48 50 public: 49 51 CameraManager(Ogre::Viewport* viewport); … … 57 59 void useCamera(Ogre::Camera* camera); 58 60 59 static CameraManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 60 static CameraManager* getInstancePtr() { return singletonRef_s; } 61 static CameraManager* getInstancePtr() { return singletonPtr_s; } 61 62 62 63 private: … … 67 68 Ogre::Camera* fallbackCamera_; 68 69 69 static CameraManager* singleton Ref_s;70 static CameraManager* singletonPtr_s; 70 71 }; 71 72 } -
code/branches/resource/src/orxonox/LevelManager.cc
r3343 r3366 45 45 SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)"); 46 46 47 LevelManager* LevelManager::singleton Ref_s = 0;47 LevelManager* LevelManager::singletonPtr_s = 0; 48 48 49 49 LevelManager::LevelManager() 50 50 { 51 assert(singletonRef_s == 0);52 singletonRef_s = this;53 54 51 RegisterRootObject(LevelManager); 55 52 this->setConfigValues(); … … 64 61 LevelManager::~LevelManager() 65 62 { 66 assert(singletonRef_s != 0);67 singletonRef_s = 0;68 63 } 69 64 -
code/branches/resource/src/orxonox/LevelManager.h
r3339 r3366 35 35 #include <list> 36 36 #include <string> 37 38 #include "util/Singleton.h" 37 39 #include "core/OrxonoxClass.h" 38 40 … … 42 44 class _OrxonoxExport LevelManager 43 45 // tolua_end 44 : public OrxonoxClass46 : public Singleton<LevelManager>, public OrxonoxClass 45 47 { // tolua_export 48 friend class Singleton<LevelManager>; 46 49 public: 47 50 LevelManager(); … … 59 62 std::string getAvailableLevelListItem(unsigned int index) const; //tolua_export 60 63 61 static LevelManager* getInstancePtr() { return singleton Ref_s; }62 static LevelManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } // tolua_export64 static LevelManager* getInstancePtr() { return singletonPtr_s; } 65 static LevelManager& getInstance() { return Singleton<LevelManager>::getInstance(); } // tolua_export 63 66 64 67 private: … … 73 76 std::string defaultLevelName_; 74 77 75 static LevelManager* singleton Ref_s;78 static LevelManager* singletonPtr_s; 76 79 }; // tolua_export 77 80 } // tolua_export -
code/branches/resource/src/orxonox/PawnManager.cc
r3196 r3366 34 34 namespace orxonox 35 35 { 36 PawnManager* PawnManager::singleton Ref_s = 0;36 PawnManager* PawnManager::singletonPtr_s = 0; 37 37 38 38 PawnManager::PawnManager() 39 39 { 40 40 RegisterRootObject(PawnManager); 41 42 assert(PawnManager::singletonRef_s == 0);43 PawnManager::singletonRef_s = this;44 41 } 45 42 46 43 PawnManager::~PawnManager() 47 44 { 48 assert(PawnManager::singletonRef_s != 0);49 PawnManager::singletonRef_s = 0;50 45 } 51 46 52 47 void PawnManager::touch() 53 48 { 54 if (!PawnManager::singleton Ref_s)49 if (!PawnManager::singletonPtr_s) 55 50 new PawnManager(); 56 51 } -
code/branches/resource/src/orxonox/PawnManager.h
r3196 r3366 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "util/Singleton.h" 33 35 #include "interfaces/Tickable.h" 34 36 35 37 namespace orxonox 36 38 { 37 class _OrxonoxExport PawnManager : p ublic Tickable39 class _OrxonoxExport PawnManager : protected Singleton<PawnManager>, public Tickable 38 40 { 41 friend class Singleton<PawnManager>; 39 42 public: 40 43 static void touch(); … … 46 49 virtual ~PawnManager(); 47 50 48 static PawnManager* singleton Ref_s;51 static PawnManager* singletonPtr_s; 49 52 }; 50 53 } -
code/branches/resource/src/orxonox/PlayerManager.cc
r3297 r3366 37 37 namespace orxonox 38 38 { 39 PlayerManager* PlayerManager::singleton Ref_s = 0;39 PlayerManager* PlayerManager::singletonPtr_s = 0; 40 40 41 41 PlayerManager::PlayerManager() 42 42 { 43 43 RegisterRootObject(PlayerManager); 44 45 assert(singletonRef_s == 0);46 singletonRef_s = this;47 44 48 45 this->getConnectedClients(); … … 51 48 PlayerManager::~PlayerManager() 52 49 { 53 assert(singletonRef_s);54 singletonRef_s = 0;55 50 } 56 51 -
code/branches/resource/src/orxonox/PlayerManager.h
r3196 r3366 34 34 #include <cassert> 35 35 #include <map> 36 #include "util/Singleton.h" 36 37 #include "network/ClientConnectionListener.h" 37 38 38 39 namespace orxonox 39 40 { 40 class _OrxonoxExport PlayerManager : public ClientConnectionListener41 class _OrxonoxExport PlayerManager : public Singleton<PlayerManager>, public ClientConnectionListener 41 42 { 43 friend class Singleton<PlayerManager>; 42 44 public: 43 45 PlayerManager(); 44 46 virtual ~PlayerManager(); 45 46 inline static PlayerManager& getInstance()47 { assert(singletonRef_s); return *singletonRef_s; }48 47 49 48 PlayerInfo* getClient(unsigned int clientID) const; … … 57 56 std::map<unsigned int, PlayerInfo*> clients_; 58 57 59 static PlayerManager* singleton Ref_s;58 static PlayerManager* singletonPtr_s; 60 59 }; 61 60 } -
code/branches/resource/src/orxonox/objects/pickup/BaseItem.h
r3196 r3366 51 51 Daniel 'Huty' Haggenmueller 52 52 */ 53 class _OrxonoxExport BaseItem 54 // tolua_end 55 : public BaseObject 56 // tolua_begin 53 class _OrxonoxExport BaseItem : public BaseObject 57 54 { 58 55 // tolua_end -
code/branches/resource/src/orxonox/objects/pickup/PickupInventory.h
r3196 r3366 43 43 namespace orxonox 44 44 { 45 // tolua_end46 45 /** 47 46 @brief Static class for the inventory GUI window. 48 47 @author Daniel 'Huty' Haggenmueller 49 48 */ 50 // tolua_begin51 49 class _OrxonoxExport PickupInventory 52 50 { -
code/branches/resource/src/orxonox/objects/quest/QuestDescription.h
r3196 r3366 54 54 Damian 'Mozork' Frick 55 55 */ 56 class _OrxonoxExport QuestDescription 56 class _OrxonoxExport QuestDescription : public BaseObject 57 { 57 58 // tolua_end 58 : public BaseObject59 { // tolua_export60 59 public: 61 60 QuestDescription(BaseObject* creator); -
code/branches/resource/src/orxonox/objects/quest/QuestManager.cc
r3349 r3366 47 47 { 48 48 //! Pointer to the current (and single) instance of this class. 49 /*static*/ QuestManager* QuestManager::singleton Ref_s = NULL;49 /*static*/ QuestManager* QuestManager::singletonPtr_s = NULL; 50 50 51 51 /** … … 58 58 { 59 59 RegisterRootObject(QuestManager); 60 61 assert(singletonRef_s == 0);62 singletonRef_s = this;63 60 } 64 61 … … 70 67 { 71 68 72 }73 74 /**75 @brief76 Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with.77 @return78 Returns a reference to the single instance of the Quest Manager.79 */80 /*static*/ QuestManager & QuestManager::getInstance()81 {82 assert(singletonRef_s);83 return *singletonRef_s;84 69 } 85 70 -
code/branches/resource/src/orxonox/objects/quest/QuestManager.h
r3196 r3366 40 40 #include <map> 41 41 #include <string> 42 43 #include "util/Singleton.h" 42 44 #include "core/OrxonoxClass.h" 43 45 … … 71 73 Damian 'Mozork' Frick 72 74 */ 73 class _OrxonoxExport QuestManager 74 // tolua_end 75 : public OrxonoxClass 76 // tolua_begin 75 class _OrxonoxExport QuestManager : public Singleton<QuestManager>, public orxonox::OrxonoxClass 77 76 { 78 77 // tolua_end 78 friend class Singleton<QuestManager>; 79 79 public: 80 80 QuestManager(); 81 81 virtual ~QuestManager(); 82 82 83 static QuestManager& getInstance(); // tolua_export //!< Returns a reference to the single instance of the Quest Manager. 83 //! Returns a reference to the single instance of the Quest Manager. 84 static QuestManager& getInstance() { return Singleton<QuestManager>::getInstance(); } // tolua_export 84 85 85 86 bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager. … … 92 93 93 94 private: 94 static QuestManager* singleton Ref_s;95 static QuestManager* singletonPtr_s; 95 96 96 97 std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's. -
code/branches/resource/src/orxonox/overlays/console/InGameConsole.cc
r3327 r3366 60 60 SetConsoleCommand(InGameConsole, closeConsole, true); 61 61 62 InGameConsole* InGameConsole::singleton Ref_s = 0;62 InGameConsole* InGameConsole::singletonPtr_s = 0; 63 63 64 64 /** … … 76 76 RegisterObject(InGameConsole); 77 77 78 assert(singletonRef_s == 0);79 singletonRef_s = this;80 81 78 this->bActive_ = false; 82 79 this->cursor_ = 0.0f; … … 131 128 if (this->consoleOverlay_) 132 129 Ogre::OverlayManager::getSingleton().destroy(consoleOverlay_); 133 134 singletonRef_s = 0;135 130 } 136 131 -
code/branches/resource/src/orxonox/overlays/console/InGameConsole.h
r3327 r3366 34 34 35 35 #include <string> 36 36 37 #include "util/OgreForwardRefs.h" 38 #include "util/Singleton.h" 37 39 #include "core/Shell.h" 38 40 #include "core/WindowEventListener.h" … … 40 42 namespace orxonox 41 43 { 42 class _OrxonoxExport InGameConsole : public S hellListener, public WindowEventListener44 class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener 43 45 { 46 friend class Singleton<InGameConsole>; 44 47 public: // functions 45 48 InGameConsole(); … … 51 54 52 55 void update(const Clock& time); 53 54 static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; }55 static InGameConsole* getInstancePtr() { return singletonRef_s; }56 56 57 57 static void openConsole(); … … 112 112 bool bHidesAllInput_; 113 113 114 static InGameConsole* singleton Ref_s;114 static InGameConsole* singletonPtr_s; 115 115 }; 116 116 } -
code/branches/resource/src/orxonox/overlays/notifications/NotificationManager.cc
r3196 r3366 46 46 const std::string NotificationManager::NONE = "none"; 47 47 48 NotificationManager* NotificationManager::singleton Ref_s = NULL;48 NotificationManager* NotificationManager::singletonPtr_s = NULL; 49 49 50 50 /** … … 55 55 { 56 56 RegisterRootObject(NotificationManager); 57 58 assert(singletonRef_s == 0);59 singletonRef_s = this;60 57 61 58 this->highestIndex_ = 0; … … 70 67 } 71 68 72 /**73 @brief74 Returns the current (and single) instance of the NotificationManager. Creates one, if there isn't one to begin with.75 @return76 Returns a reference to the single instance of the NotificationManager.77 */78 /*static*/ NotificationManager & NotificationManager::getInstance()79 {80 assert(singletonRef_s);81 return *singletonRef_s;82 }83 84 69 /** 85 70 @brief -
code/branches/resource/src/orxonox/overlays/notifications/NotificationManager.h
r3196 r3366 40 40 #include <map> 41 41 #include <string> 42 43 #include "util/Singleton.h" 42 44 #include "core/OrxonoxClass.h" 43 45 … … 52 54 Damian 'Mozork' Frick 53 55 */ 54 class _OrxonoxExport NotificationManager : public OrxonoxClass56 class _OrxonoxExport NotificationManager : public Singleton<NotificationManager>, public OrxonoxClass 55 57 { 58 friend class Singleton<NotificationManager>; 56 59 public: 57 60 NotificationManager(); … … 60 63 static const std::string ALL; 61 64 static const std::string NONE; 62 63 static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.64 65 65 66 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. … … 88 89 89 90 private: 90 static NotificationManager* singleton Ref_s;91 static NotificationManager* singletonPtr_s; 91 92 92 93 int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. -
code/branches/resource/src/orxonox/sound/SoundManager.cc
r3342 r3366 38 38 namespace orxonox 39 39 { 40 SoundManager* SoundManager::singleton Ref_s = NULL;40 SoundManager* SoundManager::singletonPtr_s = NULL; 41 41 42 42 /** … … 45 45 SoundManager::SoundManager() 46 46 { 47 assert(singletonRef_s == NULL);48 singletonRef_s = this;49 50 47 this->device_ = NULL; 51 48 this->soundavailable_ = true; … … 93 90 SoundManager::~SoundManager() 94 91 { 95 assert(singletonRef_s != NULL);96 singletonRef_s = NULL;97 98 92 alcDestroyContext(this->context_); 99 93 alcCloseDevice(this->device_); -
code/branches/resource/src/orxonox/sound/SoundManager.h
r3280 r3366 32 32 #include <cassert> 33 33 #include <list> 34 #include "util/Singleton.h" 34 35 #include "interfaces/Tickable.h" 35 36 … … 42 43 * 43 44 */ 44 class _OrxonoxExport SoundManager : public Tickable45 class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public Tickable 45 46 { 47 friend class Singleton<SoundManager>; 46 48 public: 47 49 SoundManager(); … … 52 54 bool isSoundAvailable(); 53 55 54 static SoundManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }55 56 56 private: 57 57 ALCdevice* device_; … … 60 60 bool soundavailable_; 61 61 62 static SoundManager* singleton Ref_s;62 static SoundManager* singletonPtr_s; 63 63 }; // class SoundManager 64 64 } // namespace orxonox -
code/branches/resource/src/util/SignalHandler.cc
r3301 r3366 41 41 namespace orxonox 42 42 { 43 SignalHandler* SignalHandler::singleton Ref_s = NULL;43 SignalHandler* SignalHandler::singletonPtr_s = NULL; 44 44 } 45 45 … … 122 122 } 123 123 // if the signalhandler has already been destroyed then don't do anything 124 if( SignalHandler::singleton Ref_s == 0 )124 if( SignalHandler::singletonPtr_s == 0 ) 125 125 { 126 126 COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl; -
code/branches/resource/src/util/SignalHandler.h
r3068 r3366 40 40 #include <list> 41 41 #include <string> 42 #include "Singleton.h" 42 43 43 44 namespace orxonox … … 67 68 typedef std::list<SignalCallbackRec> SignalCallbackList; 68 69 69 class SignalHandler 70 class SignalHandler : public Singleton<SignalHandler> 70 71 { 72 friend class Singleton<SignalHandler>; 71 73 public: 72 SignalHandler() { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; } 73 ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; } 74 inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; } 74 SignalHandler() { } 75 ~SignalHandler() { } 75 76 76 77 void registerCallback( SignalCallback cb, void * someData ); … … 87 88 SignalCallbackList callbackList; 88 89 89 static SignalHandler* singleton Ref_s;90 static SignalHandler* singletonPtr_s; 90 91 91 92 std::string appName; … … 98 99 namespace orxonox 99 100 { 100 class _UtilExport SignalHandler 101 class _UtilExport SignalHandler : public Singleton<SignalHandler> 101 102 { 103 friend class Singleton<SignalHandler>; 102 104 public: 103 SignalHandler() { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; } 104 ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; } 105 inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; } 105 SignalHandler() { } 106 ~SignalHandler() { } 106 107 void doCatch( const std::string & appName, const std::string & filename ) {} 107 108 void dontCatch() {} … … 109 110 110 111 private: 111 static SignalHandler* singleton Ref_s;112 static SignalHandler* singletonPtr_s; 112 113 }; 113 114 } -
code/branches/resource/src/util/Singleton.h
r3364 r3366 40 40 Usage: 41 41 Inherit publicly from Singleton<MyClass> and provide access to 42 MyClass::singleton Ref_s.43 This can be done with a friend declaration.42 MyClass::singletonPtr_s. 43 This can easily be done with a friend declaration. 44 44 */ 45 45 template <class T> … … 50 50 static T& getInstance() 51 51 { 52 assert(T::singleton Ref_s != NULL);53 return *T::singleton Ref_s;52 assert(T::singletonPtr_s != NULL); 53 return *T::singletonPtr_s; 54 54 } 55 55 56 56 protected: 57 // Constructor sets the singleton instance pointer57 //! Constructor sets the singleton instance pointer 58 58 Singleton() 59 59 { 60 assert(T::singleton Ref_s == NULL);61 T::singleton Ref_s = static_cast<T*>(this);60 assert(T::singletonPtr_s == NULL); 61 T::singletonPtr_s = static_cast<T*>(this); 62 62 } 63 // Constructor resets the singleton instance pointer 63 64 //! Constructor resets the singleton instance pointer 64 65 ~Singleton() 65 66 { 66 assert(T::singleton Ref_s != NULL);67 T::singleton Ref_s = NULL;67 assert(T::singletonPtr_s != NULL); 68 T::singletonPtr_s = NULL; 68 69 } 69 70
Note: See TracChangeset
for help on using the changeset viewer.