Index: code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
===================================================================
--- code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc	(revision 1641)
+++ code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc	(revision 1642)
@@ -58,4 +58,6 @@
     SetConsoleCommand(InGameConsole, closeConsole, true);
 
+    InGameConsole* InGameConsole::singletonRef_s = 0;
+
     /**
         @brief Constructor: Creates and initializes the InGameConsole.
@@ -71,4 +73,7 @@
         RegisterObject(InGameConsole);
 
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
+
         this->bActive_ = false;
         this->cursor_ = 0.0f;
@@ -87,128 +92,8 @@
     InGameConsole::~InGameConsole(void)
     {
-        this->destroy();
-    }
-
-    /**
-        @brief Returns a reference to the only existing instance of InGameConsole.
-    */
-    InGameConsole& InGameConsole::getInstance()
-    {
-        static InGameConsole instance;
-        return instance;
-    }
-
-    /**
-        @brief Sets the config values, describing the size of the console.
-    */
-    void InGameConsole::setConfigValues()
-    {
-        SetConfigValue(relativeWidth, 0.8);
-        SetConfigValue(relativeHeight, 0.4);
-        SetConfigValue(blinkTime, 0.5);
-        SetConfigValue(scrollSpeed_, 3.0f);
-        SetConfigValue(noiseSize_, 1.0f);
-        SetConfigValue(cursorSymbol_, '|');
-    }
-
-    /**
-        @brief Initializes the InGameConsole.
-    */
-    void InGameConsole::initialise()
-    {
-        // create the corresponding input state
-        InputManager::createSimpleInputState("console", 40)->setKeyHandler(Shell::getInstance().getInputBuffer());
-
-        // create overlay and elements
-        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
-
-        // create actual overlay
-        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
-
-        // create a container
-        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
-        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
-        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
-        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
-        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
-
-        // create BorderPanel
-        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
-        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
-        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
-        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
-        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
-        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
-        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
-        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
-        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
-        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
-        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
-
-        // create a new font to match the requested size exactly
-        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
-            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
-        font->setType(Ogre::FT_TRUETYPE);
-        font->setSource("Monofur.ttf");
-        font->setTrueTypeSize(18);
-        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
-        font->setTrueTypeResolution(192);
-        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
-        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
-
-        // create the text lines
-        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
-        for (int i = 0; i < LINES; i++)
-        {
-            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
-            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
-            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
-            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
-            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
-            this->consoleOverlayTextAreas_[i]->setLeft(8);
-            this->consoleOverlayTextAreas_[i]->setCaption("");
-            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
-        }
-
-        // create cursor (also a text area overlay element)
-        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
-        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
-        this->consoleOverlayCursor_->setFontName("MonofurConsole");
-        this->consoleOverlayCursor_->setCharHeight(18);
-        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
-        this->consoleOverlayCursor_->setLeft(7);
-        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
-        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
-
-        // create noise
-        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
-        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
-        this->consoleOverlayNoise_->setPosition(5,0);
-        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
-        // comment following line to disable noise
-        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
-
-        this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
-
-        // move overlay "above" the top edge of the screen
-        // we take -1.2 because the border makes the panel bigger
-        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
-
-        Shell::getInstance().addOutputLevel(true);
-
-        COUT(4) << "Info: InGameConsole initialized" << std::endl;
-    }
-
-    /**
-        @brief Destroys all the elements if necessary.
-    */
-    void InGameConsole::destroy()
-    {
         this->deactivate();
 
-        // destroy the input state previously created
-        SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
-        if (inputState)
-            InputManager::destroyState("console");
+        // destroy the input state previously created (InputBuffer gets destroyed by the Shell)
+        InputManager::getInstance().destroyState("console");
 
         Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
@@ -239,4 +124,108 @@
             this->consoleOverlayTextAreas_ = 0;
         }
+
+        singletonRef_s = 0;
+    }
+
+    /**
+        @brief Sets the config values, describing the size of the console.
+    */
+    void InGameConsole::setConfigValues()
+    {
+        SetConfigValue(relativeWidth, 0.8);
+        SetConfigValue(relativeHeight, 0.4);
+        SetConfigValue(blinkTime, 0.5);
+        SetConfigValue(scrollSpeed_, 3.0f);
+        SetConfigValue(noiseSize_, 1.0f);
+        SetConfigValue(cursorSymbol_, '|');
+    }
+
+    /**
+        @brief Initializes the InGameConsole.
+    */
+    void InGameConsole::initialise()
+    {
+        // create the corresponding input state
+        InputManager::getInstance().createSimpleInputState("console", 40)
+            ->setKeyHandler(Shell::getInstance().getInputBuffer());
+
+        // create overlay and elements
+        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
+
+        // create actual overlay
+        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
+
+        // create a container
+        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
+        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
+        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
+        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
+        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
+
+        // create BorderPanel
+        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
+        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
+        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
+        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
+        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
+        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
+        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
+        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
+        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
+        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
+        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
+
+        // create a new font to match the requested size exactly
+        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
+            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
+        font->setType(Ogre::FT_TRUETYPE);
+        font->setSource("Monofur.ttf");
+        font->setTrueTypeSize(18);
+        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
+        font->setTrueTypeResolution(192);
+        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
+        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
+
+        // create the text lines
+        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
+        for (int i = 0; i < LINES; i++)
+        {
+            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
+            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
+            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
+            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
+            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
+            this->consoleOverlayTextAreas_[i]->setLeft(8);
+            this->consoleOverlayTextAreas_[i]->setCaption("");
+            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
+        }
+
+        // create cursor (also a text area overlay element)
+        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
+        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
+        this->consoleOverlayCursor_->setFontName("MonofurConsole");
+        this->consoleOverlayCursor_->setCharHeight(18);
+        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
+        this->consoleOverlayCursor_->setLeft(7);
+        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
+        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
+
+        // create noise
+        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
+        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
+        this->consoleOverlayNoise_->setPosition(5,0);
+        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
+        // comment following line to disable noise
+        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
+
+        this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
+
+        // move overlay "above" the top edge of the screen
+        // we take -1.2 because the border makes the panel bigger
+        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
+
+        Shell::getInstance().addOutputLevel(true);
+
+        COUT(4) << "Info: InGameConsole initialized" << std::endl;
     }
 
@@ -491,5 +480,5 @@
         {
             this->bActive_ = true;
-            InputManager::requestEnterState("console");
+            InputManager::getInstance().requestEnterState("console");
             Shell::getInstance().registerListener(this);
 
@@ -513,5 +502,5 @@
         {
             this->bActive_ = false;
-            InputManager::requestLeaveState("console");
+            InputManager::getInstance().requestLeaveState("console");
             Shell::getInstance().unregisterListener(this);
 
