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
use std::marker;
use std::iter;
use crate::{Bitmask, MaskType, entity::EntitiesStorage, storage::{IntoSendStorage, FastIndexExt, ReadOnlyStorage}};
use crate::entity::Entity;
use super::SafeIter;
use super::{DataAccesses, FromComponent, UnorderedData};
use crate::storage::{StorageRef};
use std::any::TypeId;
#[cfg(components_64)]
use num_traits::Zero;
pub struct Not<'a, T: 'static>{
_marker: marker::PhantomData<&'a T>,
}
impl<'a, T: 'static> FromComponent<'a, ()> for Not<'a, T>{
fn from_component(_: ()) -> Not<'a,T>{
Not{
_marker: marker::PhantomData
}
}
}
pub struct StorageNot<'a, T>{
entities_masks: &'a [(Entity, MaskType)],
component_mask: MaskType,
_marker_t: marker::PhantomData<&'a T>,
}
impl<'a, T> StorageNot<'a, T>{
pub fn new(entities_masks: &'a [(Entity, MaskType)], component_mask: MaskType) -> StorageNot<'a,T>{
StorageNot{
entities_masks,
component_mask,
_marker_t: marker::PhantomData,
}
}
}
impl<'a, T> FastIndexExt for StorageNot<'a, T>
where T: 'static,
{
type FastIndex = ();
type StaticTypeId = Not<'static, T>;
fn fast_index(&self, _guid: usize) -> () {
}
}
impl<'a, 'r, T> StorageRef<'r> for StorageNot<'a, T>
where T: 'static,
{
type Data = Not<'a, T>;
type Component = ();
unsafe fn get_fast_unchecked(&'r mut self, _idx: ()) -> (){
}
unsafe fn get_unchecked(&'r mut self, _guid: usize) -> (){
}
fn contains(&self, guid: usize) -> bool{
self.entities_masks[guid].1.clone() & self.component_mask.clone() == MaskType::zero()
}
}
impl<'a, 'r, T> IntoSendStorage<'r> for StorageNot<'a, T>
where T: 'static,
{
type SendStorage = StorageNot<'a, T>;
fn into_send_storage(&'r mut self) -> Self::SendStorage {
StorageNot {
entities_masks: self.entities_masks,
component_mask: self.component_mask.clone(),
_marker_t: self._marker_t,
}
}
}
unsafe impl<'a, T> ReadOnlyStorage for StorageNot<'a, T>{}
unsafe impl<T> SafeIter<'_> for Not<'_, T>{}
impl<'a, T: 'static> UnorderedData<'a> for Not<'a,T> {
type Iter = iter::Repeat<()>;
type IterMut = iter::Repeat<()>;
type Components = T;
type ComponentsRef = ();
type Storage = StorageNot<'a, T>;
fn query_mask<E: EntitiesStorage>(entities: &E) -> Bitmask{
Bitmask::not(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(StorageNot{
entities_masks,
component_mask,
_marker_t: marker::PhantomData,
})
}
}
impl<'a, T: 'static> DataAccesses for Not<'a, T> {
fn reads() -> Vec<TypeId>{ vec![] }
fn writes() -> Vec<TypeId>{ vec![] }
}