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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#[macro_export]
macro_rules! define_component_descriptor {
    ($item:ident) => {
        ComponentDescriptor {
            component_id: $item::ID,
            allocation_size: <$item::Allocator as ComponentAllocator<'_, $item>>::ALLOCATION_SIZE,
            allocation_alignment:
                <$item::Allocator as ComponentAllocator<'_, $item>>::ALLOCATION_ALIGNMENT,
            pool_count: $item::POOLS_PER_ALLOCATION,
            pool_stride: <$item::Allocator as ComponentAllocator<'_, $item>>::POOL_STRIDE,
            allocator_fns: AbstractComponentAllocatorDescriptor {
                write_to_pool:
                    <$item::Allocator as ComponentAllocator<'_, $item>>::write_component_memory,
                read_from_pool:
                    <$item::Allocator as ComponentAllocator<'_, $item>>::read_component_memory,
                drop_in_pool:
                    <$item::Allocator as ComponentAllocator<'_, $item>>::drop_component_memory,
                move_component: <$item::Allocator as ComponentAllocator<'_, $item>>::move_component,
            },
        }
    };
}

macro_rules! expr {
    ($x:expr) => {
        $x
    };
}

macro_rules! tuple_index {
    ($tuple:expr, $idx:tt) => {
        expr!($tuple.$idx)
    };
}

#[macro_export]
macro_rules! define_test_components {
    () => {
        #[repr(C)]
        #[derive(Debug, PartialEq, Clone, Copy)]
        pub struct Position {
            pub x: f32,
            pub y: f32,
            pub z: f32,
        }

        impl Component for Position {
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "Position";
            type Allocator = DefaultAllocator;
        }

        impl Default for Position {
            fn default() -> Self {
                Self {
                    x: 1.0,
                    y: 2.0,
                    z: 3.0,
                }
            }
        }

        #[repr(C)]
        #[derive(Debug, PartialEq, Clone, Copy)]
        pub struct PositionSeparateAllocs {
            pub x: f32,
            pub y: f32,
            pub z: f32,
        }

        impl Component for PositionSeparateAllocs {
            type Allocator = DefaultAllocator;
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "PositionSeparateAllocs";
            const POOLS_PER_ALLOCATION: usize = 1;
        }

        impl Default for PositionSeparateAllocs {
            fn default() -> Self {
                Self {
                    x: 1.0,
                    y: 2.0,
                    z: 3.0,
                }
            }
        }

        #[repr(C)]
        #[derive(Debug, PartialEq, Clone, Copy)]
        pub struct PositionMassiveAllocs {
            pub x: f32,
            pub y: f32,
            pub z: f32,
        }

        impl Component for PositionMassiveAllocs {
            type Allocator = DefaultAllocator;
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "PositionMassiveAllocs";
            const POOLS_PER_ALLOCATION: usize = 4096;
        }

        impl Default for PositionMassiveAllocs {
            fn default() -> Self {
                Self {
                    x: 1.0,
                    y: 2.0,
                    z: 3.0,
                }
            }
        }

        #[repr(C)]
        #[derive(Debug, PartialEq, Clone, Copy)]
        pub struct Velocity {
            pub x: f32,
            pub y: f32,
            pub z: f32,
        }

        impl Default for Velocity {
            fn default() -> Self {
                Self {
                    x: 1.0,
                    y: 2.0,
                    z: 3.0,
                }
            }
        }

        impl Component for Velocity {
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "Velocity";
            type Allocator = DefaultAllocator;
        }

        #[repr(C)]
        #[derive(Debug, PartialEq, Clone, Copy)]
        pub struct Rotation {
            pub x: f32,
            pub y: f32,
            pub z: f32,
        }

        impl Component for Rotation {
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "Rotation";
            type Allocator = DefaultAllocator;
        }

        impl Default for Rotation {
            fn default() -> Self {
                Self {
                    x: 1.0,
                    y: 2.0,
                    z: 3.0,
                }
            }
        }

        #[repr(C)]
        #[derive(Debug, PartialEq, Clone)]
        pub struct RotationMassiveAllocs {
            pub x: f32,
            pub y: f32,
            pub z: f32,
        }

        impl Component for RotationMassiveAllocs {
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "RotationMassiveAllocs";
            const POOLS_PER_ALLOCATION: usize = 4096;
            type Allocator = DefaultAllocator;
        }

        #[repr(C)]
        #[derive(Debug, PartialEq, Clone)]
        pub struct RotationSeparateAllocs {
            pub x: f32,
            pub y: f32,
            pub z: f32,
        }

        impl Component for RotationSeparateAllocs {
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "RotationSeparateAllocs";
            const POOLS_PER_ALLOCATION: usize = 4096;
            type Allocator = DefaultAllocator;
        }

        #[repr(C)]
        #[derive(Debug, PartialEq, Clone)]
        pub struct Transform {
            pub matrix: [f32; 16],
        }
        impl Component for Transform {
            #[cfg(not(feature = "const_type_name"))]
            const NAME: &'static str = "Transform";
            type Allocator = DefaultAllocator;
        }
    };
}