In this chapter, we will use a classic design pattern named Command to implement a replay system for our racing game. Its mechanism will record the player's controller inputs and the corresponding timestamp. This approach will permit us to play back the recorded inputs in the proper order and with the correct timing.
Replay features are often a must-have in racing games. With the Command pattern, we are going to implement this system in a scalable and modular manner. This pattern proposes a mechanism that permits encapsulating information needed to perform an "action" or trigger a state change. It also decouples the requester of an "action" from the object that will perform it. This encapsulation and decoupling permit us to queue action requests so we can execute them at a later time.
All of this might...