src/Timer.hh
author terom
Mon, 08 Dec 2008 12:46:37 +0000
changeset 283 7540b0859579
parent 205 905028e58ed1
child 300 417183866f35
permissions -rw-r--r--
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
#ifndef TIMER_HH
#define TIMER_HH

#include <ClanLib/core.h>

/**
 * A time interval, measured in real milliseconds
 */
typedef unsigned long TimeMS;

/**
 * Abstract tick count, defined as a number of Timer::interval's against real time
 */
typedef uint32_t TickCount;

/**
 * Used to implement Physics ticks and Graphics frames. This will attempt to trigger sig_tick every <interval> ms,
 * but if we miss some ticks or something else, then the tick_length passed to sig_tick will be longer than interval...
 */
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