JacksEscape/main.cpp

44 lines
1.0 KiB
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-05 11:40:42 +08:00
#include "app.h"
#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-05 11:55:26 +08:00
HWND win = initgraph(1280, 720);
SetWindowTextA(win, "JacksEscape");
2024-03-04 15:05:21 +08:00
App *app = app_NewApp();
while (!app->wantQuit) {
if (time_Since(frameCounter).microseconds >= 1000000) { // 1 sec
2024-03-05 11:55:26 +08:00
/* Duration d = */ time_Reset(&frameCounter);
char buf[128];
snprintf(buf, sizeof(buf) - 1, "JacksEscape (%d FPS)", frameCount);
SetWindowTextA(win, buf);
2024-03-04 15:05:21 +08:00
frameCount = 0;
}
frameCount++;
app_Advance(app, time_Reset(&lastUpdate));
2024-03-01 15:06:58 +08:00
2024-03-04 16:13:43 +08:00
BeginBatchDraw();
cleardevice();
app_Render(app);
EndBatchDraw();
2024-03-04 15:05:21 +08:00
2024-03-05 11:55:26 +08:00
Duration toSleep = {.microseconds = 1000000 / 60 - time_Reset(&lastFrame).microseconds};
2024-03-04 15:05:21 +08:00
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;
}