Fun with Win32 message pump

For the last week I have been working with some circa 1999 simulator code for a flight sim (fully 3D rotating environment etc). The idea of the current development is releasing the game as a standalone/multiplayer shareware game. The code base is Win32 C++ and used to run on a dual Pentium Pro 200 machines with 256 Megabytes of RAM, plus a ~$3,000 professional OpenGL video card.

My major problem this week has been that the menu system key strokes get/got lost. After a lot fiddling/debugging and restoring original code from Subversion (god bless source control) I found that the messages (key strokes) where in the message queue, just not coming out. I could press a key (like up) and have the UI do nothing. If I then grabbed the diagnostics window and pulled it across the OpenGL window, the menu action would occur. Very strange.

The program uses the message pump to co-ordinate between threads, but as there are a few threads, and a lot of messages, it took a while before I knew what each message was doing and why.

So yesterday, I finally noticed that the number of messages might be the problem.

It turns out that the code that check for input and checking for the end of the current render cycle was running too fast that the system delayed the keyboard input.

I now have a very dirty sleep(5) in a critical place, which slows it down enough that I can explore the menu system. The problem with this is it’s easy to turn off some part of the graphics pipeline and speed the whole thing up, so that input is missed again, and thus you cannot turn the feature back on.

Anyway, in my current to-do list is change to use Direct Input to manage the keyboard/joystick, and look at a different game message pump/queue, than the main windows message pump.