diff options
| author | Sébastien Crozet <developer@crozet.re> | 2020-12-20 15:47:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-20 15:47:22 +0100 |
| commit | d7cd20d3e4b0fdd963705bbef42520dc05811a56 (patch) | |
| tree | f580c1fc928f3b587273e2bc1cfe0b095bdb9a27 /src_testbed/testbed.rs | |
| parent | 2c8e6b29d647f32a88694b8704cb31b7823963fb (diff) | |
| parent | b2db9e0a06490a644b12ce777fe27bbfa99c37b1 (diff) | |
| download | rapier-d7cd20d3e4b0fdd963705bbef42520dc05811a56.tar.gz rapier-d7cd20d3e4b0fdd963705bbef42520dc05811a56.tar.bz2 rapier-d7cd20d3e4b0fdd963705bbef42520dc05811a56.zip | |
Merge pull request #80 from rezural/extract-physics-state
Extract Physics into module, make new public
Diffstat (limited to 'src_testbed/testbed.rs')
| -rw-r--r-- | src_testbed/testbed.rs | 110 |
1 files changed, 3 insertions, 107 deletions
diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs index 0881d05..4fac8e1 100644 --- a/src_testbed/testbed.rs +++ b/src_testbed/testbed.rs @@ -4,9 +4,10 @@ use std::path::Path; use std::rc::Rc; use crate::engine::GraphicsManager; +use crate::physics::{PhysicsEvents, PhysicsSnapshot, PhysicsState}; use crate::plugin::TestbedPlugin; use crate::ui::TestbedUi; -use crossbeam::channel::Receiver; + use kiss3d::camera::Camera; use kiss3d::event::Event; use kiss3d::event::{Action, Key, WindowEvent}; @@ -20,9 +21,7 @@ use na::{self, Point2, Point3, Vector3}; use rapier::dynamics::{ ActivationStatus, IntegrationParameters, JointSet, RigidBodyHandle, RigidBodySet, }; -use rapier::geometry::{ - BroadPhase, ColliderHandle, ColliderSet, ContactEvent, NarrowPhase, ProximityEvent, -}; +use rapier::geometry::{BroadPhase, ColliderHandle, ColliderSet, NarrowPhase}; #[cfg(feature = "dim3")] use rapier::geometry::{InteractionGroups, Ray}; use rapier::math::Vector; @@ -98,109 +97,6 @@ bitflags! { } } -pub struct PhysicsSnapshot { - timestep_id: usize, - broad_phase: Vec<u8>, - narrow_phase: Vec<u8>, - bodies: Vec<u8>, - colliders: Vec<u8>, - joints: Vec<u8>, -} - -impl PhysicsSnapshot { - fn new( - timestep_id: usize, - broad_phase: &BroadPhase, - narrow_phase: &NarrowPhase, - bodies: &RigidBodySet, - colliders: &ColliderSet, - joints: &JointSet, - ) -> bincode::Result<Self> { - Ok(Self { - timestep_id, - broad_phase: bincode::serialize(broad_phase)?, - narrow_phase: bincode::serialize(narrow_phase)?, - bodies: bincode::serialize(bodies)?, - colliders: bincode::serialize(colliders)?, - joints: bincode::serialize(joints)?, - }) - } - - fn restore( - &self, - ) -> bincode::Result<( - usize, - BroadPhase, - NarrowPhase, - RigidBodySet, - ColliderSet, - JointSet, - )> { - Ok(( - self.timestep_id, - bincode::deserialize(&self.broad_phase)?, - bincode::deserialize(&self.narrow_phase)?, - bincode::deserialize(&self.bodies)?, - bincode::deserialize(&self.colliders)?, - bincode::deserialize(&self.joints)?, - )) - } - - fn print_snapshot_len(&self) { - let total = self.broad_phase.len() - + self.narrow_phase.len() - + self.bodies.len() - + self.colliders.len() - + self.joints.len(); - println!("Snapshot length: {}B", total); - println!("|_ broad_phase: {}B", self.broad_phase.len()); - println!("|_ narrow_phase: {}B", self.narrow_phase.len()); - println!("|_ bodies: {}B", self.bodies.len()); - println!("|_ colliders: {}B", self.colliders.len()); - println!("|_ joints: {}B", self.joints.len()); - } -} - -pub struct PhysicsEvents { - pub contact_events: Receiver<ContactEvent>, - pub proximity_events: Receiver<ProximityEvent>, -} - -impl PhysicsEvents { - fn poll_all(&self) { - while let Ok(_) = self.contact_events.try_recv() {} - while let Ok(_) = self.proximity_events.try_recv() {} - } -} - -pub struct PhysicsState { - pub broad_phase: BroadPhase, - pub narrow_phase: NarrowPhase, - pub bodies: RigidBodySet, - pub colliders: ColliderSet, - pub joints: JointSet, - pub pipeline: PhysicsPipeline, - pub query_pipeline: QueryPipeline, - pub integration_parameters: IntegrationParameters, - pub gravity: Vector<f32>, -} - -impl PhysicsState { - fn new() -> Self { - Self { - broad_phase: BroadPhase::new(), - narrow_phase: NarrowPhase::new(), - bodies: RigidBodySet::new(), - colliders: ColliderSet::new(), - joints: JointSet::new(), - pipeline: PhysicsPipeline::new(), - query_pipeline: QueryPipeline::new(), - integration_parameters: IntegrationParameters::default(), - gravity: Vector::y() * -9.81, - } - } -} - pub struct TestbedState { pub running: RunMode, pub draw_colls: bool, |
