Index: code/branches/main_reto_vs05/src/run_manager.cc
===================================================================
--- code/branches/main_reto_vs05/src/run_manager.cc	(revision 232)
+++ code/branches/main_reto_vs05/src/run_manager.cc	(revision 288)
@@ -26,20 +26,16 @@
 
 
-#include "Ogre.h"
-//#include "OgreRoot.h"
-//#include "OgreSceneManager.h"
-//#include "OgreSceneNode.h"
-//#include "OgreCamera.h"
-//#include "OgreViewport.h"
-//#include "OgreRenderWindow.h"
-//#include "OgreOverlay.h"
-//#include "OgreOverlayManager.h"
-//#include "OgreOverlayElement.h"
-//#include "OgreTextureManager.h"
-//#include "OgreMaterialManager.h"
-//#include "OgreLogManager.h"
-//#include "OgreVector3.h"
-//#include "OgreStringConverter.h"
-//#include "OgreWindowEventUtilities.h"
+#include "OgreVector3.h"
+#include "OgreStringConverter.h"
+#include "OgreRoot.h"
+#include "OgreSceneManager.h"
+#include "OgreSceneNode.h"
+#include "OgreCamera.h"
+#include "OgreViewport.h"
+#include "OgreRenderWindow.h"
+#include "OgreTextureManager.h"
+#include "OgreMaterialManager.h"
+#include "OgreLogManager.h"
+#include "OgreWindowEventUtilities.h"
 
 //Use this define to signify OIS will be used as a DLL
@@ -51,5 +47,4 @@
 #include "orxonox_scene.h"
 #include "orxonox_ship.h"
-#include "camera_manager.h"
 #include "inertial_node.h"
 
@@ -58,14 +53,14 @@
 #include "weapon/base_weapon.h"
 
+#include "hud/hud_overlay.h"
+#include "hud/test_overlay.h"
+
 #include "run_manager.h"
 
