Changeset 916 for code/branches/input/src/orxonox/Orxonox.cc
- Timestamp:
- Mar 21, 2008, 3:50:44 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/orxonox/Orxonox.cc
r900 r916 58 58 #include "util/Sleep.h" 59 59 60 // loader and audio 61 //#include "loader/LevelLoader.h" 60 // audio 62 61 #include "audio/AudioManager.h" 63 62 … … 70 69 #include "objects/Tickable.h" 71 70 #include "tools/Timer.h" 72 #include " objects/NPC.h"71 #include "tools/OrxListener.h" 73 72 #include "core/ArgReader.h" 74 73 #include "core/Factory.h" … … 83 82 namespace orxonox 84 83 { 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 127 85 Orxonox* Orxonox::singletonRef_ = NULL; 128 86 … … 134 92 this->ogre_ = new GraphicsEngine(); 135 93 this->dataPath_ = ""; 136 // this->loader_ = 0;137 94 this->auMan_ = 0; 138 95 this->singletonRef_ = 0; … … 143 100 this->root_ = 0; 144 101 // turn frame smoothing on by setting a value different from 0 145 this->frameSmoothingTime_ = 0. 1f;102 this->frameSmoothingTime_ = 0.0f; 146 103 } 147 104 … … 157 114 * initialization of Orxonox object 158 115 * @param argc argument counter 159 * @param argv list of argumen ts116 * @param argv list of argumenst 160 117 * @param path path to config (in home dir or something) 161 118 */ … … 174 131 ar.checkArgument("data", this->dataPath_, false); 175 132 ar.checkArgument("ip", serverIp_, false); 176 //mode = "presentation";177 133 if(ar.errorHandling()) die(); 178 134 if(mode == std::string("server")) … … 451 407 void Orxonox::createFrameListener() 452 408 { 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_); 462 410 } 463 411 … … 477 425 ms.height = height; 478 426 } 479 //ogre_->getRoot()->startRendering();480 427 mainLoop(); 481 428 } … … 509 456 while (true) 510 457 { 511 // Pump messages in all registered RenderWindows458 // Pump messages in all registered RenderWindows 512 459 Ogre::WindowEventUtilities::messagePump(); 513 460 … … 531 478 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) 532 479 (it++)->tick((float)evt.timeSinceLastFrame); 533 534 // Update the timers535 updateTimers((float)evt.timeSinceLastFrame);536 480 537 481 if (mode_ != SERVER) … … 554 498 } 555 499 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 time561 */562 void Orxonox::updateTimers(float dt)563 {564 // Iterate through all Timers565 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 frame570 it->time_ -= dt;571 572 if (it->time_ <= 0)573 {574 // It's time to call the function575 if (it->bLoop_)576 it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.577 else578 it->stopTimer(); // Stop the timer if we don't want to loop579 580 (it++)->run();581 }582 else583 ++it;584 }585 else586 ++it;587 }588 589 }590 500 /** 591 501 Method for calculating the average time between recently fired events.
Note: See TracChangeset
for help on using the changeset viewer.