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"
|
2024-03-05 14:17:53 +08:00
|
|
|
#include "easyx.h"
|
2024-03-05 11:40:42 +08:00
|
|
|
#include "types.h"
|
2024-03-05 14:17:53 +08:00
|
|
|
#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-25 21:10:40 +08:00
|
|
|
#ifdef __MINGW32__
|
2024-03-05 15:37:36 +08:00
|
|
|
SetProcessDPIAware();
|
2024-03-25 21:10:40 +08:00
|
|
|
#endif
|
2024-03-19 11:59:09 +08:00
|
|
|
HWND win = initgraph(SCREEN_WIDTH, SCREEN_HEIGHT);
|
2024-03-05 11:55:26 +08:00
|
|
|
SetWindowTextA(win, "JacksEscape");
|
2024-03-04 15:05:21 +08:00
|
|
|
|
2024-03-25 21:10:40 +08:00
|
|
|
#ifdef __MINGW32__
|
2024-03-05 14:17:53 +08:00
|
|
|
settextstyle(TEXTHEIGHT, 0, "Courier New");
|
2024-03-25 21:10:40 +08:00
|
|
|
#else // MSVC
|
|
|
|
settextstyle(TEXTHEIGHT, 0, L"Courier New");
|
|
|
|
#endif
|
2024-03-05 14:17:53 +08:00
|
|
|
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);
|
2024-03-05 14:17:53 +08:00
|
|
|
|
|
|
|
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 14:17:53 +08:00
|
|
|
|
2024-03-05 15:20:32 +08:00
|
|
|
Duration toSleep = {.microseconds = 1000000 / 300 - time_Reset(&lastFrame).microseconds};
|
2024-03-04 15:05:21 +08:00
|
|
|
duration_Sleep(toSleep);
|
|
|
|
}
|
|
|
|
|
|
|
|
closegraph();
|
2024-03-28 14:04:43 +08:00
|
|
|
app_DeleteApp(app);
|
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;
|
|
|
|
}
|