6 个版本

0.0.5 2024 年 5 月 11 日
0.0.4 2024 年 5 月 8 日
0.0.3 2024 年 4 月 23 日
0.0.0 2021 年 10 月 9 日

615游戏开发 中排名

Download history 6/week @ 2024-04-28 252/week @ 2024-05-05 36/week @ 2024-05-12 1/week @ 2024-05-19

316 每月下载量

MPL-2.0 许可证

56KB
551 代码行

Xanadu

GitHub Actions Workflow Status Crates.io Version docs.rs

A toy ECS library; works on Windows, macOS, Linux and WebAssembly.

基准测试

基准测试

用法

use xanadu::ecs::{Mut, World};

#[repr(C)]
#[derive(Debug, Default, Clone, Copy, bytemuck::Pod, bytemuck::Zeroable, PartialEq)]
pub struct Position {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

fn main() {
    let mut world = World::builder().register_component::<Position>().build();
    for i in 0..5 {
        let entity = world.new_entity();
        world.attach_component(
            entity,
            Position {
                x: i as f64,
                y: i as f64,
                z: i as f64,
            },
        );
    }

    world.execute::<'_, Position, _>(&print_system);
    world.execute::<'_, Mut<Position>, _>(&shuffle_system);
    world.execute::<'_, Mut<Position>, _>(&increment_system);
    world.execute::<'_, Mut<Position>, _>(&shuffle_system);
    println!("Shuffled and incremented");
    world.execute::<'_, Position, _>(&print_system);
}

fn print_system(pos: &Position) {
    println!("Pos: [{}, {}, {}]", pos.x, pos.y, pos.z);
}

fn shuffle_system(pos: &mut Position) {
    let tmp = pos.x;
    pos.x = pos.y;
    pos.y = pos.z;
    pos.z = tmp;
}

fn increment_system(pos: &mut Position) {
    pos.x += 1.0;
    pos.y += 2.0;
    pos.z += 3.0;
}

测试

cargo t --workspace
wasm-pack test --node
wasm-pack test --firefox --headless -- --features test_in_browser

依赖项

~0.4–1MB
~20K SLoC