
#ifndef __WFX_KERNEL_TIMETASK_H__
#define __WFX_KERNEL_TIMETASK_H__

#include <WFX/WFXIncludes.h>
#include <WFX/kernel/Task.h>
#include <WFX/kernel/Timer.h>
#include <WFX/lang/Singleton.h>

namespace WFX {

    namespace kernel {

        /**
         * the Timer task interface
         * keeps track of how many seconds have passed since the last Frame
         * and other time based information
         * Task interface as well as DesiredFPS functionality must be implemented by 
         * system specific implementation
         */
        class TimeTask : public Task, public WFX::lang::Singleton<TimeTask> {
            public:
                static ULong ThisFrame;
                static ULong LastFrame;
                /** Time difference between this and the last frame in seconds */
                static Real DeltaTime;
                static Real FPS;
                
                /**
                 * Ctor/Dtor
                 */
                TimeTask();
                virtual ~TimeTask() {};

                /** Task::update() */
                virtual void update();

                /** 
                 * return current Ticks
                 */
                virtual ULong getTicks() = 0;

                /**
                 * set the desired FPS
                 * if this value is > 0 the TimeTask tries
                 * to slow the application down to reach the desired FPS
                 * default value is 100
                 */
                void setDesiredFPS(Int fps) {
                    DesiredFPS = fps;
                    DesiredDTime = 1/fps;
                }

                /**
                 * adds a Timer to the Timer list
                 */
                void addTimer(Timer* t) {
                    Timers.push_back(t);
                }

                /**
                 * removes the given Timer from the Timer list
                 */
                void removeTimer(Timer* t) {
                    StoppedTimers.push_back(t);
                }
                
            protected:
                /** desired framerate */
                Int DesiredFPS;
                /** desired DeltaTime in seconds */
                Real DesiredDTime;
                /** Timer list */
                std::list<Timer*> Timers;
                std::list<Timer*> StoppedTimers;

        };

    }

}


#endif //include guard


