implement body hash

This commit is contained in:
Quaternions 2023-10-11 18:30:56 -07:00
parent 9a12265881
commit c21c587edc
2 changed files with 3 additions and 22 deletions

View File

@ -179,7 +179,7 @@ pub struct Unit64Mat3{
///[-1.0,1.0] = [-2^32,2^32] ///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy)] #[derive(Clone,Copy,Hash)]
pub struct Planar64(i64); pub struct Planar64(i64);
impl Planar64{ impl Planar64{
pub const ONE:Self=Self(2<<32); pub const ONE:Self=Self(2<<32);
@ -221,7 +221,7 @@ impl std::ops::Div<i64> for Planar64{
///[-1.0,1.0] = [-2^32,2^32] ///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy)] #[derive(Clone,Copy,Hash)]
pub struct Planar64Vec3(glam::I64Vec3); pub struct Planar64Vec3(glam::I64Vec3);
impl Planar64Vec3{ impl Planar64Vec3{
pub fn new(x:i32,y:i32,z:i32)->Self{ pub fn new(x:i32,y:i32,z:i32)->Self{

View File

@ -49,32 +49,13 @@ pub enum InputInstruction {
//for interpolation / networking / playback reasons, most playback heads will always want //for interpolation / networking / playback reasons, most playback heads will always want
//to be 1 instruction ahead to generate the next state for interpolation. //to be 1 instruction ahead to generate the next state for interpolation.
} }
#[derive(Clone)] #[derive(Clone,Hash)]
pub struct Body { pub struct Body {
position: Planar64Vec3,//I64 where 2^32 = 1 u position: Planar64Vec3,//I64 where 2^32 = 1 u
velocity: Planar64Vec3,//I64 where 2^32 = 1 u/s velocity: Planar64Vec3,//I64 where 2^32 = 1 u/s
acceleration: Planar64Vec3,//I64 where 2^32 = 1 u/s/s acceleration: Planar64Vec3,//I64 where 2^32 = 1 u/s/s
time: TIME,//nanoseconds x xxxxD! time: TIME,//nanoseconds x xxxxD!
} }
trait MyHash{
fn hash(&self) -> u64;
}
impl MyHash for Body {
fn hash(&self) -> u64 {
let mut hasher=std::collections::hash_map::DefaultHasher::new();
for &el in self.position.as_ref().iter() {
std::hash::Hasher::write(&mut hasher, el.to_ne_bytes().as_slice());
}
for &el in self.velocity.as_ref().iter() {
std::hash::Hasher::write(&mut hasher, el.to_ne_bytes().as_slice());
}
for &el in self.acceleration.as_ref().iter() {
std::hash::Hasher::write(&mut hasher, el.to_ne_bytes().as_slice());
}
std::hash::Hasher::write(&mut hasher, self.time.to_ne_bytes().as_slice());
return std::hash::Hasher::finish(&hasher);//hash check to see if walk target is valid
}
}
pub enum MoveRestriction { pub enum MoveRestriction {
Air, Air,