rt300@0
|
1 //
|
rt300@0
|
2 // timeController.h
|
rt300@0
|
3 // tweakathlon
|
rt300@0
|
4 //
|
rt300@0
|
5 // Created by Robert Tubb on 10/02/2014.
|
rt300@0
|
6 //
|
rt300@0
|
7 //
|
rt300@0
|
8
|
rt300@0
|
9 #ifndef __tweakathlon__timeController__
|
rt300@0
|
10 #define __tweakathlon__timeController__
|
rt300@0
|
11 #include "ofMain.h"
|
rt300@0
|
12 #include <iostream>
|
rt300@0
|
13 #include "boost/function.hpp"
|
rt300@0
|
14 #include <boost/bind.hpp>
|
rt300@0
|
15 #import "TimedCallController.h"
|
rt300@0
|
16
|
rt300@0
|
17 typedef boost::function<void(void)> TimerCallbackFunction;
|
rt300@0
|
18 typedef map<unsigned long long, TimerCallbackFunction> TimesAndCallsMap;
|
rt300@0
|
19 typedef std::pair<unsigned long long, TimerCallbackFunction> TimeAndCallPair;
|
rt300@0
|
20
|
rt300@0
|
21 typedef unsigned long long TimerID; // the id is just the time it's set to fire, microsecs(?)
|
rt300@0
|
22 typedef unsigned long long TimerMicrosec; //microsecs(?)
|
rt300@0
|
23 typedef unsigned long long TimerMillisec;
|
rt300@0
|
24
|
rt300@0
|
25 class TimeController{
|
rt300@0
|
26
|
rt300@0
|
27 public:
|
rt300@0
|
28
|
rt300@0
|
29
|
rt300@0
|
30 //----------------
|
rt300@0
|
31 //----------------
|
rt300@0
|
32 void init(){
|
rt300@0
|
33 iosTimer = [[TimedCallController alloc] init];
|
rt300@0
|
34 [iosTimer setAppRef:(id)this];
|
rt300@0
|
35 };
|
rt300@0
|
36
|
rt300@0
|
37 //----------------
|
rt300@0
|
38 // called from testApp.update()
|
rt300@0
|
39 void tick(){
|
rt300@0
|
40 TimerID timeNow = getMicrosecTimeNow();
|
rt300@0
|
41 callAndEraseAllExpired(timeNow);
|
rt300@0
|
42
|
rt300@0
|
43 };
|
rt300@0
|
44
|
rt300@0
|
45 //----------------
|
rt300@0
|
46 void cancelEvent(TimerID which);
|
rt300@0
|
47 //----------------
|
rt300@0
|
48 TimerID scheduleEvent(TimerCallbackFunction cbfunc, int howLongMillisec);
|
rt300@0
|
49 //----------------
|
rt300@0
|
50 void startStopwatch();
|
rt300@0
|
51 TimerMicrosec stopStopwatch();
|
rt300@0
|
52 TimerMicrosec getStopwatchElapsedTime();
|
rt300@0
|
53
|
rt300@0
|
54 void startCountDown(){
|
rt300@0
|
55
|
rt300@0
|
56 };
|
rt300@0
|
57 void countdownFinished(){
|
rt300@0
|
58
|
rt300@0
|
59 };
|
rt300@0
|
60 //----------------
|
rt300@0
|
61
|
rt300@0
|
62 private:
|
rt300@0
|
63 TimesAndCallsMap timesAndCalls;
|
rt300@0
|
64 TimerMillisec stopWatchStartTime; // millisec
|
rt300@0
|
65 bool stopWatchRunning;
|
rt300@0
|
66 //----------------
|
rt300@0
|
67 void callAndEraseAllExpired(TimerMicrosec timeNow);
|
rt300@0
|
68
|
rt300@0
|
69 TimedCallController* iosTimer;
|
rt300@0
|
70
|
rt300@0
|
71 TimerMicrosec getMicrosecTimeNow(){
|
rt300@0
|
72 double time_sec = [NSDate timeIntervalSinceReferenceDate];
|
rt300@0
|
73 return TimerMicrosec(time_sec*1000000);
|
rt300@0
|
74 }
|
rt300@0
|
75
|
rt300@0
|
76 };
|
rt300@0
|
77
|
rt300@0
|
78
|
rt300@0
|
79
|
rt300@0
|
80 #endif /* defined(__tweakathlon__timeController__) */
|