Mercurial > hg > tweakathon2ios
diff timeController.h @ 0:a223551fdc1f
First commit - copy from tweakathlon.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 10 Oct 2014 11:46:42 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timeController.h Fri Oct 10 11:46:42 2014 +0100 @@ -0,0 +1,80 @@ + // +// timeController.h +// tweakathlon +// +// Created by Robert Tubb on 10/02/2014. +// +// + +#ifndef __tweakathlon__timeController__ +#define __tweakathlon__timeController__ +#include "ofMain.h" +#include <iostream> +#include "boost/function.hpp" +#include <boost/bind.hpp> +#import "TimedCallController.h" + +typedef boost::function<void(void)> TimerCallbackFunction; +typedef map<unsigned long long, TimerCallbackFunction> TimesAndCallsMap; +typedef std::pair<unsigned long long, TimerCallbackFunction> TimeAndCallPair; + +typedef unsigned long long TimerID; // the id is just the time it's set to fire, microsecs(?) +typedef unsigned long long TimerMicrosec; //microsecs(?) +typedef unsigned long long TimerMillisec; + +class TimeController{ + +public: + + + //---------------- + //---------------- + void init(){ + iosTimer = [[TimedCallController alloc] init]; + [iosTimer setAppRef:(id)this]; + }; + + //---------------- + // called from testApp.update() + void tick(){ + TimerID timeNow = getMicrosecTimeNow(); + callAndEraseAllExpired(timeNow); + + }; + + //---------------- + void cancelEvent(TimerID which); + //---------------- + TimerID scheduleEvent(TimerCallbackFunction cbfunc, int howLongMillisec); + //---------------- + void startStopwatch(); + TimerMicrosec stopStopwatch(); + TimerMicrosec getStopwatchElapsedTime(); + + void startCountDown(){ + + }; + void countdownFinished(){ + + }; + //---------------- + +private: + TimesAndCallsMap timesAndCalls; + TimerMillisec stopWatchStartTime; // millisec + bool stopWatchRunning; + //---------------- + void callAndEraseAllExpired(TimerMicrosec timeNow); + + TimedCallController* iosTimer; + + TimerMicrosec getMicrosecTimeNow(){ + double time_sec = [NSDate timeIntervalSinceReferenceDate]; + return TimerMicrosec(time_sec*1000000); + } + +}; + + + +#endif /* defined(__tweakathlon__timeController__) */