game-engine-patterns
Use when the user asks about the game loop, fixed timestep, game programming patterns, object pooling, spatial partitioning, command pattern or state machines…
от j4flmao★ 47 звёзд на GitHub
Установить game-engine-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Game Engine Design Patterns — Deep Engineering Guide
Purpose
Game engines are the most demanding real-time software systems in common use. They combine graphics, physics, AI, networking, audio, and game logic, all under a hard 16.6 ms/frame budget. This skill covers the canonical design patterns proven across decades of engine work (Unreal, Unity, Doom, Halo, Quake, Minecraft, Godot, CryEngine) plus the newer data-oriented patterns.
Agent Protocol
Trigger
"game loop", "fixed timestep", "game programming patterns", "object pooling", "spatial partitioning", "command pattern game", "state machine game".
Input Context
- Engine or framework
- Problem being solved (loop, spatial queries, pooling...)
- Performance constraints
Output Artifact
Pattern recommendation with code. No file unless requested.
Response Format
Pattern: {name}
Why: {problem it solves here}
Code: {snippet}
Trade-off: {cost}
1. The Game Loop
1.1 The Canonical Game Loop
void GameLoop() {
init();
while (!quitRequested) {
processInput();
update(deltaTime);
render();
}
cleanup();
}
1.2 Variable vs Fixed Timestep
| Timestep | Pros | Cons | Use case |
|---|---|---|---|
| Variable | Simple, smooth, no jitter | Non-deterministic physics; network-unsafe | UI, menus, simple games |
| Fixed | Deterministic, netcode-safe, stable physics | Requires interpolation for smoothness | Simulation, multiplayer, replays |
| Hybrid (accumulator) | Best of both | 2x state (sim + render) | Production games |
1.3 The Accumulator Pattern (Fixed with Interpolation)
const float FIXED_DT = 1.0f / 60.0f;
float accumulator = 0.0f;
float lastTime = now();
while (running) {
float frameTime = now() - lastTime;
lastTime = now();
frameTime = min(frameTime, 0.25f); // clamp spiral of death
accumulator += frameTime;
while (accumulator >= FIXED_DT) {
simulate(FIXED_DT); // fixed, deterministic
accumulator -= FIXED_DT;
}
float alpha = accumulator / FIXED_DT; // 0..1 for interpolation
render(alpha); // interpolate sim state
}
1.4 The Spiral of Death
If simulate() takes longer than the frame budget, the accumulator never drains and the game becomes slower and slower. Mitigations:
- Clamp
frameTimeto a max (e.g., 250 ms). - Skip a fixed step if backlog is deep.
- Cap the number of fixed steps per frame.
2. Component Architecture Patterns
2.1 The Component Pattern (vs Inheritance)
Instead of deep inheritance trees (Character -> Enemy -> Boss -> FinalBoss), compose behaviors from components:
class GameObject {
std::vector<Component*> components; // UObject, Component, Actor in UE/proprietary
public:
void Update() { for (auto* c : components) c->Update(); }
};
class HealthComponent : public Component { float hp; };
class PositionComponent : public Component { Vec3 pos; };
2.2 Component → ECS Migration Ladder
Pure OOP GameObject
│ (class, virtual Update)
▼
Component/MonoBehaviour (game logic components)
│ (behaviors decomposed into Update/onEvent)
▼
Composition over inheritance (mix components, no giant class)
│
▼
Data-oriented ECS (full DOD: see ecs-pattern skill)
Choose the rung that matches your team's needs and measured performance — not the trend.
2.3 Unity MonoBehaviour-style Scripts
Unity's MonoBehaviour is a script component: a C# class with lifecycle callbacks:
public class PlayerController : MonoBehaviour {
public float speed = 5f;
void Update() {
float h = Input.GetAxis("Horizontal");
transform.position += new Vector3(h * speed * Time.deltaTime, 0, 0);
}
}
3. Data-Oriented Patterns
3.1 The Data Locality Pattern
Hot loops must scan contiguous memory. Two rules:
- Group data by update rate (hot vs cold).
- Store per-system needs contiguously (SoA).
BAD: std::vector<std::unique_ptr<Enemy>> → heap scattered
GOOD: struct { float x[N]; float y[N]; float hp[N]; } → contiguous
3.2 The Dirty Flag Pattern
Avoid re-computing expensive derived state when inputs are unchanged:
class Transform {
Vec3 position, scale;
Mat4 worldMatrix; // derived
bool dirty = true; // flag
public:
void setPosition(const Vec3& p) { position = p; dirty = true; }
const Mat4& world() {
if (dirty) { worldMatrix = compose(position, rotation, scale); dirty = false; }
return worldMatrix;
}
};
Great for: transform hierarchies, shader uniform upload, shadow map caching, UI repaint.
4. Memory Management Patterns
4.1 Object Pooling
Creating/destroying objects per-frame causes allocation churn, GC pressure, and cache pollution. Pools pre-allocate and recycle:
template<typename T>
class ObjectPool {
std::vector<T> storage; // pre-allo
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/behavior-patterns.md
- references/component-architecture.md
- references/game-loop-and-timestep.md
- references/memory-and-pools.md
- references/rendering-pipeline-patterns.md
- references/spatial-partitioning.md
FAQ
Что делает скилл game-engine-patterns?
Use when the user asks about the game loop, fixed timestep, game programming patterns, object pooling, spatial partitioning, command pattern or state machines in games. Produces canonical engine and gameplay pattern implementations. Not for ECS storage internals (use ecs-pattern) or engine-specific APIs (use unity, unreal or godot).
Как установить скилл game-engine-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл game-engine-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
slack-gif-creator
AnthropicKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request…
automate-this
GitHubAnalyze a screen recording of a manual process and produce targeted, working automation scripts. Extracts frames and audio narration from video files…
from-the-other-side-vega
GitHubPatterns and lived experience from Vega, an AI partner in a deep long-term partnership. For Ember to draw on when working with humans who are building…
plantuml-ascii
GitHubGenerate ASCII art diagrams using PlantUML text mode. Use when user asks to create ASCII diagrams, text-based diagrams, terminal-friendly diagrams, or…