2022-05-29 19:31:21 +00:00
|
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
struct EngineStatistics {
|
2022-07-09 20:21:56 +00:00
|
|
|
long long lastSampleTime;
|
2022-05-29 19:31:21 +00:00
|
|
|
float frameTime;
|
|
|
|
uint32_t verts;
|
|
|
|
uint32_t DC;
|
|
|
|
|
2022-07-09 20:21:56 +00:00
|
|
|
long long frames;
|
|
|
|
long long FPS;
|
2022-05-29 19:31:21 +00:00
|
|
|
};
|
|
|
|
extern EngineStatistics* ES;
|
|
|
|
|
|
|
|
inline void PerfomanceSamplerInit(){
|
|
|
|
ES = new EngineStatistics();
|
|
|
|
ES->frames = 0;
|
|
|
|
ES->lastSampleTime = 0;
|
|
|
|
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
2022-07-09 20:21:56 +00:00
|
|
|
|
2022-05-29 19:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SamplePerformance(void) {
|
|
|
|
ES->frames++;
|
|
|
|
ES->DC = 0;
|
|
|
|
ES->verts = 0;
|
2022-07-09 20:21:56 +00:00
|
|
|
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
|
|
|
unsigned long long MilliSecondsPast = now - ES->lastSampleTime;
|
2022-05-29 19:31:21 +00:00
|
|
|
if (MilliSecondsPast >= 1000) {
|
|
|
|
|
|
|
|
ES->frameTime = (float)1000 / ES->frames;
|
|
|
|
ES->FPS = ES->frames;
|
|
|
|
ES->frames = 0;
|
|
|
|
ES->lastSampleTime = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void ShowStats() {
|
|
|
|
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
|
|
|
|
|
|
|
ImGui::Text("FPS: %i", ES->FPS);
|
|
|
|
ImGui::Text("Frame Time: %f", ES->frameTime);
|
|
|
|
ImGui::Text("Verts: %i", ES->verts);
|
|
|
|
ImGui::Text("Draw Calls: %i", ES->DC);
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
}
|