Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2007, 11:49:42 PM (17 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
Location:
code/branches/main_reto_vs05/src
Files:
6 added
3 deleted
7 edited
1 moved

Legend:

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

    r232 r288  
    2626 */
    2727
     28//#define WITH_HIERARCHY
     29
    2830#include "OgrePlatform.h"
    2931#include "OgreException.h"
     
    3133#include "orxonox.h"
    3234
     35#ifdef WITH_HIERARCHY
    3336#include "class_hierarchy/BaseObject.h"
    3437#include "class_hierarchy/Test.h"
     
    3639#include "class_hierarchy/test2.h"
    3740#include "class_hierarchy/test3.h"
     41#endif
    3842
    3943
     
    5054#endif
    5155  {
    52 #if 1
     56#ifndef WITH_HIERARCHY
    5357    try {
    5458      // create an orxonox application and run it
  • code/branches/main_reto_vs05/src/orxonox.cc

    r169 r288  
    9999          ogre_->initialise();
    100100
    101           runMgr_ = new RunManager(ogre_);
     101    runMgr_ = RunManager::createSingleton();
     102    runMgr_->initialise(ogre_);
    102103
    103104          return true;
     
    113114                  delete timer_;
    114115          if (runMgr_)
    115                   delete runMgr_;
     116      RunManager::destroySingleton();
    116117          if (ogre_)
    117118                  delete ogre_;
  • code/branches/main_reto_vs05/src/orxonox_prerequisites.h

    r232 r288  
    5252  }
    5353
     54
     55  namespace hud {
     56   
     57    class HUDOverlay;
     58    class TestOverlay;
     59
     60  }
     61
    5462}
    5563
  • code/branches/main_reto_vs05/src/orxonox_ship.cc

    r232 r288  
    3232#include "OgreEntity.h"
    3333#include "OgreSceneManager.h"
     34#include "OgreParticleSystem.h"
    3435
    3536#include "inertial_node.h"
     
    127128    railGunStation_->selectWeapon(0);
    128129
     130    // create some nice effects
     131
     132    ParticleSystem *particles = RunManager::getSingletonPtr()
     133      ->getSceneManagerPtr()->createParticleSystem("asdf", "Examples/Smoke");
     134
     135    fishNode->getSceneNode()->attachObject(particles);
     136
     137
     138
     139
    129140          return true;
    130141  }
  • 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}
  • code/branches/main_reto_vs05/src/run_manager.h

    r232 r288  
    3232#include "OgrePrerequisites.h"
    3333#include "OgreWindowEventUtilities.h"
    34 #include "OgreTextureManager.h"
    35 #include "OgreSingleton.h"
     34//#include "OgreTextureManager.h"
    3635
    3736#include <OIS/OISPrereqs.h>
     
    4443  // let the class inherit from WindowEventListener in order for the RunMgr
    4544  // to act as the central point of all the calcuations in Orxonox
    46   class RunManager : public Ogre::WindowEventListener,
    47                      public Ogre::Singleton<RunManager>
     45  class RunManager : public Ogre::WindowEventListener
    4846  {
    4947  public:
    50     RunManager(OgreControl*);
    51 
    5248    virtual ~RunManager();
    53     //void initialise(OgreControl*);
     49   
     50    void initialise(OgreControl*);
    5451
    5552    bool tick(unsigned long, Ogre::Real);
     
    6562    int getNumberOfAmmos();
    6663
     64    static RunManager* createSingleton();
     65
     66    static void destroySingleton();
     67
    6768    static RunManager& getSingleton(void);
    6869
     
    7172
    7273  protected:
     74    RunManager();
     75
    7376          void createCamera(void);
    7477
     
    9396          /** OUTPUT **/
    9497
    95           void updateStats(void);
    96 
    9798          void showDebugOverlay(bool);
    9899
    99100  protected:
     101    // directly Ogre related fields
    100102          Ogre::SceneManager *sceneMgr_;
    101103          Ogre::RenderWindow *window_;
    102104          Ogre::Camera       *camera_;
     105
     106
     107    // self made orxonox fields
    103108          OgreControl  *ogre_;
    104109          OrxonoxScene *backgroundScene_;
    105110          OrxonoxShip  *playerShip_;
     111    hud::TestOverlay *hud_;
    106112
     113    // Bullet manager
     114    weapon::BulletManager *bulletManager_;
     115
     116    const Ogre::Real mouseSensitivity_;
     117
     118          // previously elapsed render time
     119          unsigned long totalTime_;
     120
     121
     122    // fields from the example framework
    107123          bool statsOn_;
    108           std::string debugText_;
    109124
    110125          unsigned int screenShotCounter_;
    111126          // just to stop toggles flipping too fast
    112127          Ogre::Real timeUntilNextToggle_;
    113           //bool leftButtonDown_;
    114           Ogre::TextureFilterOptions filtering_;
    115           int aniso_;
    116 
    117           int sceneDetailIndex_;
    118           Ogre::Overlay* debugOverlay_;
    119128
    120129          //OIS Input devices
     
    124133          OIS::JoyStick* joystick_;
    125134
    126     const Ogre::Real mouseSensitivity_;
    127 
    128     // Bullet array
    129           /*Bullet **bullets_;
    130           int bulletsSize_;
    131           int bulletsIndex_;*/
    132     weapon::BulletManager *bulletManager_;
    133 
    134           // previously elapsed render time
    135           unsigned long totalTime_;
     135    // singleton pointer
     136    static RunManager *singletonPtr_s;
    136137
    137138  };
  • code/branches/main_reto_vs05/src/weapon/barrel_gun.cc

    r232 r288  
    9595  void BarrelGun::primaryFiring(unsigned int time)
    9696  {
    97     if (time > 1000/primaryFiringRate_)
     97    if (time > (unsigned int)1000/primaryFiringRate_)
    9898    {
    9999      currentState_ = IDLE;
     
    133133  void BarrelGun::secondaryFiring(unsigned int time)
    134134  {
    135     if (time > 1000/secondaryFiringRate_)
     135    if (time > (unsigned int)1000/secondaryFiringRate_)
    136136      currentState_ = IDLE;
    137137  }
  • code/branches/main_reto_vs05/src/weapon/base_weapon.cc

    r232 r288  
    9898    }
    9999
    100     switch (currentState_)
     100    if (currentState_ != IDLE)
    101101    {
    102     case IDLE:
     102      switch (currentState_)
     103      {
     104      case PRIMARY_FIRE:
     105        primaryFiring((unsigned int)(time - actionStartTime_));
     106        break;
     107
     108      case SECONDARY_FIRE:
     109        secondaryFiring((unsigned int)(time - actionStartTime_));
     110        break;
     111
     112      case RELOADING:
     113        break;
     114
     115      case CHANGING_AMMO:
     116        break;
     117      }
     118    }
     119
     120    if (currentState_ == IDLE)
     121    {
    103122      // first, process next action
    104123      if (nextAction_ != NOTHING)
     
    142161        }
    143162      }
    144 
    145       break;
    146 
    147     case PRIMARY_FIRE:
    148       primaryFiring((unsigned int)(time - actionStartTime_));
    149       break;
    150 
    151     case SECONDARY_FIRE:
    152       secondaryFiring((unsigned int)(time - actionStartTime_));
    153       break;
    154 
    155     case RELOADING:
    156       break;
    157 
    158     case CHANGING_AMMO:
    159       break;
    160163    }
    161164
Note: See TracChangeset for help on using the changeset viewer.