Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 12, 2007, 10:37:30 PM (17 years ago)
Author:
landauf
Message:

added files from objecthierarchy, changed includes

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
    16#include "BaseObject.h"
    27
     
    510    CreateFactory(BaseObject);
    611
     12    /**
     13        @brief Constructor: Registers the object in the BaseObject-list.
     14    */
    715    BaseObject::BaseObject()
    816    {
     
    1018    }
    1119
     20    /**
     21        @brief Destructor
     22    */
    1223    BaseObject::~BaseObject()
    1324    {
    1425    }
    15    
    1626}
  • 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
    18#ifndef _BaseObject_H__
    29#define _BaseObject_H__
    310
    4 #include "../core/IdentifierIncludes.h"
     11#include "../core/CoreIncludes.h"
     12#include "tinyxml/tinyxml.h"
    513
    614namespace orxonox
    715{
     16    //! The BaseObject is the parent of all classes representing an instance in the game.
    817    class BaseObject : virtual public OrxonoxClass
    918    {
     
    1120            BaseObject();
    1221            virtual ~BaseObject();
    13                         virtual void loadParams(TiXmlElement* xmlElem) {}
    14            
     22            virtual void loadParams(TiXmlElement* xmlElem) {}
    1523    };
    1624}
  • code/branches/FICN/src/orxonox/objects/CMakeLists.txt

    r482 r496  
    33SET( OBJECTS_SRC_FILES
    44  BaseObject.cc
     5  WorldEntity.cc
    56  test1.cc
    67  test2.cc
  • code/branches/FICN/src/orxonox/objects/Test.h

    r258 r496  
    33
    44#include "BaseObject.h"
    5 #include "../core/IdentifierIncludes.h"
     5#include "../core/CoreIncludes.h"
    66
    77namespace 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
    113#ifndef _Tickable_H__
    214#define _Tickable_H__
    315
    4 #include <OgreFrameListener.h>
    5 #include "../core/IdentifierIncludes.h"
     16#include "../core/CoreIncludes.h"
     17#include "OgreFrameListener.h"
    618
    719namespace orxonox
    820{
    9     class TickFrameListener;
     21    class TickFrameListener; // Forward declaration
    1022
     23    //! The Tickable interface provides a tick(dt) function, that gets called every frame.
    1124    class Tickable : virtual public OrxonoxClass
    1225    {
    1326        public:
     27            /**
     28                @brief Gets called every frame.
     29                @param dt The time since the last frame
     30            */
    1431            virtual void tick(float dt) = 0;
    1532
    1633        protected:
     34            /**
     35                @brief Constructor: Registers the object in the Tickable-list
     36            */
    1737            Tickable() { RegisterRootObject(Tickable); }
    1838    };
    1939
     40    //! The TickFrameListener calls the tick(dt) function of all Tickables every frame.
    2041    class TickFrameListener : public Ogre::FrameListener
    2142    {
    2243        private:
     44            /** @brief Gets called before a frame gets rendered. */
    2345            bool frameStarted(const Ogre::FrameEvent &evt)
    2446            {
     47                // Iterate through all Tickables and call their tick(dt) function
    2548                for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
    2649                    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
    130#ifndef _Timer_H__
    231#define _Timer_H__
    332
    4 #include <OgreFrameListener.h>
    5 #include "../core/IdentifierIncludes.h"
     33#include "../core/CoreIncludes.h"
     34#include "OgreFrameListener.h"
    635
    736namespace orxonox
    837{
     38    //! TimerBase is the parent of the Timer class.
    939    class TimerBase : public OrxonoxClass
    1040    {
     
    1242
    1343        public:
     44            /** @brief Constructor: Sets the default-values. */
    1445            TimerBase()
    1546            {
     
    2556            virtual void run() const = 0;
    2657
     58            /** @brief Starts the Timer: Function-call after 'interval' seconds. */
    2759            inline void startTimer() { this->bActive_ = true; this->time_ = this->interval_; }
     60            /** @brief Stops the Timer. */
    2861            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. */
    2963            inline void pauseTimer() { this->bActive_ = false; }
     64            /** @brief Unpauses the Timer - continues with the given state. */
    3065            inline void unpauseTimer() { this->bActive_ = true; }
     66            /** @returns true if the Timer is active (= not stoped, not paused). */
    3167            inline bool isActive() const { return this->bActive_; }
    3268
    3369        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
    3773
    38             float time_;
     74            float time_;        //!< Internal variable, counting the time till the next function-call
    3975    };
    4076
     77    //! The Timer is a callback-object, calling a given function after a given time-interval.
    4178    template <class T = BaseObject>
    4279    class Timer : public TimerBase
    4380    {
    4481        public:
     82            /** @brief Constructor: Sets the default-values. */
    4583            Timer()
    4684            {
     
    4987            }
    5088
     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            */
    5196            Timer(float interval, bool bLoop, T* object, void (T::*timerFunction)())
    5297            {
     
    5499            }
    55100
     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            */
    56108            void setTimer(float interval, bool bLoop, T* object, void (T::*timerFunction)())
    57109            {
     
    65117            }
    66118
     119            /** @brief Calls the given function of the given object. */
    67120            void run() const
    68121            {
     
    75128    };
    76129
     130    //! The TimerFrameListener manages all Timers in the game.
    77131    class TimerFrameListener : public Ogre::FrameListener
    78132    {
    79133        private:
     134            /** @brief Gets called before a frame gets rendered. */
    80135            bool frameStarted(const Ogre::FrameEvent &evt)
    81136            {
     137                // Iterate through all Timers
    82138                for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; ++it)
    83139                {
    84140                    if (it->isActive())
    85141                    {
     142                        // If active: Decrease the timer by the duration of the last frame
    86143                        it->time_ -= evt.timeSinceLastFrame;
    87144
    88145                        if (it->time_ <= 0)
    89146                        {
     147                            // It's time to call the function
    90148                            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.
    92150                            else
    93                                 it->stopTimer();
     151                                it->stopTimer(); // Stop the timer if we don't want to loop
    94152
    95153                            it->run();
  • code/branches/FICN/src/orxonox/objects/test3.cc

    r356 r496  
    1010    {
    1111        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));
    1225    }
    1326
     
    1528    {
    1629    }
     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
    1743        #define testandcout(code) \
    1844          std::cout << #code << " " << code << "\n"
  • code/branches/FICN/src/orxonox/objects/test3.h

    r356 r496  
    1515            virtual ~Test3();
    1616
     17            void setConfigValues();
     18
    1719            void usefullClassesIsATest(Test1* test1);
    1820            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_;
    1932    };
    2033}
Note: See TracChangeset for help on using the changeset viewer.