Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2018, 2:07:03 PM (7 years ago)
Author:
adamc
Message:

merged HS17 into FS18

Location:
code/branches/ScriptableController_FS18
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController_FS18

  • code/branches/ScriptableController_FS18/src/libraries/tools/Timer.cc

    r11071 r11855  
    158158    }
    159159
     160    Timer::Timer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
     161    {
     162        this->init();
     163        RegisterObject(Timer);
     164
     165        this->setTimer(interval, bLoop, func, bKillAfterCall);
     166    }
     167
    160168    /**
    161169        @brief Initializes the Timer
     
    193201        this->executor_ = executor;
    194202        this->bActive_ = true;
     203        this->isStdFunction_ = false;
    195204
    196205        this->time_ = this->interval_;
    197206        this->bKillAfterCall_ = bKillAfterCall;
    198207
    199         executor->getFunctor()->setSafeMode(true);
     208        if(executor != nullptr)
     209            executor->getFunctor()->setSafeMode(true);
     210    }
     211
     212    void Timer::setTimer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
     213    {
     214        // Without the cast, the call would be ambiguous, because nullptr is castable to
     215        // both, ExecutorPtr and std::function.
     216        this->setTimer(interval, bLoop, static_cast<ExecutorPtr>(nullptr), bKillAfterCall);
     217        this->function_ = func;
     218        this->isStdFunction_ = true;
    200219    }
    201220
     
    207226        bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer
    208227
    209         (*this->executor_)();
     228        if(this->isStdFunction_)
     229            this->function_();
     230        else
     231            (*this->executor_)();
    210232
    211233        if (temp)
Note: See TracChangeset for help on using the changeset viewer.