if/else in your loop will process windows messages before anything. It will not block loop too long (of course if your WndProc will be good). Usually there is not so much messages. I dont think there is a better way to prevent window from stop responding and save FPS. If you will keep your message processing code good i think your loop will be great.
Here is my code, i believe it will be interesting for you, and it is quite usable. But one day i will code a new one. At least it is much better than many other. For playable game you will definitely need a stable state update() rate. Windows messages will not break it.
// Game loop paramters.
const int TICKS_PER_SECOND = 70; // Update() rate per second
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 10;
Run() function:
DWORD next_game_tick = GetTickCount();
int loops;
MSG msg = {0};
m_bIsGameRunning = true;
while( msg.message != WM_QUIT && m_bIsGameRunning )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
g_pWindow->HandleMessage(msg); // translate and dispatch the message
else
{
// *Update*
loops = 0;
while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP)
{
Update();
next_game_tick += SKIP_TICKS;
loops++;
}
// *Draw*
Render();
}
}
m_bIsGameRunning = false;