Update-render loop blocking message handling

Following a Direct2D tuturial I've created a realtime update&render-loop like below. But when the update&render-loop takes long (eg when I have a Sleep(5000) somewhere in the Update()), normal messages handling like clicking the close window, can have to wait up to 5s.

So what is the proper way to split the message handling and realtime update&render-loop in two separate threads?
1
2
3
4
5
6
7
8
9
10
11
12
while (message.message != WM_QUIT)
    {
        if (PeekMessage(&message, windowHandle, 0, 0, PM_REMOVE))
            DispatchMessage(&message);
        else                                             
        {
            GameController::Update();
            graphics->BeginDraw();
            GameController::Render();
            graphics->EndDraw();
        }
    }


Last edited on
The GUI is typically single threaded. You're not expected to sit around for seconds in Draw() handlers.
Why do you have a Sleep(5000)? If you tell the program to sleep for 5 seconds, that's exactly what it will do.

If you want to implement some sort of timer in your game, you can't do it as a single call, you have to have some sort of notion of "starting" a timer, and you need to check each timestep of your game if the elapsed time has passed.
Topic archived. No new replies allowed.