# HG changeset patch # User alfadur # Date 1565188134 -10800 # Node ID 0076bf6029695324ff40c81756127766d658e11d # Parent b043b5d5219ab51f4087c33922e003f3846ca5c2 start gear data group implementation diff -r b043b5d5219a -r 0076bf602969 rust/hwphysics/src/data.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/hwphysics/src/data.rs Wed Aug 07 17:28:54 2019 +0300 @@ -0,0 +1,97 @@ +use std::any::{Any, TypeId}; + +const BLOCK_SIZE: usize = 8192; + +pub trait TypeTuple { + type Storage: Default; + + fn len() -> usize; + fn get_types(dest: &mut Vec); +} + +//TODO macroise this template for tuples up to sufficient size +impl TypeTuple for (T,) { + type Storage = (Vec,); + + #[inline] + fn len() -> usize { + 1 + } + + #[inline] + fn get_types(dest: &mut Vec) { + dest.push(TypeId::of::()); + } +} + +pub struct GearDataCollection { + len: usize, + blocks: T::Storage, +} + +impl GearDataCollection { + fn new() -> Self { + Self { + len: 0, + blocks: T::Storage::default(), + } + } + + fn iter(&self, f: F) {} +} + +pub struct GearDataGroup { + group_selector: u64, + data: Box, +} + +impl GearDataGroup { + fn iter() {} +} + +pub struct GearDataManager { + types: Vec, + groups: Vec, +} + +impl GearDataManager { + pub fn new() -> Self { + Self { + types: vec![], + groups: vec![], + } + } + + pub fn register(&mut self) { + assert!(self.types.len() <= 64); + let id = TypeId::of::(); + if !self.types.contains(&id) { + self.types.push(id); + } + } + + fn create_selector(&self, types: &[TypeId]) -> u64 { + let mut selector = 0u64; + for (i, typ) in self.types.iter().enumerate() { + if types.contains(&typ) { + selector |= 1 << (i as u64) + } + } + selector + } + + pub fn iter(&self, f: F) { + let mut types = vec![]; + T::get_types(&mut types); + let selector = self.create_selector(&types); + for group in &self.groups { + if group.group_selector & selector == selector { + group + .data + .downcast_ref::>() + .unwrap() + .iter(f); + } + } + } +} diff -r b043b5d5219a -r 0076bf602969 rust/hwphysics/src/lib.rs --- a/rust/hwphysics/src/lib.rs Wed Aug 07 00:54:42 2019 +0300 +++ b/rust/hwphysics/src/lib.rs Wed Aug 07 17:28:54 2019 +0300 @@ -1,5 +1,6 @@ pub mod collision; pub mod common; +mod data; mod grid; pub mod physics; pub mod time;