Cougr Core is a Soroban-compatible ECS (Entity Component System) framework designed for building on-chain video games on the Stellar blockchain.
This crate provides a complete ECS architecture adapted for no_std and WebAssembly (WASM) compatibility, built on top of the soroban-sdk. It follows an architecture inspired by Bevy ECS, providing a modular and efficient foundation for decentralized gaming experiences.
- ✅ Complete ECS Architecture: Entities, Components, Systems, World, Resources, Events, and Queries
- ✅ Soroban-SDK Integration: Native support for Stellar smart contracts
- ✅ no_std Compatible: Works in constrained environments
- ✅ WASM Ready: Optimized for WebAssembly execution
- ✅ Type-Safe: Leverages Rust's type system for safety
- ✅ Efficient Storage: Optimized component storage systems
- entity: Entity management with unique IDs and generation tracking
- component: Component types and registry for attaching data to entities
- world: Central ECS world containing all entities, components, and systems
- system: System trait and implementations for game logic
- storage: Efficient component storage (Table and Sparse storage)
- resource: Global resources accessible to systems
- event: Event system for communication between systems
- query: Query system for filtering entities by components
Add to your Cargo.toml:
[dependencies]
cougr-core = "0.0.1"use cougr_core::prelude::*;
// Create a world
let mut world = World::new();
// Spawn an entity
let entity = world.spawn_empty();
// Add components
let position = Component::new(
symbol_short!("position"),
position_data
);
world.add_component_to_entity(entity.id(), position);
// Query entities
let entities = world.query_entities(&[symbol_short!("position")]);Provides entity management functionality:
EntityId: Unique identifier with generation trackingEntity: Entity container with component trackingEntityManager: Handles entity lifecycle (spawn, despawn, lookup)
Defines component types and management:
Component: Base component type with Soroban serializationComponentId: Unique component type identifierComponentRegistry: Manages component type registrationComponentTrait: Trait for implementing custom components
Central ECS container:
World: Main ECS world containing all entities and components- Methods for entity/component management
- Resource and event management
- Query execution
System execution framework:
Systemtrait: Define game logic systemsSystemParam: Parameter types for systems- Pre-built systems: MovementSystem, CollisionSystem, HealthSystem
Component storage implementations:
Storage: Base storage typeTableStorage: Dense storage for common componentsSparseStorage: Sparse storage for rare components
Global state management:
Resource: Global resources accessible to all systemsResourceTrait: Trait for implementing custom resources- Example:
GameStateresource
Event system for inter-system communication:
Event: Base event typeEventReader: Read events in systemsEventWriter: Send events from systems- Pre-built events:
CollisionEvent,DamageEvent
Entity filtering and querying:
Query: Filter entities by componentsQueryState: Cached query resultsQueryBuilder: Fluent query constructionQueryFilter: Custom filter trait
cargo buildcargo testcargo build --target wasm32-unknown-unknown --releaseThe crate is optimized for small WASM binary size:
- LTO enabled
- Single codegen unit
- Size optimization (
opt-level = "z")
- Rust Version: 1.70.0+
- Edition: 2021
- Target: wasm32-unknown-unknown
- Soroban SDK: 23.0.2
Licensed under MIT OR Apache-2.0
This is part of the Cougr framework for on-chain gaming on Stellar. Contributions are welcome!