Fixed perfomance counter

* Added vert-count and draw call count
* extracted performance function to seperate header as inline functions
This commit is contained in:
2022-05-29 21:31:21 +02:00
parent 02727c74bb
commit d9f0f40ad9
4 changed files with 65 additions and 57 deletions

View File

@ -1,36 +1,18 @@
#include "BarinkEngine.h"
#include <imgui.h>
#include <chrono>
extern void Start();
extern void Update();
extern void ImmediateGraphicsDraw();
extern void Stop();
using namespace BarinkEngine;
struct EngineStatistics{
unsigned int lastSampleTime;
unsigned int frames;
float frameTime;
unsigned int FPS;
};
EngineStatistics* ES;
int main(int argc, char* argv[]) {
ES = new EngineStatistics();
ES->frames = 0;
ES->lastSampleTime = 0;
// Setup performance sampler
PerfomanceSamplerInit();
// Startup services
BarinkWindow MainWindow = BarinkWindow(800, 600);
Renderer renderer = Renderer();
InputManager InputSystem = InputManager();
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
BarinkEngine::InputManager InputSystem = BarinkEngine::InputManager();
InputSystem.attach(&MainWindow);
@ -39,27 +21,14 @@ int main(int argc, char* argv[]) {
// First call to setup game
Start();
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now().time_since_epoch()).count();
// Runtime loop
while (!MainWindow.WindowShouldClose()) {
ES->frames++;
unsigned int now = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now().time_since_epoch()).count();
unsigned int MilliSecondsPast = ES->lastSampleTime - now;
if ( MilliSecondsPast >= 1000) {
ES->FPS = 1000 / ES->frames ;
ES->frameTime = ES->frames / 1000;
ES->frames = 0;
ES->lastSampleTime = now;
}
SamplePerformance();
// Execute main logic
InputSystem.PollEvents();
Update();
@ -86,13 +55,3 @@ int main(int argc, char* argv[]) {
return 0;
}
void ShowStats() {
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove );
ImGui::Text("Frames: %i", ES->frames);
ImGui::Text("FPS: %i", ES->FPS);
ImGui::Text("Frame Time: %f", ES->frameTime);
ImGui::End();
}