Changeset 452 for code/branches
- Timestamp:
- Dec 10, 2007, 3:21:33 PM (17 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/core/ClassFactory.h
r447 r452 1 1 /*! 2 2 @file ClassFactory.h 3 @brief Definition of the ClassFactory class3 @brief Definition and implementation of the ClassFactory class 4 4 5 5 The ClassFactory is able to create new objects of a specific class. -
code/branches/objecthierarchy/src/orxonox/core/Identifier.h
r447 r452 1 1 /*! 2 2 @file Identifier.h 3 @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes .3 @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes. 4 4 5 5 The Identifier contains all needed informations about the class it belongs to: -
code/branches/objecthierarchy/src/orxonox/core/Iterator.h
r447 r452 1 1 /*! 2 2 @file Iterator.h 3 @brief Definition of the Iterator class.3 @brief Definition and implementation of the Iterator class. 4 4 5 5 The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type. -
code/branches/objecthierarchy/src/orxonox/core/ObjectList.h
r447 r452 1 1 /*! 2 2 @file ObjectList.h 3 @brief Definition of the ObjectList class.3 @brief Definition and implementation of the ObjectList class. 4 4 5 5 The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class. -
code/branches/objecthierarchy/src/orxonox/objects/BaseObject.cc
r258 r452 1 /*! 2 @file BaseObject.cc 3 @brief Implementation of the BaseObject class. 4 */ 5 1 6 #include "BaseObject.h" 2 7 … … 5 10 CreateFactory(BaseObject); 6 11 12 /** 13 @brief Constructor: Registers the object in the BaseObject-list. 14 */ 7 15 BaseObject::BaseObject() 8 16 { … … 10 18 } 11 19 20 /** 21 @brief Destructor 22 */ 12 23 BaseObject::~BaseObject() 13 24 { -
code/branches/objecthierarchy/src/orxonox/objects/BaseObject.h
r443 r452 1 /*! 2 @file BaseObject.h 3 @brief Definition of the BaseObject class. 4 5 The BaseObject is the parent of all classes representing an instance in the game. 6 */ 7 1 8 #ifndef _BaseObject_H__ 2 9 #define _BaseObject_H__ … … 6 13 namespace orxonox 7 14 { 15 //! The BaseObject is the parent of all classes representing an instance in the game. 8 16 class BaseObject : virtual public OrxonoxClass 9 17 { -
code/branches/objecthierarchy/src/orxonox/objects/Tickable.h
r443 r452 1 /*! 2 @file Tickable.h 3 @brief Definition of the Tickable interface. 4 5 The Tickable interface provides a tick(dt) function, that gets called every frame. 6 float dt is the time since the last frame. 7 8 Attention: 9 Classes derived from a Tickable that want to have a tick(dt) function on their part, MUST call the 10 parent::tick(dt) function explicit in their implementation of tick(dt) because it's a virtual function. 11 */ 12 1 13 #ifndef _Tickable_H__ 2 14 #define _Tickable_H__ … … 7 19 namespace orxonox 8 20 { 9 class TickFrameListener; 21 class TickFrameListener; // Forward declaration 10 22 23 //! The Tickable interface provides a tick(dt) function, that gets called every frame. 11 24 class Tickable : virtual public OrxonoxClass 12 25 { 13 26 public: 27 /** 28 @brief Gets called every frame. 29 @param dt The time since the last frame 30 */ 14 31 virtual void tick(float dt) = 0; 15 32 16 33 protected: 34 /** 35 @brief Constructor: Registers the object in the Tickable-list 36 */ 17 37 Tickable() { RegisterRootObject(Tickable); } 18 38 }; 19 39 40 //! The TickFrameListener calls the tick(dt) function of all Tickables every frame. 20 41 class TickFrameListener : public Ogre::FrameListener 21 42 { 22 43 private: 44 /** @brief Gets called before a frame gets rendered. */ 23 45 bool frameStarted(const Ogre::FrameEvent &evt) 24 46 { 47 // Iterate through all Tickables and call their tick(dt) function 25 48 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 26 49 it->tick(evt.timeSinceLastFrame); -
code/branches/objecthierarchy/src/orxonox/objects/Timer.h
r443 r452 1 /*! 2 @file Timer.h 3 @brief Definition and Implementation of the Timer class. 4 5 The Timer is a callback-object, calling a given function after a given time-interval. 6 7 Usage: 8 header.h: 9 class ClassName 10 { 11 public: 12 ClassName(); 13 void functionName(); 14 Timer myTimer; 15 }; 16 17 source.cc: 18 ClassName::ClassName() 19 { 20 myTimer.setTimer(interval_in_seconds, bLoop, this, &ClassName::functionName); 21 } 22 23 void ClassName::functionName() 24 { 25 whateveryouwant(); 26 something(else); 27 } 28 */ 29 1 30 #ifndef _Timer_H__ 2 31 #define _Timer_H__ … … 7 36 namespace orxonox 8 37 { 38 //! TimerBase is the parent of the Timer class. 9 39 class TimerBase : public OrxonoxClass 10 40 { … … 12 42 13 43 public: 44 /** @brief Constructor: Sets the default-values. */ 14 45 TimerBase() 15 46 { … … 25 56 virtual void run() const = 0; 26 57 58 /** @brief Starts the Timer: Function-call after 'interval' seconds. */ 27 59 inline void startTimer() { this->bActive_ = true; this->time_ = this->interval_; } 60 /** @brief Stops the Timer. */ 28 61 inline void stopTimer() { this->bActive_ = false; this->time_ = this->interval_; } 62 /** @brief Pauses the Timer - it will continue with the actual state if you unpause it. */ 29 63 inline void pauseTimer() { this->bActive_ = false; } 64 /** @brief Unpauses the Timer - continues with the given state. */ 30 65 inline void unpauseTimer() { this->bActive_ = true; } 66 /** @returns true if the Timer is active (= not stoped, not paused). */ 31 67 inline bool isActive() const { return this->bActive_; } 32 68 33 69 protected: 34 float interval_; 35 bool bLoop_; 36 bool bActive_; 70 float interval_; //!< The time-interval in seconds 71 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 72 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 37 73 38 float time_; 74 float time_; //!< Internal variable, counting the time till the next function-call 39 75 }; 40 76 77 //! The Timer is a callback-object, calling a given function after a given time-interval. 41 78 template <class T = BaseObject> 42 79 class Timer : public TimerBase 43 80 { 44 81 public: 82 /** @brief Constructor: Sets the default-values. */ 45 83 Timer() 46 84 { … … 49 87 } 50 88 89 /** 90 @brief Constructor: Initializes the Timer with given values. 91 @param interval The timer-interval in seconds 92 @param bLoop If true, the function gets called every 'interval' seconds 93 @param object The object owning the timer and the function 94 @param timerFunction A function pointer to the function to call 95 */ 51 96 Timer(float interval, bool bLoop, T* object, void (T::*timerFunction)()) 52 97 { … … 54 99 } 55 100 101 /** 102 @brief Initializes the Timer with given values. 103 @param interval The timer-interval in seconds 104 @param bLoop If true, the function gets called every 'interval' seconds 105 @param object The object owning the timer and the function 106 @param timerFunction A function pointer to the function to call 107 */ 56 108 void setTimer(float interval, bool bLoop, T* object, void (T::*timerFunction)()) 57 109 { … … 65 117 } 66 118 119 /** @brief Calls the given function of the given object. */ 67 120 void run() const 68 121 { … … 75 128 }; 76 129 130 //! The TimerFrameListener manages all Timers in the game. 77 131 class TimerFrameListener : public Ogre::FrameListener 78 132 { 79 133 private: 134 /** @brief Gets called before a frame gets rendered. */ 80 135 bool frameStarted(const Ogre::FrameEvent &evt) 81 136 { 137 // Iterate through all Timers 82 138 for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; ++it) 83 139 { 84 140 if (it->isActive()) 85 141 { 142 // If active: Decrease the timer by the duration of the last frame 86 143 it->time_ -= evt.timeSinceLastFrame; 87 144 88 145 if (it->time_ <= 0) 89 146 { 147 // It's time to call the function 90 148 if (it->bLoop_) 91 it->time_ += it->interval_; 149 it->time_ += it->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously. 92 150 else 93 it->stopTimer(); 151 it->stopTimer(); // Stop the timer if we don't want to loop 94 152 95 153 it->run();
Note: See TracChangeset
for help on using the changeset viewer.