Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 6, 2008, 4:45:49 PM (16 years ago)
Author:
scheusso
Message:

some changes

File:
1 edited

Legend:

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

    r790 r868  
    8080namespace orxonox
    8181{
    82    // put this in a seperate Class or solve the problem in another fashion
    83   class OrxListener : public Ogre::FrameListener
     82 
     83 
     84 
     85  // put this in a seperate Class or solve the problem in another fashion
     86  class OrxListenerStandalone : public Ogre::FrameListener
    8487  {
    8588    public:
    86       OrxListener(OIS::Keyboard *keyboard, audio::AudioManager*  auMan, gameMode mode)
     89      OrxListenerStandalone(OIS::Keyboard *keyboard, audio::AudioManager*  auMan)
    8790      {
    8891        mKeyboard = keyboard;
    89         mode_=mode;
    9092        auMan_ = auMan;
    9193      }
     
    9698        updateAI();
    9799
    98         if(mode_ == PRESENTATION)
    99           server_g->tick(evt.timeSinceLastFrame);
    100         else if(mode_ == CLIENT)
    101           client_g->tick(evt.timeSinceLastFrame);
    102100
    103101        usleep(10);
     
    116114
    117115    private:
    118       gameMode mode_;
    119116      OIS::Keyboard *mKeyboard;
    120117      audio::AudioManager*  auMan_;
    121118  };
    122 
     119 
     120  class OrxListenerServer : public Ogre::FrameListener
     121  {
     122    public:
     123      OrxListenerServer(){}
     124
     125      bool frameStarted(const Ogre::FrameEvent& evt)
     126      {
     127        updateAI();
     128
     129        server_g->tick(evt.timeSinceLastFrame);
     130        usleep(10);
     131
     132        return true;
     133      }
     134
     135      void updateAI()
     136      {
     137        for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it)
     138        {
     139          it->update();
     140        }
     141      }
     142
     143    private:
     144  };
     145 
     146 
     147  class OrxListenerClient : public Ogre::FrameListener
     148  {
     149    public:
     150      OrxListenerClient(OIS::Keyboard *keyboard, audio::AudioManager*  auMan)
     151      {
     152        mKeyboard = keyboard;
     153        auMan_ = auMan;
     154      }
     155
     156      bool frameStarted(const Ogre::FrameEvent& evt)
     157      {
     158        auMan_->update();
     159        updateAI();
     160
     161        client_g->tick(evt.timeSinceLastFrame);
     162
     163        usleep(10);
     164
     165        mKeyboard->capture();
     166        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
     167      }
     168
     169      void updateAI()
     170      {
     171        for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it)
     172        {
     173          it->update();
     174        }
     175      }
     176
     177    private:
     178      OIS::Keyboard *mKeyboard;
     179      audio::AudioManager*  auMan_;
     180  };
     181   
    123182  // init static singleton reference of Orxonox
    124183  Orxonox* Orxonox::singletonRef_ = NULL;
     
    137196    this->mouse_ = 0;
    138197    this->inputManager_ = 0;
    139     this->frameListener_ = 0;
     198    this->frameListener_.client = 0;
    140199    this->root_ = 0;
    141200  }
     
    181240      mode_ = CLIENT;
    182241    }
    183     else if(mode == std::string("presentation"))
    184     {
    185       serverInit(path);
    186       mode_ = PRESENTATION;
    187     }
    188242    else{
    189243      standaloneInit(path);
     
    193247
    194248  /**
    195    * start modules
     249   * calls the appropriate start function
    196250   */
    197251  void Orxonox::start()
     252  {
     253    switch (mode_){
     254      case CLIENT:
     255        startClient();
     256        break;
     257      case SERVER:
     258        startServer();
     259        break;
     260      case STANDALONE:
     261      default:
     262        startStandalone();
     263        break;
     264    }
     265  }
     266
     267  /**
     268   * start server modules
     269   */
     270  void Orxonox::startServer()
     271  {
     272    //TODO: start modules
     273    //ogre_->startRender();
     274    //TODO: run engine
     275    Factory::createClassHierarchy();
     276    createScene();
     277    setupScene();
     278    //setupInputSystem();
     279    COUT(4) << "************** Server here *************" << std::endl;
     280    createFrameListener();
     281   
     282    //TODO make a server framelistener caller
     283    // startRenderLoop();
     284  }
     285 
     286  /**
     287   * start client modules
     288   */
     289  void Orxonox::startClient()
     290  {
     291    //TODO: start modules
     292    ogre_->startRender();
     293    //TODO: run engine
     294    Factory::createClassHierarchy();
     295    createScene();
     296    setupInputSystem();
     297   
     298    COUT(4) << "************** Client here *************" << std::endl;
     299    createFrameListener();
     300    client_g->establishConnection();
     301    // TODO : server-client initialization
     302    startRenderLoop();
     303  }
     304 
     305  /**
     306   * start standalone modules
     307   */
     308  void Orxonox::startStandalone()
    198309  {
    199310    //TODO: start modules
     
    210321    createFrameListener();
    211322    switch(mode_){
    212     case PRESENTATION:
    213       //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener());
    214       //std::cout << "could not add framelistener" << std::endl;
    215       server_g->open();
    216       break;
    217     case CLIENT:
    218       client_g->establishConnection();
    219       break;
    220     case SERVER:
    221     case STANDALONE:
    222     default:
    223       break;
     323      case CLIENT:
     324        client_g->establishConnection();
     325        break;
     326      case SERVER:
     327      case STANDALONE:
     328      default:
     329        break;
    224330    }
    225331    startRenderLoop();
    226332  }
    227 
     333 
    228334  /**
    229335   * @return singleton object
     
    379485
    380486    // load this file from config
    381     loader_ = new loader::LevelLoader("sample.oxw");
    382     loader_->loadLevel();
     487    if(mode_==STANDALONE){
     488      loader_ = new loader::LevelLoader("sample.oxw");
     489      loader_->loadLevel();
     490    }
    383491
    384492    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
     
    458566
    459567    //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future
    460       frameListener_ = new OrxListener(keyboard_, auMan_, mode_);
    461     ogre_->getRoot()->addFrameListener(frameListener_);
     568      if(mode_==CLIENT){
     569        frameListener_.client = new OrxListenerClient(keyboard_, auMan_);
     570        ogre_->getRoot()->addFrameListener(frameListener_.client);
     571      }else if(mode_==SERVER){
     572        frameListener_.server = new OrxListenerServer();
     573        ogre_->getRoot()->addFrameListener(frameListener_.server);
     574      }else{
     575        frameListener_.standalone = new OrxListenerStandalone(keyboard_, auMan_);
     576        ogre_->getRoot()->addFrameListener(frameListener_.standalone);
     577      }
     578   
    462579  }
    463580
     
    479596    ogre_->getRoot()->startRendering();
    480597  }
     598 
    481599}
     600
Note: See TracChangeset for help on using the changeset viewer.