src/Timer.hh
author saiam
Sun, 07 Dec 2008 19:40:40 +0000
changeset 251 6a6208e5c7a1
parent 205 905028e58ed1
child 283 7540b0859579
permissions -rw-r--r--
Added recoil parameter for weapons, but it is not used yet.
#ifndef TIMER_HH
#define TIMER_HH

#include <ClanLib/core.h>

typedef unsigned long TimeMS;
typedef uint32_t TickCount;

class Timer : public CL_KeepAlive {
    protected:
        // the target tick interval
        TimeMS interval;

        // number of ticks
        TickCount ticks;

        bool enabled;

        // time of last tick
        TimeMS last_tick;

        CL_Signal_v1<TimeMS> _sig_tick;
        
    public:
        /*
         * Interval is in milliseconds
         */
        Timer (TimeMS interval);
        
        /*
         * Returns the tick counter
         */
        TickCount get_ticks (void);
        
        /*
         * Start the timer, this should be called once keepalive starts getting called
         */
        void start (void);
        
    private:
        void keep_alive (void);
    
    public:
        CL_Signal_v1<TimeMS>& sig_tick (void) { return _sig_tick; }
};

#endif