tx2-core
A high-performance native ECS engine for cross-platform applications, games, and simulations.
tx2-core is the native Rust implementation of the TX-2 world runtime, providing an authoritative Entity-Component-System architecture that powers desktop apps, game-like experiences, and high-performance servers. It's designed to work seamlessly with the broader TX-2 ecosystem for isomorphic state synchronization across web, native, and CLI environments.
Features
Core ECS Architecture
- Type-safe entity-component system with compile-time guarantees
- Flexible component registration supporting any serializable Rust type
- Efficient query system for component iteration and filtering
- System scheduling with dependency tracking and execution ordering
- World snapshots for save/load, time-travel debugging, and checkpointing
Rendering & Graphics
- GPU-accelerated rendering via
wgpu(WebGPU API) - Automatic render batching by component type for optimal performance
- Instanced rendering support for drawing thousands of entities efficiently
- Cross-platform windowing using
winit(Windows, macOS, Linux)
Serialization & Sync
- Delta compression via
tx2-linkfor efficient state synchronization - Field-level change detection to minimize network bandwidth
- Multiple serialization formats (MessagePack, Bincode, JSON)
- Schema versioning for backward-compatible protocol evolution
Application Framework
- Event-driven architecture with platform event integration
- Fixed timestep simulation for deterministic physics and gameplay
- Hot-reload support for rapid development iteration
- Extensible system pipeline for custom game logic
Quick Start
use ;
use ;
// Define components
// Create a world
let mut world = new;
world.;
world.;
// Spawn entities
let player = world.create_entity;
world.add_component;
world.add_component;
// Query and iterate
for in world.
Running the Example
This demonstrates:
- Window creation with
winit - Basic rendering setup with
wgpu - Entity creation and component management
- Event loop integration
Architecture
tx2-core follows a pure ECS architecture where:
- Entities are unique identifiers (UUIDs) representing game objects
- Components are pure data structs attached to entities
- Systems are functions that operate on queries of components
- World manages all entities, components, and systems
Component Storage
Components are stored in type-erased hashmaps, allowing:
- Dynamic component registration at runtime
- Zero-cost abstractions via generics
- Efficient batch operations on component types
System Execution
Systems are executed in a deterministic order based on:
- Explicit dependencies between systems
- Read/write access patterns to prevent data races
- Fixed timestep scheduling for consistent simulation
Integration with TX-2 Ecosystem
tx2-core is designed to work as part of the broader TX-2 stack:
- tx2-ecs (TypeScript/Node): Web runtime with reactive UI rendering
- tx2-link: Protocol for syncing worlds between runtimes (WebSocket, IPC, stdio)
- tx2-pack: Binary snapshot format for save/load and time-travel replay
- tx2-core: Native engine (this crate)
The same world state can be:
- Rendered as a 3D game in tx2-core
- Displayed as a web dashboard in tx2-ecs
- Synchronized in realtime via tx2-link
- Saved/loaded using tx2-pack
One world, many views.
Performance
tx2-core is built for high-performance applications:
- Batch rendering: Components of the same type are rendered together
- GPU instancing: Draw thousands of entities in a single draw call
- Delta compression: 11.9× reduction in network traffic (2.28MB → 196KB)
- Memory efficiency: Struct-of-arrays layout for cache-friendly iteration
- Zero-copy serialization: Direct memory mapping for fast snapshots
Serialization & Networking
World state can be serialized for:
- Save/load: Checkpoint entire worlds to disk
- Network sync: Delta-compressed updates to clients
- Time-travel: Replay simulation from any point in time
- Hot-reload: Preserve state across code changes
Supported formats:
- MessagePack: Compact binary format (default)
- Bincode: Fast Rust-native serialization
- JSON: Human-readable debugging format
Examples
Creating Entities
let entity = world.create_entity;
world.add_component;
world.add_component;
Querying Components
// Iterate over all entities with Position and Velocity
for in world.
World Snapshots
// Create a snapshot of the current world state
let snapshot = world.create_snapshot;
// Restore from snapshot
world.restore_from_snapshot?;
Delta Compression
use DeltaCompressor;
let mut compressor = new;
// Generate delta between two snapshots
let delta = compressor.create_delta?;
// Apply delta to reconstruct current state
let reconstructed = compressor.apply_delta?;
Rendering
tx2-core includes a rendering abstraction built on wgpu:
use ;
// Create renderer
let mut renderer = new.await;
// Prepare render batches from world
let batches = renderer.prepare_batches;
// Render frame
renderer.render?;
Application Framework
Build complete applications with the App framework:
use App;
let mut app = new?;
app.run;
Development Status
tx2-core is in active development. Current status:
- Core ECS implementation
- Component registration and queries
- World serialization
- Delta compression integration
- Basic rendering with wgpu
- Window and event handling
- Render batching
- Advanced physics integration
- Audio system
- Asset loading pipeline
- Scripting integration
Dependencies
serde- Serialization frameworkuuid- Entity identifierswinit- Cross-platform windowingwgpu- WebGPU rendering APItx2-link- World synchronization protocol
License
MIT
Contributing
Contributions are welcome! This is part of the broader TX-2 project for building isomorphic applications with a unified world model.