Skip to main content

Crate crcbl_ecs

Crate crcbl_ecs 

Source
Expand description

Entity/component storage built on system-owned arrays.

§Model

  • Entity — a generational id (crcbl_core::Handle<EntityMarker>) from crcbl_core::Pool. An entity carries no data of its own.
  • System — owns a dense Vec<T> of component data plus a sparse entity→index map. Systems iterate their own arrays linearly (SoA, cache-friendly). Cross-system access uses sparse lookups for cold paths.
  • Schedule — an ordered sequence of systems run each tick. Each system declares the Shared resources its tick reads and writes (SystemTrait::access); the schedule derives the conflicts between them at registration, groups the systems into stages no two systems of which conflict, and, in debug builds, panics on a tick touching a resource its system did not declare. Handed a crcbl_jobs::Pool, it ticks each stage’s systems across the pool’s threads, with the same result as running them one by one.
  • World — the container: entity pool, schedule, deferred-destruction queue. World::tick() runs the schedule then sweeps dead entities.
  • quantize — how a replicated component declares its wire form: fixed point, half float and smallest-three rotations, applied in SystemTrait::replicate before the server compares anything.

§Example

use crcbl_ecs::*;

let mut world = World::new();

// Create entities.
let player = world.spawn();
let npc    = world.spawn();

// Register a position system and attach data.
let mut positions = System::<(f32, f32, f32)>::new("position");
positions.attach(player, (0.0, 0.0, 0.0));
positions.attach(npc,    (10.0, 0.0, 5.0));
world.register_system(Box::new(positions));

// Run one tick.
world.tick();

// Inspect.
let stats = Inspector::collect(&world);
assert_eq!(stats[0].name, "position");
assert_eq!(stats[0].entity_count, 2);

// Despawn an entity — deferred until sweep.
world.despawn(npc);
world.tick();
assert_eq!(world.entity_count(), 1);

Modules§

quantize
Per-component quantization for replication: how many bits each replicated field is worth on the wire.

Structs§

Access
The Shared resources a system’s tick reads and writes, by name.
ClientInputs
The client input frames for one server tick.
Conflict
Two systems whose ticks touch one resource in a way that cannot overlap: after must run after before, as it was registered.
DebugCtx
Stub struct for debug-draw context.
EntityMarker
Zero-sized marker type for entity handles.
Inspector
Collects system statistics from a World.
Schedule
An ordered sequence of systems run each tick.
Shared
A named handle to state that more than one system — or a system and the code driving the world — holds: the seam a system’s Access declaration describes.
System
A system that owns a dense Vec<T> of component data plus a sparse entity→index map.
SystemStats
Per-system stats collected by Inspector::collect.
TickTime
One system’s measured tick cost: the last tick, and the mean over the last TICK_TIME_WINDOW ticks.
World
The top-level ECS container.

Enums§

AccessError
A declaration the schedule refused, or a resource it would not register.
ConflictKind
How two systems’ declarations collide on one resource.

Constants§

TICK_TIME_WINDOW
How many ticks a system’s TickTime::mean averages over.

Traits§

ComponentHash
Trait for component types whose byte representation is safe and deterministic to hash.
GameModule
Game-specific logic compiled into the binary (static binding).
SystemTrait
Object-safe trait every system in the Schedule must implement.

Type Aliases§

DebugDrawFn
Callback type for per-system debug drawing.
Entity
An entity is a generational id backed by crcbl_core::Pool<EntityMarker>.
ScheduleClock
A clock a schedule times its systems on: shared with the pool’s workers when the systems tick there, hence Sync, and Send so a world that owns one can move to the thread that runs it.