Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 916


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
Location:
code/branches/input
Files:
2 added
6 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.
  • code/branches/input/src/orxonox/objects/Tickable.h

    r900 r916  
    4141#define _Tickable_H__
    4242
    43 #include <OgreFrameListener.h>
    44 
    4543#include "../OrxonoxPrereqs.h"
    4644#include "core/OrxonoxClass.h"
     
    6462    };
    6563
    66 #if 0
    67     //! The TickFrameListener calls the tick(dt) function of all Tickables every frame.
    68     class _OrxonoxExport TickFrameListener : public Ogre::FrameListener
    69     {
    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) function
    75                 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
    76                     (it++)->tick(evt.timeSinceLastFrame);
    77 
    78                 return FrameListener::frameStarted(evt);
    79             }
    80     };
    81 #endif
    8264}
    8365
  • code/branches/input/src/orxonox/tools/Timer.cc

    r893 r916  
    4646        this->time_ = 0;
    4747    }
     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
    4873}
  • code/branches/input/src/orxonox/tools/Timer.h

    r900 r916  
    5858#define _Timer_H__
    5959
    60 #include <OgreFrameListener.h>
    6160#include "../OrxonoxPrereqs.h"
     61#include "objects/Tickable.h"
    6262
    6363namespace orxonox
    6464{
    6565    //! TimerBase is the parent of the Timer class.
    66     class _OrxonoxExport TimerBase : public OrxonoxClass
     66    class _OrxonoxExport TimerBase : public Tickable
    6767    {
    68         //friend class TimerFrameListener;
    69         friend class Orxonox;
    70 
    7168        public:
    7269            TimerBase();
     
    8481            /** @brief Returns true if the Timer is active (= not stoped, not paused). @return True = Time is active */
    8582            inline bool isActive() const { return this->bActive_; }
     83
     84            void tick(float dt);
    8685
    8786        protected:
     
    146145    };
    147146
    148 #if 0
    149     //! The TimerFrameListener manages all Timers in the game.
    150     class TimerFrameListener : public Ogre::FrameListener
    151     {
    152         private:
    153             /** @brief Gets called before a frame gets rendered. */
    154             bool frameStarted(const Ogre::FrameEvent &evt)
    155             {
    156                 // Iterate through all Timers
    157                 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 frame
    162                         it->time_ -= evt.timeSinceLastFrame;
    163 
    164                         if (it->time_ <= 0)
    165                         {
    166                             // It's time to call the function
    167                             if (it->bLoop_)
    168                                 it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.
    169                             else
    170                                 it->stopTimer(); // Stop the timer if we don't want to loop
    171 
    172                             (it++)->run();
    173                         }
    174                         else
    175                             ++it;
    176                     }
    177                     else
    178                         ++it;
    179                 }
    180 
    181                 return FrameListener::frameStarted(evt);
    182             }
    183     };
    184 #endif
    185147}
    186148
  • code/branches/input/visual_studio/orxonox_vc8.sln

    r893 r916  
    1919                {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}
    2020                {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F}
    21         EndProjectSection
    22 EndProject
    23 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loader", "vc8\loader.vcproj", "{E283910F-F911-40FB-A09D-D025CA821912}"
    24         ProjectSection(WebsiteProperties) = preProject
    25                 Debug.AspNetCompiler.Debug = "True"
    26                 Release.AspNetCompiler.Debug = "False"
    27         EndProjectSection
    28         ProjectSection(ProjectDependencies) = postProject
    29                 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}
    3021        EndProjectSection
    3122EndProject
     
    8980                {271715F3-5B90-4110-A552-70C788084A86}.Release|Win32.ActiveCfg = Release|Win32
    9081                {271715F3-5B90-4110-A552-70C788084A86}.Release|Win32.Build.0 = Release|Win32
    91                 {E283910F-F911-40FB-A09D-D025CA821912}.Debug|Win32.ActiveCfg = Debug|Win32
    92                 {E283910F-F911-40FB-A09D-D025CA821912}.Release_SSE|Win32.ActiveCfg = Release_SSE|Win32
    93                 {E283910F-F911-40FB-A09D-D025CA821912}.Release_SSE2|Win32.ActiveCfg = Release_SSE2|Win32
    94                 {E283910F-F911-40FB-A09D-D025CA821912}.Release|Win32.ActiveCfg = Release|Win32
    9582                {35575B59-E1AE-40E8-89C4-2862B5B09B68}.Debug|Win32.ActiveCfg = Debug|Win32
    9683                {35575B59-E1AE-40E8-89C4-2862B5B09B68}.Debug|Win32.Build.0 = Debug|Win32
  • code/branches/input/visual_studio/vc8/orxonox.vcproj

    r893 r916  
    287287                                RelativePath="..\..\src\orxonox\InputManager.cc"
    288288                                >
     289                                <FileConfiguration
     290                                        Name="Debug|Win32"
     291                                        ExcludedFromBuild="true"
     292                                        >
     293                                        <Tool
     294                                                Name="VCCLCompilerTool"
     295                                        />
     296                                </FileConfiguration>
    289297                        </File>
    290298                        <File
     
    632640                                </File>
    633641                                <File
     642                                        RelativePath="..\..\src\orxonox\tools\OrxListener.cc"
     643                                        >
     644                                </File>
     645                                <File
    634646                                        RelativePath="..\..\src\orxonox\tools\Timer.cc"
    635                                         >
    636                                 </File>
    637                         </Filter>
    638                         <Filter
    639                                 Name="loader"
    640                                 >
    641                                 <File
    642                                         RelativePath="..\..\src\loader\LevelLoader.cc"
    643647                                        >
    644648                                </File>
     
    806810                                </File>
    807811                                <File
     812                                        RelativePath="..\..\src\orxonox\tools\OrxListener.h"
     813                                        >
     814                                </File>
     815                                <File
    808816                                        RelativePath="..\..\src\orxonox\tools\Timer.h"
    809                                         >
    810                                 </File>
    811                         </Filter>
    812                         <Filter
    813                                 Name="loader"
    814                                 >
    815                                 <File
    816                                         RelativePath="..\..\src\loader\LevelLoader.h"
    817                                         >
    818                                 </File>
    819                                 <File
    820                                         RelativePath="..\..\src\loader\LoaderPrereqs.h"
    821817                                        >
    822818                                </File>
Note: See TracChangeset for help on using the changeset viewer.