#include "app.h" #include "fio.h" #include "gfx.h" #include "config.h" #include "renderer_api.h" extern void __RegisterRuntimeCVars(void); VY_CVAR_I(rt_Fullscreen, "Show window in fullscreen mode. [0/1] Default: 0", 0); VY_CVAR_I(rt_WindowWidth, "Window width. Default: 1024", 1024); VY_CVAR_I(rt_WindowHeight, "Window height. Default: 768", 768); #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include static LRESULT CALLBACK win32WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: PostQuitMessage(0); return 0; default: return DefWindowProcW(hWnd, uMsg, wParam, lParam); } } VY_DLLEXPORT int vyWin32Entry(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { __RegisterRuntimeCVars(); vy_fio_config fio_config = {0}; if (!vyInitFIO(&fio_config)) { vyReportError("FIO", "Init failed."); return 1; } WNDCLASSEXW wndclass = { .cbSize = sizeof(wndclass), .hInstance = hInstance, .lpszClassName = L"vyWndClass", .style = CS_OWNDC, .lpfnWndProc = win32WndProc, }; if (!RegisterClassExW(&wndclass)) { vyReportError("CORE", "RegisterClassEx failed: %u", GetLastError()); return 1; } HWND wnd = NULL; if (rt_Fullscreen.i) { /* Fullscreen window */ int w = GetSystemMetrics(SM_CXSCREEN); int h = GetSystemMetrics(SM_CYSCREEN); wnd = CreateWindowExW(WS_EX_APPWINDOW, L"vyWndClass", L"Voyage", WS_POPUP, 0, 0, w, h, NULL, NULL, hInstance, NULL); ShowWindow(wnd, SW_SHOW); } else { /* Windowed mode */ int w = rt_WindowWidth.i; int h = rt_WindowHeight.i; wnd = CreateWindowExW(WS_EX_APPWINDOW, L"vyWndClass", L"Voyage", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, w, h, NULL, NULL, hInstance, NULL); ShowWindow(wnd, SW_SHOW); } if (!wnd) { vyReportError("CORE", "Failed to create the game window: %u", GetLastError()); return 1; } vy_renderer_init_info renderer_info = {.hWnd = wnd, .hInstance = hInstance}; if (!vyInitGFX(&renderer_info)) { vyReportError("GFX", "Init failed."); return 1; } /* Main Loop */ bool keep_running = true; while (keep_running) { MSG msg; while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { keep_running = false; } else { TranslateMessage(&msg); DispatchMessageW(&msg); } } } vyShutdownGFX(); DestroyWindow(wnd); UnregisterClassW(L"vyWndClass", hInstance); vyShutdownFIO(); return 0; } #endif