Skip to content

About

Robert Nystrom's Game Programming Patterns, implemented in C++ on top of Storm Engine v2 with igloo specs.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Game Programming Patterns

Worked examples from Robert Nystrom's Game Programming Patterns, implemented in C++ on top of Storm Engine v2.

Each pattern is a self-contained example under patterns/<category>/<name>/, with its own engine shell (Game + GameStateMachine + a PlayState), igloo specs, and README. Categories follow the book's structure.

The Patterns

Design Patterns Revisited — patterns/design/

Pattern Status Reference
Command ✅ chapter
Flyweight ✅ chapter
Observer ✅ chapter
Prototype ✅ chapter
Singleton ✅ chapter
State ✅ chapter

Sequencing Patterns — patterns/sequencing/

Pattern Status Reference
Double Buffer ✅ chapter
Game Loop ✅ chapter
Update Method ✅ chapter

Behavioral Patterns — patterns/behavioral/

Pattern Status Reference
Bytecode ✅ chapter
Subclass Sandbox ✅ chapter
Type Object ✅ chapter

Decoupling Patterns — patterns/decoupling/

Pattern Status Reference
Component ✅ chapter
Event Queue ✅ chapter
Service Locator ✅ chapter

Optimization Patterns — patterns/optimization/

Pattern Status Reference
Data Locality ✅ chapter
Dirty Flag ✅ chapter
Object Pool ✅ chapter
Spatial Partition ✅ chapter

Requirements

  • Storm Engine v2 — nothing to install. It is a submodule at external/storm-engine-v2, pinned to the revision these examples are written against, and the build compiles it from there. Clone with submodules:

    git clone --recurse-submodules <this repo>

    Already cloned without them? make engine fetches and builds the pinned revision. Nothing is installed system-wide, and the build deliberately has no "use the system engine instead" path — that is how a local build and CI came to run different engines (2.3.0 here, 2.3.1 in CI) without either saying so.

  • SDL2, SDL2_image, SDL2_ttf, SDL2_mixer

  • igloo (header-only test framework)

Staying up to date with the engine

The submodule pins a commit, so a build is reproducible until someone moves it on purpose:

make engine-update    # advance the pin to the engine's newest main, and rebuild
make engine-version   # which revision is pinned

An automatic "always newest" was rejected: a red build should be traceable to a commit in this repo, not to one that landed in the engine five minutes ago.

Build, run, test

The font the demos draw with is shared (include/pixelFont.h + its SDL drawer), and its spec lives in patterns/__shared__/ — that folder is not a pattern; __template__ is the one to copy.

Each pattern builds independently from its own directory (binaries land in the repo-root bin/):

cd patterns/design/command
make            # builds the example
make run
make test       # builds the igloo specs
make run-test

Adding a new pattern

  1. Copy patterns/__template__/ to patterns/<category>/<name>/.
  2. In its Makefile, set NAME and make the include path point at the root common.mk (../../../common.mk for a <category>/<name> folder).
  3. Replace REPLACEME in src/game.cpp (window title) and the README (including its reference link).
  4. Implement the pattern in src/states/playState.cpp (and add classes under src/), with specs under specs/.
  5. Flip the pattern's status to ✅ above.

The shared build config lives in common.mk; it locates the repo root from its own path, so patterns work at any folder depth. It builds against the pinned engine via engine.mk, and force-includes include/engineGlobal.h — a bridge that puts the engine's namespace storm names back in the global scope so the pattern code reads GameState rather than storm::GameState.

About

Robert Nystrom's Game Programming Patterns, implemented in C++ on top of Storm Engine v2 with igloo specs.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Sponsor this project

Packages

Contributors

Languages