rust/hwphysics/src/data.rs
changeset 15380 6e3e5be8b2e2
parent 15379 27915135f87f
child 15381 52844baced17
equal deleted inserted replaced
15379:27915135f87f 15380:6e3e5be8b2e2
    21                 $(types.push(TypeId::of::<$t>()));+
    21                 $(types.push(TypeId::of::<$t>()));+
    22             }
    22             }
    23 
    23 
    24             unsafe fn iter<F: FnMut(GearId, Self)>(slices: &[*mut u8], count: usize, mut f: F) {
    24             unsafe fn iter<F: FnMut(GearId, Self)>(slices: &[*mut u8], count: usize, mut f: F) {
    25                 for i in 0..count {
    25                 for i in 0..count {
    26                     unsafe {
    26                     f(*(*slices.get_unchecked(0) as *const GearId).add(i),
    27                         f(*(*slices.get_unchecked(0) as *const GearId).add(i),
    27                       ($(&*(*slices.get_unchecked($n + 1) as *mut $t).add(i)),+,));
    28                           ($(&*(*slices.get_unchecked($n + 1) as *mut $t).add(i)),+,));
       
    29                     }
       
    30                 }
    28                 }
    31             }
    29             }
    32         }
    30         }
    33 
    31 
    34         impl<$($t: 'static),+> TypeTuple for ($(&mut $t),+,) {
    32         impl<$($t: 'static),+> TypeTuple for ($(&mut $t),+,) {
    36                 $(types.push(TypeId::of::<$t>()));+
    34                 $(types.push(TypeId::of::<$t>()));+
    37             }
    35             }
    38 
    36 
    39             unsafe fn iter<F: FnMut(GearId, Self)>(slices: &[*mut u8], count: usize, mut f: F) {
    37             unsafe fn iter<F: FnMut(GearId, Self)>(slices: &[*mut u8], count: usize, mut f: F) {
    40                 for i in 0..count {
    38                 for i in 0..count {
    41                     unsafe {
    39                     f(*(*slices.get_unchecked(0) as *const GearId).add(i),
    42                         f(*(*slices.get_unchecked(0) as *const GearId).add(i),
    40                       ($(&mut *(*slices.get_unchecked($n + 1) as *mut $t).add(i)),+,));
    43                           ($(&mut *(*slices.get_unchecked($n + 1) as *mut $t).add(i)),+,));
       
    44                     }
       
    45                 }
    41                 }
    46             }
    42             }
    47         }
    43         }
    48     }
    44     }
    49 }
    45 }
   380             self.element_sizes[self.types.len()] = size_of::<T>() as u16;
   376             self.element_sizes[self.types.len()] = size_of::<T>() as u16;
   381             self.types.push(id);
   377             self.types.push(id);
   382         }
   378         }
   383     }
   379     }
   384 
   380 
   385 
       
   386     pub fn iter<T: TypeTuple + 'static, F: FnMut(T)>(&mut self, mut f: F) {
   381     pub fn iter<T: TypeTuple + 'static, F: FnMut(T)>(&mut self, mut f: F) {
   387         self.iter_id(|_, x| f(x));
   382         self.iter_id(|_, x| f(x));
   388     }
   383     }
   389 
   384 
   390     pub fn iter_id<T: TypeTuple + 'static, F: FnMut(GearId, T)>(&mut self, mut f: F) {
   385     pub fn iter_id<T: TypeTuple + 'static, F: FnMut(GearId, T)>(&mut self, mut f: F) {