Skip to main content
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.


iluwatarAbout 4 minBehavioralGame programming
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.


iluwatarAbout 2 minBehavioralGame programmingDomain
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.


iluwatarLess than 1 minuteBehavioralGame programmingPerformance
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

Dirty Flag

iluwatarLess than 1 minuteBehavioralGame programmingPerformance
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.


iluwatarAbout 3 minBehavioralPerformanceGame programming
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.


iluwatarAbout 3 minConcurrencyGame programming
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.


iluwatarAbout 2 minBehavioralGame programming
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.


iluwatarAbout 1 minCreationalGame programmingPerformance
Service Locator

Intent

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

Class diagram

Service Locator

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.


iluwatarLess than 1 minuteArchitecturalGame programmingPerformance
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.


iluwatarAbout 1 minBehavioralPerformanceGame programming