Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 20, 2008, 1:47:41 AM (16 years ago)
Author:
landauf
Message:

added MovableEntity with network optimization for constant velocity and rotation

added new Timer feature to destroy a Timer right after it called the function

Location:
code/branches/objecthierarchy/src/orxonox/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/tools/Timer.cc

    r1755 r1968  
    9292        this->bLoop_ = false;
    9393        this->bActive_ = false;
     94        this->bKillAfterCall_ = false;
    9495
    9596        this->time_ = 0;
     
    112113    {
    113114        (*this->executor_)();
     115
     116        if (this->bKillAfterCall_)
     117            delete this;
    114118    }
    115119
     
    136140            {
    137141                // It's time to call the function
    138                 if (this->bLoop_)
     142                if (this->bLoop_ && !this->bKillAfterCall_)
    139143                {
    140144                    this->time_ += this->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.
  • code/branches/objecthierarchy/src/orxonox/tools/Timer.h

    r1755 r1968  
    116116            TimerBase();
    117117
    118             Executor* executor_; //!< The executor of the function that should be called when the time expires
    119 
    120             long long interval_; //!< The time-interval in micro seconds
    121             bool bLoop_;         //!< If true, the function gets called every 'interval' seconds
    122             bool bActive_;       //!< If true, the Timer ticks and calls the function if the time's up
    123 
    124             long long time_;     //!< Internal variable, counting the time till the next function-call
     118            Executor* executor_;  //!< The executor of the function that should be called when the time expires
     119
     120            long long interval_;  //!< The time-interval in micro seconds
     121            bool bLoop_;          //!< If true, the function gets called every 'interval' seconds
     122            bool bActive_;        //!< If true, the Timer ticks and calls the function if the time's up
     123            bool bKillAfterCall_; //!< If true the timer gets deleted after it called the function
     124
     125            long long time_;      //!< Internal variable, counting the time till the next function-call
    125126    };
    126127
     
    139140                @param exeuctor A executor of the function to call
    140141            */
    141             Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor)
    142             {
    143                 this->setTimer(interval, bLoop, object, exeuctor);
     142            Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false)
     143            {
     144                this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall);
    144145            }
    145146
     
    151152                @param exeuctor A executor of the function to call
    152153            */
    153             void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor)
     154            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false)
    154155            {
    155156                this->deleteExecutor();
     
    162163
    163164                this->time_ = this->interval_;
     165                this->bKillAfterCall_ = bKillAfterCall;
    164166            }
    165167    };
     
    177179                @param exeuctor A executor of the function to call
    178180            */
    179             StaticTimer(float interval, bool bLoop, ExecutorStatic* executor)
    180             {
    181                 this->setTimer(interval, bLoop, executor);
     181            StaticTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)
     182            {
     183                this->setTimer(interval, bLoop, executor, bKillAfterCall);
    182184            }
    183185
     
    189191                @param executor A executor of the function to call
    190192            */
    191             void setTimer(float interval, bool bLoop, ExecutorStatic* executor)
     193            void setTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)
    192194            {
    193195                this->deleteExecutor();
     
    199201
    200202                this->time_ = this->interval_;
     203                this->bKillAfterCall_ = bKillAfterCall;
    201204            }
    202205    };
Note: See TracChangeset for help on using the changeset viewer.