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