Games (in most cases) are simulations. Traditionally, this means that you update the simulation, imagine its current state (for example, visualize the graphics) and repeat. The natural view for this is a loop.
The Win32 message pump, on the other hand, is a platform-specific feature that focuses on the event-driven applications that make up most Windows applications. This is by no means the standard for applications on all platforms, so it is not surprising that not all software fits perfectly into the model. Therefore, to make changes to a typical program suitable for the Win32 model, you usually drop this queue at a time, in one iteration of the loop, using PeekMessage until it is empty. Or you put this logic in a separate thread and use GetMessage if necessary.
For most games, given performance, there is no other practical way to do this. First, if you tried to make an event-driven game, not a poll, you will need a higher resolution than Windows, which can reliably give you if you want to maintain the high performance that many games play. Secondly, Windows is only one of the platforms on which games are written, and game processing ideal for the Win32 model will be simply an inconvenience for dedicated gaming platforms that expect a canonical game cycle.
Finally, problems with "adopting 100% CPU" are inappropriate. Most modern games are designed to be used in full screen mode with exclusive access to hardware, and not just in one of several other existing applications. Customers of such games actually require the game to make the most of their equipment, and this cannot be done if intentional Sleep () calls or updates depend on external timers that wake the application N times per second. Obviously, there are exceptions for many games, for example. those that are designed to work mainly in the window, but it is important to note the difference.
Kylotan
source share