#world #component #storage #framework #entities #vector #secsy

已删除 secsy_world

secsy 框架的数据存储组件

1 个不稳定发布

0.0.1 2023年7月23日

#95#entities


用于 secsy

GPL-3.0-or-later

13KB
172

secsy_world

这是 secsy 框架的世界数据存储组件。

此组件的主要功能是 World 类型,它是一个类似于 ECS 的数据存储结构,用于存储内部实体的组件数据。实体通过其 ID 进行引用,然后使用该 ID 获取或设置对应实体 ID 的数据。

还可以查询 World 中的类型,这会返回具有该类型组件的实体的 ID 向量。然后可以使用此向量对具有该类型的每个实体运行代码,或者,例如,将其与不同类型的查询进行比较,以便可以使用传统的面向数据的游戏编程模式。

示例

use secsy::secsy_world;
use secsy_world::entities::*;
use secsy_world::world::*;

fn main() {
    let mut world = World::new();

    let a = secsy_ecs::spawn_entity_with!(world, 1, 2.0, (3, 3), '4', "5");
    let b = secsy_ecs::spawn_entity_with!(world, 1.0, (2, 2), '3', "4");
    let c = secsy_ecs::spawn_entity_with!(world, 1, (2, 2), '3', "4");
    let d = secsy_ecs::spawn_entity_with!(world, 1, 2.0, '3', "4");
    let e = secsy_ecs::spawn_entity_with!(world, 1, 2.0, (3, 3), "4");
    let e = secsy_ecs::spawn_entity_with!(world, 1, 2.0, (3, 3), '4');
    let f = secsy_ecs::spawn_entity_with!(world, 1.0, (2, 2), '3');
    let g = secsy_ecs::spawn_entity_with!(world, 1, (2, 2), "3");
    let h = secsy_ecs::spawn_entity_with!(world, 1, 2.0, '3', "4");
    let i = secsy_ecs::spawn_entity_with!(world, 1, (2, 2), "3");
    let j = secsy_ecs::spawn_entity_with!(world, 1.0, (2, 2), '3');

    let qi = world.query::<i32>().unwrap();
    let qf = world.query::<f64>().unwrap();
    let qt = world.query::<(i32, i32)>().unwrap();
    let qc = world.query::<char>().unwrap();
    let qs = world.query::<&str>().unwrap();

    let has_ints_and_chars: Vec<EntityId> = 
        qi.iter().filter(|i| qc.contains(i)).cloned().collect();

    let has_floats_and_strings: Vec<EntityId> =
        qf.iter().filter(|i| qs.contains(i)).cloned().collect();

    let has_tuples_and_ints: Vec<EntityId> = 
        qt.iter().filter(|i| qi.contains(i)).cloned().collect();

    println!("{:?}", has_ints_and_chars);
    println!("{:?}", has_floats_and_strings);
    println!("{:?}", has_tuples_and_ints);
}

无运行时依赖