-namespace Ogre {
-  using namespace orxonox;
-  template<> RunManager* Singleton<RunManager>::ms_Singleton = 0;
-}
 
 namespace orxonox {
   using namespace Ogre;
   using namespace weapon;
+  using namespace hud;
 
   /**
@@ -82,30 +77,26 @@
   */
 
-  RunManager* RunManager::getSingletonPtr(void)
-  {
-      return ms_Singleton;
-  }
-  RunManager& RunManager::getSingleton(void)
-  {  
-      assert( ms_Singleton );  return ( *ms_Singleton );  
-  }
-
-
-  /**
-  * Contructor only needs the render window and the Root object which are both
-  * the OgreControl object.
-  * Right now the constructor does all the initialisation work. This could also
-  * be done in a new method "initialize()", for whatever purpose.
-  * 
-  * 
+
+  RunManager* RunManager::singletonPtr_s = NULL;
+
+
+  /**
+  * Contructor only needs the Root object.
+  */
+  RunManager::RunManager()
+        : ogre_(NULL), window_(NULL), screenShotCounter_(0),
+        timeUntilNextToggle_(0), mouseSensitivity_(0.003), inputManager_(0),
+        mouse_(0), keyboard_(0), joystick_(0), statsOn_(true)
+  {
+  }
+
+  /**
   * @param ogre_ The OgreControl object holding the render window and the Root
   */
-  RunManager::RunManager(OgreControl * ogre)
-        : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false),
-        statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0),
-        filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0),
-        mouseSensitivity_(0.003),
-        debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0)
-  {
+  void RunManager::initialise(OgreControl *ogre)
+    {
+    ogre_ = ogre;
+    window_ = ogre->getRenderWindow();
+
     // SETTING UP THE SCENE
 
@@ -126,14 +117,7 @@
 
     // Create a space ship object and its SceneNode.
-    // Some ideas about the steering: The ship should only receive events like
-    // up, down, left, right, roll left, roll right, move down, move up, etc).
-    // Multiple interpretations of these commands would make the game more
-    // but it also makes AI steering more difficult, since for every type of
-    // steering, new methods have to be written.
-    // --> clearly define how a space ship can fly (rolling?, conservation of
-    // impuls?, direct mouse sight steeering?, etc.)
     // It should also be considered, that the ship should provide another Node
     // for a camera to be attached (otherwise the spaceship in front of the
-    // would be very static, never moving at all).
+    // ship would be very static, never moving at all).
 
     // Construct a new spaceship and give it the node
@@ -145,5 +129,5 @@
 
     // load all resources and create the entities by calling the initialise()
-    // methods for each object (don't initialise in the constructor!).
+    // methods for each object (no constructor initialisations!).
     backgroundScene_->initialise();
     playerShip_->initialise();
@@ -151,8 +135,4 @@
 
     // CAMERA AND VIEWPORT
-    // TODO: create a camera manager. It should be able to change its position
-    // around the space ship (predefined states would be nice too). And it should
-    // also be able to switch between different locations (like ship, spactator,
-    // certain fixed positions (e.g. finish line, etc.)). These are just ideas.
 
     // create camera and viewport
@@ -160,16 +140,16 @@
     createViewports();
 
+    // create HUD
+    hud_ = new hud::TestOverlay(window_);
+    hud_->show();
+
 
     // Set default mipmap level (NB some APIs ignore this)
     TextureManager::getSingleton().setDefaultNumMipmaps(5);
 
-    
 
     // HUMAN INTERFACE
 
-    using namespace OIS;
-
-    debugOverlay_ = OverlayManager::getSingleton()
-      .getByName("Core/DebugOverlay");
+    using namespace OIS;    
 
     LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
@@ -201,5 +181,5 @@
     windowResized(window_);
 
-    showDebugOverlay(true);
+    //showDebugOverlay(true);
 
     // REGISTER THIS OBJECT AS A WINDOW EVENT LISTENER IN OGRE
@@ -225,9 +205,11 @@
     if (bulletManager_)
       delete bulletManager_;
-  }
-
-
-  /**
-  * Method to compute anyting between 2 frames.
+    if (hud_)
+      delete hud_;
+  }
+
+
+  /**
+  * Method to compute anything between 2 frames.
   * 
   * Everything that needs to be computed during the games happens right here.
@@ -250,6 +232,14 @@
 
 
-    // Update the 'HUD'
-    updateStats();
+    // Update the HUD
+    hud_->setDebugText(" | Speed = "
+      + StringConverter::toString(playerShip_->getSpeed())
+      + " | Left Ammo = "
+      + StringConverter::toString(playerShip_
+      ->getMainWeapon()->getAmmoState())
+      + " | Ammo stock = "
+      + StringConverter::toString(playerShip_->getAmmoStock()));
+
+    hud_->tick(time, deltaTime);
 
     // update the bullet positions
@@ -404,30 +394,4 @@
     {
       statsOn_ = !statsOn_;
-      showDebugOverlay(statsOn_);
-      timeUntilNextToggle_ = 1;
-    }
-
-    if( keyboard_->isKeyDown(KC_T) && timeUntilNextToggle_ <= 0 )
-    {
-      switch(filtering_)
-      {
-      case TFO_BILINEAR:
-        filtering_ = TFO_TRILINEAR;
-        aniso_ = 1;
-        break;
-      case TFO_TRILINEAR:
-        filtering_ = TFO_ANISOTROPIC;
-        aniso_ = 8;
-        break;
-      case TFO_ANISOTROPIC:
-        filtering_ = TFO_BILINEAR;
-        aniso_ = 1;
-        break;
-      default: break;
-      }
-      MaterialManager::getSingleton().setDefaultTextureFiltering(filtering_);
-      MaterialManager::getSingleton().setDefaultAnisotropy(aniso_);
-
-      showDebugOverlay(statsOn_);
       timeUntilNextToggle_ = 1;
     }
@@ -439,39 +403,5 @@
       window_->writeContentsToFile(ss.str());
       timeUntilNextToggle_ = 0.5;
-      debugText_ = "Saved: " + ss.str();
-    }
-
-    if(keyboard_->isKeyDown(KC_R) && timeUntilNextToggle_ <=0)
-    {
-      sceneDetailIndex_ = (sceneDetailIndex_+1)%3 ;
-      switch(sceneDetailIndex_) {
-          case 0 : camera_->setPolygonMode(PM_SOLID); break;
-          case 1 : camera_->setPolygonMode(PM_WIREFRAME); break;
-          case 2 : camera_->setPolygonMode(PM_POINTS); break;
-      }
-      timeUntilNextToggle_ = 0.5;
-    }
-
-    static bool displayCameraDetails = false;
-    if(keyboard_->isKeyDown(KC_P) && timeUntilNextToggle_ <= 0)
-    {
-      displayCameraDetails = !displayCameraDetails;
-      timeUntilNextToggle_ = 0.5;
-      if (!displayCameraDetails)
-        debugText_ = "";
-    }
-
-    // Print camera details
-    if(displayCameraDetails)
-      debugText_ = " | Speed = "
-            + StringConverter::toString(playerShip_->getSpeed())
-            + " | Left Ammo = "
-            + StringConverter::toString(playerShip_
-            ->getMainWeapon()->getAmmoState())
-            + " | Ammo stock = "
-            + StringConverter::toString(playerShip_->getAmmoStock());
-    // debugText_ = "P: " + StringConverter::toString(camera_
-    //      ->getDerivedPosition()) + " " + "O: "
-    //      + StringConverter::toString(camera_->getDerivedOrientation());
+    }
 
     // Return true to continue rendering
@@ -507,76 +437,26 @@
 
   /**
-  * Show the debug overlay of desired.
+  * Show an overlay desired.
   * @param show Whether or not to show the debug overlay
   */
   void RunManager::showDebugOverlay(bool show)
   {
-    if (debugOverlay_)
+    if (hud_)
     {
       if (show)
-        debugOverlay_->show();
+        hud_->show();
       else
-        debugOverlay_->hide();
-    }
-  }
-
-
-  /**
-  * Show stats (e.g. FPS) in the left lower corner of the screen.
-  * Copied from the ExampleFrameListener.h in the Ogre SDK
-  */
-  void RunManager::updateStats(void)
-  {
-    static String currFps = "Current FPS: ";
-    static String avgFps = "Average FPS: ";
-    static String bestFps = "Best FPS: ";
-    static String worstFps = "Worst FPS: ";
-    static String tris = "Triangle Count: ";
-    static String batches = "Batch Count: ";
-
-    // update stats when necessary
-    try {
-      OverlayElement* guiAvg = OverlayManager::getSingleton()
-        .getOverlayElement("Core/AverageFps");
-      OverlayElement* guiCurr = OverlayManager::getSingleton()
-        .getOverlayElement("Core/CurrFps");
-      OverlayElement* guiBest = OverlayManager::getSingleton()
-        .getOverlayElement("Core/BestFps");
-      OverlayElement* guiWorst = OverlayManager::getSingleton()
-        .getOverlayElement("Core/WorstFps");
-
-      const RenderTarget::FrameStats& stats = window_->getStatistics();
-      guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
-      guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS));
-      guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)
-        +" "+StringConverter::toString(stats.bestFrameTime)+" ms");
-      guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)
-        +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
-
-      OverlayElement* guiTris = OverlayManager::getSingleton()
-        .getOverlayElement("Core/NumTris");
-      guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
-
-      OverlayElement* guiBatches = OverlayManager::getSingleton()
-        .getOverlayElement("Core/NumBatches");
-      guiBatches->setCaption(batches
-        + StringConverter::toString(stats.batchCount));
-
-      OverlayElement* guiDbg = OverlayManager::getSingleton()
-        .getOverlayElement("Core/DebugText");
-      guiDbg->setCaption(debugText_);
-    }
-    catch(...) { /* ignore */ }
-  }
-
+        hud_->hide();
+    }
+  }
 
 
   /**
   * Simple camera creator.
-  * playerShip_Node->attachObject(camera_) should no be here! This is what the camera
-  * manager is for. Right now, this method should do just fine, setting the
-  * cam behind the ship.
-  */
-  void RunManager::createCamera(void)
+  * playerShip_Node->attachObject(camera_) should not be here! This is what
+  * the camera manager is for. Right now, this method should do just fine,
+  * setting the cam behind the ship.
+  */
+  void RunManager::createCamera()
   {
     camera_ = sceneMgr_->createCamera("PlayerCam");
@@ -589,10 +469,8 @@
   /**
   * Simple viewport creator.
-  * TODO: fully understand the concept of viewports concerning orxnox.
-  * E.g. do we need splitscreen mode?
   * For now the viewport uses the entire render window and is based on the one
   * camera created so far.
   */
-  void RunManager::createViewports(void)
+  void RunManager::createViewports()
   {
     // Create one viewport, entire window
@@ -605,3 +483,29 @@
   }
 
+
+  RunManager* RunManager::createSingleton()
+  {
+    if (singletonPtr_s)
+      return NULL;
+    singletonPtr_s = new RunManager();
+    return singletonPtr_s;
+  }
+
+  void RunManager::destroySingleton()
+  {
+    if (singletonPtr_s)
+      delete singletonPtr_s;
+  }
+
+
+  RunManager& RunManager::getSingleton()
+  {
+    return *singletonPtr_s;
+  }
+
+  RunManager* RunManager::getSingletonPtr()
+  {
+    return singletonPtr_s;
+  }
+
 }
