Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while(Run)
- {
- FILETIME GameDllLastWrite = Win32GetFileTime(DLLSourcePath);
- if (CompareFileTime(&GameDllWriteTime, &GameDllLastWrite))
- {
- Win32UnloadCode(&Win32Code, DLLCopyPath);
- BOOL CopyResult = CopyFile(DLLSourcePath, DLLCopyPath, FALSE);
- if(!CopyResult)
- {
- Win32Code = Win32LoadCode(DLLCopyPath); // we got here after we unloaded the library yet we failed to copy to allow loading the new library
- goto EndCompareTime;
- }
- Win32Code = Win32LoadCode(DLLCopyPath);
- GameDllWriteTime = GameDllLastWrite;
- EndCompareTime:
- (void)0;
- }
- MSG Msg;
- while (PeekMessageA(&Msg, WindowHandle, 0, 0, PM_REMOVE))
- {
- UINT Message = Msg.message;
- switch (Message)
- {
- case WM_KEYUP:
- case WM_KEYDOWN:
- case WM_SYSKEYDOWN:
- case WM_SYSKEYUP:
- {
- ProcessKeyboard(Message, Msg.wParam, Msg.lParam, &GameState);
- } break;
- case WM_SIZE:
- {
- ProcessResize(WindowHandle, &BitMapInfo, &Win32Code, &GameState);
- } break;
- }
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- Win32Code.GameUpdate(&GameState);
- Win32PresentBitMapToScreen(WindowHandle, DeviceContext, &BitMapInfo, GameState.BackBuffer);
- QueryPerformanceCounter(&EndingTime);
- u64 ElapsedMicroSeconds = EndingTime.QuadPart - StartingTime.QuadPart;
- ElapsedMicroSeconds *= 1000000;
- ElapsedMicroSeconds /= Frequency.QuadPart;
- #if SLEEP_ON
- u64 FrameTimeInMicroSeconds = 16000;
- u64 SleepTime = FrameTimeInMicroSeconds - ElapsedMicroSeconds; // this might wrap if we sleep for too long
- if (SleepTime > 0 && SleepTime < FrameTimeInMicroSeconds)
- {
- Sleep((DWORD)SleepTime/1000);
- }
- #endif
- QueryPerformanceCounter(&EndingTime);
- u64 ElapsedMicrosecondsAfterSleep = EndingTime.QuadPart - StartingTime.QuadPart;
- ElapsedMicrosecondsAfterSleep *= 1000000;
- ElapsedMicrosecondsAfterSleep /= Frequency.QuadPart;
- StartingTime = EndingTime; // reset our starting time
- #if DEBUG_PRINT_MS
- char Buffer[1024];
- wsprintf(Buffer, "Elapsed Microseconds = %d \t| AfterSleep =%d \t| SleepTime = %d\n", ElapsedMicroSeconds, (s32)ElapsedMicrosecondsAfterSleep, (s32)SleepTime);
- OutputDebugString(Buffer);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement