[Orxonox-commit 856] r3366 - in branches/resource/src: core core/input orxonox orxonox/objects/pickup orxonox/objects/quest orxonox/overlays/console orxonox/overlays/notifications orxonox/sound util

rgrieder at orxonox.net rgrieder at orxonox.net
Wed Jul 29 22:27:10 CEST 2009


Author: rgrieder
Date: 2009-07-29 22:27:10 +0200 (Wed, 29 Jul 2009)
New Revision: 3366

Modified:
   branches/resource/src/core/Clock.h
   branches/resource/src/core/ConfigFileManager.cc
   branches/resource/src/core/ConfigFileManager.h
   branches/resource/src/core/Core.cc
   branches/resource/src/core/Core.h
   branches/resource/src/core/GUIManager.cc
   branches/resource/src/core/GUIManager.h
   branches/resource/src/core/Game.cc
   branches/resource/src/core/Game.h
   branches/resource/src/core/GraphicsManager.cc
   branches/resource/src/core/GraphicsManager.h
   branches/resource/src/core/Language.cc
   branches/resource/src/core/Language.h
   branches/resource/src/core/LuaBind.cc
   branches/resource/src/core/LuaBind.h
   branches/resource/src/core/Shell.cc
   branches/resource/src/core/Shell.h
   branches/resource/src/core/TclBind.cc
   branches/resource/src/core/TclBind.h
   branches/resource/src/core/TclThreadManager.cc
   branches/resource/src/core/TclThreadManager.h
   branches/resource/src/core/input/InputManager.cc
   branches/resource/src/core/input/InputManager.h
   branches/resource/src/orxonox/CameraManager.cc
   branches/resource/src/orxonox/CameraManager.h
   branches/resource/src/orxonox/LevelManager.cc
   branches/resource/src/orxonox/LevelManager.h
   branches/resource/src/orxonox/PawnManager.cc
   branches/resource/src/orxonox/PawnManager.h
   branches/resource/src/orxonox/PlayerManager.cc
   branches/resource/src/orxonox/PlayerManager.h
   branches/resource/src/orxonox/objects/pickup/BaseItem.h
   branches/resource/src/orxonox/objects/pickup/PickupInventory.h
   branches/resource/src/orxonox/objects/quest/QuestDescription.h
   branches/resource/src/orxonox/objects/quest/QuestManager.cc
   branches/resource/src/orxonox/objects/quest/QuestManager.h
   branches/resource/src/orxonox/overlays/console/InGameConsole.cc
   branches/resource/src/orxonox/overlays/console/InGameConsole.h
   branches/resource/src/orxonox/overlays/notifications/NotificationManager.cc
   branches/resource/src/orxonox/overlays/notifications/NotificationManager.h
   branches/resource/src/orxonox/sound/SoundManager.cc
   branches/resource/src/orxonox/sound/SoundManager.h
   branches/resource/src/util/SignalHandler.cc
   branches/resource/src/util/SignalHandler.h
   branches/resource/src/util/Singleton.h
Log:
Derived all singletons implemented in a usual manner from orxonox::Singleton<T>.
This resolves inconsistencies with the singletonPtr_s variable in case of exceptions (asserts were being triggered then).
And while at it replaced singletonRef_s with singletonPtr_s for it to be less misleading (as fabian has already pointed out).

Modified: branches/resource/src/core/Clock.h
===================================================================
--- branches/resource/src/core/Clock.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Clock.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -26,14 +26,6 @@
  *
  */
 
-/**
-    @file
-    @brief Declaration of the Core class.
-
-    The Core class is a singleton, only used to configure some variables
-    in the core through the config-file.
-*/
-
 #ifndef _Clock_H__
 #define _Clock_H__
 

Modified: branches/resource/src/core/ConfigFileManager.cc
===================================================================
--- branches/resource/src/core/ConfigFileManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/ConfigFileManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -41,7 +41,7 @@
 {
     const char* const DEFAULT_CONFIG_FILE = "default.ini";
 
-    ConfigFileManager* ConfigFileManager::singletonRef_s = 0;
+    ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
 
     SetConsoleCommandShortcutExtern(config).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());
     SetConsoleCommandShortcutExtern(tconfig).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());
@@ -481,17 +481,12 @@
     ConfigFileManager::ConfigFileManager()
          : mininmalFreeType_(ConfigFileType::numberOfReservedTypes)
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
     }
 
     ConfigFileManager::~ConfigFileManager()
     {
         for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); )
             delete (it++)->second;
-
-        assert(singletonRef_s != 0);
-        singletonRef_s = 0;
     }
 
     void ConfigFileManager::setFilename(ConfigFileType type, const std::string& filename)

Modified: branches/resource/src/core/ConfigFileManager.h
===================================================================
--- branches/resource/src/core/ConfigFileManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/ConfigFileManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -37,6 +37,7 @@
 #include <map>
 
 #include "util/OrxEnum.h"
