Changeset 496 for code/branches/FICN/src/orxonox/objects
- Timestamp:
- Dec 12, 2007, 10:37:30 PM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox/objects
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/objects/BaseObject.cc
r480 r496 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 { 14 25 } 15 16 26 } -
code/branches/FICN/src/orxonox/objects/BaseObject.h
r480 r496 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__ 3 10 4 #include "../core/IdentifierIncludes.h" 11 #include "../core/CoreIncludes.h" 12 #include "tinyxml/tinyxml.h" 5 13 6 14 namespace orxonox 7 15 { 16 //! The BaseObject is the parent of all classes representing an instance in the game. 8 17 class BaseObject : virtual public OrxonoxClass 9 18 { … … 11 20 BaseObject(); 12 21 virtual ~BaseObject(); 13 virtual void loadParams(TiXmlElement* xmlElem) {} 14 22 virtual void loadParams(TiXmlElement* xmlElem) {} 15 23 }; 16 24 } -
code/branches/FICN/src/orxonox/objects/CMakeLists.txt
r482 r496 3 3 SET( OBJECTS_SRC_FILES 4 4 BaseObject.cc 5 WorldEntity.cc 5 6 test1.cc 6 7 test2.cc -
code/branches/FICN/src/orxonox/objects/Test.h
r258 r496 3 3 4 4 #include "BaseObject.h" 5 #include "../core/ IdentifierIncludes.h"5 #include "../core/CoreIncludes.h" 6 6 7 7 namespace orxonox -
code/branches/FICN/src/orxonox/objects/Tickable.h
r433 r496 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__ 3 15 4 #include <OgreFrameListener.h>5 #include " ../core/IdentifierIncludes.h"16 #include "../core/CoreIncludes.h" 17 #include "OgreFrameListener.h" 6 18 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/FICN/src/orxonox/objects/Timer.h
r433 r496 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__ 3 32 4 #include <OgreFrameListener.h>5 #include " ../core/IdentifierIncludes.h"33 #include "../core/CoreIncludes.h" 34 #include "OgreFrameListener.h" 6 35 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(); -
code/branches/FICN/src/orxonox/objects/test3.cc
r356 r496 10 10 { 11 11 RegisterObject(Test3); 12 13 this->setConfigValues(); 14 } 15 16 void Test3::setConfigValues() 17 { 18 SetConfigValue(value_int_, -100); 19 SetConfigValue(value_double_, 10.555678); 20 SetConfigValue(value_bool_, true); 21 SetConfigValue(value_string_, "Dies ist ein Test"); 22 SetConfigValue(value_vector2_, Vector2(101, 202)); 23 SetConfigValue(value_vector3_, Vector3(13, 26, 39)); 24 SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887)); 12 25 } 13 26 … … 15 28 { 16 29 } 30 31 #include <fstream> 32 void Test3::configOutput() 33 { 34 std::cout << this->value_int_ << std::endl; 35 std::cout << this->value_double_ << std::endl; 36 std::cout << this->value_bool_ << std::endl; 37 std::cout << this->value_string_ << std::endl; 38 std::cout << this->value_vector2_ << std::endl; 39 std::cout << this->value_vector3_ << std::endl; 40 std::cout << this->value_colourvalue_ << std::endl; 41 } 42 17 43 #define testandcout(code) \ 18 44 std::cout << #code << " " << code << "\n" -
code/branches/FICN/src/orxonox/objects/test3.h
r356 r496 15 15 virtual ~Test3(); 16 16 17 void setConfigValues(); 18 17 19 void usefullClassesIsATest(Test1* test1); 18 20 void usefullClassesIsATest(Test2* test2); 21 22 void configOutput(); 23 24 private: 25 int value_int_; 26 double value_double_; 27 bool value_bool_; 28 std::string value_string_; 29 Vector2 value_vector2_; 30 Vector3 value_vector3_; 31 ColourValue value_colourvalue_; 19 32 }; 20 33 }
Note: See TracChangeset
for help on using the changeset viewer.