Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Archives
Today
Total
관리 메뉴

For me

[DirectX12] 6) Timer 본문

DirectX12

[DirectX12] 6) Timer

GiveZero 2023. 1. 15. 22:50

Unity의 DeltaTime을 사용하기 위해 구현하고,

게임 내 FPS를 확인하기 위하여 구현

 

Timer.h

더보기
#pragma once


class Timer
{
	DECLARE_SINGLE(Timer);
public:
	void Init();
	void Update();

	uint32 GetFps() { return _fps; }
	float GetDeltaTime() { return _deltaTime; }

private:
	uint64	_frequency = 0;
	uint64	_prevCount = 0;
	float	_deltaTime = 0.f;

private:
	uint32	_frameCount = 0;
	float	_frameTime = 0.f;
	uint32	_fps = 0;
};

 

Timer.cpp

더보기
#include "Timer.h"

void Timer::Init()
{
	::QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&_frequency));
	::QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&_prevCount)); // CPU 클럭
}

void Timer::Update()
{
	uint64 currentCount;
	::QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&currentCount));

	_deltaTime = (currentCount - _prevCount) / static_cast<float>(_frequency);
	_prevCount = currentCount;

	_frameCount++;
	_frameTime += _deltaTime;

	if (_frameTime > 1.f)
	{
		_fps = static_cast<uint32>(_frameCount / _frameTime);

		_frameTime = 0.f;
		_frameCount = 0;
	}
}

'DirectX12' 카테고리의 다른 글

[DirectX12] 8) Material  (0) 2023.01.16
[DirectX12] 7) Component  (0) 2023.01.16
[DirectX12] 5) Input  (0) 2023.01.15
[DirectX12] 4) Texture Mapping  (0) 2023.01.15
[DirectX12] 3) DirectX12 초기화 - 2  (0) 2023.01.15