| [670] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
 | 3 |  * | 
|---|
 | 4 |  * | 
|---|
 | 5 |  *   License notice: | 
|---|
 | 6 |  * | 
|---|
 | 7 |  *   This program is free software; you can redistribute it and/or | 
|---|
 | 8 |  *   modify it under the terms of the GNU General Public License | 
|---|
 | 9 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
 | 10 |  *   of the License, or (at your option) any later version. | 
|---|
 | 11 |  * | 
|---|
 | 12 |  *   This program is distributed in the hope that it will be useful, | 
|---|
 | 13 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 14 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 15 |  *   GNU General Public License for more details. | 
|---|
 | 16 |  * | 
|---|
 | 17 |  *   You should have received a copy of the GNU General Public License | 
|---|
 | 18 |  *   along with this program; if not, write to the Free Software | 
|---|
 | 19 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
 | 20 |  * | 
|---|
 | 21 |  *   Author: | 
|---|
 | 22 |  *      Fabian 'x3n' Landau | 
|---|
 | 23 |  *   Co-authors: | 
|---|
 | 24 |  *      ... | 
|---|
 | 25 |  * | 
|---|
 | 26 |  */ | 
|---|
 | 27 |  | 
|---|
| [496] | 28 | /*! | 
|---|
 | 29 |     @file Tickable.h | 
|---|
 | 30 |     @brief Definition of the Tickable interface. | 
|---|
 | 31 |  | 
|---|
 | 32 |     The Tickable interface provides a tick(dt) function, that gets called every frame. | 
|---|
| [640] | 33 |     float dt is the time since the last frame in seconds. | 
|---|
| [496] | 34 |  | 
|---|
 | 35 |     Attention: | 
|---|
 | 36 |     Classes derived from a Tickable that want to have a tick(dt) function on their part, MUST call the | 
|---|
 | 37 |     parent::tick(dt) function explicit in their implementation of tick(dt) because it's a virtual function. | 
|---|
 | 38 | */ | 
|---|
 | 39 |  | 
|---|
| [384] | 40 | #ifndef _Tickable_H__ | 
|---|
 | 41 | #define _Tickable_H__ | 
|---|
 | 42 |  | 
|---|
| [708] | 43 | #include <OgreFrameListener.h> | 
|---|
 | 44 |  | 
|---|
 | 45 | #include "../OrxonoxPrereqs.h" | 
|---|
| [871] | 46 | #include "core/OrxonoxClass.h" | 
|---|
| [708] | 47 |  | 
|---|
| [384] | 48 | namespace orxonox | 
|---|
 | 49 | { | 
|---|
| [496] | 50 |     class TickFrameListener; // Forward declaration | 
|---|
| [384] | 51 |  | 
|---|
| [496] | 52 |     //! The Tickable interface provides a tick(dt) function, that gets called every frame. | 
|---|
| [729] | 53 |     class _OrxonoxExport Tickable : virtual public OrxonoxClass | 
|---|
| [384] | 54 |     { | 
|---|
 | 55 |         public: | 
|---|
| [496] | 56 |             /** | 
|---|
 | 57 |                 @brief Gets called every frame. | 
|---|
| [640] | 58 |                 @param dt The time since the last frame in seconds | 
|---|
| [496] | 59 |             */ | 
|---|
| [384] | 60 |             virtual void tick(float dt) = 0; | 
|---|
 | 61 |  | 
|---|
 | 62 |         protected: | 
|---|
| [871] | 63 |             Tickable(); | 
|---|
| [384] | 64 |     }; | 
|---|
 | 65 |  | 
|---|
| [496] | 66 |     //! The TickFrameListener calls the tick(dt) function of all Tickables every frame. | 
|---|
| [729] | 67 |     class _OrxonoxExport TickFrameListener : public Ogre::FrameListener | 
|---|
| [384] | 68 |     { | 
|---|
 | 69 |         private: | 
|---|
| [496] | 70 |             /** @brief Gets called before a frame gets rendered. */ | 
|---|
| [384] | 71 |             bool frameStarted(const Ogre::FrameEvent &evt) | 
|---|
 | 72 |             { | 
|---|
| [496] | 73 |                 // Iterate through all Tickables and call their tick(dt) function | 
|---|
| [646] | 74 |                 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ) | 
|---|
 | 75 |                     (it++)->tick(evt.timeSinceLastFrame); | 
|---|
| [384] | 76 |  | 
|---|
 | 77 |                 return FrameListener::frameStarted(evt); | 
|---|
 | 78 |             } | 
|---|
 | 79 |     }; | 
|---|
 | 80 | } | 
|---|
 | 81 |  | 
|---|
| [673] | 82 | #endif /* _Tickable_H__ */ | 
|---|