Changeset 916 for code/branches/input
- Timestamp:
- Mar 21, 2008, 3:50:44 PM (17 years ago)
- Location:
- code/branches/input
- Files:
-
- 2 added
- 6 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. -
code/branches/input/src/orxonox/objects/Tickable.h
r900 r916 41 41 #define _Tickable_H__ 42 42 43 #include <OgreFrameListener.h>44 45 43 #include "../OrxonoxPrereqs.h" 46 44 #include "core/OrxonoxClass.h" … … 64 62 }; 65 63 66 #if 067 //! The TickFrameListener calls the tick(dt) function of all Tickables every frame.68 class _OrxonoxExport TickFrameListener : public Ogre::FrameListener69 {70 private:71 /** @brief Gets called before a frame gets rendered. */72 bool frameStarted(const Ogre::FrameEvent &evt)73 {74 // Iterate through all Tickables and call their tick(dt) function75 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )76 (it++)->tick(evt.timeSinceLastFrame);77 78 return FrameListener::frameStarted(evt);79 }80 };81 #endif82 64 } 83 65 -
code/branches/input/src/orxonox/tools/Timer.cc
r893 r916 46 46 this->time_ = 0; 47 47 } 48 49 /** 50 @brief Updates the timer before the frames are rendered. 51 */ 52 void TimerBase::tick(float dt) 53 { 54 if (this->bActive_) 55 { 56 // If active: Decrease the timer by the duration of the last frame 57 this->time_ -= dt; 58 59 if (this->time_ <= 0) 60 { 61 // It's time to call the function 62 if (this->bLoop_) 63 // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously. 64 this->time_ += this->interval_; 65 else 66 this->stopTimer(); // Stop the timer if we don't want to loop 67 68 this->run(); 69 } 70 } 71 } 72 48 73 } -
code/branches/input/src/orxonox/tools/Timer.h
r900 r916 58 58 #define _Timer_H__ 59 59 60 #include <OgreFrameListener.h>61 60 #include "../OrxonoxPrereqs.h" 61 #include "objects/Tickable.h" 62 62 63 63 namespace orxonox 64 64 { 65 65 //! TimerBase is the parent of the Timer class. 66 class _OrxonoxExport TimerBase : public OrxonoxClass66 class _OrxonoxExport TimerBase : public Tickable 67 67 { 68 //friend class TimerFrameListener;69 friend class Orxonox;70 71 68 public: 72 69 TimerBase(); … … 84 81 /** @brief Returns true if the Timer is active (= not stoped, not paused). @return True = Time is active */ 85 82 inline bool isActive() const { return this->bActive_; } 83 84 void tick(float dt); 86 85 87 86 protected: … … 146 145 }; 147 146 148 #if 0149 //! The TimerFrameListener manages all Timers in the game.150 class TimerFrameListener : public Ogre::FrameListener151 {152 private:153 /** @brief Gets called before a frame gets rendered. */154 bool frameStarted(const Ogre::FrameEvent &evt)155 {156 // Iterate through all Timers157 for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; )158 {159 if (it->isActive())160 {161 // If active: Decrease the timer by the duration of the last frame162 it->time_ -= evt.timeSinceLastFrame;163 164 if (it->time_ <= 0)165 {166 // It's time to call the function167 if (it->bLoop_)168 it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.169 else170 it->stopTimer(); // Stop the timer if we don't want to loop171 172 (it++)->run();173 }174 else175 ++it;176 }177 else178 ++it;179 }180 181 return FrameListener::frameStarted(evt);182 }183 };184 #endif185 147 } 186 148 -
code/branches/input/visual_studio/orxonox_vc8.sln
r893 r916 19 19 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC} 20 20 {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F} 21 EndProjectSection22 EndProject23 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loader", "vc8\loader.vcproj", "{E283910F-F911-40FB-A09D-D025CA821912}"24 ProjectSection(WebsiteProperties) = preProject25 Debug.AspNetCompiler.Debug = "True"26 Release.AspNetCompiler.Debug = "False"27 EndProjectSection28 ProjectSection(ProjectDependencies) = postProject29 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}30 21 EndProjectSection 31 22 EndProject … … 89 80 {271715F3-5B90-4110-A552-70C788084A86}.Release|Win32.ActiveCfg = Release|Win32 90 81 {271715F3-5B90-4110-A552-70C788084A86}.Release|Win32.Build.0 = Release|Win32 91 {E283910F-F911-40FB-A09D-D025CA821912}.Debug|Win32.ActiveCfg = Debug|Win3292 {E283910F-F911-40FB-A09D-D025CA821912}.Release_SSE|Win32.ActiveCfg = Release_SSE|Win3293 {E283910F-F911-40FB-A09D-D025CA821912}.Release_SSE2|Win32.ActiveCfg = Release_SSE2|Win3294 {E283910F-F911-40FB-A09D-D025CA821912}.Release|Win32.ActiveCfg = Release|Win3295 82 {35575B59-E1AE-40E8-89C4-2862B5B09B68}.Debug|Win32.ActiveCfg = Debug|Win32 96 83 {35575B59-E1AE-40E8-89C4-2862B5B09B68}.Debug|Win32.Build.0 = Debug|Win32 -
code/branches/input/visual_studio/vc8/orxonox.vcproj
r893 r916 287 287 RelativePath="..\..\src\orxonox\InputManager.cc" 288 288 > 289 <FileConfiguration 290 Name="Debug|Win32" 291 ExcludedFromBuild="true" 292 > 293 <Tool 294 Name="VCCLCompilerTool" 295 /> 296 </FileConfiguration> 289 297 </File> 290 298 <File … … 632 640 </File> 633 641 <File 642 RelativePath="..\..\src\orxonox\tools\OrxListener.cc" 643 > 644 </File> 645 <File 634 646 RelativePath="..\..\src\orxonox\tools\Timer.cc" 635 >636 </File>637 </Filter>638 <Filter639 Name="loader"640 >641 <File642 RelativePath="..\..\src\loader\LevelLoader.cc"643 647 > 644 648 </File> … … 806 810 </File> 807 811 <File 812 RelativePath="..\..\src\orxonox\tools\OrxListener.h" 813 > 814 </File> 815 <File 808 816 RelativePath="..\..\src\orxonox\tools\Timer.h" 809 >810 </File>811 </Filter>812 <Filter813 Name="loader"814 >815 <File816 RelativePath="..\..\src\loader\LevelLoader.h"817 >818 </File>819 <File820 RelativePath="..\..\src\loader\LoaderPrereqs.h"821 817 > 822 818 </File>
Note: See TracChangeset
for help on using the changeset viewer.