This commit is contained in:
Asuro
2025-02-08 18:54:09 +01:00
parent 149de529e6
commit aa18ffd1a5
8 changed files with 285 additions and 339 deletions

View File

@@ -41,55 +41,6 @@ namespace
Shutdown ShutdownFunc;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
LRESULT Res = 0;
switch (message)
{
default:
{
Res = DefWindowProcW(hwnd, message, wparam, lparam);
break;
}
}
return Res;
}
HWND InitWindow()
{
uint32_t startWidth = 1920;
uint32_t startHeight = 1080;
HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL);
WNDCLASSEXW wnd;
bx::memSet(&wnd, 0, sizeof(wnd));
wnd.cbSize = sizeof(wnd);
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = WndProc;
wnd.hInstance = instance;
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.lpszClassName = L"EngineWin";
wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassExW(&wnd);
HWND window = CreateWindowExW(0, L"EngineWin", L"PuzGame", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, startWidth, startHeight, NULL, NULL, instance, 0);
if (window == NULL)
{
DWORD err = GetLastError();
printf("Failed to create window: %#x!\n", err);
}
DevData.hDevDir = CreateFileW(L"cmake-build", FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (DevData.hDevDir == NULL)
{
printf("Failed to monitor dev dir!\n");
}
return window;
}
unsigned long FileWatcherThread(void* data)
{
DWORD bytesReturned = 0;
@@ -185,44 +136,28 @@ bool ReloadDLL()
int main()
{
HWND window = InitWindow();
if (window == NULL) return 1;
char PathBuf[512]{ 0 };
GetCurrentDirectory(sizeof(PathBuf), PathBuf);
printf("Current path: %s\n", PathBuf);
char PathBuf[512]{ 0 };
GetCurrentDirectory(sizeof(PathBuf), PathBuf);
if (!ReloadDLL()) return 1;
printf("Current path: %s\n", PathBuf);
DWORD fileWatcherThreadId = 0;
CreateThread(NULL, 0, FileWatcherThread, NULL, 0, &fileWatcherThreadId);
if (!ReloadDLL()) return 1;
DWORD fileWatcherThreadId = 0;
CreateThread(NULL, 0, FileWatcherThread, NULL, 0, &fileWatcherThreadId);
StartupFunc(window);
bool isRunning = true;
while (isRunning)
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
StartupFunc(nullptr);
bool isRunning = true;
while (isRunning)
{
if (DevData.FileWatcher.Change)
{
if (msg.message == WM_QUIT)
{
isRunning = false;
}
DevData.FileWatcher.Change = false;
ShutdownFunc();
ReloadDLL();
StartupFunc(nullptr);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (DevData.FileWatcher.Change)
{
DevData.FileWatcher.Change = false;
ShutdownFunc();
ReloadDLL();
StartupFunc(window);
}
UpdateFunc();
}
return 0;
UpdateFunc();
}
return 0;
}