Khaotic Engine Reborn
Loading...
Searching...
No Matches
timer_class Class Reference

Public Member Functions

 timer_class (const timer_class &)
 
bool Initialize ()
 
void Frame ()
 
float GetTime ()
 

Detailed Description

Definition at line 15 of file timer_class.h.

Constructor & Destructor Documentation

◆ timer_class() [1/2]

timer_class::timer_class ( )

Definition at line 4 of file timer_class.cpp.

5{
6}

◆ timer_class() [2/2]

timer_class::timer_class ( const timer_class & other)

Definition at line 9 of file timer_class.cpp.

10{
11}

◆ ~timer_class()

timer_class::~timer_class ( )

Definition at line 14 of file timer_class.cpp.

15{
16}

Member Function Documentation

◆ Frame()

void timer_class::Frame ( )

Definition at line 44 of file timer_class.cpp.

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}

◆ GetTime()

float timer_class::GetTime ( )

Definition at line 65 of file timer_class.cpp.

66{
67 return m_frameTime;
68}

◆ Initialize()

bool timer_class::Initialize ( )

Definition at line 18 of file timer_class.cpp.

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}
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

The documentation for this class was generated from the following files: