Bytecode

Intent

Allows encoding behavior as instructions for a virtual machine.

Explanation

Real world example

A team is working on a new game where wizards battle against each other. The wizard behavior needs to be carefully adjusted and iterated hundreds of times through playtesting. It's not optimal to ask the programmer to make changes each time the game designer wants to vary the behavior, so the wizard behavior is implemented as a data-driven virtual machine.


iluwatarBehavioralGame programmingAbout 3 min
Component

Intent

The component design pattern enables developers to decouple attributes of an objects. Essentially allowing a single component to be inheritable by multiple domains/objects without linking the objects to each other. In addition to this benefit, the component design pattern allows developer to write maintainable and comprehensible code which is less likely to result in monolithic classes.


iluwatarGame programmingDomainAbout 2 min
Data Locality

Intent

Accelerate memory access by arranging data to take advantage of CPU caching.

Modern CPUs have caches to speed up memory access. These can access memory adjacent to recently accessed memory much quicker. Take advantage of that to improve performance by increasing data locality keeping data in contiguous memory in the order that you process it.


iluwatarBehavioralGame programmingPerformanceLess than 1 minute
Dirty Flag

Also known as

  • IsDirty pattern

Intent

To avoid expensive re-acquisition of resources. The resources retain their identity, are kept in some fast-access storage, and are re-used to avoid having to acquire them again.

Class diagram

Applicability


iluwatarBehavioralGame programmingPerformanceLess than 1 minute
Double Buffer

Intent

Double buffering is a term used to describe a device that has two buffers. The usage of multiple buffers increases the overall throughput of a device and helps prevents bottlenecks. This example shows using double buffer pattern on graphics. It is used to show one image or frame while a separate frame is being buffered to be shown next. This method makes animations and games look more realistic than the same done in a single buffer mode.


iluwatarBehavioralPerformanceGame programmingLess than 1 minute
Event Queue

Intent

The intent of the event queue design pattern, also known as message queues, is to decouple the relationship between the sender and receiver of events within a system. By decoupling the two parties, they do not interact with the event queue simultaneously. Essentially, the event queue handles and processes requests in an asynchronous manner, therefore, this system can be described as a first in, first out design pattern model. Event Queue is a suitable pattern if there is a resource with limited accessibility (i.e. Audio or Database), however, you need to provide access to all the requests which seeks this resource. Upon accessing an event from the queue, the program also removes it from the queue.


iluwatarConcurrencyGame programmingAbout 3 min
Game Loop

Intent

A game loop runs continuously during gameplay. Each turn of the loop, it processes user input without blocking, updates the game state, and renders the game. It tracks the passage of time to control the rate of gameplay.

This pattern decouples progression of game time from user input and processor speed.


iluwatarBehavioralGame programmingAbout 3 min
Object Pool

Also known as

Resource Pool

Intent

When objects are expensive to create and they are needed only for short periods of time it is advantageous to utilize the Object Pool pattern. The Object Pool provides a cache for instantiated objects tracking which ones are in use and which are available.


iluwatarCreationalGame programmingPerformanceAbout 1 min
Service Locator

Intent

Encapsulate the processes involved in obtaining a service with a strong abstraction layer.

Class diagram

Applicability

The service locator pattern is applicable whenever we want to locate/fetch various services using JNDI which, typically, is a redundant and expensive lookup. The service Locator pattern addresses this expensive lookup by making use of caching techniques ie. for the very first time a particular service is requested, the service Locator looks up in JNDI, fetched the relevant service and then finally caches this service object. Now, further lookups of the same service via Service Locator is done in its cache which improves the performance of application to great extent.


iluwatarArchitecturalGame programmingPerformanceLess than 1 minute
Spatial Partition

Intent

As explained in the book Game Programming Patterns by Bob Nystrom, spatial partition pattern helps to efficiently locate objects by storing them in a data structure organized by their positions.


iluwatarBehavioralPerformanceGame programmingAbout 1 min
2