rt300@0: // rt300@0: // timeController.h rt300@0: // tweakathlon rt300@0: // rt300@0: // Created by Robert Tubb on 10/02/2014. rt300@0: // rt300@0: // rt300@0: rt300@0: #ifndef __tweakathlon__timeController__ rt300@0: #define __tweakathlon__timeController__ rt300@0: #include "ofMain.h" rt300@0: #include rt300@0: #include "boost/function.hpp" rt300@0: #include rt300@0: #import "TimedCallController.h" rt300@0: rt300@0: typedef boost::function TimerCallbackFunction; rt300@0: typedef map TimesAndCallsMap; rt300@0: typedef std::pair TimeAndCallPair; rt300@0: rt300@0: typedef unsigned long long TimerID; // the id is just the time it's set to fire, microsecs(?) rt300@0: typedef unsigned long long TimerMicrosec; //microsecs(?) rt300@0: typedef unsigned long long TimerMillisec; rt300@0: rt300@0: class TimeController{ rt300@0: rt300@0: public: rt300@0: rt300@0: rt300@0: //---------------- rt300@0: //---------------- rt300@0: void init(){ rt300@0: iosTimer = [[TimedCallController alloc] init]; rt300@0: [iosTimer setAppRef:(id)this]; rt300@0: }; rt300@0: rt300@0: //---------------- rt300@0: // called from testApp.update() rt300@0: void tick(){ rt300@0: TimerID timeNow = getMicrosecTimeNow(); rt300@0: callAndEraseAllExpired(timeNow); rt300@0: rt300@0: }; rt300@0: rt300@0: //---------------- rt300@0: void cancelEvent(TimerID which); rt300@0: //---------------- rt300@0: TimerID scheduleEvent(TimerCallbackFunction cbfunc, int howLongMillisec); rt300@0: //---------------- rt300@0: void startStopwatch(); rt300@0: TimerMicrosec stopStopwatch(); rt300@0: TimerMicrosec getStopwatchElapsedTime(); rt300@0: rt300@0: void startCountDown(){ rt300@0: rt300@0: }; rt300@0: void countdownFinished(){ rt300@0: rt300@0: }; rt300@0: //---------------- rt300@0: rt300@0: private: rt300@0: TimesAndCallsMap timesAndCalls; rt300@0: TimerMillisec stopWatchStartTime; // millisec rt300@0: bool stopWatchRunning; rt300@0: //---------------- rt300@0: void callAndEraseAllExpired(TimerMicrosec timeNow); rt300@0: rt300@0: TimedCallController* iosTimer; rt300@0: rt300@0: TimerMicrosec getMicrosecTimeNow(){ rt300@0: double time_sec = [NSDate timeIntervalSinceReferenceDate]; rt300@0: return TimerMicrosec(time_sec*1000000); rt300@0: } rt300@0: rt300@0: }; rt300@0: rt300@0: rt300@0: rt300@0: #endif /* defined(__tweakathlon__timeController__) */