The Game, Part 2: Main Loop
Patterns emerge in software engineering in which we realize that one solution to a recurring problem is implemented more often than any other. This is as true in game programming as it is in any other area of programming.
One such pattern is the main game loop pattern. While not every game uses this approach, most—even the vast majority—do. It is so common, in fact, that it usually isn’t even talked about as a specific pattern; it’s simply the way games are done, 9 times out of 10.
At its core, it is a simple enough concept: you typically have a single function that executes frequently—once per frame being a very common interval—which is responsible for making the core logic of the game happen. This ...