Crates.io | secsy_world |
lib.rs | secsy_world |
version | 0.0.1 |
source | src |
created_at | 2023-07-23 05:26:01.812088 |
updated_at | 2023-07-23 05:26:01.812088 |
description | The data storage component for the secsy framework |
homepage | |
repository | |
max_upload_size | |
id | 923593 |
size | 12,125 |
This is the world data storage component of the secsy framework.
The main feature of this crate is the World
type, which is an ECS-ish data
storage structure which stores the component data of the entities within it.
Entities are referred to by their IDs, which are then used to get or set the
data corresponding to that entity ID.
A World
can also be queried for a type, which returns a vector of IDs for
entities which have a component of that type. This vector can then be used to
run code for every entity with that type, or, for example, be checked against
a query for a different type, so that traditional data-oriented game programming
patterns may be employed.
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);
}