-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.impl.hpp
More file actions
63 lines (51 loc) · 1.11 KB
/
timer.impl.hpp
File metadata and controls
63 lines (51 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "time.hpp"
namespace doot{
Timer::Timer(f32 fps){
setMaxUpdatesPerSecond(fps);
tInvoke= tBegin= tBeginp= current_time();
}
void Timer::setMaxUpdatesPerSecond(f32 cap){
if(cap==-1 || cap==0)
targetTime= 0_ns;
targetTime= sec(1)/cap;
}
void Timer::invoke(){
/*
|__________|________|
process wait
^tbegp ^tinvk ^tbeg
*/
tInvoke= current_time();
nsec tProcess= tInvoke-tBegin;
nsec dt= tBegin-tBeginp;
spf= 1000000.f/usec(dt);
if(!finite(spf))
spf= 0;
spf_avg= spf_avg*.8 + spf*.2;
nsec wait= targetTime-tProcess;
waiting= true;
if(wait>200_us)
sleep(wait);
else
;
waiting= false;
tBeginp= tBegin;
tBegin= current_time();
ass(finite(tBegin));
total_time+= tBegin-tBeginp;
tick++;
}
/**thisrate * k = thatrate*/
f32 Timer::getRelativeRate(Timer& that){
re that.spf/spf;
}
void profiler::start(str name_){
name= name_;
beg= current_time();
};
void profiler::stop(){
end= current_time();
cout(str("profiler: ")+name+": "+msec(end-beg)+" ms");
//"profiler: %20s: %5lli ms", (cstr)name, msec(end-beg)));
};
};