+#include "util/Singleton.h"
 
 namespace orxonox
 {
@@ -266,8 +267,9 @@
     ///////////////////////
     // ConfigFileManager //
     ///////////////////////
-    class _CoreExport ConfigFileManager
+    class _CoreExport ConfigFileManager : public Singleton<ConfigFileManager>
     {
+        friend class Singleton<ConfigFileManager>;
         public:
             ConfigFileManager();
             ~ConfigFileManager();
@@ -304,8 +306,6 @@
             void updateConfigValues();
             void updateConfigValues(ConfigFileType type);
 
-            static ConfigFileManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
-
         private:
             ConfigFileManager(const ConfigFileManager&);
 
@@ -314,7 +314,7 @@
             std::map<ConfigFileType, ConfigFile*> configFiles_;
             unsigned int mininmalFreeType_;
 
-            static ConfigFileManager* singletonRef_s;
+            static ConfigFileManager* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/core/Core.cc
===================================================================
--- branches/resource/src/core/Core.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Core.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -82,7 +82,7 @@
 namespace orxonox
 {
     //! Static pointer to the singleton
-    Core* Core::singletonRef_s  = 0;
+    Core* Core::singletonPtr_s  = 0;
 
     SetCommandLineArgument(mediaPath, "").information("Path to the media/data files");
     SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
@@ -138,7 +138,7 @@
                 .description("The maximal level of debug output shown in the ingame shell")
                 .callback(this, &CoreConfiguration::debugLevelChanged);
 
-            SetConfigValue(language_, Language::getLanguage().defaultLanguage_)
+            SetConfigValue(language_, Language::getInstance().defaultLanguage_)
                 .description("The language of the ingame text")
                 .callback(this, &CoreConfiguration::languageChanged);
             SetConfigValue(bInitializeRandomNumberGenerator_, true)
@@ -178,7 +178,7 @@
         void languageChanged()
         {
             // Read the translation file after the language was configured
-            Language::getLanguage().readTranslatedLanguageFile();
+            Language::getInstance().readTranslatedLanguageFile();
         }
 
         /**
@@ -251,17 +251,10 @@
         : identifierDestroyer_(Identifier::destroyAllIdentifiers)
         // Cleanup guard for external console commands that don't belong to an Identifier
         , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands)
+        , configuration_(new CoreConfiguration()) // Don't yet create config values!
         , bDevRun_(false)
         , bGraphicsLoaded_(false)
-        , configuration_(new CoreConfiguration()) // Don't yet create config values!
     {
-        if (singletonRef_s != 0)
-        {
-            COUT(0) << "Error: The Core singleton cannot be recreated! Shutting down." << std::endl;
-            abort();
-        }
-        Core::singletonRef_s = this;
-
         // Parse command line arguments first
         CommandLine::parseCommandLine(cmdLine);
 
@@ -327,9 +320,6 @@
     */
     Core::~Core()
     {
-        // Don't assign singletonRef_s with NULL! Recreation is not supported
-        // The is quite simply because of the pre-main code that uses heap allocation
-        // And we correctly deallocate these resources in this destructor.
     }
 
     void Core::loadGraphics()

Modified: branches/resource/src/core/Core.h
===================================================================
--- branches/resource/src/core/Core.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Core.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -45,6 +45,7 @@
 #include <boost/scoped_ptr.hpp>
 #include "util/OutputHandler.h"
 #include "util/ScopeGuard.h"
+#include "util/Singleton.h"
 
 namespace orxonox
 {
@@ -57,10 +58,13 @@
     @details
         The class provides information about the media, config and log path.
         It determines those by the use of platform specific functions.
+    @remark
+        You should only create this singleton once because it destroys the identifiers!
     */
-    class _CoreExport Core
+    class _CoreExport Core : public Singleton<Core>
     {
         typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;
+        friend class Singleton<Core>;
 
         public:
             /**
@@ -81,8 +85,6 @@
             void loadGraphics();
             void unloadGraphics();
 
-            static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
-
             static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
             static void  setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
             static const std::string& getLanguage();
@@ -135,7 +137,7 @@
             bool                          bDevRun_;             //!< True for runs in the build directory (not installed)
             bool                          bGraphicsLoaded_;
 
-            static Core* singletonRef_s;
+            static Core* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/core/GUIManager.cc
===================================================================
--- branches/resource/src/core/GUIManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/GUIManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -86,7 +86,7 @@
 
     static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
 
-    GUIManager* GUIManager::singletonRef_s = 0;
+    GUIManager* GUIManager::singletonPtr_s = 0;
 
     /**
     @brief
@@ -104,9 +104,6 @@
         : renderWindow_(renderWindow)
         , resourceProvider_(0)
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         using namespace CEGUI;
 
         COUT(3) << "Initialising CEGUI." << std::endl;
@@ -160,8 +157,6 @@
     {
         // destroy our own tolua interfaces
         LuaBind::getInstance().closeToluaInterfaces(this->luaState_);
-
-        singletonRef_s = 0;
     }
 
     /**

Modified: branches/resource/src/core/GUIManager.h
===================================================================
--- branches/resource/src/core/GUIManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/GUIManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -44,6 +44,7 @@
 #include <boost/scoped_ptr.hpp>
 
 #include "util/OgreForwardRefs.h"
+#include "util/Singleton.h"
 #include "input/InputHandler.h"
 
 namespace orxonox
@@ -59,8 +60,9 @@
         Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler.
         Those input events are then injected into CEGUI in Lua.
     */
-    class _CoreExport GUIManager : public InputHandler
+    class _CoreExport GUIManager : public Singleton<GUIManager>, public InputHandler
     {
+        friend class Singleton<GUIManager>;
     public:
         GUIManager(Ogre::RenderWindow* renderWindow);
         ~GUIManager();
@@ -72,8 +74,7 @@
 
         void setCamera(Ogre::Camera* camera);
 
-        static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
-        static GUIManager* getInstancePtr() { return singletonRef_s; }
+        static GUIManager* getInstancePtr() { return singletonPtr_s; }
 
     private:
         GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
@@ -98,7 +99,7 @@
         CEGUI::Logger*           ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
         lua_State*               luaState_;         //!< Lua state, access point to the Lua engine
 
-        static GUIManager*       singletonRef_s;    //!< Singleton reference to GUIManager
+        static GUIManager*       singletonPtr_s;    //!< Singleton reference to GUIManager
 
     };
 }

Modified: branches/resource/src/core/Game.cc
===================================================================
--- branches/resource/src/core/Game.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Game.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -61,7 +61,7 @@
     SetConsoleCommandShortcutExternAlias(stop_game, "exit");
 
     std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s;
-    Game* Game::singletonRef_s = 0;
+    Game* Game::singletonPtr_s = 0;
 
 
     /**
@@ -113,13 +113,6 @@
     */
     Game::Game(const std::string& cmdLine)
     {
-        if (singletonRef_s != 0)
-        {
-            COUT(0) << "Error: The Game singleton cannot be recreated! Shutting down." << std::endl;
-            abort();
-        }
-        singletonRef_s = this;
-
         this->bAbort_ = false;
         bChangingState_ = false;
 
@@ -162,7 +155,6 @@
     */
     Game::~Game()
     {
-        // Don't assign singletonRef_s with NULL! Recreation is not supported
     }
 
     /**

Modified: branches/resource/src/core/Game.h
===================================================================
--- branches/resource/src/core/Game.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Game.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -47,6 +47,7 @@
 #include <boost/preprocessor/cat.hpp>
 
 #include "util/Debug.h"
+#include "util/Singleton.h"
 
 /**
 @def
@@ -74,9 +75,12 @@
     /**
     @brief
         Main class responsible for running the game.
+    @remark
+        You should only create this singleton once because it owns the Core class! (see remark there)
     */
-    class _CoreExport Game
+    class _CoreExport Game : public Singleton<Game>
     {
+        friend class Singleton<Game>;
         typedef std::vector<shared_ptr<GameState> > GameStateVector;
         typedef std::map<std::string, shared_ptr<GameState> > GameStateMap;
         typedef boost::shared_ptr<GameStateTreeNode> GameStateTreeNodePtr;
@@ -103,7 +107,6 @@
 
         template <class T>
         static bool declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bConsoleMode);
-        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
 
     private:
         class _CoreExport GameStateFactory
@@ -174,7 +177,7 @@
         unsigned int                       minimumSleepTime_;
 
         static std::map<std::string, GameStateInfo> gameStateDeclarations_s;
-        static Game* singletonRef_s;        //!< Pointer to the Singleton
+        static Game* singletonPtr_s;        //!< Pointer to the Singleton
     };
 
     template <class T>

Modified: branches/resource/src/core/GraphicsManager.cc
===================================================================
--- branches/resource/src/core/GraphicsManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/GraphicsManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -82,7 +82,7 @@
             { orxonox::WindowEventListener::moveWindow(); }
     };
 
-    GraphicsManager* GraphicsManager::singletonRef_s = 0;
+    GraphicsManager* GraphicsManager::singletonPtr_s = 0;
 
     /**
     @brief
@@ -97,9 +97,6 @@
     {
         RegisterObject(GraphicsManager);
 
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         this->setConfigValues();
 
         // Ogre setup procedure
@@ -153,9 +150,6 @@
         delete this->ogreLogger_;
 
         delete this->ogreWindowEventListener_;
-
-        assert(singletonRef_s);
-        singletonRef_s = 0;
     }
 
     void GraphicsManager::setConfigValues()

Modified: branches/resource/src/core/GraphicsManager.h
===================================================================
--- branches/resource/src/core/GraphicsManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/GraphicsManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -41,6 +41,7 @@
 #include <cassert>
 #include <string>
 #include <OgreLog.h>
+#include "util/Singleton.h"
 #include "OrxonoxClass.h"
 
 namespace orxonox
@@ -49,8 +50,9 @@
     @brief
         Graphics engine manager class
     */
-    class _CoreExport GraphicsManager : public OrxonoxClass, public Ogre::LogListener
+    class _CoreExport GraphicsManager : public Singleton<GraphicsManager>, public OrxonoxClass, public Ogre::LogListener
     {
+        friend class Singleton<GraphicsManager>;
     public:
         GraphicsManager();
         ~GraphicsManager();
@@ -66,9 +68,6 @@
 
         void setCamera(Ogre::Camera* camera);
 
-        inline static GraphicsManager& getInstance()
-            { assert(singletonRef_s); return *singletonRef_s; }
-
     private:
         GraphicsManager(GraphicsManager&); // don't mess with singletons
 
@@ -106,7 +105,7 @@
         // console commands
         ConsoleCommand*     ccPrintScreen_;
 
-        static GraphicsManager* singletonRef_s;        //!< Pointer to the Singleton
+        static GraphicsManager* singletonPtr_s;        //!< Pointer to the Singleton
     };
 }
 

Modified: branches/resource/src/core/Language.cc
===================================================================
--- branches/resource/src/core/Language.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Language.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -88,16 +88,13 @@
     // ###        Language         ###
     // ###############################
 
-    Language* Language::singletonRef_s = 0;
+    Language* Language::singletonPtr_s = 0;
 
     /**
         @brief Constructor: Reads the default language file and sets some values.
     */
     Language::Language()
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         this->defaultLanguage_ = "default";
         this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
 
@@ -112,9 +109,6 @@
     {
         for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
             delete (it->second);
-
-        assert(singletonRef_s);
-        singletonRef_s = 0;
     }
 
     /**

Modified: branches/resource/src/core/Language.h
===================================================================
--- branches/resource/src/core/Language.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Language.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -36,10 +36,10 @@
 
     Usage:
      - Set the entry with the default string:
-       Language::getLanguage()->addEntry("label of the entry", "the string to translate");
+       Language::getInstance()->addEntry("label of the entry", "the string to translate");
 
      - Get the localisation of the entry in the configured language:
-       std::cout << Language::getLanguage()->getLocalisation("name of the entry") << std::endl;
+       std::cout << Language::getInstance()->getLocalisation("name of the entry") << std::endl;
 */
 
 #ifndef _Language_H__
@@ -50,12 +50,13 @@
 #include <map>
 #include <string>
 #include <cassert>
+#include "util/Singleton.h"
 
 #define AddLanguageEntry(label, fallbackstring) \
-    orxonox::Language::getLanguage().addEntry(label, fallbackstring)
+    orxonox::Language::getInstance().addEntry(label, fallbackstring)
 
 #define GetLocalisation(label) \
-    orxonox::Language::getLanguage().getLocalisation(label)
+    orxonox::Language::getInstance().getLocalisation(label)
 
 
 namespace orxonox
@@ -111,15 +112,15 @@
     // ###         Language        ###
     // ###############################
     //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map.
-    class _CoreExport Language
+    class _CoreExport Language : public Singleton<Language>
     {
+        friend class Singleton<Language>;
         friend class CoreConfiguration;
 
         public:
             Language();
             ~Language();
 
-            static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; }
             void addEntry(const LanguageEntryLabel& label, const std::string& entry);
             const std::string& getLocalisation(const LanguageEntryLabel& label) const;
 
@@ -136,7 +137,7 @@
             std::string defaultLocalisation_;                       //!< The returned string, if an entry unavailable entry is requested
             std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
 
-            static Language* singletonRef_s;
+            static Language* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/core/LuaBind.cc
===================================================================
--- branches/resource/src/core/LuaBind.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/LuaBind.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -42,13 +42,10 @@
 
 namespace orxonox
 {
-  LuaBind* LuaBind::singletonRef_s = NULL;
+  LuaBind* LuaBind::singletonPtr_s = NULL;
 
   LuaBind::LuaBind()
   {
-    assert(LuaBind::singletonRef_s == 0);
-    LuaBind::singletonRef_s = this;
-
     this->includePath_ = Core::getMediaPathString();
 
     luaState_ = lua_open();
@@ -74,9 +71,6 @@
   LuaBind::~LuaBind()
   {
     this->closeToluaInterfaces(luaState_);
-
-    assert(singletonRef_s);
-    LuaBind::singletonRef_s = NULL;
   };
 
   void LuaBind::luaPrint(const std::string& str)

Modified: branches/resource/src/core/LuaBind.h
===================================================================
--- branches/resource/src/core/LuaBind.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/LuaBind.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -44,13 +44,16 @@
 #include <lua.h>
 }
 
+#include "util/Singleton.h"
+
 // tolua_begin
 namespace orxonox
 {
-  class _CoreExport LuaBind
+  class _CoreExport LuaBind : public Singleton<LuaBind>
   {
+// tolua_end
+    friend class Singleton<LuaBind>;
 
-// tolua_end
     struct LoadS {
       const char *s;
       size_t size;
@@ -60,7 +63,7 @@
       LuaBind();
       ~LuaBind();
 
-      inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export
+      static LuaBind& getInstance() { return Singleton<LuaBind>::getInstance(); } // tolua_export
 
     void loadFile(const std::string& filename, bool luaTags);
     void loadString(const std::string& code);
@@ -88,7 +91,7 @@
     void closeToluaInterfaces(lua_State* state);
 
     private:
-      static LuaBind* singletonRef_s;
+      static LuaBind* singletonPtr_s;
 
       std::string luaSource_;
       std::string output_;

Modified: branches/resource/src/core/Shell.cc
===================================================================
--- branches/resource/src/core/Shell.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Shell.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -50,13 +50,10 @@
     SetConsoleCommandShortcut(OutputHandler, info);
     SetConsoleCommandShortcut(OutputHandler, debug);
 
-    Shell* Shell::singletonRef_s = 0;
+    Shell* Shell::singletonPtr_s = 0;
 
     Shell::Shell()
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         int level = Core::getSoftDebugLevel(OutputHandler::LD_Shell);
         Core::setSoftDebugLevel(OutputHandler::LD_Shell, -1);
 
@@ -91,7 +88,6 @@
         OutputHandler::getOutStream().setOutputBuffer(0);
         if (this->inputBuffer_)
             delete this->inputBuffer_;
-        singletonRef_s = 0;
     }
 
     void Shell::setConfigValues()

Modified: branches/resource/src/core/Shell.h
===================================================================
--- branches/resource/src/core/Shell.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/Shell.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -59,14 +59,13 @@
             virtual void exit() {}
     };
 
-    class _CoreExport Shell : virtual public OrxonoxClass, public OutputBufferListener
+    class _CoreExport Shell : public Singleton<Shell>, virtual public OrxonoxClass, public OutputBufferListener
     {
+        friend class Singleton<Shell>;
         public:
             Shell();
             virtual ~Shell();
 
-            static Shell& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
-
             static void clearShell();
             static void history();
 
@@ -147,7 +146,7 @@
 
             ConfigFileType commandHistoryConfigFileType_;
 
-            static Shell* singletonRef_s;
+            static Shell* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/core/TclBind.cc
===================================================================
--- branches/resource/src/core/TclBind.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/TclBind.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -45,12 +45,10 @@
     SetConsoleCommandShortcut(TclBind, tcl);
     SetConsoleCommandShortcut(TclBind, bgerror);
 
-    TclBind* TclBind::singletonRef_s = 0;
+    TclBind* TclBind::singletonPtr_s = 0;
 
     TclBind::TclBind(const std::string& datapath)
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
         this->interpreter_ = 0;
         this->bSetTclDataPath_ = false;
         this->setDataPath(datapath);
@@ -60,7 +58,6 @@
     {
         if (this->interpreter_)
             delete this->interpreter_;
-        singletonRef_s = 0;
     }
 
     void TclBind::setDataPath(const std::string& datapath)

Modified: branches/resource/src/core/TclBind.h
===================================================================
--- branches/resource/src/core/TclBind.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/TclBind.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -33,17 +33,17 @@
 
 #include <cassert>
 #include <string>
+#include "util/Singleton.h"
 
 namespace orxonox
 {
-    class _CoreExport TclBind
+    class _CoreExport TclBind : public Singleton<TclBind>
     {
+        friend class Singleton<TclBind>;
         public:
             TclBind(const std::string& datapath);
             ~TclBind();
 
-            static TclBind& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
-
             static std::string tcl(const std::string& tclcode);
             static void bgerror(std::string error);
 
@@ -67,7 +67,7 @@
             std::string tclDataPath_;
             bool bSetTclDataPath_;
 
-            static TclBind* singletonRef_s;
+            static TclBind* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/core/TclThreadManager.cc
===================================================================
--- branches/resource/src/core/TclThreadManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/TclThreadManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -90,9 +90,6 @@
     {
         RegisterRootObject(TclThreadManager);
 
-        assert(TclThreadManager::singletonPtr_s == 0);
-        TclThreadManager::singletonPtr_s = this;
-
         this->numInterpreterBundles_ = 0;
 
         this->interpreterBundlesMutex_ = new boost::shared_mutex();
@@ -115,8 +112,6 @@
     */
     TclThreadManager::~TclThreadManager()
     {
-        TclThreadManager::singletonPtr_s = 0;
-
         delete this->interpreterBundlesMutex_;
 //        delete this->mainInterpreterMutex_; // <-- temporary disabled to avoid crash if a thread is still actively queriyng
         delete this->messageQueue_;

Modified: branches/resource/src/core/TclThreadManager.h
===================================================================
--- branches/resource/src/core/TclThreadManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/TclThreadManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -36,14 +36,16 @@
 #include <map>
 #include <string>
 
+#include "util/Singleton.h"
 #include "OrxonoxClass.h"
 
 struct Tcl_Interp;
 
 namespace orxonox
 {
-    class _CoreExport TclThreadManager : public OrxonoxClass
+    class _CoreExport TclThreadManager : public Singleton<TclThreadManager>, public OrxonoxClass
     {
+        friend class Singleton<TclThreadManager>;
         friend class TclBind;
         friend _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command);
         friend _CoreExport void sourceThread(std::string file);
@@ -53,8 +55,6 @@
             TclThreadManager(Tcl::interpreter* interpreter);
             virtual ~TclThreadManager();
 
-            static TclThreadManager& getInstance() { assert(TclThreadManager::singletonPtr_s); return *TclThreadManager::singletonPtr_s; }
-
             static unsigned int      create();
             static Tcl::interpreter* createWithId(unsigned int id);
             static void              destroy(unsigned int id);

Modified: branches/resource/src/core/input/InputManager.cc
===================================================================
--- branches/resource/src/core/input/InputManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/input/InputManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -63,7 +63,7 @@
     // Abuse of this source file for the InputHandler
     InputHandler InputHandler::EMPTY;
 
-    InputManager* InputManager::singletonRef_s = 0;
+    InputManager* InputManager::singletonPtr_s = 0;
 
     //! Defines the |= operator for easier use.
     inline InputManager::State operator|=(InputManager::State& lval, InputManager::State rval)
@@ -92,9 +92,6 @@
     {
         RegisterRootObject(InputManager);
 
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         CCOUT(4) << "Constructing..." << std::endl;
 
         this->setConfigValues();
@@ -137,8 +134,8 @@
             this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "reload"), false);
         }
 
-        internalState_ = Nothing;
         CCOUT(4) << "Construction complete." << std::endl;
+        internalState_ = Nothing;
     }
 
     void InputManager::setConfigValues()
@@ -296,7 +293,6 @@
             this->destroyDevices();
 
         CCOUT(4) << "Destruction complete." << std::endl;
-        singletonRef_s = 0;
     }
 
     /**

Modified: branches/resource/src/core/input/InputManager.h
===================================================================
--- branches/resource/src/core/input/InputManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/core/input/InputManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -36,6 +36,7 @@
 #include <string>
 #include <vector>
 
+#include "util/Singleton.h"
 #include "core/WindowEventListener.h"
 #include "InputState.h"
 
@@ -61,8 +62,9 @@
         - Keyboard construction is mandatory , mouse and joy sticks are not.
           If the OIS::InputManager or the Keyboard fail, an exception is thrown.
     */
-    class _CoreExport InputManager : public WindowEventListener
+    class _CoreExport InputManager : public Singleton<InputManager>, public WindowEventListener
     {
+        friend class Singleton<InputManager>;
     public:
         //! Represents internal states of the InputManager.
         enum State
@@ -167,9 +169,6 @@
         OIS::InputManager* getOISInputManager()
             { return this->oisInputManager_; }
 
-        //! Returns a reference to the singleton instance
-        static InputManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
-
     private: // functions
         // don't mess with a Singleton
         InputManager(const InputManager&);
@@ -210,7 +209,7 @@
         std::set<InputState*>               stateLeaveRequests_;   //!< Requests to leave a running state
         std::set<InputState*>               stateDestroyRequests_; //!< Requests to destroy a state
 
-        static InputManager*                singletonRef_s;        //!< Pointer reference to the singleton
+        static InputManager*                singletonPtr_s;        //!< Pointer reference to the singleton
     };
 }
 

Modified: branches/resource/src/orxonox/CameraManager.cc
===================================================================
--- branches/resource/src/orxonox/CameraManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/CameraManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -41,22 +41,16 @@
 
 namespace orxonox
 {
-    CameraManager* CameraManager::singletonRef_s = 0;
+    CameraManager* CameraManager::singletonPtr_s = 0;
 
     CameraManager::CameraManager(Ogre::Viewport* viewport)
         : viewport_(viewport)
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         this->fallbackCamera_ = 0;
     }
 
     CameraManager::~CameraManager()
     {
-        assert(singletonRef_s != 0);
-        singletonRef_s = 0;
-
         if (this->fallbackCamera_)
             this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
     }

Modified: branches/resource/src/orxonox/CameraManager.h
===================================================================
--- branches/resource/src/orxonox/CameraManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/CameraManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -40,11 +40,13 @@
 #include <cassert>
 #include <list>
 #include "util/OgreForwardRefs.h"
+#include "util/Singleton.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport CameraManager
+    class _OrxonoxExport CameraManager : public Singleton<CameraManager>
     {
+            friend class Singleton<CameraManager>;
         public:
             CameraManager(Ogre::Viewport* viewport);
             ~CameraManager();
@@ -56,8 +58,7 @@
 
             void useCamera(Ogre::Camera* camera);
 
-            static CameraManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
-            static CameraManager* getInstancePtr() { return singletonRef_s; }
+            static CameraManager* getInstancePtr() { return singletonPtr_s; }
 
         private:
             CameraManager(const CameraManager&); // don't use
@@ -66,7 +67,7 @@
             Ogre::Viewport*       viewport_;
             Ogre::Camera*         fallbackCamera_;
 
-            static CameraManager* singletonRef_s;
+            static CameraManager* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/orxonox/LevelManager.cc
===================================================================
--- branches/resource/src/orxonox/LevelManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/LevelManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -44,13 +44,10 @@
 {
     SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
 
-    LevelManager* LevelManager::singletonRef_s = 0;
+    LevelManager* LevelManager::singletonPtr_s = 0;
 
     LevelManager::LevelManager()
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         RegisterRootObject(LevelManager);
         this->setConfigValues();
 
@@ -63,8 +60,6 @@
 
     LevelManager::~LevelManager()
     {
-        assert(singletonRef_s != 0);
-        singletonRef_s = 0;
     }
 
     void LevelManager::setConfigValues()

Modified: branches/resource/src/orxonox/LevelManager.h
===================================================================
--- branches/resource/src/orxonox/LevelManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/LevelManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -34,6 +34,8 @@
 #include <cassert>
 #include <list>
 #include <string>
+
+#include "util/Singleton.h"
 #include "core/OrxonoxClass.h"
 
 // tolua_begin
@@ -41,8 +43,9 @@
 {
     class _OrxonoxExport LevelManager
     // tolua_end
-        : public OrxonoxClass
+        : public Singleton<LevelManager>, public OrxonoxClass
     { // tolua_export
+            friend class Singleton<LevelManager>;
         public:
             LevelManager();
             virtual ~LevelManager();
@@ -58,8 +61,8 @@
             void compileAvailableLevelList(); //tolua_export
             std::string getAvailableLevelListItem(unsigned int index) const; //tolua_export
 
-            static LevelManager* getInstancePtr() { return singletonRef_s; }
-            static LevelManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
+            static LevelManager* getInstancePtr() { return singletonPtr_s; }
+            static LevelManager& getInstance()    { return Singleton<LevelManager>::getInstance(); } // tolua_export
 
         private:
             LevelManager(const LevelManager&);
@@ -72,7 +75,7 @@
             // config values
             std::string defaultLevelName_;
 
-            static LevelManager* singletonRef_s;
+            static LevelManager* singletonPtr_s;
     }; // tolua_export
 } // tolua_export
 

Modified: branches/resource/src/orxonox/PawnManager.cc
===================================================================
--- branches/resource/src/orxonox/PawnManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/PawnManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -33,25 +33,20 @@
 
 namespace orxonox
 {
-    PawnManager* PawnManager::singletonRef_s = 0;
+    PawnManager* PawnManager::singletonPtr_s = 0;
 
     PawnManager::PawnManager()
     {
         RegisterRootObject(PawnManager);
-
-        assert(PawnManager::singletonRef_s == 0);
-        PawnManager::singletonRef_s = this;
     }
 
     PawnManager::~PawnManager()
     {
-        assert(PawnManager::singletonRef_s != 0);
-        PawnManager::singletonRef_s = 0;
     }
 
     void PawnManager::touch()
     {
-        if (!PawnManager::singletonRef_s)
+        if (!PawnManager::singletonPtr_s)
             new PawnManager();
     }
 

Modified: branches/resource/src/orxonox/PawnManager.h
===================================================================
--- branches/resource/src/orxonox/PawnManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/PawnManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -30,12 +30,15 @@
 #define _PawnManager_H__
 
 #include "OrxonoxPrereqs.h"
+
+#include "util/Singleton.h"
 #include "interfaces/Tickable.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport PawnManager : public Tickable
+    class _OrxonoxExport PawnManager : protected Singleton<PawnManager>, public Tickable
     {
+            friend class Singleton<PawnManager>;
         public:
             static void touch();
 
@@ -45,7 +48,7 @@
             PawnManager();
             virtual ~PawnManager();
 
-            static PawnManager* singletonRef_s;
+            static PawnManager* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/orxonox/PlayerManager.cc
===================================================================
--- branches/resource/src/orxonox/PlayerManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/PlayerManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -36,22 +36,17 @@
 
 namespace orxonox
 {
-    PlayerManager* PlayerManager::singletonRef_s = 0;
+    PlayerManager* PlayerManager::singletonPtr_s = 0;
 
     PlayerManager::PlayerManager()
     {
         RegisterRootObject(PlayerManager);
 
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         this->getConnectedClients();
     }
 
     PlayerManager::~PlayerManager()
     {
-        assert(singletonRef_s);
-        singletonRef_s = 0;
     }
 
     void PlayerManager::clientConnected(unsigned int clientID)

Modified: branches/resource/src/orxonox/PlayerManager.h
===================================================================
--- branches/resource/src/orxonox/PlayerManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/PlayerManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -33,19 +33,18 @@
 
 #include <cassert>
 #include <map>
+#include "util/Singleton.h"
 #include "network/ClientConnectionListener.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport PlayerManager : public ClientConnectionListener
+    class _OrxonoxExport PlayerManager : public Singleton<PlayerManager>, public ClientConnectionListener
     {
+            friend class Singleton<PlayerManager>;
         public:
             PlayerManager();
             virtual ~PlayerManager();
 
-            inline static PlayerManager& getInstance()
-                { assert(singletonRef_s); return *singletonRef_s; }
-
             PlayerInfo* getClient(unsigned int clientID) const;
             inline const std::map<unsigned int, PlayerInfo*>& getClients() const
                 { return this->clients_; }
@@ -56,7 +55,7 @@
 
             std::map<unsigned int, PlayerInfo*> clients_;
 
-            static PlayerManager* singletonRef_s;
+            static PlayerManager* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/orxonox/objects/pickup/BaseItem.h
===================================================================
--- branches/resource/src/orxonox/objects/pickup/BaseItem.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/objects/pickup/BaseItem.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -50,10 +50,7 @@
         @author
             Daniel 'Huty' Haggenmueller
     */
-    class _OrxonoxExport BaseItem
-// tolua_end
-        : public BaseObject
-// tolua_begin
+    class _OrxonoxExport BaseItem : public BaseObject
     {
 // tolua_end
     public:

Modified: branches/resource/src/orxonox/objects/pickup/PickupInventory.h
===================================================================
--- branches/resource/src/orxonox/objects/pickup/PickupInventory.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/objects/pickup/PickupInventory.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -42,12 +42,10 @@
 // tolua_begin
 namespace orxonox
 {
-// tolua_end
     /**
         @brief Static class for the inventory GUI window.
         @author Daniel 'Huty' Haggenmueller
     */
-// tolua_begin
     class _OrxonoxExport PickupInventory
     {
 // tolua_end

Modified: branches/resource/src/orxonox/objects/quest/QuestDescription.h
===================================================================
--- branches/resource/src/orxonox/objects/quest/QuestDescription.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/objects/quest/QuestDescription.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -53,10 +53,9 @@
     @author
         Damian 'Mozork' Frick
     */
-    class _OrxonoxExport QuestDescription
+    class _OrxonoxExport QuestDescription : public BaseObject
+    {
 // tolua_end
-        : public BaseObject
-    { // tolua_export
         public:
             QuestDescription(BaseObject* creator);
             virtual ~QuestDescription();

Modified: branches/resource/src/orxonox/objects/quest/QuestManager.cc
===================================================================
--- branches/resource/src/orxonox/objects/quest/QuestManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/objects/quest/QuestManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -46,7 +46,7 @@
 namespace orxonox
 {
     //! Pointer to the current (and single) instance of this class.
-    /*static*/ QuestManager* QuestManager::singletonRef_s = NULL;
+    /*static*/ QuestManager* QuestManager::singletonPtr_s = NULL;
 
     /**
     @brief
@@ -57,9 +57,6 @@
     QuestManager::QuestManager()
     {
         RegisterRootObject(QuestManager);
-
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
     }
 
     /**
@@ -73,18 +70,6 @@
 
     /**
     @brief
-        Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with.
-    @return
-        Returns a reference to the single instance of the Quest Manager.
-    */
-    /*static*/ QuestManager & QuestManager::getInstance()
-    {
-        assert(singletonRef_s);
-        return *singletonRef_s;
-    }
-
-    /**
-    @brief
         Registers a Quest with the QuestManager to make it globally accessable.
         Uses it's id to make sure to be able to be identify and retrieve it later.
     @param quest

Modified: branches/resource/src/orxonox/objects/quest/QuestManager.h
===================================================================
--- branches/resource/src/orxonox/objects/quest/QuestManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/objects/quest/QuestManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -39,6 +39,8 @@
 #include <list>
 #include <map>
 #include <string>
+
+#include "util/Singleton.h"
 #include "core/OrxonoxClass.h"
 
 // tolua_begin
@@ -70,17 +72,16 @@
     @author
         Damian 'Mozork' Frick
     */
-    class _OrxonoxExport QuestManager
-// tolua_end
-        : public OrxonoxClass
-// tolua_begin
+    class _OrxonoxExport QuestManager : public Singleton<QuestManager>, public orxonox::OrxonoxClass
     {
 // tolua_end
+            friend class Singleton<QuestManager>;
         public:
             QuestManager();
             virtual ~QuestManager();
 
-            static QuestManager& getInstance(); // tolua_export //!< Returns a reference to the single instance of the Quest Manager.
+            //! Returns a reference to the single instance of the Quest Manager.
+            static QuestManager& getInstance() { return Singleton<QuestManager>::getInstance(); } // tolua_export
 
             bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
             bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
@@ -91,7 +92,7 @@
             QuestContainer* getQuestTree(std::string & name); // tolua_export
 
         private:
-            static QuestManager* singletonRef_s;
+            static QuestManager* singletonPtr_s;
 
             std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
             std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.

Modified: branches/resource/src/orxonox/overlays/console/InGameConsole.cc
===================================================================
--- branches/resource/src/orxonox/overlays/console/InGameConsole.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/overlays/console/InGameConsole.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -59,7 +59,7 @@
     SetConsoleCommand(InGameConsole, openConsole, true);
     SetConsoleCommand(InGameConsole, closeConsole, true);
 
-    InGameConsole* InGameConsole::singletonRef_s = 0;
+    InGameConsole* InGameConsole::singletonPtr_s = 0;
 
     /**
         @brief Constructor: Creates and initializes the InGameConsole.
@@ -75,9 +75,6 @@
     {
         RegisterObject(InGameConsole);
 
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         this->bActive_ = false;
         this->cursor_ = 0.0f;
         this->cursorSymbol_ = '|';
@@ -130,8 +127,6 @@
 
         if (this->consoleOverlay_)
             Ogre::OverlayManager::getSingleton().destroy(consoleOverlay_);
-
-        singletonRef_s = 0;
     }
 
     /**

Modified: branches/resource/src/orxonox/overlays/console/InGameConsole.h
===================================================================
--- branches/resource/src/orxonox/overlays/console/InGameConsole.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/overlays/console/InGameConsole.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -33,14 +33,17 @@
 #include "OrxonoxPrereqs.h"
 
 #include <string>
+
 #include "util/OgreForwardRefs.h"
+#include "util/Singleton.h"
 #include "core/Shell.h"
 #include "core/WindowEventListener.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport InGameConsole : public ShellListener, public WindowEventListener
+    class _OrxonoxExport InGameConsole : public Singleton<InGameConsole>, public ShellListener, public WindowEventListener
     {
+        friend class Singleton<InGameConsole>;
     public: // functions
         InGameConsole();
         ~InGameConsole();
@@ -51,9 +54,6 @@
 
         void update(const Clock& time);
 
-        static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
-        static InGameConsole* getInstancePtr() { return singletonRef_s; }
-
         static void openConsole();
         static void closeConsole();
 
@@ -111,7 +111,7 @@
         char cursorSymbol_;
         bool bHidesAllInput_;
 
-        static InGameConsole* singletonRef_s;
+        static InGameConsole* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/orxonox/overlays/notifications/NotificationManager.cc
===================================================================
--- branches/resource/src/orxonox/overlays/notifications/NotificationManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/overlays/notifications/NotificationManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -45,7 +45,7 @@
     const std::string NotificationManager::ALL = "all";
     const std::string NotificationManager::NONE = "none";
 
-    NotificationManager* NotificationManager::singletonRef_s = NULL;
+    NotificationManager* NotificationManager::singletonPtr_s = NULL;
 
     /**
     @brief
@@ -55,9 +55,6 @@
     {
         RegisterRootObject(NotificationManager);
 
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-
         this->highestIndex_ = 0;
     }
 
@@ -71,18 +68,6 @@
 
     /**
     @brief
-        Returns the current (and single) instance of the NotificationManager. Creates one, if there isn't one to begin with.
-    @return
-        Returns a reference to the single instance of the NotificationManager.
-    */
-    /*static*/ NotificationManager & NotificationManager::getInstance()
-    {
-        assert(singletonRef_s);
-        return *singletonRef_s;
-    }
-    
-    /**
-    @brief
         Registers a Notification within the NotificationManager and makes sure that the Notification is displayed in all the NotificationQueues associated with its sender.
     @param notification
         The Notification to be registered.

Modified: branches/resource/src/orxonox/overlays/notifications/NotificationManager.h
===================================================================
--- branches/resource/src/orxonox/overlays/notifications/NotificationManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/overlays/notifications/NotificationManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -39,6 +39,8 @@
 #include <ctime>
 #include <map>
 #include <string>
+
+#include "util/Singleton.h"
 #include "core/OrxonoxClass.h"
 
 namespace orxonox
@@ -51,8 +53,9 @@
     @author
         Damian 'Mozork' Frick
     */
-    class _OrxonoxExport NotificationManager : public OrxonoxClass
+    class _OrxonoxExport NotificationManager : public Singleton<NotificationManager>, public OrxonoxClass
     {
+            friend class Singleton<NotificationManager>;
         public:
             NotificationManager();
             virtual ~NotificationManager();
@@ -60,8 +63,6 @@
             static const std::string ALL;
             static const std::string NONE;
 
-            static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.
-
             bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
             bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
 
@@ -87,7 +88,7 @@
                 { return this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
 
         private:
-            static NotificationManager* singletonRef_s;
+            static NotificationManager* singletonPtr_s;
 
             int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
 

Modified: branches/resource/src/orxonox/sound/SoundManager.cc
===================================================================
--- branches/resource/src/orxonox/sound/SoundManager.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/sound/SoundManager.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -37,16 +37,13 @@
 
 namespace orxonox
 {
-    SoundManager* SoundManager::singletonRef_s = NULL;
+    SoundManager* SoundManager::singletonPtr_s = NULL;
 
     /**
      * Default constructor
      */
     SoundManager::SoundManager()
     {
-        assert(singletonRef_s == NULL);
-        singletonRef_s = this;
-
         this->device_ = NULL;
         this->soundavailable_ = true;
         if(!alutInitWithoutContext(NULL,NULL))
@@ -92,9 +89,6 @@
 
     SoundManager::~SoundManager()
     {
-        assert(singletonRef_s != NULL);
-        singletonRef_s = NULL;
-
         alcDestroyContext(this->context_);
         alcCloseDevice(this->device_);
         alutExit();

Modified: branches/resource/src/orxonox/sound/SoundManager.h
===================================================================
--- branches/resource/src/orxonox/sound/SoundManager.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/orxonox/sound/SoundManager.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -31,6 +31,7 @@
 
 #include <cassert>
 #include <list>
+#include "util/Singleton.h"
 #include "interfaces/Tickable.h"
 
 namespace orxonox
@@ -41,8 +42,9 @@
      * function every tick. It is a singleton.
      *
      */
-    class _OrxonoxExport SoundManager : public Tickable 
+    class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public Tickable
     {
+        friend class Singleton<SoundManager>;
     public:
         SoundManager();
         ~SoundManager();
@@ -51,15 +53,13 @@
         void tick(float dt);
         bool isSoundAvailable();
 
-        static SoundManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
-
     private:
         ALCdevice* device_;
         ALCcontext* context_;
         std::list<SoundBase*> soundlist_;
         bool soundavailable_;
 
-        static SoundManager* singletonRef_s;
+        static SoundManager* singletonPtr_s;
     }; // class SoundManager
 } // namespace orxonox
 

Modified: branches/resource/src/util/SignalHandler.cc
===================================================================
--- branches/resource/src/util/SignalHandler.cc	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/util/SignalHandler.cc	2009-07-29 20:27:10 UTC (rev 3366)
@@ -40,7 +40,7 @@
 
 namespace orxonox
 {
-    SignalHandler* SignalHandler::singletonRef_s = NULL;
+    SignalHandler* SignalHandler::singletonPtr_s = NULL;
 }
 
 #ifdef ORXONOX_PLATFORM_LINUX
@@ -121,7 +121,7 @@
           break;
       }
       // if the signalhandler has already been destroyed then don't do anything
-      if( SignalHandler::singletonRef_s == 0 )
+      if( SignalHandler::singletonPtr_s == 0 )
       {
         COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "can't write backtrace because SignalHandler already destroyed" << std::endl;
         exit(EXIT_FAILURE);

Modified: branches/resource/src/util/SignalHandler.h
===================================================================
--- branches/resource/src/util/SignalHandler.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/util/SignalHandler.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -39,6 +39,7 @@
 #include <cassert>
 #include <list>
 #include <string>
+#include "Singleton.h"
 
 namespace orxonox
 {
@@ -66,12 +67,12 @@
     typedef std::list<SignalRec> SignalRecList;
     typedef std::list<SignalCallbackRec> SignalCallbackList;
 
-    class SignalHandler
+    class SignalHandler : public Singleton<SignalHandler>
     {
+        friend class Singleton<SignalHandler>;
     public:
-        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
-        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; }
-        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
+        SignalHandler()  { }
+        ~SignalHandler() { }
 
         void registerCallback( SignalCallback cb, void * someData );
 
@@ -86,7 +87,7 @@
 
         SignalCallbackList callbackList;
 
-        static SignalHandler* singletonRef_s;
+        static SignalHandler* singletonPtr_s;
 
         std::string appName;
         std::string filename;
@@ -97,18 +98,18 @@
 
 namespace orxonox
 {
-    class _UtilExport SignalHandler
+    class _UtilExport SignalHandler : public Singleton<SignalHandler>
     {
+        friend class Singleton<SignalHandler>;
     public:
-        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
-        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; }
-        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
+        SignalHandler()  { }
+        ~SignalHandler() { }
         void doCatch( const std::string & appName, const std::string & filename ) {}
         void dontCatch() {}
         void registerCallback( SignalCallback cb, void * someData ) {}
 
     private:
-        static SignalHandler* singletonRef_s;
+        static SignalHandler* singletonPtr_s;
     };
 }
 

Modified: branches/resource/src/util/Singleton.h
===================================================================
--- branches/resource/src/util/Singleton.h	2009-07-29 20:04:40 UTC (rev 3365)
+++ branches/resource/src/util/Singleton.h	2009-07-29 20:27:10 UTC (rev 3366)
@@ -39,8 +39,8 @@
 
         Usage:
         Inherit publicly from Singleton<MyClass> and provide access to
-        MyClass::singletonRef_s.
-        This can be done with a friend declaration.
+        MyClass::singletonPtr_s.
+        This can easily be done with a friend declaration.
     */
     template <class T>
     class Singleton
@@ -49,22 +49,23 @@
         //! Returns a reference to the singleton instance
         static T& getInstance()
         {
-            assert(T::singletonRef_s != NULL);
-            return *T::singletonRef_s;
+            assert(T::singletonPtr_s != NULL);
+            return *T::singletonPtr_s;
         }
 
     protected:
-        // Constructor sets the singleton instance pointer
+        //! Constructor sets the singleton instance pointer
         Singleton()
         {
-            assert(T::singletonRef_s == NULL);
-            T::singletonRef_s = static_cast<T*>(this);
+            assert(T::singletonPtr_s == NULL);
+            T::singletonPtr_s = static_cast<T*>(this);
         }
-        // Constructor resets the singleton instance pointer
+
+        //! Constructor resets the singleton instance pointer
         ~Singleton()
         {
-            assert(T::singletonRef_s != NULL);
-            T::singletonRef_s = NULL;
+            assert(T::singletonPtr_s != NULL);
+            T::singletonPtr_s = NULL;
         }
 
     private:




More information about the Orxonox-commit mailing list