/
redgpu
/
nv_rt
Обзор
Документация
Войти
/
redgpu
/
nv_rt
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
External/NRIFramework/Source/Timer.cpp
64 строки
2 KB
Constantine Tarasenkov
NRDSample commit 3dd5136f292ad958c698627d2ee19959a4117f7e, NRI commit b5cfe2c4161ccc39421041ba9ec55331af9221d1
19 апр 2024, 05:54
19 апр 2024, 05:54
491b2d5
Код
Авторство
О чём код?
#include "Timer.h" #include <math.h> #if defined(_WIN32) #include <windows.h> #elif defined(__linux__) || defined(__SCE__) || defined(__APPLE__) #include <time.h> #ifdef USE_MONOTONIC_TIMER constexpr clockid_t CLOCKID = CLOCK_MONOTONIC; #else constexpr clockid_t CLOCKID = CLOCK_REALTIME; #endif #else #error "Undefined platform" #endif #define MY_MIN( a, b ) ( a < b ? a : b ) #define MY_MAX( a, b ) ( a > b ? a : b ) inline uint64_t _GetTicks() { #if defined(_WIN32) uint64_t ticks; QueryPerformanceCounter((LARGE_INTEGER*)&ticks); return ticks; #elif defined(__linux__) || defined(__SCE__) || defined(__APPLE__) struct timespec spec; clock_gettime(CLOCKID, &spec); return uint64_t(spec.tv_sec) * 1000000000ull + spec.tv_nsec; #endif } Timer::Timer() { #if defined(_WIN32) uint64_t ticksPerSecond = 1; QueryPerformanceFrequency((LARGE_INTEGER*)&ticksPerSecond); m_InvTicksPerMs = 1000.0 / ticksPerSecond; #elif defined(__linux__) || defined(__SCE__) || defined(__APPLE__) m_InvTicksPerMs = 1.0 / 1000000.0; #endif } void Timer::UpdateFrameTime() { if (m_Time != 0) { double ms = (_GetTicks() - m_Time) * m_InvTicksPerMs; m_Delta = float(ms); float relativeDelta = fabsf(m_Delta - m_SmoothedDelta) / (MY_MIN(m_Delta, m_SmoothedDelta) + 1e-7f); float f = relativeDelta / (1.0f + relativeDelta); m_SmoothedDelta = m_SmoothedDelta + (m_Delta - m_SmoothedDelta) * MY_MAX(f, 1.0f / 32.0f); m_VerySmoothedDelta = m_VerySmoothedDelta + (m_Delta - m_VerySmoothedDelta) * MY_MAX(f, 1.0f / 64.0f); } m_Time = _GetTicks(); } double Timer::GetTimeStamp() const { return _GetTicks() * m_InvTicksPerMs; }