Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 21, 2008, 3:50:44 PM (16 years ago)
Author:
rgrieder
Message:
  • removed all our FrameListeners except one (OrxListener will soon be vanished too) —> all timers are now tickable
  • some minor irrelevant changes in orxonox.cc
File:
1 edited

Legend:

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

    r900 r916  
    5858#include "util/Sleep.h"
    5959
    60 // loader and audio
    61 //#include "loader/LevelLoader.h"
     60// audio
    6261#include "audio/AudioManager.h"
    6362
     
    7069#include "objects/Tickable.h"
    7170#include "tools/Timer.h"
    72 #include "objects/NPC.h"
     71#include "tools/OrxListener.h"
    7372#include "core/ArgReader.h"
    7473#include "core/Factory.h"
     
    8382namespace orxonox
    8483{
    85    // put this in a seperate Class or solve the problem in another fashion
    86   class OrxListener : public Ogre::FrameListener
    87   {
    88     public:
    89       OrxListener(OIS::Keyboard *keyboard, audio::AudioManager*  auMan, gameMode mode)
    90       {
    91         mKeyboard = keyboard;
    92         mode_=mode;
    93         auMan_ = auMan;
    94       }
    95 
    96       bool frameStarted(const Ogre::FrameEvent& evt)
    97       {
    98         auMan_->update();
    99         updateAI();
    100 
    101         if(mode_ == PRESENTATION)
    102           server_g->tick(evt.timeSinceLastFrame);
    103         else if(mode_ == CLIENT)
    104           client_g->tick(evt.timeSinceLastFrame);
    105 
    106         usleep(10);
    107 
    108         mKeyboard->capture();
    109         return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
    110       }
    111 
    112       void updateAI()
    113       {
    114         for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it)
    115         {
    116           it->update();
    117         }
    118       }
    119 
    120     private:
    121       gameMode mode_;
    122       OIS::Keyboard *mKeyboard;
    123       audio::AudioManager*  auMan_;
    124   };
    125 
    126   // init static singleton reference of Orxonox
     84  /// init static singleton reference of Orxonox
    12785  Orxonox* Orxonox::singletonRef_ = NULL;
    12886
     
    13492    this->ogre_ = new GraphicsEngine();
    13593    this->dataPath_ = "";
    136 //    this->loader_ = 0;
    13794    this->auMan_ = 0;
    13895    this->singletonRef_ = 0;
     
    143100    this->root_ = 0;
    144101    // turn frame smoothing on by setting a value different from 0
    145     this->frameSmoothingTime_ = 0.1f;
     102    this->frameSmoothingTime_ = 0.0f;
    146103  }
    147104
     
    157114   * initialization of Orxonox object
    158115   * @param argc argument counter
    159    * @param argv list of arguments
     116   * @param argv list of argumenst
    160117   * @param path path to config (in home dir or something)
    161118   */
     
    174131    ar.checkArgument("data", this->dataPath_, false);
    175132    ar.checkArgument("ip", serverIp_, false);
    176     //mode = "presentation";
    177133    if(ar.errorHandling()) die();
    178134    if(mode == std::string("server"))
     
    451407  void Orxonox::createFrameListener()
    452408  {
    453     //TickFrameListener* TickFL = new TickFrameListener();
    454     //ogre_->getRoot()->addFrameListener(TickFL);
    455 
    456     //TimerFrameListener* TimerFL = new TimerFrameListener();
    457     //ogre_->getRoot()->addFrameListener(TimerFL);
    458 
    459     //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future
    460       frameListener_ = new OrxListener(keyboard_, auMan_, mode_);
    461     ogre_->getRoot()->addFrameListener(frameListener_);
     409    frameListener_ = new OrxListener(auMan_, mode_);
    462410  }
    463411
     
    477425      ms.height = height;
    478426    }
    479     //ogre_->getRoot()->startRendering();
    480427    mainLoop();
    481428  }
     
    509456          while (true)
    510457          {
    511                   //Pump messages in all registered RenderWindows
     458                  // Pump messages in all registered RenderWindows
    512459      Ogre::WindowEventUtilities::messagePump();
    513460
     
    531478      for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
    532479        (it++)->tick((float)evt.timeSinceLastFrame);
    533 
    534       // Update the timers
    535       updateTimers((float)evt.timeSinceLastFrame);
    536480
    537481      if (mode_ != SERVER)
     
    554498  }
    555499
    556   /**
    557     Timer updater function.
    558     Updates all timers with the current dt.
    559     Timers have been tested since their displacement.
    560     @param dt The delta time
    561   */
    562   void Orxonox::updateTimers(float dt)
    563   {
    564     // Iterate through all Timers
    565     for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; )
    566     {
    567       if (it->isActive())
    568       {
    569         // If active: Decrease the timer by the duration of the last frame
    570         it->time_ -= dt;
    571 
    572         if (it->time_ <= 0)
    573         {
    574           // It's time to call the function
    575           if (it->bLoop_)
    576             it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.
    577           else
    578             it->stopTimer(); // Stop the timer if we don't want to loop
    579 
    580           (it++)->run();
    581         }
    582         else
    583         ++it;
    584       }
    585       else
    586       ++it;
    587     }
    588 
    589   }
    590500  /**
    591501    Method for calculating the average time between recently fired events.
Note: See TracChangeset for help on using the changeset viewer.