73 lines
1.4 KiB
C++
73 lines
1.4 KiB
C++
/**
|
|
* @file Test.h
|
|
* @brief 测试基类与计时工具定义。
|
|
*/
|
|
#pragma once
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include "Id.h"
|
|
|
|
|
|
#define TEST_ENTITY_COMPONENTS 0
|
|
#define TEST_WINDOW_COMPONENTS 0
|
|
#define TEST_RENDERER 1
|
|
|
|
class Test
|
|
{
|
|
public:
|
|
virtual bool initialize() = 0;
|
|
virtual void run() = 0;
|
|
virtual bool shutdown() = 0;
|
|
};
|
|
|
|
#if _WIN64
|
|
#include <Windows.h>
|
|
class time_it
|
|
{
|
|
public:
|
|
using clock = std::chrono::high_resolution_clock;
|
|
using time_stamp = std::chrono::steady_clock::time_point;
|
|
|
|
constexpr float dt_avg() const { return _dt_avg * 1e-3f; }
|
|
void begin()
|
|
{
|
|
_start = clock::now();
|
|
}
|
|
|
|
void end()
|
|
{
|
|
|
|
auto dt = clock::now() - _start;
|
|
_msg_avg += ((float)std::chrono::duration_cast<std::chrono::milliseconds>(dt).count() - _msg_avg) / (float)_counter;
|
|
++_counter;
|
|
_dt_avg = _msg_avg;
|
|
|
|
if (std::chrono::duration_cast<std::chrono::seconds>(clock::now() - _seconds).count() >= 1)
|
|
{
|
|
OutputDebugStringA("Avg. frame (ms): ");
|
|
OutputDebugStringA(std::to_string(_msg_avg).c_str());
|
|
OutputDebugStringA((" " + std::to_string(_counter)).c_str());
|
|
OutputDebugStringA(" fps");
|
|
OutputDebugStringA("\n");
|
|
_msg_avg = 0.f;
|
|
_counter = 1;
|
|
_seconds = clock::now();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
float _dt_avg{ 16.7f };
|
|
float _msg_avg{ 0.f };
|
|
int _counter{ 1 };
|
|
time_stamp _start;
|
|
time_stamp _seconds{ clock::now() };
|
|
};
|
|
|
|
|
|
#endif
|