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
85
use std::marker::PhantomData;
use std::ops::Deref;
use std::fmt;
use component::ComponentManager;
pub use entity::builder::*;
pub use entity::data::*;
pub use entity::iter::*;
pub use entity::manager::*;
pub mod builder;
pub mod data;
pub mod iter;
pub mod manager;
pub type Id = u64;
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Entity {
id: Id,
}
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct IndexedEntity<C>
where
C: ComponentManager,
{
index: usize,
entity: Entity,
_marker: PhantomData<C>,
}
impl<C> fmt::Debug for IndexedEntity<C> where C: ComponentManager {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("IndexedEntity")
.field("index", &self.index)
.field("entity", &self.entity)
.finish()
}
}
impl Entity {
#[inline]
pub fn nil() -> Entity {
Default::default()
}
#[inline]
pub fn id(self) -> Id {
self.id
}
}
impl<C> IndexedEntity<C>
where
C: ComponentManager,
{
#[inline]
pub fn index(&self) -> usize {
self.index
}
#[doc(hidden)]
#[inline]
pub fn __clone(&self) -> Self {
IndexedEntity {
index: self.index,
entity: self.entity,
_marker: PhantomData,
}
}
}
impl<C> Deref for IndexedEntity<C>
where
C: ComponentManager,
{
type Target = Entity;
fn deref(&self) -> &Entity {
&self.entity
}
}