GAMES104 Modern Game Engine - How to Build a Game World

Words: 482

Composition of the Game World

CategoryExamplesAbstraction in the Engine
Dynamic objectsTanks, drones, NPCsGameObject (GO)
Static objectsHouses, hangars, watchtowersGameObject
EnvironmentTerrain, sky, vegetationSeparate systems (terrain system, TOD)
Invisible objectsAir walls, triggers, rulesGameObject

Conclusion: everything is a GameObject (abbreviated as GO).


Component-Based Architecture

Why Not Deep Inheritance

  • Diamond problem of multiple inheritance (is an amphibious tank a “vehicle” or a “boat”?)
  • Code bloat and maintenance difficulty

Component-Based Solution

Split “properties” and “behaviors” into independent Components and assemble them as needed:

Drone ExampleCorresponding Component
Spatial positionTransform
AppearanceModel/Mesh
Movement capabilityMotor
HealthHealth
AI patrolAI_Patrol
Attack behaviorCombat

Advantages:

  1. Composition > inheritance
  2. Dynamic add/remove at runtime (Unity/UE)
  3. Data and behavior are decoupled, which helps parallel and batch processing (ECS later)

Making the World Move: Tick Mechanism

  • Tick = the engine advances the world by one step at every fixed frame interval (e.g., 33 ms)
  • Every Component implements Tick(float deltaTime):
    1. Motor updates position
    2. Animation updates bones
    3. Physics updates colliders
    4. Combat detects firing
  • To improve cache hit rates, modern engines batch Tick by system (first tick all Motors, then all Animations…)

Inter-Object Communication: Event System

Direct Call (Tight Coupling)Event Mail (Loose Coupling)
Shell explodes → call takeDamage() on each nearby object one by oneShell explodes → PostEvent(“Damage”, 100) → nearby objects check their mail on the next Tick and lose health
  • Mailbox model = determinism + extensibility
  • Implementation details: string hashing / RTTI / reflection (UE Blueprint, Unity SendMessage)

Scene Management: From Brute-Force Traversal to Spatial Acceleration

MethodCore IdeaSuitable For
Brute force O(n²)Traverse all objects every frameSmall demos
Uniform gridDivide the world into cells; check only neighboring cellsUniformly distributed objects
Quadtree / OctreeRecursive subdivision; empty regions are no longer split2D/3D sparse worlds
BVHMerge bounding boxes bottom-upMany dynamic objects; fast updates

Engines usually ship with multiple structures built in, so products can switch based on the characteristics of the scene.


Advanced Topics

ProblemCommon Strategy
Event ordering issueIntroduce a post office concept, rather than having every component trigger or listen to events arbitrarily
Tick takes too longTime compensation / frame skipping / batched processing (deferred processing)
Render thread and logic thread synchronizationLogic ticks first → writes a snapshot → render thread consumes it, with an extra 1~2 frames of latency
Drawbacks of the component patternQuery overhead, cache-unfriendly → the advanced course introduces ECS (SOA + System batching)
Physics and animation couplingAnimation provides the initial pose → physics simulation → animation blends the interpolated result back, achieving “realistic, satisfying falls”
Event debuggingVisualized mail: 3D floating text, frame-by-frame Pause, Log flood

One-Sentence Summary

The game world = a GameObject container + Component assembly + Tick advancement + Event communication + spatial index acceleration.
Understand these five steps, and you have the “map” for writing an engine by hand.

Reference Information

This post contains some AI-assisted content, reviewed and edited by the author before publishing.
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...