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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use std::marker;
use std::iter;
use crate::{
Bitmask, MaskType, entity::EntitiesStorage,
storage::{IntoSendStorage, FastIndexExt, ReadOnlyStorage, StorageRef},
entity::Entity,
};
use super::SafeIter;
use super::{DataAccesses, FromComponent, UnorderedData};
use std::any::TypeId;
#[cfg(components_64)]
use num_traits::Zero;
pub struct Has<T>{
_marker: marker::PhantomData<T>,
}
impl<T> FromComponent<'_, ()> for Has<T>{
fn from_component(_: ()) -> Has<T>{
Has{
_marker: marker::PhantomData
}
}
}
pub struct StorageHas<'a, T>{
entities_masks: &'a [(Entity, MaskType)],
component_mask: MaskType,
_marker_t: marker::PhantomData<&'a T>,
}
impl<'a, T> StorageHas<'a, T>{
pub fn new(entities_masks: &'a [(Entity, MaskType)], component_mask: MaskType) -> StorageHas<'a,T>{
StorageHas{
entities_masks,
component_mask,
_marker_t: marker::PhantomData,
}
}
}
impl<'a, 'r, T> FastIndexExt for StorageHas<'a, T>
where T: 'static,
{
type FastIndex = ();
type StaticTypeId = Has<T>;
fn fast_index(&self, _guid: usize) -> () {
()
}
}
impl<'a, 'r, T> StorageRef<'r> for StorageHas<'a, T>
where T: 'static,
{
type Data = Has<T>;
type Component = ();
unsafe fn get_fast_unchecked(&mut self, _idx: ()) -> (){
}
unsafe fn get_unchecked(&mut self, _guid: usize) -> (){
}
fn contains(&self, guid: usize) -> bool{
&self.entities_masks[guid].1 & &self.component_mask != MaskType::zero()
}
}
impl<'a, 'r, T> IntoSendStorage<'r> for StorageHas<'a, T>
where T: 'static,
{
type SendStorage = StorageHas<'a, T>;
fn into_send_storage(&'r mut self) -> Self::SendStorage {
StorageHas {
entities_masks: self.entities_masks,
component_mask: self.component_mask.clone(),
_marker_t: marker::PhantomData
}
}
}
unsafe impl<'a, T: 'static> ReadOnlyStorage for StorageHas<'a, T>{}
unsafe impl<T> SafeIter<'_> for Has<T> {}
impl<'a, T: 'static> UnorderedData<'a> for Has<T> {
type Iter = iter::Repeat<()>;
type IterMut = iter::Repeat<()>;
type Components = T;
type ComponentsRef = ();
type Storage = StorageHas<'a, T>;
fn query_mask<E: EntitiesStorage>(entities: &E) -> Bitmask{
Bitmask::has(entities.component_mask::<T>())
}
fn into_iter<E: EntitiesStorage>(_: &'a E) -> Self::Iter{
iter::repeat(())
}
fn into_iter_mut<E: EntitiesStorage>(entities: &'a E) -> Self::Iter {
Self::into_iter(entities)
}
fn storage<E: EntitiesStorage>(entities: &'a E) -> Option<Self::Storage> {
let entities_masks = entities.entities_ref();
let component_mask = entities.component_mask::<T>();
Some(StorageHas{
entities_masks,
component_mask,
_marker_t: marker::PhantomData,
})
}
}
impl<'a, T: 'static> DataAccesses for Has<T> {
fn reads() -> Vec<TypeId>{ vec![] }
fn writes() -> Vec<TypeId>{ vec![] }
}