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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! # Xanadu
//!
//! Xanadu is a toy ECS library which works on Windows, Linux, macOS and WebAssembly.
//!
//! ## Example
//!
//! ```rust
//! 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;
//! }
//! ```
/// Collections to be used in ECS, but can be used independently.
/// ECS module; main module of this library.
///
/// # ECS
///
/// ECS stands for Entity-Component-System. It is a design pattern used in game development. It is
/// known for its performance when dealing with large number of entities.
///
/// # Entities
///
/// Entities are unique identifiers that have no intrinsic properties on their own. They are just
/// identities used to keep track of components attached to them. In Xanadu, entities are just
/// [`GenerationalId`](collections::GenerationalId)s.
///
/// # Components
///
/// Components are data structures that can be attached to entities. In Xanadu, components are
/// types which implement [`Component`](ecs::Component) trait.
///
/// # Systems
///
/// Systems are functions that operate on components. In Xanadu, systems are types which implement
/// [`System`](ecs::System) trait. They are usually functions that take a reference to a component
/// and return nothing.