-
Notifications
You must be signed in to change notification settings - Fork 3
/
TimeOps.h
33 lines (25 loc) · 955 Bytes
/
TimeOps.h
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
//----------------------------------------------------------------------------------------------------------------------
// Time related routines
// Copyright (c) 2024 Samuel Gomes
//----------------------------------------------------------------------------------------------------------------------
#pragma once
#include <cstdint>
/// @brief GetTicks returns the number of "ticks" (ms) since the program started execution where 1000 "ticks" (ms) = 1 second.
/// @return Ticks in ms.
extern int64_t GetTicks();
/// @brief Calculates and returns the Hertz when repeatedly called inside a loop
/// @return A positive Hertz value
uint32_t Time_GetHertz()
{
static uint32_t counter = 0, finalFPS = 0;
static uint64_t lastTime = 0;
uint64_t currentTime = GetTicks();
if (currentTime >= lastTime + 1000)
{
lastTime = currentTime;
finalFPS = counter;
counter = 0;
}
++counter;
return finalFPS;
}