-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cpp
More file actions
54 lines (47 loc) · 1.2 KB
/
Copy pathtimer.cpp
File metadata and controls
54 lines (47 loc) · 1.2 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
//-----------------------------------------------------------------------------
// File: timer.cpp
//
// Implementation of the timer
//-----------------------------------------------------------------------------
#include "timer.h"
#include "maths.h"
#include "win.h"
#include <memory>
#include "mem.h"
#define new mem_new
timer_t&
timer_t::get_instance()
{
static std::auto_ptr<timer_t> instance(new timer_t());
return *instance;
}
bool
timer_t::init()
{
LARGE_INTEGER li;
if (QueryPerformanceFrequency(&li)) {
cpu_frequency = li.QuadPart;
return cpu_frequency != 0;
}
return false;
}
void
timer_t::start(timerid_t timerid)
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
timers[timerid].start_ticks = li.QuadPart;
timers[timerid].mark_ticks = li.QuadPart;
timers[timerid].elapsed_time = 0.0f;
timers[timerid].mark_time = 0.0f;
}
void
timer_t::mark(timerid_t timerid)
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
__int64 now = li.QuadPart;
timers[timerid].elapsed_time = (m_lltof(now) - m_lltof(timers[timerid].mark_ticks)) / m_lltof(cpu_frequency);
timers[timerid].mark_ticks = now;
timers[timerid].mark_time = (m_lltof(now) - m_lltof(timers[timerid].start_ticks)) / m_lltof(cpu_frequency);
}