Patrones en los videojuegos I: Patrones de Arquitectura

by Aitor Llamas Jiménez 11/2/2021
building-blocksvideogames-developmentarchitecture-patterns
Archivado
Este artículo se publicó originalmente en mi antiguo blog de tecnología: Building Blocks. Actualmente está archivado y probablemente obsoleto.

As both a software developer and a gamer, I’ve always been interested on differences between software and game development. In this article series I will cover some software patterns I find interesting from the game development industry.

Game Loop

Game Loop

When talking about game development patterns the most important one is the Game Loop. Every videogame runs inside a Game Loop. Unlike most other software, games keep moving even when the user isn’t providing input. For this reason, we need to make a loop that processes user input, but doesn’t wait for it.

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.

Read more about this pattern

Object Pool

Object Pool

The object pool tries to improve performance and memory use by reusing objects from a fixed pool instead of allocating and freeing them individually.

Define a pool class that maintains a collection of reusable objects. Each object supports an “in use” query to tell if it is currently “alive”. When the pool is initialized, it creates the entire collection of objects up front (usually in a single contiguous allocation) and initializes them all to the “not in use” state.

When you want a new object, ask the pool for one. It finds an available object, initializes it to “in use”, and returns it. When the object is no longer needed, it is set back to the “not in use” state. This way, objects can be freely created and destroyed without needing to allocate memory or other resources.

This pattern is used widely in games for obvious things like game entities and visual effects, but it is also used for less visible data structures such as currently playing sounds. Use Object Pool when:

Read more about this pattern

Entity Component System

ECS (“Entity Component System”) describes a design approach which promotes code reusability by separating data from behavior. Data is often stored in cache-friendly ways which benefits performance. An ECS has the following characteristics:

Read more about this pattern