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-04-25 11:28:59 +08:00
|
|
|
#else
|
|
|
|
HINSTANCE user32Dll = LoadLibraryA("user32.dll");
|
|
|
|
if (user32Dll) {
|
|
|
|
typedef BOOL(WINAPI * SetProcessDPIAwareFuncType)();
|
|
|
|
SetProcessDPIAwareFuncType setProcessDPIAwareFunc = (SetProcessDPIAwareFuncType)GetProcAddress(user32Dll, "SetProcessDPIAware");
|
|
|
|
if (setProcessDPIAwareFunc) {
|
|
|
|
if (!setProcessDPIAwareFunc())
|
|
|
|
WARN("failed to set process DPI awareness");
|
|
|
|
}
|
|
|
|
FreeLibrary(user32Dll);
|
|
|
|
}
|
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-04-16 20:29:38 +08:00
|
|
|
vector_Vector *debugText = vector_Create(1);
|
|
|
|
bool debugPressed = false;
|
2024-03-05 14:17:53 +08:00
|
|
|
|
2024-04-22 04:29:48 +08:00
|
|
|
App *app = app_NewApp();
|
|
|
|
app->window = win;
|
2024-03-04 15:05:21 +08:00
|
|
|
while (!app->wantQuit) {
|
2024-04-23 15:42:03 +08:00
|
|
|
// Check if the window is still open
|
|
|
|
// On Windows/MinGW, the loop stucks open when the window is closed
|
|
|
|
if (!IsWindow(win))
|
|
|
|
break;
|
|
|
|
|
2024-03-04 15:05:21 +08:00
|
|
|
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();
|
|
|
|
app_Render(app);
|
2024-03-05 14:17:53 +08:00
|
|
|
|
2024-04-16 20:29:38 +08:00
|
|
|
if (app->debugOn) {
|
|
|
|
app_DebugText(app, debugText);
|
|
|
|
render_DrawText(10, 10, (const char *)vector_Data(debugText));
|
|
|
|
}
|
2024-03-05 14:17:53 +08:00
|
|
|
|
2024-03-04 16:13:43 +08:00
|
|
|
EndBatchDraw();
|
2024-03-04 15:05:21 +08:00
|
|
|
|
2024-04-16 20:29:38 +08:00
|
|
|
// Check debug button status
|
|
|
|
if ((GetAsyncKeyState(VK_F3) & 0x8000) != 0) {
|
|
|
|
if (!debugPressed)
|
|
|
|
app->debugOn = !app->debugOn;
|
|
|
|
debugPressed = true;
|
|
|
|
} else
|
|
|
|
debugPressed = false;
|
|
|
|
|
2024-03-05 14:17:53 +08:00
|
|
|
|
2024-03-30 22:53:36 +08:00
|
|
|
Duration toSleep = {.microseconds = 1000000 / 200 - 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;
|
|
|
|
}
|