JacksEscape/Main.cpp

38 lines
909 B
C++
Raw Normal View History

2024-03-04 15:05:21 +08:00
#include <cwchar>
2024-03-01 14:38:18 +08:00
#include <graphics.h>
2024-03-01 15:06:58 +08:00
#include <stdio.h>
2024-03-04 15:05:21 +08:00
#include "App.h"
2024-03-01 15:06:58 +08:00
#include "Types.h"
2024-03-01 14:38:18 +08:00
int main() {
2024-03-01 15:06:58 +08:00
TimePoint startup = time_Now();
2024-03-04 15:05:21 +08:00
TimePoint lastFrame, lastUpdate, frameCounter;
lastFrame = lastUpdate = frameCounter = time_Now();
int frameCount = 0;
2024-03-01 15:06:58 +08:00
2024-03-04 15:05:21 +08:00
initgraph(1280, 720);
App *app = app_NewApp();
while (!app->wantQuit) {
if (time_Since(frameCounter).microseconds >= 1000000) { // 1 sec
Duration d = time_Reset(&frameCounter);
fprintf(stderr, "[Main] %d frames in the last %.4lf seconds\n", frameCount, duration_Seconds(d));
frameCount = 0;
}
frameCount++;
app_Advance(app, time_Reset(&lastUpdate));
2024-03-01 15:06:58 +08:00
2024-03-04 15:05:21 +08:00
app_Render();
Duration toSleep = {.microseconds = 1000000 / 30 - time_Reset(&lastFrame).microseconds};
duration_Sleep(toSleep);
}
closegraph();
2024-03-01 15:06:58 +08:00
printf("%.6lf seconds has elapsed\n", duration_Seconds(time_Since(startup)));
2024-03-01 14:38:18 +08:00
return 0;
}