aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-11-03 14:43:21 +0100
committerCrozet Sébastien <developer@crozet.re>2020-11-03 14:43:21 +0100
commit0cf59d78bda1669226f861e438d43a08b099d747 (patch)
tree001d68cfa4aea673b73f69d2f95f549a675ac195
parent036a24614171eff0f99495b8b6f1c09e58cb4f9a (diff)
downloadrapier-0cf59d78bda1669226f861e438d43a08b099d747.tar.gz
rapier-0cf59d78bda1669226f861e438d43a08b099d747.tar.bz2
rapier-0cf59d78bda1669226f861e438d43a08b099d747.zip
Implement Clone for everything that can be cloned.
-rw-r--r--src/data/maybe_serializable_data.rs3
-rw-r--r--src/data/pubsub.rs3
-rw-r--r--src/dynamics/rigid_body_set.rs1
-rw-r--r--src/geometry/broad_phase_multi_sap.rs5
-rw-r--r--src/geometry/collider_set.rs1
-rw-r--r--src/geometry/contact.rs1
-rw-r--r--src/geometry/contact_generator/contact_generator_workspace.rs6
-rw-r--r--src/geometry/contact_generator/heightfield_shape_contact_generator.rs6
-rw-r--r--src/geometry/contact_generator/pfm_pfm_contact_generator.rs5
-rw-r--r--src/geometry/contact_generator/trimesh_shape_contact_generator.rs5
-rw-r--r--src/geometry/interaction_graph.rs1
-rw-r--r--src/geometry/narrow_phase.rs1
-rw-r--r--src/geometry/proximity.rs12
-rw-r--r--src/pipeline/query_pipeline.rs1
14 files changed, 51 insertions, 0 deletions
diff --git a/src/data/maybe_serializable_data.rs b/src/data/maybe_serializable_data.rs
index db38963..8b14e1a 100644
--- a/src/data/maybe_serializable_data.rs
+++ b/src/data/maybe_serializable_data.rs
@@ -9,6 +9,9 @@ pub trait MaybeSerializableData: DowncastSync {
fn as_serialize(&self) -> Option<(u32, &dyn Serialize)> {
None
}
+
+ /// Clones `self`.
+ fn clone_dyn(&self) -> Box<dyn MaybeSerializableData>;
}
impl_downcast!(sync MaybeSerializableData);
diff --git a/src/data/pubsub.rs b/src/data/pubsub.rs
index b2c9e27..80fb3a2 100644
--- a/src/data/pubsub.rs
+++ b/src/data/pubsub.rs
@@ -5,6 +5,7 @@ use std::marker::PhantomData;
/// A permanent subscription to a pub-sub queue.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct Subscription<T> {
// Position on the cursor array.
id: u32,
@@ -12,6 +13,7 @@ pub struct Subscription<T> {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
struct PubSubCursor {
// Position on the offset array.
id: u32,
@@ -36,6 +38,7 @@ impl PubSubCursor {
/// A pub-sub queue.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct PubSub<T> {
deleted_messages: u32,
deleted_offsets: u32,
diff --git a/src/dynamics/rigid_body_set.rs b/src/dynamics/rigid_body_set.rs
index 2efc2cf..f7064ed 100644
--- a/src/dynamics/rigid_body_set.rs
+++ b/src/dynamics/rigid_body_set.rs
@@ -75,6 +75,7 @@ impl BodyPair {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
/// A set of rigid bodies that can be handled by a physics pipeline.
pub struct RigidBodySet {
// NOTE: the pub(crate) are needed by the broad phase
diff --git a/src/geometry/broad_phase_multi_sap.rs b/src/geometry/broad_phase_multi_sap.rs
index 1afda5a..21413ef 100644
--- a/src/geometry/broad_phase_multi_sap.rs
+++ b/src/geometry/broad_phase_multi_sap.rs
@@ -132,6 +132,7 @@ impl Endpoint {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
struct SAPAxis {
min_bound: f32,
max_bound: f32,
@@ -331,6 +332,7 @@ impl SAPAxis {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
struct SAPRegion {
axes: [SAPAxis; DIM],
existing_proxies: BitVec,
@@ -411,6 +413,7 @@ impl SAPRegion {
/// A broad-phase based on multiple Sweep-and-Prune instances running of disjoint region of the 3D world.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct BroadPhase {
proxies: Proxies,
regions: HashMap<Point<i32>, SAPRegion>,
@@ -438,6 +441,7 @@ pub struct BroadPhase {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub(crate) struct BroadPhaseProxy {
handle: ColliderHandle,
aabb: AABB<f32>,
@@ -445,6 +449,7 @@ pub(crate) struct BroadPhaseProxy {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
struct Proxies {
elements: Vec<BroadPhaseProxy>,
first_free: u32,
diff --git a/src/geometry/collider_set.rs b/src/geometry/collider_set.rs
index d2bb8cc..0ba5911 100644
--- a/src/geometry/collider_set.rs
+++ b/src/geometry/collider_set.rs
@@ -17,6 +17,7 @@ pub(crate) struct RemovedCollider {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
/// A set of colliders that can be handled by a physics `World`.
pub struct ColliderSet {
pub(crate) removed_colliders: PubSub<RemovedCollider>,
diff --git a/src/geometry/contact.rs b/src/geometry/contact.rs
index 53e9064..a4a176e 100644
--- a/src/geometry/contact.rs
+++ b/src/geometry/contact.rs
@@ -172,6 +172,7 @@ impl Contact {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
/// The description of all the contacts between a pair of colliders.
pub struct ContactPair {
/// The pair of colliders involved.
diff --git a/src/geometry/contact_generator/contact_generator_workspace.rs b/src/geometry/contact_generator/contact_generator_workspace.rs
index fb6d7b4..e89395f 100644
--- a/src/geometry/contact_generator/contact_generator_workspace.rs
+++ b/src/geometry/contact_generator/contact_generator_workspace.rs
@@ -9,6 +9,12 @@ use crate::geometry::contact_generator::{
// Note we have this newtype because it simplifies the serialization/deserialization code.
pub struct ContactGeneratorWorkspace(pub Box<dyn MaybeSerializableData>);
+impl Clone for ContactGeneratorWorkspace {
+ fn clone(&self) -> Self {
+ ContactGeneratorWorkspace(self.0.clone_dyn())
+ }
+}
+
impl<T: MaybeSerializableData> From<T> for ContactGeneratorWorkspace {
fn from(data: T) -> Self {
Self(Box::new(data) as Box<dyn MaybeSerializableData>)
diff --git a/src/geometry/contact_generator/heightfield_shape_contact_generator.rs b/src/geometry/contact_generator/heightfield_shape_contact_generator.rs
index 62c6365..70360c9 100644
--- a/src/geometry/contact_generator/heightfield_shape_contact_generator.rs
+++ b/src/geometry/contact_generator/heightfield_shape_contact_generator.rs
@@ -12,6 +12,7 @@ use crate::ncollide::bounding_volume::BoundingVolume;
use erased_serde::Serialize;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
struct SubDetector {
#[cfg_attr(feature = "serde-serialize", serde(skip))]
generator: Option<PrimitiveContactGenerator>,
@@ -21,6 +22,7 @@ struct SubDetector {
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct HeightFieldShapeContactGeneratorWorkspace {
timestamp: bool,
#[cfg_attr(feature = "serde-serialize", serde(skip))]
@@ -182,4 +184,8 @@ impl MaybeSerializableData for HeightFieldShapeContactGeneratorWorkspace {
self,
))
}
+
+ fn clone_dyn(&self) -> Box<dyn MaybeSerializableData> {
+ Box::new(self.clone())
+ }
}
diff --git a/src/geometry/contact_generator/pfm_pfm_contact_generator.rs b/src/geometry/contact_generator/pfm_pfm_contact_generator.rs
index 027c398..e18e77f 100644
--- a/src/geometry/contact_generator/pfm_pfm_contact_generator.rs
+++ b/src/geometry/contact_generator/pfm_pfm_contact_generator.rs
@@ -9,6 +9,7 @@ use ncollide::query;
use ncollide::query::algorithms::{gjk::GJKResult, VoronoiSimplex};
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct PfmPfmContactManifoldGeneratorWorkspace {
#[cfg_attr(
feature = "serde-serialize",
@@ -136,4 +137,8 @@ impl MaybeSerializableData for PfmPfmContactManifoldGeneratorWorkspace {
self,
))
}
+
+ fn clone(&self) -> Box<MaybeSerializableData> {
+ Box::new(self.clone())
+ }
}
diff --git a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs
index 26ccfaa..3f7d7cd 100644
--- a/src/geometry/contact_generator/trimesh_shape_contact_generator.rs
+++ b/src/geometry/contact_generator/trimesh_shape_contact_generator.rs
@@ -8,6 +8,7 @@ use crate::ncollide::bounding_volume::{BoundingVolume, AABB};
use erased_serde::Serialize;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct TrimeshShapeContactGeneratorWorkspace {
interferences: Vec<usize>,
local_aabb2: AABB<f32>,
@@ -213,4 +214,8 @@ impl MaybeSerializableData for TrimeshShapeContactGeneratorWorkspace {
self,
))
}
+
+ fn clone_dyn(&self) -> Box<dyn MaybeSerializableData> {
+ Box::new(self.clone())
+ }
}
diff --git a/src/geometry/interaction_graph.rs b/src/geometry/interaction_graph.rs
index c0cf093..2abb6d1 100644
--- a/src/geometry/interaction_graph.rs
+++ b/src/geometry/interaction_graph.rs
@@ -10,6 +10,7 @@ pub type TemporaryInteractionIndex = EdgeIndex;
/// A graph where nodes are collision objects and edges are contact or proximity algorithms.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct InteractionGraph<T> {
pub(crate) graph: Graph<ColliderHandle, T>,
}
diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs
index e3e52e5..059a640 100644
--- a/src/geometry/narrow_phase.rs
+++ b/src/geometry/narrow_phase.rs
@@ -29,6 +29,7 @@ use std::collections::HashMap;
/// The narrow-phase responsible for computing precise contact information between colliders.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct NarrowPhase {
contact_graph: InteractionGraph<ContactPair>,
proximity_graph: InteractionGraph<ProximityPair>,
diff --git a/src/geometry/proximity.rs b/src/geometry/proximity.rs
index 88e6e76..d3e0dc4 100644
--- a/src/geometry/proximity.rs
+++ b/src/geometry/proximity.rs
@@ -15,6 +15,18 @@ pub struct ProximityPair {
pub(crate) detector_workspace: Option<Box<dyn Any + Send + Sync>>,
}
+// TODO: use the `derive(Clone)` instead?
+impl Clone for ProximityPair {
+ fn clone(&self) -> Self {
+ ProximityPair {
+ pair: self.pair.clone(),
+ proximity: self.proximity.clone(),
+ detector: None,
+ detector_workspace: None,
+ }
+ }
+}
+
impl ProximityPair {
pub(crate) fn new(
pair: ColliderPair,
diff --git a/src/pipeline/query_pipeline.rs b/src/pipeline/query_pipeline.rs
index 00d4396..c21574a 100644
--- a/src/pipeline/query_pipeline.rs
+++ b/src/pipeline/query_pipeline.rs
@@ -5,6 +5,7 @@ use crate::geometry::{
/// A pipeline for performing queries on all the colliders of a scene.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Clone)]
pub struct QueryPipeline {
quadtree: WQuadtree<ColliderHandle>,
tree_built: bool,