JacksEscape/main.cpp

55 lines
1.3 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 "easyx.h"
2024-03-05 11:40:42 +08:00
#include "types.h"
#include "render_util.h"
#include "util/vector.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
settextstyle(TEXTHEIGHT, 0, "Courier New");
vector_Vector *debugText = vector_Create(1);
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);
app_DebugText(app, debugText);
render_DrawText(10, 10, (const char *)vector_Data(debugText));
2024-03-04 16:13:43 +08:00
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;
}