Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 7, 2008, 12:11:25 AM (17 years ago)
Author:
rgrieder
Message:
  • rearranged function calls in Orxonox.cc has yet to be looked at clearly, commented and COUTed
  • works so far, but using 3 little hacks… in hacky classes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ogre/src/orxonox/Orxonox.cc

    r1219 r1243  
    6565#include "core/InputBuffer.h"
    6666#include "core/InputManager.h"
     67#include "core/TclBind.h"
    6768
    6869// audio
     
    166167    this->ogre_ = &GraphicsEngine::getSingleton();
    167168    this->timer_ = 0;
    168     this->dataPath_ = "";
    169     this->auMan_ = 0;
     169    //this->auMan_ = 0;
    170170    this->orxonoxHUD_ = 0;
    171171    this->inputHandler_ = 0;
     
    186186    Loader::close();
    187187    InputManager::destroy();
    188     if (this->auMan_)
    189       delete this->auMan_;
     188    //if (this->auMan_)
     189    //  delete this->auMan_;
    190190    if (this->timer_)
    191191      delete this->timer_;
     
    196196    if (server_g)
    197197      delete server_g;
    198   }
    199 
    200   /**
    201     @brief Immediately deletes the orxonox object.
    202     Never use if you can help it while rendering!
    203   */
    204   void Orxonox::abortImmediateForce()
    205   {
    206     COUT(1) << "*** Orxonox Error: Orxonox object was unexpectedly destroyed." << std::endl;
    207     delete this;
    208198  }
    209199
     
    243233   * @param path path to config (in home dir or something)
    244234   */
    245   void Orxonox::init(int argc, char **argv, std::string path)
     235  bool Orxonox::init(int argc, char **argv, std::string path)
    246236  {
    247237    //TODO: find config file (assuming executable directory)
     
    249239    //TODO: give config file to Ogre
    250240    std::string mode;
     241    std::string dataPath;
    251242
    252243    ArgReader ar(argc, argv);
    253244    ar.checkArgument("mode", mode, false);
    254     ar.checkArgument("data", this->dataPath_, false);
     245    ar.checkArgument("data", dataPath, false);
    255246    ar.checkArgument("ip", serverIp_, false);
    256     if(ar.errorHandling()) abortImmediateForce();
    257     if(mode == std::string("client"))
    258     {
     247    if(ar.errorHandling())
     248      return false;
     249
     250    if (mode == "client")
    259251      mode_ = CLIENT;
    260       clientInit(path);
    261     }
    262     else if(mode== std::string("server")){
     252    else if (mode == "server")
    263253      mode_ = SERVER;
    264       serverInit(path);
    265     }
    266     else{
     254    else
    267255      mode_ = STANDALONE;
    268       standaloneInit(path);
    269     }
    270   }
    271 
    272   void Orxonox::serverInit(std::string path)
    273   {
    274     COUT(2) << "initialising server" << std::endl;
    275 
    276     ogre_->setConfigPath(path);
    277     ogre_->setup();
    278     //root_ = ogre_->getRoot();
    279     if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */);
    280 
    281     server_g = new network::Server();
    282   }
    283 
    284   void Orxonox::clientInit(std::string path)
    285   {
    286     COUT(2) << "initialising client" << std::endl;\
    287 
    288     ogre_->setConfigPath(path);
    289     ogre_->setup();
    290     if(serverIp_.compare("")==0)
    291       client_g = new network::Client();
    292     else
    293       client_g = new network::Client(serverIp_, NETWORK_PORT);
    294     if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */);
    295   }
    296 
    297   void Orxonox::standaloneInit(std::string path)
    298   {
    299     COUT(2) << "initialising standalone mode" << std::endl;
    300 
    301     ogre_->setConfigPath(path);
    302     ogre_->setup();
    303     if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */);
     256
     257    //if (mode_ == DEDICATED)
     258      // TODO: decide what to do here
     259    //else
     260
     261    // for playable server, client and standalone, the startup
     262    // procedure until the GUI is the identical
     263
     264    TclBind::getInstance().setDataPath(dataPath);
     265    ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
     266    Factory::createClassHierarchy();
     267
     268    if (!ogre_->setup(path))       // creates ogre root and other essentials
     269      return false;
     270
     271    return true;
    304272  }
    305273
     
    307275   * start modules
    308276   */
    309   void Orxonox::start()
    310   {
    311     switch(mode_){
     277  bool Orxonox::start()
     278  {
     279    //if (mode == DEDICATED)
     280    // do something else
     281    //else
     282
     283    if (!ogre_->loadRenderer())    // creates the render window
     284      return false;
     285
     286    // Calls the InputHandler which sets up the input devices.
     287    // The render window width and height are used to set up the mouse movement.
     288    if (!InputManager::initialise(ogre_->getWindowHandle(),
     289          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
     290      return false;
     291
     292    // TODO: Spread this so that this call onyl initialises things needed for the GUI
     293    ogre_->initialiseResources();
     294
     295    // TOOD: load the GUI here
     296    // set InputManager to GUI mode
     297    InputManager::setInputState(InputManager::IS_GUI);
     298    // TODO: run GUI here
     299
     300    // The following lines depend very much on the GUI, so they're probably misplaced here..
     301
     302    InputManager::setInputState(InputManager::IS_NONE);
     303
     304    if (!loadPlayground())
     305      return false;
     306
     307    switch (mode_)
     308    {
     309    case SERVER:
     310      if (!serverLoad())
     311        return false;
     312      break;
    312313    case CLIENT:
    313       clientStart();
    314       break;
    315     case SERVER:
    316       serverStart();
     314      if (!clientLoad())
     315        return false;
    317316      break;
    318317    default:
    319       standaloneStart();
     318      if (!standaloneLoad())
     319        return false;
    320320    }
    321   }
    322 
    323   void Orxonox::clientStart(){
    324     ogre_->initialise();
    325     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    326     Factory::createClassHierarchy();
    327 
    328 
    329     auMan_ = new audio::AudioManager();
    330 
     321
     322    InputManager::setInputState(InputManager::IS_NORMAL);
     323
     324    return startRenderLoop();
     325  }
     326
     327  bool Orxonox::loadPlayground()
     328  {
     329    ogre_->createNewScene();
     330
     331          // Init audio
     332    //auMan_ = new audio::AudioManager();
     333    //auMan_->ambientAdd("a1");
     334    //auMan_->ambientAdd("a2");
     335    //auMan_->ambientAdd("a3");
     336    //auMan->ambientAdd("ambient1");
     337    //auMan_->ambientStart();
     338
     339    // Load the HUD
    331340    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
    332341    orxonoxHUD_ = new HUD();
     
    335344    hudOverlay->show();
    336345
    337     client_g->establishConnection();
    338     client_g->tick(0);
    339 
    340 
    341     //setupInputSystem();
    342 
    343     startRenderLoop();
    344   }
    345 
    346   void Orxonox::serverStart(){
    347     //TODO: start modules
    348     ogre_->initialise();
    349     //TODO: run engine
    350     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    351     Factory::createClassHierarchy();
    352     createScene();
    353     setupInputSystem();
    354 
    355     server_g->open();
    356 
    357     startRenderLoop();
    358   }
    359 
    360   void Orxonox::standaloneStart(){
    361     //TODO: start modules
    362     ogre_->initialise();
    363     //TODO: run engine
    364     ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini");
    365     Factory::createClassHierarchy();
    366     createScene();
    367     setupInputSystem();
    368 
    369     startRenderLoop();
    370   }
    371 
    372   void Orxonox::createScene(void)
    373   {
    374           // Init audio
    375     auMan_ = new audio::AudioManager();
    376 
    377     // load this file from config
    378     Level* startlevel = new Level("levels/sample.oxw");
    379     Loader::open(startlevel);
    380 
    381     Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
    382     orxonoxHUD_ = new HUD();
    383     orxonoxHUD_->setEnergyValue(20);
    384     orxonoxHUD_->setEnergyDistr(20,20,60);
    385     hudOverlay->show();
    386 
    387         /*
    388     auMan_->ambientAdd("a1");
    389     auMan_->ambientAdd("a2");
    390     auMan_->ambientAdd("a3");
    391     //auMan->ambientAdd("ambient1");
    392     auMan_->ambientStart();
    393   */
    394   }
    395 
    396   /**
    397     @brief Calls the InputHandler which sets up the input devices.
    398     The render window width and height are used to set up the mouse movement.
    399   */
    400   void Orxonox::setupInputSystem()
    401   {
    402     if (!InputManager::initialise(ogre_->getWindowHandle(),
    403           ogre_->getWindowWidth(), ogre_->getWindowHeight()))
    404       abortImmediateForce();
    405     InputManager::setInputState(InputManager::IS_NORMAL);
    406   }
    407 
    408   /**
    409     Main loop of the orxonox game.
    410     This is a new solution, using the ogre engine instead of being used by it.
    411     An alternative solution would be to simply use the timer of the Root object,
    412     but that implies using Ogre in any case. There would be no way to test
    413     our code without the help of the root object.
    414     There's even a chance that we can dispose of the root object entirely
    415     in server mode.
    416     About the loop: The design is almost exactly like the one in ogre, so that
    417     if any part of ogre registers a framelisteners, it will still behave
    418     correctly. Furthermore the time smoothing feature from ogre has been
    419     implemented too. If turned on (see orxonox constructor), it will calculate
    420     the dt_n by means of the recent most dt_n-1, dt_n-2, etc.
    421   */
    422   void Orxonox::startRenderLoop()
    423   {
    424346    InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));
    425347    /*
     
    432354    ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
    433355    */
    434 
    435356    orxonoxConsole_ = new InGameConsole(ib);
    436357    ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true);
     
    441362    ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true);
    442363
     364    return true;
     365  }
     366
     367  bool Orxonox::serverLoad()
     368  {
     369    COUT(2) << "initialising server" << std::endl;
     370
     371    server_g = new network::Server();
     372
     373    if (!loadScene())
     374      return false;
     375
     376    server_g->open();
     377
     378    return true;
     379  }
     380
     381  bool Orxonox::clientLoad()
     382  {
     383    COUT(2) << "initialising client" << std::endl;\
     384
     385    if (serverIp_.compare("") == 0)
     386      client_g = new network::Client();
     387    else
     388      client_g = new network::Client(serverIp_, NETWORK_PORT);
     389
     390    client_g->establishConnection();
     391    client_g->tick(0);
     392
     393    return true;
     394  }
     395
     396  bool Orxonox::standaloneLoad()
     397  {
     398    COUT(2) << "initialising standalone mode" << std::endl;
     399
     400    if (!loadScene())
     401      return false;
     402
     403    return true;
     404  }
     405
     406  bool Orxonox::loadScene()
     407  {
     408    Level* startlevel = new Level("levels/sample.oxw");
     409    Loader::open(startlevel);
     410
     411    return true;
     412  }
     413
     414
     415  /**
     416    Main loop of the orxonox game.
     417    About the loop: The design is almost exactly like the one in ogre, so that
     418    if any part of ogre registers a framelisteners, it will still behave
     419    correctly. Furthermore the time smoothing feature from ogre has been
     420    implemented too. If turned on (see orxonox constructor), it will calculate
     421    the dt_n by means of the recent most dt_n-1, dt_n-2, etc.
     422  */
     423  bool Orxonox::startRenderLoop()
     424  {
    443425    // first check whether ogre root object has been created
    444426    if (Ogre::Root::getSingletonPtr() == 0)
    445427    {
    446428      COUT(2) << "*** Orxonox Error: Could not start rendering. No Ogre root object found" << std::endl;
    447       return;
     429      return false;
    448430    }
    449431    Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
     
    510492      ogreRoot._fireFrameEnded(evt);
    511493          }
     494
     495    return true;
    512496  }
    513497
Note: See TracChangeset for help on using the changeset viewer.