#ecs #game #component #entity #full #part

实体_组件

提供完整 ECS(实体-组件-系统)的实体和组件部分

8 个版本 (稳定版)

1.1.2 2021年3月29日
1.1.1 2021年3月27日
0.100.0 2021年1月3日
0.99.0 2020年12月20日

#1696 in 游戏开发


2 个库 中使用

Apache-2.0

28KB
492

支持开源开发者!♥️

Become a patron

实体组件

完整 ECS(实体-组件-系统)的实体和组件部分

为什么您会使用这个 ECS 库?

  • 与所有平台兼容,包括 WASM!
  • 依赖项最少。
  • 代码体积小。
  • 稳定、经过测试、基准测试,100% 完成。

使用方法

将以下内容添加到您的 Cargo.toml 文件中

entity_component = "*"

使用方法如下

use entity_component::*;

fn main() {
    // Creating components
    struct A(f32);
    struct B(f32);
    // Creating entity repository
    let mut entities = Entities::default();
    // Creating component storages
    let mut storage = Components::<A>::default();
    let mut storage2 = Components::<B>::default();
    // Create entities and add components
    for i in 0..10000 {
        let e = entities.create();
        if i % 5 == 0 {
            storage.insert(e, A(1.0));
        }
        if i % 6 == 0 {
            storage2.insert(e, B(1.0));
        }
    }
    // Join on all entities having both A and B.
    // We take a mutable reference to the A component and an immutable
    // reference to the B component.
    join!(&mut storage && &storage2)
        .for_each(|(s, s2)| s.unwrap().0 += s2.unwrap().0);

    // Same thing, but we also get the entities id that align with the
    // matched components.
    join!(&entities && &mut storage && &storage2)
        .for_each(|(_e, s, s2)| s.unwrap().0 += s2.unwrap().0);
}

维护者信息

  • 维护者:Jojolepro
  • 联系方式:jojolepro [at] jojolepro [dot] com
  • 网站: jojolepro.com
  • Patreon: patreon

依赖项

~500–700KB
~14K SLoC