2022-05-28 11:32:17 +00:00
|
|
|
#include "BarinkEngine.h"
|
2022-05-28 16:49:08 +00:00
|
|
|
#include <imgui.h>
|
2022-05-29 13:23:08 +00:00
|
|
|
#include <chrono>
|
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
extern void Start();
|
2022-05-28 16:49:08 +00:00
|
|
|
extern void Update();
|
2022-05-28 19:19:16 +00:00
|
|
|
extern void ImmediateGraphicsDraw();
|
2022-05-28 16:49:08 +00:00
|
|
|
extern void Stop();
|
2022-05-27 20:47:36 +00:00
|
|
|
|
|
|
|
using namespace BarinkEngine;
|
|
|
|
|
|
|
|
|
2022-05-29 13:23:08 +00:00
|
|
|
struct EngineStatistics{
|
|
|
|
unsigned int lastSampleTime;
|
|
|
|
unsigned int frames;
|
|
|
|
float frameTime;
|
|
|
|
unsigned int FPS;
|
|
|
|
};
|
|
|
|
|
|
|
|
EngineStatistics* ES;
|
|
|
|
|
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
int main(int argc, char* argv[]) {
|
2022-05-29 13:23:08 +00:00
|
|
|
ES = new EngineStatistics();
|
|
|
|
ES->frames = 0;
|
|
|
|
ES->lastSampleTime = 0;
|
2022-05-27 20:47:36 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
// Startup services
|
2022-05-28 19:19:16 +00:00
|
|
|
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
2022-05-27 20:47:36 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
Renderer renderer = Renderer();
|
|
|
|
InputManager InputSystem = InputManager();
|
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
InputSystem.attach(&MainWindow);
|
2022-05-28 16:49:08 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
GUIManager GUISystem = GUIManager(&MainWindow);
|
2022-05-28 16:49:08 +00:00
|
|
|
|
|
|
|
// First call to setup game
|
2022-05-28 19:19:16 +00:00
|
|
|
Start();
|
2022-05-27 20:47:36 +00:00
|
|
|
|
2022-05-29 13:23:08 +00:00
|
|
|
|
|
|
|
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
// Runtime loop
|
2022-05-28 19:19:16 +00:00
|
|
|
while (!MainWindow.WindowShouldClose()) {
|
2022-05-29 13:23:08 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
InputSystem.PollEvents();
|
|
|
|
|
|
|
|
Update();
|
|
|
|
|
|
|
|
renderer.Render();
|
2022-05-27 20:47:36 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
ImmediateGraphicsDraw();
|
2022-05-28 16:49:08 +00:00
|
|
|
|
|
|
|
GUISystem.Render();
|
2022-05-29 13:23:08 +00:00
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
MainWindow.SwapBuffers();
|
2022-05-27 20:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
// Shutdown game
|
|
|
|
Stop();
|
2022-05-27 20:47:36 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
|
|
|
|
// Shutdown Services
|
2022-05-29 13:23:08 +00:00
|
|
|
delete ES;
|
2022-05-27 20:47:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-29 13:23:08 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
}
|