freecs
A high-performance, archetype-based Entity Component System (ECS) written in Rust.
## Features
- ๐ **Archetype-based Storage**: Optimal cache coherency through grouped component storage
- ๐ **Built-in Parallel Processing**: Leverages rayon for efficient multi-threading
- ๐ฆ **Zero-overhead Component Access**: Direct slice indexing for component data
- ๐ก๏ธ **Type-safe Component Management**: Compile-time component type checking
- ๐ง **Dynamic Components**: Add or remove components at runtime
- ๐งน **Table Defragmentation**: Maintains optimal memory layout
- ๐ **Batch Operations**: Efficient bulk entity operations
- ๐พ **Serialization Support**: Built-in serde support for all core types
## Quick Start
Add this to your `Cargo.toml`:
```toml
freecs = "0.1.1"
And in main.rs:
use ;
// Define your components
// Create a world with your components
world!
Running the Demo
The project includes a demo:
Controls:
- Use arrow keys to rotate the camera
- Press Escape to exit
Data Oriented vs Object Oriented
When processing entities, the cache-friendly layout makes a significant difference:
// Given 10,000 entities with Position and Velocity:
// Traditional OOP: Cache misses, unpredictable memory access
for entity in entities
// freecs: Streaming through contiguous memory
for table in &mut world.tables
Benefits of Macro-based Generation
- Inlining: The entire ECS can be inlined into your crate by inlining the
impl_world!macro - Zero Overhead: No virtual dispatch or runtime type checking. Only static dispatch is used.
- Compile-time Optimization: The compiler sees your exact component types and can optimize accordingly
- No Runtime Dependencies: The core ECS can work without external crates
- Specialized Code: Generated code is specific to your component types
License
This project is licensed under the MIT License - see the LICENSE file for details.