Clean up of sandbox
* Added a statistics panel * Added comments to `Sandbox.cpp` * Moved utility functions and GUI code out of sandbox.cpp
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
#include "BarinkEngine.h"
|
||||
#include <imgui.h>
|
||||
#include <chrono>
|
||||
|
||||
|
||||
extern void Start();
|
||||
extern void Update();
|
||||
@ -9,7 +11,20 @@ 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;
|
||||
|
||||
// Startup services
|
||||
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
||||
@ -24,8 +39,27 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
InputSystem.PollEvents();
|
||||
|
||||
Update();
|
||||
@ -35,6 +69,8 @@ int main(int argc, char* argv[]) {
|
||||
ImmediateGraphicsDraw();
|
||||
|
||||
GUISystem.Render();
|
||||
|
||||
|
||||
|
||||
MainWindow.SwapBuffers();
|
||||
}
|
||||
@ -45,9 +81,18 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
|
||||
// Shutdown Services
|
||||
|
||||
delete ES;
|
||||
|
||||
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();
|
||||
|
||||
}
|
@ -16,6 +16,6 @@
|
||||
#include "Graphics/GUI/GUIManager.h"
|
||||
#include "Scene.h"
|
||||
|
||||
void WARN(std::string message);
|
||||
|
||||
|
||||
void ShowStats();
|
@ -2,6 +2,8 @@
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 MatColour;
|
||||
|
||||
void main(){
|
||||
FragColor = vec4(0.5f, 0.5f, 0.0f , 1.0f);
|
||||
FragColor = vec4(MatColour, 1.0f);
|
||||
}
|
Reference in New Issue
Block a user