Khaotic Engine Reborn
Loading...
Searching...
No Matches
timer_class.cpp
1#include "timer_class.h"
2
3
4timer_class::timer_class()
5{
6}
7
8
9timer_class::timer_class(const timer_class& other)
10{
11}
12
13
14timer_class::~timer_class()
15{
16}
17
18bool timer_class::Initialize()
19{
20 Logger::Get().Log("Initilazing timer class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
21
22 INT64 frequency;
23
24
25 // Get the cycles per second speed for this system.
26 QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
27 if (frequency == 0)
28 {
29 Logger::Get().Log("QueryPerformanceFrequency failed", __FILE__, __LINE__, Logger::LogLevel::Error);
30 return false;
31 }
32
33 // Store it in floating point.
34 m_frequency = (float)frequency;
35
36 // Get the initial start time.
37 QueryPerformanceCounter((LARGE_INTEGER*)&m_startTime);
38
39 Logger::Get().Log("Timer class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
40
41 return true;
42}
43
44void timer_class::Frame()
45{
46 INT64 currentTime;
47 INT64 elapsedTicks;
48
49
50 // Query the current time.
51 QueryPerformanceCounter((LARGE_INTEGER*)&currentTime);
52
53 // Calculate the difference in time since the last time we queried for the current time.
54 elapsedTicks = currentTime - m_startTime;
55
56 // Calculate the frame time.
57 m_frameTime = (float)elapsedTicks / m_frequency;
58
59 // Restart the timer.
60 m_startTime = currentTime;
61
62 return;
63}
64
65float timer_class::GetTime()
66{
67 return m_frameTime;
68}
static Logger & Get()
Definition Logger.h:20
void Log(const std::string &message, const std::string &fileName, int lineNumber, LogLevel level=LogLevel::Info)
Definition Logger.h:158