1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// Helper to query for components in the world. We have to give a query variable that will last longer
/// than the macro for this to work.
///
/// ```
/// use bbecs::query;
/// use bbecs::world::{World, ENTITY_ID, WorldMethods, DataWrapper};
/// use bbecs::components::CastComponents;
///
/// // creating the world and adding an entity for us to query later
/// let mut world = World::new();
/// world.register("size").unwrap();
/// world
/// .spawn_entity()
/// .unwrap()
/// .with_component("size", 15.0_f32)
/// .unwrap();
///
/// // Now we are querying for the size and an entity id which is automatically added to all entities
/// let query;
/// let (sizes, entity_ids) = query!(world, query, "size", ENTITY_ID);
///
/// for (index, size) in sizes.iter().enumerate() {
/// let size: &DataWrapper<f32> = size.cast().unwrap();
/// let entity_id: &DataWrapper<u32> = entity_ids[index].cast().unwrap();
///
/// assert_eq!(*size.borrow(), 15.0);
/// assert_eq!(*entity_id.borrow(), 0);
/// }
/// ```