Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 26, 2008, 11:39:55 PM (16 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()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  {
Note: See TracChangeset for help on using the changeset viewer.