Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 10, 2018, 3:16:51 PM (6 years ago)
Author:
merholzl
Message:

added scriptable controller

Location:
code/branches/mergeFS18
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/mergeFS18

  • code/branches/mergeFS18/src/libraries/core/BaseObject.cc

    r11103 r12028  
    7777        {
    7878            this->setFile(this->creator_->getFile());
    79 
     79           
    8080            // store strong-pointers on all four base objects by default (can be overwritten with weak-ptr after the constructor if necessary)
    8181            this->setNamespace(this->creator_->namespace_.createStrongPtr());
  • code/branches/mergeFS18/src/libraries/core/BaseObject.h

    r11071 r12028  
    5858    class Gametype;
    5959    class Level;
     60    class ScriptableController;
    6061
    6162    /// The BaseObject is the parent of all classes representing an instance in the game.
     
    191192
    192193            static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier);
     194
    193195
    194196        protected:
  • code/branches/mergeFS18/src/libraries/tools/Timer.cc

    r11071 r12028  
    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)
  • code/branches/mergeFS18/src/libraries/tools/Timer.h

    r11071 r12028  
    108108
    109109            Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
     110            Timer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
    110111
    111112            void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
     113            void setTimer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
    112114
    113115            void run();
     
    153155
    154156            ExecutorPtr executor_;  //!< The executor of the function that will be called when the time expires
     157            std::function<void (void)> function_;
    155158
     159            bool isStdFunction_;
    156160            long long interval_;    //!< The time-interval in micro seconds
    157161            bool bLoop_;            //!< If true, the executor gets called every @a interval seconds
Note: See TracChangeset for help on using the changeset viewer.