Game Development Reference
In-Depth Information
Understanding the game loop
The core of our game happens in the game loop . This is where all of the logic and
subsystems are processed, and the frame is rendered, many times per second. The
game loop consists of two major actions: updating and drawing .
Updating the simulation
Now we can get to the action. A game is a simulation of a world, and just like a movie
simulates motion by displaying multiple frames per second, games simulate a living
world by advancing the simulation many times per second, each time stopping to draw
a view into the current state of the game world.
The simplest update will just advance the timer, which is provided to us through the
BasicTimer class. The timer keeps track of the amount of time that has elapsed
since the previous frame, or since the timer was started—usually the start of the
game. Keeping track of the time is important because we need the frame delta (time
since the last frame) to correctly advance the simulation by just the right amount. We
also work at a millisecond level, sometimes even a fraction of a millisecond, so we
need to make use of the floating point data types to appropriately track these values.
Once the time has been updated, most games will accept and parse player input, as
this often has the most important effect on the world. Doing this before the rest of the
processing means you can act on input immediately rather than delaying by a frame.
The amount of time between an input by the player and a reaction in the game world
appearing on screen is called latency . Many games that require fast input need to
reduce or eliminate latency to ensure the player has a great experience. High latency
can make the game feel sluggish or laggy, and frustrate players.
Once we've processed the time and input, we need to process everything else re-
quired to make the game world seem alive. This can include (but is not limited to) the
following:
• Physics
• Networking
• Artificial Intelligence
• Gameplay
• Pathfinding
Search WWH ::




Custom Search