Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2007, 11:49:42 PM (16 years ago)
Author:
rgrieder
Message:
  • added Chai's HUD overlay
  • abstracted debugOverlay —> TestOverlay
  • added overlay media files
  • cleaned up RunManager a little bit
  • omitted using ogre's Singleton template
  • added useful CMake structure
  • some more things
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto_vs05/src/run_manager.cc

    r232 r288  
    2626
    2727
    28 #include "Ogre.h"
    29 //#include "OgreRoot.h"
    30 //#include "OgreSceneManager.h"
    31 //#include "OgreSceneNode.h"
    32 //#include "OgreCamera.h"
    33 //#include "OgreViewport.h"
    34 //#include "OgreRenderWindow.h"
    35 //#include "OgreOverlay.h"
    36 //#include "OgreOverlayManager.h"
    37 //#include "OgreOverlayElement.h"
    38 //#include "OgreTextureManager.h"
    39 //#include "OgreMaterialManager.h"
    40 //#include "OgreLogManager.h"
    41 //#include "OgreVector3.h"
    42 //#include "OgreStringConverter.h"
    43 //#include "OgreWindowEventUtilities.h"
     28#include "OgreVector3.h"
     29#include "OgreStringConverter.h"
     30#include "OgreRoot.h"
     31#include "OgreSceneManager.h"
     32#include "OgreSceneNode.h"
     33#include "OgreCamera.h"
     34#include "OgreViewport.h"
     35#include "OgreRenderWindow.h"
     36#include "OgreTextureManager.h"
     37#include "OgreMaterialManager.h"
     38#include "OgreLogManager.h"
     39#include "OgreWindowEventUtilities.h"
    4440
    4541//Use this define to signify OIS will be used as a DLL
     
    5147#include "orxonox_scene.h"
    5248#include "orxonox_ship.h"
    53 #include "camera_manager.h"
    5449#include "inertial_node.h"
    5550
     
    5853#include "weapon/base_weapon.h"
    5954
     55#include "hud/hud_overlay.h"
     56#include "hud/test_overlay.h"
     57
    6058#include "run_manager.h"
    6159
    62 namespace Ogre {
    63   using namespace orxonox;
    64   template<> RunManager* Singleton<RunManager>::ms_Singleton = 0;
    65 }
    6660
    6761namespace orxonox {
    6862  using namespace Ogre;
    6963  using namespace weapon;
     64  using namespace hud;
    7065
    7166  /**
     
    8277  */
    8378
    84   RunManager* RunManager::getSingletonPtr(void)
    85   {
    86       return ms_Singleton;
    87   }
    88   RunManager& RunManager::getSingleton(void)
    89   { 
    90       assert( ms_Singleton );  return ( *ms_Singleton ); 
    91   }
    92 
    93 
    94   /**
    95   * Contructor only needs the render window and the Root object which are both
    96   * the OgreControl object.
    97   * Right now the constructor does all the initialisation work. This could also
    98   * be done in a new method "initialize()", for whatever purpose.
    99   *
    100   *
     79
     80  RunManager* RunManager::singletonPtr_s = NULL;
     81
     82
     83  /**
     84  * Contructor only needs the Root object.
     85  */
     86  RunManager::RunManager()
     87        : ogre_(NULL), window_(NULL), screenShotCounter_(0),
     88        timeUntilNextToggle_(0), mouseSensitivity_(0.003), inputManager_(0),
     89        mouse_(0), keyboard_(0), joystick_(0), statsOn_(true)
     90  {
     91  }
     92
     93  /**
    10194  * @param ogre_ The OgreControl object holding the render window and the Root
    10295  */
    103   RunManager::RunManager(OgreControl * ogre)
    104         : ogre_(ogre), window_(ogre->getRenderWindow()), //leftButtonDown_(false),
    105         statsOn_(true), screenShotCounter_(0), timeUntilNextToggle_(0),
    106         filtering_(TFO_BILINEAR), aniso_(1), sceneDetailIndex_(0),
    107         mouseSensitivity_(0.003),
    108         debugOverlay_(0), inputManager_(0), mouse_(0), keyboard_(0), joystick_(0)
    109   {
     96  void RunManager::initialise(OgreControl *ogre)
     97    {
     98    ogre_ = ogre;
     99    window_ = ogre->getRenderWindow();
     100
    110101    // SETTING UP THE SCENE
    111102
     
    126117
    127118    // Create a space ship object and its SceneNode.
    128     // Some ideas about the steering: The ship should only receive events like
    129     // up, down, left, right, roll left, roll right, move down, move up, etc).
    130     // Multiple interpretations of these commands would make the game more
    131     // but it also makes AI steering more difficult, since for every type of
    132     // steering, new methods have to be written.
    133     // --> clearly define how a space ship can fly (rolling?, conservation of
    134     // impuls?, direct mouse sight steeering?, etc.)
    135119    // It should also be considered, that the ship should provide another Node
    136120    // for a camera to be attached (otherwise the spaceship in front of the
    137     // would be very static, never moving at all).
     121    // ship would be very static, never moving at all).
    138122
    139123    // Construct a new spaceship and give it the node
     
    145129
    146130    // load all resources and create the entities by calling the initialise()
    147     // methods for each object (don't initialise in the constructor!).
     131    // methods for each object (no constructor initialisations!).
    148132    backgroundScene_->initialise();
    149133    playerShip_->initialise();
     
    151135
    152136    // CAMERA AND VIEWPORT
    153     // TODO: create a camera manager. It should be able to change its position
    154     // around the space ship (predefined states would be nice too). And it should
    155     // also be able to switch between different locations (like ship, spactator,
    156     // certain fixed positions (e.g. finish line, etc.)). These are just ideas.
    157137
    158138    // create camera and viewport
     
    160140    createViewports();
    161141
     142    // create HUD
     143    hud_ = new hud::TestOverlay(window_);
     144    hud_->show();
     145
    162146
    163147    // Set default mipmap level (NB some APIs ignore this)
    164148    TextureManager::getSingleton().setDefaultNumMipmaps(5);
    165149
    166    
    167150
    168151    // HUMAN INTERFACE
    169152
    170     using namespace OIS;
    171 
    172     debugOverlay_ = OverlayManager::getSingleton()
    173       .getByName("Core/DebugOverlay");
     153    using namespace OIS;   
    174154
    175155    LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
     
    201181    windowResized(window_);
    202182
    203     showDebugOverlay(true);
     183    //showDebugOverlay(true);
    204184
    205185    // REGISTER THIS OBJECT AS A WINDOW EVENT LISTENER IN OGRE
     
    225205    if (bulletManager_)
    226206      delete bulletManager_;
    227   }
    228 
    229 
    230   /**
    231   * Method to compute anyting between 2 frames.
     207    if (hud_)
     208      delete hud_;
     209  }
     210
     211
     212  /**
     213  * Method to compute anything between 2 frames.
    232214  *
    233215  * Everything that needs to be computed during the games happens right here.
     
    250232
    251233
    252     // Update the 'HUD'
    253     updateStats();
     234    // Update the HUD
     235    hud_->setDebugText(" | Speed = "
     236      + StringConverter::toString(playerShip_->getSpeed())
     237      + " | Left Ammo = "
     238      + StringConverter::toString(playerShip_
     239      ->getMainWeapon()->getAmmoState())
     240      + " | Ammo stock = "
     241      + StringConverter::toString(playerShip_->getAmmoStock()));
     242
     243    hud_->tick(time, deltaTime);
    254244
    255245    // update the bullet positions
     
    404394    {
    405395      statsOn_ = !statsOn_;
    406       showDebugOverlay(statsOn_);
    407       timeUntilNextToggle_ = 1;
    408     }
    409 
    410     if( keyboard_->isKeyDown(KC_T) && timeUntilNextToggle_ <= 0 )
    411     {
    412       switch(filtering_)
    413       {
    414       case TFO_BILINEAR:
    415         filtering_ = TFO_TRILINEAR;
    416         aniso_ = 1;
    417         break;
    418       case TFO_TRILINEAR:
    419         filtering_ = TFO_ANISOTROPIC;
    420         aniso_ = 8;
    421         break;
    422       case TFO_ANISOTROPIC:
    423         filtering_ = TFO_BILINEAR;
    424         aniso_ = 1;
    425         break;
    426       default: break;
    427       }
    428       MaterialManager::getSingleton().setDefaultTextureFiltering(filtering_);
    429       MaterialManager::getSingleton().setDefaultAnisotropy(aniso_);
    430 
    431       showDebugOverlay(statsOn_);
    432396      timeUntilNextToggle_ = 1;
    433397    }
     
    439403      window_->writeContentsToFile(ss.str());
    440404      timeUntilNextToggle_ = 0.5;
    441       debugText_ = "Saved: " + ss.str();
    442     }
    443 
    444     if(keyboard_->isKeyDown(KC_R) && timeUntilNextToggle_ <=0)
    445     {
    446       sceneDetailIndex_ = (sceneDetailIndex_+1)%3 ;
    447       switch(sceneDetailIndex_) {
    448           case 0 : camera_->setPolygonMode(PM_SOLID); break;
    449           case 1 : camera_->setPolygonMode(PM_WIREFRAME); break;
    450           case 2 : camera_->setPolygonMode(PM_POINTS); break;
    451       }
    452       timeUntilNextToggle_ = 0.5;
    453     }
    454 
    455     static bool displayCameraDetails = false;
    456     if(keyboard_->isKeyDown(KC_P) && timeUntilNextToggle_ <= 0)
    457     {
    458       displayCameraDetails = !displayCameraDetails;
    459       timeUntilNextToggle_ = 0.5;
    460       if (!displayCameraDetails)
    461         debugText_ = "";
    462     }
    463 
    464     // Print camera details
    465     if(displayCameraDetails)
    466       debugText_ = " | Speed = "
    467             + StringConverter::toString(playerShip_->getSpeed())
    468             + " | Left Ammo = "
    469             + StringConverter::toString(playerShip_
    470             ->getMainWeapon()->getAmmoState())
    471             + " | Ammo stock = "
    472             + StringConverter::toString(playerShip_->getAmmoStock());
    473     // debugText_ = "P: " + StringConverter::toString(camera_
    474     //      ->getDerivedPosition()) + " " + "O: "
    475     //      + StringConverter::toString(camera_->getDerivedOrientation());
     405    }
    476406
    477407    // Return true to continue rendering
     
    507437
    508438  /**
    509   * Show the debug overlay of desired.
     439  * Show an overlay desired.
    510440  * @param show Whether or not to show the debug overlay
    511441  */
    512442  void RunManager::showDebugOverlay(bool show)
    513443  {
    514     if (debugOverlay_)
     444    if (hud_)
    515445    {
    516446      if (show)
    517         debugOverlay_->show();
     447        hud_->show();
    518448      else
    519         debugOverlay_->hide();
    520     }
    521   }
    522 
    523 
    524   /**
    525   * Show stats (e.g. FPS) in the left lower corner of the screen.
    526   * Copied from the ExampleFrameListener.h in the Ogre SDK
    527   */
    528   void RunManager::updateStats(void)
    529   {
    530     static String currFps = "Current FPS: ";
    531     static String avgFps = "Average FPS: ";
    532     static String bestFps = "Best FPS: ";
    533     static String worstFps = "Worst FPS: ";
    534     static String tris = "Triangle Count: ";
    535     static String batches = "Batch Count: ";
    536 
    537     // update stats when necessary
    538     try {
    539       OverlayElement* guiAvg = OverlayManager::getSingleton()
    540         .getOverlayElement("Core/AverageFps");
    541       OverlayElement* guiCurr = OverlayManager::getSingleton()
    542         .getOverlayElement("Core/CurrFps");
    543       OverlayElement* guiBest = OverlayManager::getSingleton()
    544         .getOverlayElement("Core/BestFps");
    545       OverlayElement* guiWorst = OverlayManager::getSingleton()
    546         .getOverlayElement("Core/WorstFps");
    547 
    548       const RenderTarget::FrameStats& stats = window_->getStatistics();
    549       guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
    550       guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS));
    551       guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)
    552         +" "+StringConverter::toString(stats.bestFrameTime)+" ms");
    553       guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)
    554         +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
    555 
    556       OverlayElement* guiTris = OverlayManager::getSingleton()
    557         .getOverlayElement("Core/NumTris");
    558       guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
    559 
    560       OverlayElement* guiBatches = OverlayManager::getSingleton()
    561         .getOverlayElement("Core/NumBatches");
    562       guiBatches->setCaption(batches
    563         + StringConverter::toString(stats.batchCount));
    564 
    565       OverlayElement* guiDbg = OverlayManager::getSingleton()
    566         .getOverlayElement("Core/DebugText");
    567       guiDbg->setCaption(debugText_);
    568     }
    569     catch(...) { /* ignore */ }
    570   }
    571 
     449        hud_->hide();
     450    }
     451  }
    572452
    573453
    574454  /**
    575455  * Simple camera creator.
    576   * playerShip_Node->attachObject(camera_) should no be here! This is what the camera
    577   * manager is for. Right now, this method should do just fine, setting the
    578   * cam behind the ship.
    579   */
    580   void RunManager::createCamera(void)
     456  * playerShip_Node->attachObject(camera_) should not be here! This is what
     457  * the camera manager is for. Right now, this method should do just fine,
     458  * setting the cam behind the ship.
     459  */
     460  void RunManager::createCamera()
    581461  {
    582462    camera_ = sceneMgr_->createCamera("PlayerCam");
     
    589469  /**
    590470  * Simple viewport creator.
    591   * TODO: fully understand the concept of viewports concerning orxnox.
    592   * E.g. do we need splitscreen mode?
    593471  * For now the viewport uses the entire render window and is based on the one
    594472  * camera created so far.
    595473  */
    596   void RunManager::createViewports(void)
     474  void RunManager::createViewports()
    597475  {
    598476    // Create one viewport, entire window
     
    605483  }
    606484
     485
     486  RunManager* RunManager::createSingleton()
     487  {
     488    if (singletonPtr_s)
     489      return NULL;
     490    singletonPtr_s = new RunManager();
     491    return singletonPtr_s;
     492  }
     493
     494  void RunManager::destroySingleton()
     495  {
     496    if (singletonPtr_s)
     497      delete singletonPtr_s;
     498  }
     499
     500
     501  RunManager& RunManager::getSingleton()
     502  {
     503    return *singletonPtr_s;
     504  }
     505
     506  RunManager* RunManager::getSingletonPtr()
     507  {
     508    return singletonPtr_s;
     509  }
     510
    607511}
Note: See TracChangeset for help on using the changeset viewer.