Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 26, 2008, 11:39:55 PM (17 years ago)
Author:
rgrieder
Message:
  • removed getRoot() from GaphicsEngine —> added getRenderWindow() —> added 3 function to control render loop
  • rearranged the sequence of methods in Orxonox.cc to make it a little bit more logical
  • added deletion code in Orxonox.cc destructor
  • fixed a bug in AudioManger destructor
  • fixed a bug in InputHandler destroy()
Location:
code/branches/network/src/orxonox
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/orxonox/GraphicsEngine.cc

    r926 r929  
    3333
    3434#include <OgreRoot.h>
     35#include <OgreException.h>
    3536#include <OgreConfigFile.h>
    3637#include <OgreTextureManager.h>
     
    6162  GraphicsEngine::~GraphicsEngine()
    6263  {
     64    if (!this->root_)
     65      delete this->root_;
    6366  }
    6467
     
    7881    root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
    7982#endif*/
    80 #if defined(_DEBUG) && defined(WIN32)
     83#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG)
    8184    std::string plugin_filename = "plugins_d.cfg";
    8285#else
     
    110113  }
    111114
    112   void GraphicsEngine::startRender()
     115  void GraphicsEngine::initialise()
    113116  {
    114     root_->initialise(true, "OrxonoxV2");
    115     this->renderWindow_ = root_->getAutoCreatedWindow();
     117    this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
    116118    TextureManager::getSingleton().setDefaultNumMipmaps(5);
    117119    //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
  • code/branches/network/src/orxonox/GraphicsEngine.h

    r926 r929  
    1010#include <string>
    1111
     12#include <OgrePrerequisites.h>
    1213#include <OgreRoot.h>
    1314#include <OgreSceneManager.h>
    1415
    1516#include "OrxonoxPrereqs.h"
    16 #include "core/BaseObject.h"
     17#include "core/OrxonoxClass.h"
    1718
    1819
     
    2223   * graphics engine manager class
    2324 */
    24   class _OrxonoxExport GraphicsEngine : public BaseObject
     25  class _OrxonoxExport GraphicsEngine : public OrxonoxClass
    2526  {
    2627    public:
     
    2829      inline void setConfigPath(std::string path) { this->configPath_ = path; };
    2930      // find a better way for this
    30       inline Ogre::Root* getRoot() { return root_; };
     31      //inline Ogre::Root* getRoot() { return root_; };
    3132      void setConfigValues();
    3233      void setup();
     
    3435      void loadRessourceLocations(std::string path);
    3536      Ogre::SceneManager* getSceneManager();
    36       void startRender();
     37      void initialise();
    3738
    3839      // several window properties
     40      Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
    3941      size_t getWindowHandle();
    4042      int getWindowWidth() const;
    4143      int getWindowHeight() const;
    4244
     45      // Ogre Root access for Orxonox
     46      void frameStarted(Ogre::FrameEvent &evt)
     47      { if (root_) root_->_fireFrameStarted(evt); }
     48      void frameEnded  (Ogre::FrameEvent &evt)
     49      { if (root_) root_->_fireFrameEnded(evt);   }
     50      void renderOneFrame()
     51      { if (root_) root_->_updateAllRenderTargets(); }
     52
    4353      virtual ~GraphicsEngine();
     54
    4455    private:
    4556      Ogre::Root*         root_;        //!< Ogre's root
  • code/branches/network/src/orxonox/InputHandler.cc

    r928 r929  
    4444    @brief Constructor only resets the pointer values to 0.
    4545  */
    46   InputHandler::InputHandler()
     46  InputHandler::InputHandler() :
     47      mouse_(0), keyboard_(0), inputSystem_(0),
     48      uninitialized_(true)
    4749  {
    4850    //RegisterObject(InputHandler);
    49     this->mouse_       = 0;
    50     this->keyboard_    = 0;
    51     this->inputSystem_ = 0;
     51  }
     52
     53  /**
     54    @brief Destructor only called at the end of the program
     55  */
     56  InputHandler::~InputHandler()
     57  {
     58    this->destroy();
    5259  }
    5360
     
    7178  void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
    7279  {
    73     if (!inputSystem_)
     80    if (this->uninitialized_ || !this->inputSystem_)
    7481    {
    7582      // Setup basic variables
     
    104111        this->setWindowExtents(windowWidth, windowHeight);
    105112      }
     113
     114      uninitialized_ = false;
    106115    }
    107116
     
    120129  void InputHandler::destroy()
    121130  {
    122     this->inputSystem_->destroyInputObject(this->mouse_);
    123     this->inputSystem_->destroyInputObject(this->keyboard_);
    124     OIS::InputManager::destroyInputSystem(this->inputSystem_);
    125 
    126     //TODO: If the InputHandler has been destroyed, how does it know?
     131    if (!this->inputSystem_)
     132    {
     133      this->inputSystem_->destroyInputObject(this->mouse_);
     134      this->inputSystem_->destroyInputObject(this->keyboard_);
     135      OIS::InputManager::destroyInputSystem(this->inputSystem_);
     136    }
     137
     138    this->uninitialized_ = true;
    127139  }
    128140
  • code/branches/network/src/orxonox/InputHandler.h

    r928 r929  
    6161    // don't mess with a Singleton
    6262    InputHandler ();
    63     InputHandler (const InputHandler&) { }
    64     ~InputHandler() { }
     63    InputHandler (const InputHandler&);
     64    InputHandler& operator=(const InputHandler& instance);
     65    ~InputHandler();
    6566
    6667    void callListeners(InputEvent &evt);
     
    7677    OIS::Keyboard     *keyboard_;       //!< OIS mouse
    7778    OIS::Mouse        *mouse_;          //!< OIS keyboard
     79
     80    /**
     81      @bref Tells whether initialise has been called successfully
     82      Also true if destroy() has been called.
     83    */
     84    bool uninitialized_;
    7885
    7986    //! denotes the maximum number of different keys there are in OIS.
  • code/branches/network/src/orxonox/Orxonox.cc

    r928 r929  
    3737//#include <OgreException.h>
    3838#include <OgreFrameListener.h>
    39 #include <OgreRoot.h>
    4039#include <OgreOverlay.h>
    4140#include <OgreOverlayManager.h>
     
    8685    this->auMan_ = 0;
    8786    this->inputHandler_ = 0;
    88     this->root_ = 0;
     87    //this->root_ = 0;
    8988    // turn on frame smoothing by setting a value different from 0
    9089    this->frameSmoothingTime_ = 0.0f;
     
    9796  Orxonox::~Orxonox()
    9897  {
    99     // nothing to delete as for now
    100     inputHandler_->destroy();
     98    // keep in mind: the order of deletion is very important!
     99
     100    if (this->bulletMgr_)
     101      delete this->bulletMgr_;
     102    if (this->orxonoxHUD_)
     103      delete this->orxonoxHUD_;
     104    Loader::close();
     105    this->inputHandler_->destroy();
     106    if (this->auMan_)
     107      delete this->auMan_;
     108    if (this->timer_)
     109      delete this->timer_;
     110    if (this->ogre_)
     111      delete this->ogre_;
     112
     113    if (client_g)
     114      delete client_g;
     115    if (server_g)
     116      delete server_g;
     117  }
     118
     119  /**
     120   * error kills orxonox
     121   */
     122  void Orxonox::abortImmediate(/* some error code */)
     123  {
     124    //TODO: destroy and destruct everything and print nice error msg
     125    delete this;
     126  }
     127
     128  /**
     129    Asks the mainloop nicely to abort.
     130  */
     131  void Orxonox::abortRequest()
     132  {
     133    bAbort_ = true;
     134  }
     135
     136  /**
     137   * @return singleton object
     138   */
     139  Orxonox* Orxonox::getSingleton()
     140  {
     141    static Orxonox theOnlyInstance;
     142    return &theOnlyInstance;
    101143  }
    102144
     
    118160    ar.checkArgument("data", this->dataPath_, false);
    119161    ar.checkArgument("ip", serverIp_, false);
    120     if(ar.errorHandling()) die();
     162    if(ar.errorHandling()) abortImmediate();
    121163    if(mode == std::string("client"))
    122164    {
     
    134176  }
    135177
     178  void Orxonox::serverInit(std::string path)
     179  {
     180    COUT(2) << "initialising server" << std::endl;
     181   
     182    ogre_->setConfigPath(path);
     183    ogre_->setup();
     184    //root_ = ogre_->getRoot();
     185    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
     186   
     187    server_g = new network::Server();
     188  }
     189
     190  void Orxonox::clientInit(std::string path)
     191  {
     192    COUT(2) << "initialising client" << std::endl;\
     193   
     194    ogre_->setConfigPath(path);
     195    ogre_->setup();
     196    if(serverIp_.compare("")==0)
     197      client_g = new network::Client();
     198    else
     199      client_g = new network::Client(serverIp_, NETWORK_PORT);
     200    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
     201  }
     202 
     203  void Orxonox::standaloneInit(std::string path)
     204  {
     205    COUT(2) << "initialising standalone mode" << std::endl;
     206   
     207    ogre_->setConfigPath(path);
     208    ogre_->setup();
     209    //root_ = ogre_->getRoot();
     210    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
     211  }
    136212 
    137213  /**
     
    153229 
    154230  void Orxonox::clientStart(){
    155     ogre_->startRender();
     231    ogre_->initialise();
    156232    Factory::createClassHierarchy();
    157233   
     
    179255  void Orxonox::serverStart(){
    180256    //TODO: start modules
    181     ogre_->startRender();
     257    ogre_->initialise();
    182258    //TODO: run engine
    183259    Factory::createClassHierarchy();
     
    192268  void Orxonox::standaloneStart(){
    193269    //TODO: start modules
    194     ogre_->startRender();
     270    ogre_->initialise();
    195271    //TODO: run engine
    196272    Factory::createClassHierarchy();
     
    199275   
    200276    startRenderLoop();
    201   }
    202 
    203   /**
    204    * @return singleton object
    205    */
    206   Orxonox* Orxonox::getSingleton()
    207   {
    208     static Orxonox theOnlyInstance;
    209     return &theOnlyInstance;
    210   }
    211 
    212   /**
    213    * error kills orxonox
    214    */
    215   void Orxonox::die(/* some error code */)
    216   {
    217     //TODO: destroy and destruct everything and print nice error msg
    218     delete this;
    219   }
    220 
    221   /**
    222     Asks the mainloop nicely to abort.
    223   */
    224   void Orxonox::abortRequest()
    225   {
    226     bAbort_ = true;
    227   }
    228 
    229 
    230   void Orxonox::serverInit(std::string path)
    231   {
    232     COUT(2) << "initialising server" << std::endl;
    233    
    234     ogre_->setConfigPath(path);
    235     ogre_->setup();
    236     root_ = ogre_->getRoot();
    237     if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
    238    
    239     server_g = new network::Server();
    240   }
    241 
    242   void Orxonox::clientInit(std::string path)
    243   {
    244     COUT(2) << "initialising client" << std::endl;\
    245    
    246     ogre_->setConfigPath(path);
    247     ogre_->setup();
    248     if(serverIp_.compare("")==0)
    249       client_g = new network::Client();
    250     else
    251       client_g = new network::Client(serverIp_, NETWORK_PORT);
    252     if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
    253   }
    254  
    255   void Orxonox::standaloneInit(std::string path)
    256   {
    257     COUT(2) << "initialising standalone mode" << std::endl;
    258    
    259     ogre_->setConfigPath(path);
    260     ogre_->setup();
    261     root_ = ogre_->getRoot();
    262     if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
    263277  }
    264278
     
    285299    auMan_->ambientAdd("a3");
    286300    //auMan->ambientAdd("ambient1");
    287     auMan_->ambientStart();*/
     301    auMan_->ambientStart();
     302  */
    288303  }
    289304
     
    316331  {
    317332    // use the ogre timer class to measure time.
    318     Ogre::Timer *timer = new Ogre::Timer();
    319     timer->reset();
     333    if (!timer_)
     334      timer_ = new Ogre::Timer();
     335    timer_->reset();
    320336
    321337    // Contains the times of recently fired events
     
    331347
    332348      // get current time
    333       unsigned long now = timer->getMilliseconds();
     349      unsigned long now = timer_->getMilliseconds();
    334350
    335351      // create an event to pass to the frameStarted method in ogre
     
    341357      orxonoxHUD_->setTime((int)now, 0);
    342358
    343       // don't forget to call _fireFrameStarted in ogre to make sure
    344       // everything goes smoothly
    345       if (!ogre_->getRoot()->_fireFrameStarted(evt))
    346         break;
    347 
    348359      // Iterate through all Tickables and call their tick(dt) function
    349360      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
    350361        (it++)->tick((float)evt.timeSinceLastFrame);
    351362
     363      // don't forget to call _fireFrameStarted in ogre to make sure
     364      // everything goes smoothly
     365      ogre_->frameStarted(evt);
     366
    352367      if (mode_ != SERVER)
    353       {
    354         // only render in non-server mode
    355         ogre_->getRoot()->_updateAllRenderTargets();
    356       }
     368        ogre_->renderOneFrame(); // only render in non-server mode
    357369
    358370      // get current time
    359       now = timer->getMilliseconds();
     371      now = timer_->getMilliseconds();
    360372
    361373      // create an event to pass to the frameEnded method in ogre
     
    364376
    365377      // again, just to be sure ogre works fine
    366       if (!ogre_->getRoot()->_fireFrameEnded(evt))
    367         break;
     378      ogre_->frameEnded(evt);
    368379          }
    369380  }
     
    406417  }
    407418
     419  /**
     420    @brief Test method for the InputHandler.
     421    But: Is actually responsible for catching an exit event..
     422  */
    408423  void Orxonox::eventOccured(InputEvent &evt)
    409424  {
  • code/branches/network/src/orxonox/Orxonox.h

    r926 r929  
    3636      void start();
    3737      // not sure if this should be private
    38       void die(/* some error code */);
     38      void abortImmediate(/* some error code */);
    3939      void abortRequest();
     40      inline Ogre::SceneManager*  getSceneManager()        { return ogre_->getSceneManager(); };
     41      inline GraphicsEngine*      getOgrePointer()         { return ogre_; };
     42      inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
     43      inline BulletManager*       getBulletMgr()           { return this->bulletMgr_; }
     44
    4045      static Orxonox* getSingleton();
    41       inline Ogre::SceneManager* getSceneManager()         { return ogre_->getSceneManager(); };
    42       inline GraphicsEngine* getOgrePointer()              { return ogre_; };
    43       inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
    44       inline BulletManager* getBulletMgr()                 { return this->bulletMgr_; }
    4546
    46     private:
     47   private:
     48      // don't mess with singletons
    4749      Orxonox();
    48       virtual ~Orxonox();
     50      Orxonox(Orxonox& instance);
     51      Orxonox& operator=(const Orxonox& instance);
     52      ~Orxonox();
     53
    4954      // init functions
    5055      void serverInit(std::string path);
    5156      void clientInit(std::string path);
    5257      void standaloneInit(std::string path);
     58
    5359      // run functions
    5460      void serverStart();
     
    5662      void standaloneStart();
    5763
    58       void createScene(void);
     64      void createScene();
    5965      void setupInputSystem();
    6066      void startRenderLoop();
     
    6874      audio::AudioManager*  auMan_;         //!< audio manager
    6975      BulletManager*        bulletMgr_;     //!< Keeps track of the thrown bullets
    70       InputHandler*         inputHandler_;
    71       Ogre::Root*           root_;
     76      InputHandler*         inputHandler_;  //!< Handles input with key bindings
     77      Ogre::Root*           root_;          //!< Holy grail of Ogre
     78      Ogre::Timer*          timer_;         //!< Main loop timer
    7279      // TODO: make this a config-value by creating a config class for orxonox
    7380      float                 frameSmoothingTime_;
  • code/branches/network/src/orxonox/objects/Camera.cc

    r790 r929  
    66#include <OgreSceneManager.h>
    77#include <OgreSceneNode.h>
    8 #include <OgreRoot.h>
    98#include <OgreRenderWindow.h>
    109#include <OgreViewport.h>
     
    6968
    7069        // FIXME: unused var
    71         Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
     70        Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
    7271
    7372
  • code/branches/network/src/orxonox/objects/Fighter.cc

    r919 r929  
    208208
    209209            node->attachObject(cam);
    210             Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
     210            Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
    211211        }
    212212    }
  • code/branches/network/src/orxonox/objects/SpaceShip.cc

    r927 r929  
    286286
    287287        this->camNode_->attachObject(cam);
    288         Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
     288        Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
    289289    }
    290290
Note: See TracChangeset for help on using the changeset viewer.