Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openfrontio/OpenFrontIO/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The OpenFront client uses a multi-threaded architecture that separates game simulation from rendering:- Main Thread - UI, rendering (PixiJS), user input handling
- Worker Thread - Core simulation, pathfinding, game logic
Architecture Diagram
Core Components
ClientGameRunner
The main orchestrator that coordinates all client systems. File:src/client/ClientGameRunner.ts
- Lifecycle management (start, stop)
- Coordinating worker ↔ renderer communication
- Handling user input events
- Managing connection state
Worker Thread Communication
The client communicates with the worker thread viaWorkerClient.
File: src/core/worker/WorkerClient.ts
Sending Turns to Worker
Receiving Game Updates
Game updates use transferable buffers for zero-copy data transfer between threads, improving performance for large state updates.
Worker Thread Implementation
File:src/core/worker/Worker.worker.ts
The worker runs the core simulation and processes turns:
- Main thread sends Turn via
postMessage - Worker queues turn in game runner
- Worker executes up to 4 ticks before yielding
- Worker sends GameUpdate batch back to main thread
- Main thread renders updates
The worker uses a batching strategy (MAX_TICKS_BEFORE_YIELD = 4) to avoid flooding the main thread while catching up on missed turns.
Rendering System
GameRenderer
The renderer uses PixiJS for hardware-accelerated WebGL rendering. File:src/client/graphics/GameRenderer.ts
Rendering Layers
The renderer is organized into layers that render independently:| Layer | Purpose | File |
|---|---|---|
| TerrainLayer | Land/water tiles | src/client/graphics/layers/TerrainLayer.ts |
| TerritoryLayer | Player territory colors | src/client/graphics/layers/TerritoryLayer.ts |
| StructureLayer | Buildings (factories, ports, etc.) | src/client/graphics/layers/StructureLayer.ts |
| UnitLayer | Military units | src/client/graphics/layers/UnitLayer.ts |
| RailroadLayer | Railroad networks | src/client/graphics/layers/RailroadLayer.ts |
| UILayer | Hover effects, selection | src/client/graphics/layers/UILayer.ts |
| FxLayer | Explosions, animations | src/client/graphics/layers/FxLayer.ts |
| NameLayer | Player names, labels | src/client/graphics/layers/NameLayer.ts |
Transform Handler
File:src/client/graphics/TransformHandler.ts
Handles camera controls and coordinate transformations:
Input Handling
InputHandler
File:src/client/InputHandler.ts
Processes mouse and keyboard input:
Intent Generation
User actions generate intents that are sent to the server:Network Transport
Transport Layer
File:src/client/Transport.ts
Manages WebSocket connection to game server:
Message Types
Server → Client:lobby_info- Lobby state and player listprestart- Game is about to start, begin loadingstart- Game started, includes GameStartInfoturn- Turn data with bundled intentsdesync- Hash mismatch detectederror- Connection or validation error
join- Join game lobbyrejoin- Reconnect to existing sessionintent- Player action (attack, build, etc.)hash- State hash for desync detectionturn_complete- Tick executed successfully
GameView
Provides a read-only view of game state to the rendering thread. File:src/core/game/GameView.ts
UI Components
The client includes numerous UI components built with Web Components:Example: Build Menu
File:src/client/graphics/layers/BuildMenu.ts
Key UI Elements
- Leaderboard - Player rankings and stats (
src/client/graphics/layers/Leaderboard.ts) - BuildMenu - Structure construction (
src/client/graphics/layers/BuildMenu.ts) - ChatDisplay - In-game chat (
src/client/graphics/layers/ChatDisplay.ts) - RadialMenu - Quick actions (
src/client/graphics/layers/RadialMenu.ts) - ControlPanel - Game controls (
src/client/graphics/layers/ControlPanel.ts)
Performance Optimization
Efficient State Updates
Game updates use binary packed buffers instead of JSON:Rendering Optimizations
- Culling - Only render visible tiles
- Sprite batching - Batch similar sprites in single draw call
- Dirty regions - Only redraw changed areas
- Object pooling - Reuse PixiJS objects
Frame Profiler
File:src/client/graphics/FrameProfiler.ts
Tracks rendering performance:
Error Handling
The client handles various error scenarios:Desync Detection
Clients compute state hashes and send to server for comparison:desync message.
Connection Recovery
Worker Errors
Development Tools
Performance Overlay
File:src/client/graphics/layers/PerformanceOverlay.ts
Displays real-time metrics:
- Tick execution time
- Network latency
- Frame rate
- Memory usage
Diagnostic Mode
File:src/client/utilities/Diagnostic.ts
Enables debug visualizations:
- Pathfinding routes
- Attack ranges
- Territory borders
- Network packets
Next Steps
Server Architecture
Learn how the server relays intents
Core Simulation
Understand the deterministic engine