Engine Templates Deep Dive
Relevant source files
The following files were used as context for generating this wiki page:
- pkg/template/multi-shard/world.toml
- pkg/template/basic/world.toml
- pkg/template/bare-bone/world.toml
- pkg/cardinal/internal/ecs/README.md
- README.md
- pkg/template/basic/shards/game/gen/pkg/template/basic/shards/game/component/component.pb.go
- pkg/template/basic/shards/game/gen/pkg/template/basic/shards/game/system/system.pb.go
- pkg/template/multi-shard/shards/game/gen/pkg/template/multi-shard/shards/game/command/command.pb.go
Engine templates provide standardized starting points for building games using the World Engine Gamechain SDK. These templates define the project structure, shard configurations, and core ECS (Entity Component System) patterns required for Argus Labs' sharded rollup architecture.
Templates reside in pkg/template/ and categorize into three main types: bare-bone, basic, and multi-shard. Each template utilizes the Cardinal ECS framework to manage game state through entities, components, and systems.
Sources: README.md:1-5, pkg/cardinal/internal/ecs/README.md:1-5
Template Project Structure
Each template uses a world.toml file to define the global configuration for the Gamechain. This file identifies the organization and project, and lists the active shards.
Configuration Fields
The world.toml file contains the following primary keys:
| Key | Type | Description |
|---|---|---|
organization | string | The identifier for the organization owning the project. |
project | string | The unique project identifier. |
shards | array | A list of shard objects containing id, log_level, and path. |
Sources: pkg/template/basic/world.toml:1-12, pkg/template/multi-shard/world.toml:1-15
Shard Configurations
Shards are the fundamental units of scaling in the World Engine. By default, a shard's id must match its directory name under the shards/ directory.
- Bare-bone/Basic Templates: Typically define a single
gameshard. - Multi-shard Templates: Demonstrate horizontal scaling by defining multiple shards, such as
gameandchat, within the same project.
Core ECS Architecture in Templates
Templates utilize the Cardinal ECS implementation to manage high-performance game logic. This implementation organizes data into archetypes for cache-friendly access.
Data Organization
Entities are numeric identifiers, while components are pure data containers. Archetypes group entities that share the same set of components.
World*: The root container for all ECS state.
- Archetype: A collection of entities with identical component types.
- Column: Stores component data contiguously in memory for a specific type within an archetype.
Sources: pkg/cardinal/internal/ecs/README.md:9-40
Component and Command Definitions
Templates include generated Protobuf code that defines the "wire" names and structures for components and commands.
Example Components (Basic Template)
Components define the state of entities. In the basic template, these include health and identifying tags.
| Wire Name | Message Type | Fields |
|---|---|---|
gravestone | Gravestone | Nickname (string) |
health | Health | HP (int64) |
playertag | PlayerTag | Nickname (string) |
Sources: pkg/template/basic/shards/game/gen/pkg/template/basic/shards/game/component/component.pb.go:27-105
Example Commands (Multi-shard Template)
Commands represent user actions or external inputs that trigger state changes.
| Wire Name | Message Type | Purpose |
|---|---|---|
move-player | MovePlayer | Updates player coordinates (X, Y). |
player-spawn | PlayerSpawn | Initializes a new player entity. |
player-leave | PlayerLeave | Removes a player entity. |
Design Principles
The templates follow specific design features implemented in the underlying engine:
- Sparse Set Pattern: Provides O(1) operations for component access and entity management.
- Memory Alignment: Component data is stored contiguously in columns to improve cache coherency.
- Entity ID Recycling: Reuses identifiers to prevent memory fragmentation during high-frequency creation and destruction.
Sources: pkg/cardinal/internal/ecs/README.md:58-85
Summary
Engine templates simplify Gamechain development by providing pre-configured shard environments and code generation for ECS components and commands. Developers choose a template based on whether they need a clean slate (bare-bone), a functional example (basic), or a distributed architecture (multi-shard).