Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2009, 8:20:07 PM (15 years ago)
Author:
rgrieder
Message:

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/tools/Timer.h

    r5781 r5929  
    4040                ClassName();
    4141                void functionName();
    42                 Timer<ClassName> myTimer;
     42                Timer myTimer;
    4343        };
    4444
     
    4848        ClassName::ClassName()
    4949        {
    50             myTimer.setTimer(interval_in_seconds, bLoop, this, createExecutor(createFunctor(&ClassName::functionName)));
     50            myTimer.setTimer(interval_in_seconds, bLoop, createExecutor(createFunctor(&ClassName::functionName, this)));
    5151        }
    5252
     
    6969namespace orxonox
    7070{
    71     class StaticTimer;
    7271    void delay(float delay, const std::string& command);
    7372    void killdelays();
    74     void executeDelayedCommand(StaticTimer* timer, const std::string& command);
     73    void executeDelayedCommand(Timer* timer, const std::string& command);
    7574
    76     //! TimerBase is the parent of the Timer class.
    77     class _ToolsExport TimerBase : public TimeFactorListener
     75    //! The Timer is a callback-object, calling a given function after a given time-interval.
     76    class _ToolsExport Timer : public TimeFactorListener
    7877    {
    7978        public:
    80             ~TimerBase();
     79            Timer();
     80            ~Timer();
    8181
    82             void run() const;
     82            Timer(float interval, bool bLoop, Executor* executor, bool bKillAfterCall = false);
     83
     84            /**
     85                @brief Initializes the Timer with given values.
     86                @param interval The timer-interval in seconds
     87                @param bLoop If true, the function gets called every 'interval' seconds
     88                @param object The object owning the timer and the function
     89                @param executor A executor of the function to call
     90            */
     91            void setTimer(float interval, bool bLoop, Executor* executor, bool bKillAfterCall = false)
     92            {
     93                this->deleteExecutor();
     94
     95                this->setInterval(interval);
     96                this->bLoop_ = bLoop;
     97                this->executor_ = executor;
     98                this->bActive_ = true;
     99
     100                this->time_ = this->interval_;
     101                this->bKillAfterCall_ = bKillAfterCall;
     102            }
     103
     104            void run();
    83105            void deleteExecutor();
    84106
     
    116138            void tick(const Clock& time);
    117139
    118         protected:
    119             TimerBase();
    120 
     140        private:
     141            void init();
     142       
    121143            Executor* executor_;  //!< The executor of the function that should be called when the time expires
    122144
     
    128150            long long time_;      //!< Internal variable, counting the time till the next function-call
    129151    };
    130 
    131     //! The Timer is a callback-object, calling a given function after a given time-interval.
    132     template <class T = BaseObject>
    133     class Timer : public TimerBase
    134     {
    135         public:
    136             Timer() {}
    137 
    138             /**
    139                 @brief Constructor: Initializes the Timer with given values.
    140                 @param interval The timer-interval in seconds
    141                 @param bLoop If true, the function gets called every 'interval' seconds
    142                 @param object The object owning the timer and the function
    143                 @param exeuctor A executor of the function to call
    144             */
    145             Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false)
    146             {
    147                 this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall);
    148             }
    149 
    150             /**
    151                 @brief Initializes the Timer with given values.
    152                 @param interval The timer-interval in seconds
    153                 @param bLoop If true, the function gets called every 'interval' seconds
    154                 @param object The object owning the timer and the function
    155                 @param exeuctor A executor of the function to call
    156             */
    157             void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false)
    158             {
    159                 this->deleteExecutor();
    160 
    161                 this->setInterval(interval);
    162                 this->bLoop_ = bLoop;
    163                 executor->setObject(object);
    164                 this->executor_ = static_cast<Executor*>(executor);
    165                 this->bActive_ = true;
    166 
    167                 this->time_ = this->interval_;
    168                 this->bKillAfterCall_ = bKillAfterCall;
    169             }
    170     };
    171 
    172     //! The StaticTimer is a callback-object, calling a static function after a given time-interval.
    173     class _ToolsExport StaticTimer : public TimerBase
    174     {
    175         public:
    176             StaticTimer() {}
    177 
    178             /**
    179                 @brief Constructor: Initializes the Timer with given values.
    180                 @param interval The timer-interval in seconds
    181                 @param bLoop If true, the function gets called every 'interval' seconds
    182                 @param exeuctor A executor of the function to call
    183             */
    184             StaticTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)
    185             {
    186                 this->setTimer(interval, bLoop, executor, bKillAfterCall);
    187             }
    188 
    189             /**
    190                 @brief Initializes the Timer with given values.
    191                 @param interval The timer-interval in seconds
    192                 @param bLoop If true, the function gets called every 'interval' seconds
    193                 @param object The object owning the timer and the function
    194                 @param executor A executor of the function to call
    195             */
    196             void setTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)
    197             {
    198                 this->deleteExecutor();
    199 
    200                 this->setInterval(interval);
    201                 this->bLoop_ = bLoop;
    202                 this->executor_ = executor;
    203                 this->bActive_ = true;
    204 
    205                 this->time_ = this->interval_;
    206                 this->bKillAfterCall_ = bKillAfterCall;
    207             }
    208     };
    209 
    210152}
    211153
Note: See TracChangeset for help on using the changeset viewer.