From cc6d1b973002b4d366bc81ec6bf9e8240ad7b404 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 14 Dec 2020 15:51:43 +0100 Subject: Outsource the Shape trait, wquadtree, and shape types. --- src/data/arena.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/data') diff --git a/src/data/arena.rs b/src/data/arena.rs index fcec017..a3af45c 100644 --- a/src/data/arena.rs +++ b/src/data/arena.rs @@ -3,6 +3,7 @@ //! See https://github.com/fitzgen/generational-arena/blob/master/src/lib.rs. //! This has been modified to have a fully deterministic deserialization (including for the order of //! Index attribution after a deserialization of the arena. +use buckler::partitioning::IndexedData; use std::cmp; use std::iter::{self, Extend, FromIterator, FusedIterator}; use std::mem; @@ -51,6 +52,16 @@ pub struct Index { generation: u64, } +impl IndexedData for Index { + fn default() -> Self { + Self::from_raw_parts(crate::INVALID_USIZE, crate::INVALID_U64) + } + + fn index(&self) -> usize { + self.into_raw_parts().0 + } +} + impl Index { /// Create a new `Index` from its raw parts. /// -- cgit From e231bacec608fa5efd24f7a876572927dbd6c9c4 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Thu, 17 Dec 2020 10:24:36 +0100 Subject: Move all the contact manifold computations out of Rapier. --- src/data/arena.rs | 2 +- src/data/hashmap.rs | 137 ------------------------------------ src/data/maybe_serializable_data.rs | 17 ----- src/data/mod.rs | 4 +- 4 files changed, 2 insertions(+), 158 deletions(-) delete mode 100644 src/data/hashmap.rs delete mode 100644 src/data/maybe_serializable_data.rs (limited to 'src/data') diff --git a/src/data/arena.rs b/src/data/arena.rs index a3af45c..3a24cd1 100644 --- a/src/data/arena.rs +++ b/src/data/arena.rs @@ -3,7 +3,7 @@ //! See https://github.com/fitzgen/generational-arena/blob/master/src/lib.rs. //! This has been modified to have a fully deterministic deserialization (including for the order of //! Index attribution after a deserialization of the arena. -use buckler::partitioning::IndexedData; +use eagl::partitioning::IndexedData; use std::cmp; use std::iter::{self, Extend, FromIterator, FusedIterator}; use std::mem; diff --git a/src/data/hashmap.rs b/src/data/hashmap.rs deleted file mode 100644 index d2ea980..0000000 --- a/src/data/hashmap.rs +++ /dev/null @@ -1,137 +0,0 @@ -//! A hash-map that behaves deterministically when the -//! `enhanced-determinism` feature is enabled. - -#[cfg(all(feature = "enhanced-determinism", feature = "serde-serialize"))] -use indexmap::IndexMap as StdHashMap; -#[cfg(all(not(feature = "enhanced-determinism"), feature = "serde-serialize"))] -use std::collections::HashMap as StdHashMap; - -/// Serializes only the capacity of a hash-map instead of its actual content. -#[cfg(feature = "serde-serialize")] -pub fn serialize_hashmap_capacity( - map: &StdHashMap, - s: S, -) -> Result { - s.serialize_u64(map.capacity() as u64) -} - -/// Creates a new hash-map with its capacity deserialized from `d`. -#[cfg(feature = "serde-serialize")] -pub fn deserialize_hashmap_capacity< - 'de, - D: serde::Deserializer<'de>, - K, - V, - H: std::hash::BuildHasher + Default, ->( - d: D, -) -> Result, D::Error> { - struct CapacityVisitor; - impl<'de> serde::de::Visitor<'de> for CapacityVisitor { - type Value = u64; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(formatter, "an integer between 0 and 2^64") - } - - fn visit_u64(self, val: u64) -> Result { - Ok(val) - } - } - - let capacity = d.deserialize_u64(CapacityVisitor)? as usize; - Ok(StdHashMap::with_capacity_and_hasher( - capacity, - Default::default(), - )) -} - -/* - * FxHasher taken from rustc_hash, except that it does not depend on the pointer size. - */ -#[cfg(feature = "enhanced-determinism")] -pub type FxHashMap32 = indexmap::IndexMap>; -#[cfg(feature = "enhanced-determinism")] -pub use {self::FxHashMap32 as HashMap, indexmap::map::Entry}; -#[cfg(not(feature = "enhanced-determinism"))] -pub use {rustc_hash::FxHashMap as HashMap, std::collections::hash_map::Entry}; - -const K: u32 = 0x9e3779b9; - -// Same as FxHasher, but with the guarantee that the internal hash is -// an u32 instead of something that depends on the platform. -pub struct FxHasher32 { - hash: u32, -} - -impl Default for FxHasher32 { - #[inline] - fn default() -> FxHasher32 { - FxHasher32 { hash: 0 } - } -} - -impl FxHasher32 { - #[inline] - fn add_to_hash(&mut self, i: u32) { - use std::ops::BitXor; - self.hash = self.hash.rotate_left(5).bitxor(i).wrapping_mul(K); - } -} - -impl std::hash::Hasher for FxHasher32 { - #[inline] - fn write(&mut self, mut bytes: &[u8]) { - use std::convert::TryInto; - let read_u32 = |bytes: &[u8]| u32::from_ne_bytes(bytes[..4].try_into().unwrap()); - let mut hash = FxHasher32 { hash: self.hash }; - assert!(std::mem::size_of::() <= 8); - while bytes.len() >= std::mem::size_of::() { - hash.add_to_hash(read_u32(bytes) as u32); - bytes = &bytes[std::mem::size_of::()..]; - } - if (std::mem::size_of::() > 4) && (bytes.len() >= 4) { - hash.add_to_hash(u32::from_ne_bytes(bytes[..4].try_into().unwrap()) as u32); - bytes = &bytes[4..]; - } - if (std::mem::size_of::() > 2) && bytes.len() >= 2 { - hash.add_to_hash(u16::from_ne_bytes(bytes[..2].try_into().unwrap()) as u32); - bytes = &bytes[2..]; - } - if (std::mem::size_of::() > 1) && bytes.len() >= 1 { - hash.add_to_hash(bytes[0] as u32); - } - self.hash = hash.hash; - } - - #[inline] - fn write_u8(&mut self, i: u8) { - self.add_to_hash(i as u32); - } - - #[inline] - fn write_u16(&mut self, i: u16) { - self.add_to_hash(i as u32); - } - - #[inline] - fn write_u32(&mut self, i: u32) { - self.add_to_hash(i as u32); - } - - #[inline] - fn write_u64(&mut self, i: u64) { - self.add_to_hash(i as u32); - self.add_to_hash((i >> 32) as u32); - } - - #[inline] - fn write_usize(&mut self, i: usize) { - self.add_to_hash(i as u32); - } - - #[inline] - fn finish(&self) -> u64 { - self.hash as u64 - } -} diff --git a/src/data/maybe_serializable_data.rs b/src/data/maybe_serializable_data.rs deleted file mode 100644 index 8b14e1a..0000000 --- a/src/data/maybe_serializable_data.rs +++ /dev/null @@ -1,17 +0,0 @@ -use downcast_rs::{impl_downcast, DowncastSync}; -#[cfg(feature = "serde-serialize")] -use erased_serde::Serialize; - -/// Piece of data that may be serializable. -pub trait MaybeSerializableData: DowncastSync { - /// Convert this shape as a serializable entity. - #[cfg(feature = "serde-serialize")] - fn as_serialize(&self) -> Option<(u32, &dyn Serialize)> { - None - } - - /// Clones `self`. - fn clone_dyn(&self) -> Box; -} - -impl_downcast!(sync MaybeSerializableData); diff --git a/src/data/mod.rs b/src/data/mod.rs index 672bf94..eb0a229 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -1,11 +1,9 @@ //! Data structures modified with guaranteed deterministic behavior after deserialization. pub use self::coarena::Coarena; -pub use self::maybe_serializable_data::MaybeSerializableData; +pub use eagl::utils::MaybeSerializableData; pub mod arena; mod coarena; pub(crate) mod graph; -pub(crate) mod hashmap; -mod maybe_serializable_data; pub mod pubsub; -- cgit From 8fe2df126a279a435cc544b150aadf8f7b757868 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Thu, 17 Dec 2020 18:37:16 +0100 Subject: Remove some irrelevant code. --- src/data/arena.rs | 2 +- src/data/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/data') diff --git a/src/data/arena.rs b/src/data/arena.rs index 3a24cd1..8a694dc 100644 --- a/src/data/arena.rs +++ b/src/data/arena.rs @@ -3,7 +3,7 @@ //! See https://github.com/fitzgen/generational-arena/blob/master/src/lib.rs. //! This has been modified to have a fully deterministic deserialization (including for the order of //! Index attribution after a deserialization of the arena. -use eagl::partitioning::IndexedData; +use cdl::partitioning::IndexedData; use std::cmp; use std::iter::{self, Extend, FromIterator, FusedIterator}; use std::mem; diff --git a/src/data/mod.rs b/src/data/mod.rs index eb0a229..1c53db4 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -1,7 +1,7 @@ //! Data structures modified with guaranteed deterministic behavior after deserialization. pub use self::coarena::Coarena; -pub use eagl::utils::MaybeSerializableData; +pub use cdl::utils::MaybeSerializableData; pub mod arena; mod coarena; -- cgit From 8f7220f03d3c23574b9ece09d81d32e862f1b5c6 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Sun, 24 Jan 2021 11:13:44 +0100 Subject: Rename cdl to parry. --- src/data/arena.rs | 2 +- src/data/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/data') diff --git a/src/data/arena.rs b/src/data/arena.rs index 8a694dc..9d057b8 100644 --- a/src/data/arena.rs +++ b/src/data/arena.rs @@ -3,7 +3,7 @@ //! See https://github.com/fitzgen/generational-arena/blob/master/src/lib.rs. //! This has been modified to have a fully deterministic deserialization (including for the order of //! Index attribution after a deserialization of the arena. -use cdl::partitioning::IndexedData; +use parry::partitioning::IndexedData; use std::cmp; use std::iter::{self, Extend, FromIterator, FusedIterator}; use std::mem; diff --git a/src/data/mod.rs b/src/data/mod.rs index 1c53db4..edcd326 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -1,7 +1,7 @@ //! Data structures modified with guaranteed deterministic behavior after deserialization. pub use self::coarena::Coarena; -pub use cdl::utils::MaybeSerializableData; +pub use parry::utils::MaybeSerializableData; pub mod arena; mod coarena; -- cgit