Archetype ECS
A high-performance Entity Component System (ECS) library for Rust.
Installation
[]
= "1.1.3"
Quick Start
use *;
// Components are plain structs
Querying Entities
Basic Queries
// Mutable query - use .iter() or IntoIterator
let mut query = world.;
for in query.iter
// Or directly (IntoIterator)
for in world.
Getting Entity IDs
Use the Entity marker to get entity IDs during iteration:
use *;
let mut to_delete = Vecnew;
for in world.
// Delete entities after iteration
for entity in to_delete
Mixed Mutability
Read some components while writing others:
// Read Position, write Velocity
for in world.
Direct Component Access
Access components on a specific entity:
// Immutable access
if let Some = world.
// Mutable access
if let Some = world.
Resources (Global State)
Resources are typed singletons for global state:
// Insert resource
world.insert_resource;
// Read resource
if let Some = world.
// Mutate resource
if let Some = world.
Query Filters
Filter entities by component presence:
use ;
// Only entities WITH a Visible component
let query = new;
for pos in query.iter
// Only entities WITHOUT a Dead component
let query = new;
// Only entities where Position changed this frame
let query = new;
Systems & Scheduling
use ;
use TypeId;
;
Parallel Execution
use ParallelExecutor;
let systems: = vec!;
let mut executor = new;
executor.execute_parallel?;
SIMD & Chunk Processing
Process entities in parallel with SIMD-friendly access:
let mut query = world.;
query.par_for_each_chunk;
Batch Operations
// Spawn many entities efficiently
let entities = world.spawn_batch?;
Performance
| Operation | Time | Scale |
|---|---|---|
| Query Iteration | 11.1 µs | 10,000 entities |
| Entity Spawn | 42.3 µs | 1,000 entities |
| Parallel Execution | 3.1 ms | Multi-core |
License
Copyright 2024 Saptak Santra. Licensed under Apache-2.0.