c++cwinapidirectx-11direct3d11

Continuing run even when sending WM_ENTERSIZEMOVE in Direct3D 11


I'm developing a game by Win32 and Direct3D 11, but when I move or resize the window (WM_ENTERSIZEMOVE event), the game pauses run:

GIF to explain my issue

Although it's normal in window to do this, but I want player to have ability to controlling while moving to prevent cheating, because he can repeatedly touch on title bar, which will make it stop repeatedly and become almost slow (which is a issue, my game is based on speed and reactions). So, how can I keep the game runs even when I move or resize the window?

This the code in game loop:

while (msg.message != WM_QUIT) {  
  if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    TranslateMessage(&msg), DispatchMessageW(&msg);
     
  // code of the game (renderering and mechanics)
}

And this the WndProc():

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
  switch(message) {
    case WM_CLOSE:
      DestroyWindow(hwnd);
      return 0;
    case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
  }
  return DefWindowProcW(hwnd, message, wParam, lParam);
}

I looked this question, but it talks about Direct2D (and I want Direct3D 11 from SDK DirectX 2010), and i want code to be outside function.


Solution

  • Well, I found the solution (by accident 🙂). When I tried to make the program multithreaded using std::thread, I noticed the issue was solved.

    From this, I understand that the pause condition only occurs on the same thread that WndProc() was called on by DispatchMessage().

    So, to prevent Win32 from pausing your code, run it in a separate thread.