Welcome to World Engine
Relevant source files
The following files were used as context for generating this wiki page:
World Engine provides a Gamechain SDK for building high-performance decentralized games. It uses a sharded rollup architecture to manage complex game states across multiple execution environments. The core of the engine is the "Cardinal" framework, which implements a high-performance Entity Component System (ECS) to handle game logic and state transitions.
The project organizes game logic into shards, where each shard represents a distinct execution unit. Developers configure these shards using a centralized configuration and interact with them through a standardized microservice addressing system.
Sources: README.md:12-14, pkg/template/basic/world.toml, proto/worldengine/micro/v1/service.proto:20-25
Core Architecture
World Engine separates state management, execution logic, and networking into distinct layers. The architecture centers on the Cardinal ECS and a microservice-based communication protocol.
Cardinal ECS
The Cardinal ECS manages game entities and their associated data. It uses an archetype-based storage system where entities with identical component sets are stored together for efficient iteration.
- World: Acts as the root container for the ECS state, managing initialization, system scheduling, and tick execution.
- Entities: Unique identifiers representing game objects.
- Components: Pure data structures attached to entities.
- Systems: Logic functions that operate on entities filtered by component composition.
Sources: pkg/cardinal/internal/ecs/world.go:12-21, coverage_ecs.html (Archetype Section)
Sharding and Configuration
The engine supports horizontal scaling through sharding. Each shard is an independent instance of the game logic. Configuration defines the organization, project, and the list of active shards.
The diagram shows the relationship between a project and its multiple shards, each hosting an independent Cardinal ECS instance.
Sources: pkg/template/basic/world.toml, pkg/template/multi-shard/world.toml
Tick Lifecycle
World Engine processes state changes in discrete units called Ticks. A Tick executes registered systems in a specific sequence to ensure deterministic state transitions.
System Execution Phases
Cardinal organizes systems into four distinct hooks that define their execution order during a Tick.
| Hook | Description |
|---|---|
Init | Runs once during world initialization or genesis. |
PreUpdate | Executes before the main game logic phase. |
Update | Processes the primary game logic. |
PostUpdate | Executes after main logic, often used for cleanup or event processing. |
Sources: pkg/cardinal/internal/ecs/world.go:27-51, proto/gen/ts/worldengine/cardinal/v1/debug_pb.ts:285-300
Execution Flow
When Tick() is called, the engine processes systems sequentially based on their assigned hooks. System events generated during a phase are available to subsequent phases and are cleared once the tick completes.
The flowchart illustrates the sequential execution of system hooks within a single engine tick.
Sources: pkg/cardinal/internal/ecs/world.go:42-51
Networking and Service Addressing
The engine uses a structured addressing format to route messages between different services and shards. This system follows a specific NATS-compatible subject convention.
Service Address Components
Service addresses identify unique service instances within the World Engine network.
| Component | Description |
|---|---|
Realm | Defines access scope (internal or world). |
Organization | The entity that owns the project (e.g., "argus"). |
Project | Groups related services (e.g., "rampage"). |
Service ID | Unique identifier for the instance (e.g., "lobby-1"). |
Endpoint | Identifies specific functionality (e.g., "shard.message.player.connect"). |
Sources: proto/worldengine/micro/v1/service.proto:20-35
Inter-Shard Communication (ISC)
Shards communicate by emitting Epochs. An Epoch contains a collection of completed Ticks and a hash for integrity verification. This ensures that state changes can be validated across the sharded rollup architecture.
Sources: proto/gen/go/worldengine/isc/v1/epoch.pb.go:27-35, README.md:12-14
Developer Tooling and Debugging
World Engine provides a DebugService to facilitate introspection and control of the Cardinal ECS environment during development.
Debug Operations
The service allows developers to manipulate the world's execution state through standard RPC calls.
- Introspect: Returns metadata about registered commands, components, and events.
- Pause/Resume: Stops or continues tick execution.
- Step: Executes exactly one tick while the world is paused.
- GetState: Retrieves a full snapshot of the current world state, including entity mappings and component data.
- StreamPerf: Streams real-time performance timing data for every system execution within a tick.
Sources: proto/gen/ts/worldengine/cardinal/v1/debug_pb.ts:310-370
World State Snapshots
Snapshots capture the entire ECS state at a specific tick height. This includes the WorldState, which consists of the entity manager state (next ID, free IDs) and the complete list of archetypes and their component columns.
Sources: proto/gen/ts/worldengine/cardinal/v1/snapshot_pb.ts:20-60
World Engine combines a high-performance ECS with a scalable sharded architecture to provide a robust environment for blockchain-based gaming. Through structured system hooks, deterministic ticks, and comprehensive debugging tools, it enables developers to build complex, verifiable game worlds.