aboutsummaryrefslogtreecommitdiff
path: root/src_testbed
diff options
context:
space:
mode:
authorrezural <rezural@protonmail.com>2020-12-20 23:58:50 +1100
committerrezural <rezural@protonmail.com>2020-12-21 04:23:11 +1100
commitbe07227e9455e1549f1fee2f278ab2a266c5c3c2 (patch)
treea2a0c78d6f6fcac69fa54dd226a08c24a5c3fbd8 /src_testbed
parent315b84a85e67077d5e5232f3c3f4f3d80b85db81 (diff)
downloadrapier-be07227e9455e1549f1fee2f278ab2a266c5c3c2.tar.gz
rapier-be07227e9455e1549f1fee2f278ab2a266c5c3c2.tar.bz2
rapier-be07227e9455e1549f1fee2f278ab2a266c5c3c2.zip
add HarnessState to callbacks, move HarnessPlugin to src_testbed/harness/plugin
Diffstat (limited to 'src_testbed')
-rw-r--r--src_testbed/harness/mod.rs26
-rw-r--r--src_testbed/harness/plugin.rs10
-rw-r--r--src_testbed/lib.rs4
-rw-r--r--src_testbed/plugin.rs6
4 files changed, 33 insertions, 13 deletions
diff --git a/src_testbed/harness/mod.rs b/src_testbed/harness/mod.rs
index af9a45d..7d6a939 100644
--- a/src_testbed/harness/mod.rs
+++ b/src_testbed/harness/mod.rs
@@ -1,10 +1,13 @@
use crate::physics::{PhysicsEvents, PhysicsState};
-use crate::HarnessPlugin;
use rapier::dynamics::{IntegrationParameters, JointSet, RigidBodySet};
use rapier::geometry::{BroadPhase, ColliderSet, NarrowPhase};
use rapier::math::Vector;
use rapier::pipeline::{ChannelEventCollector, PhysicsPipeline, QueryPipeline};
+pub mod plugin;
+
+use plugin::HarnessPlugin;
+
// #[derive(PartialEq)]
// pub enum RunState {
// Initialized,
@@ -32,7 +35,7 @@ pub struct Harness {
pub state: HarnessState,
}
-type Callbacks = Vec<Box<dyn FnMut(&mut PhysicsState, &PhysicsEvents, f32)>>;
+type Callbacks = Vec<Box<dyn FnMut(&mut PhysicsState, &PhysicsEvents, &HarnessState, f32)>>;
#[allow(dead_code)]
impl Harness {
@@ -141,7 +144,8 @@ impl Harness {
self.plugins.push(Box::new(plugin));
}
- pub fn add_callback<F: FnMut(&mut PhysicsState, &PhysicsEvents, f32) + 'static>(
+ // type StepCallback = FnMut(&mut PhysicsState, &PhysicsEvents, f32);
+ pub fn add_callback<F: FnMut(&mut PhysicsState, &PhysicsEvents, &HarnessState, f32) + 'static>(
&mut self,
callback: F,
) {
@@ -191,10 +195,22 @@ impl Harness {
plugin.step(&mut self.physics)
}
- //FIXME: not sure if this makes sense here, basically copied from Testbed
+ for f in &mut self.callbacks {
+ f(
+ &mut self.physics,
+ &self.events,
+ &self.state,
+ self.time,
+ )
+ }
+
for plugin in &mut self.plugins {
- plugin.run_callbacks(&mut self.physics, self.time)
+ plugin.run_callbacks(&mut self.physics, &self.events,&self.state, self.time)
}
+
+ self.events.poll_all();
+
+ self.time += self.physics.integration_parameters.dt();
}
pub fn run(&mut self) {
diff --git a/src_testbed/harness/plugin.rs b/src_testbed/harness/plugin.rs
new file mode 100644
index 0000000..d5cf158
--- /dev/null
+++ b/src_testbed/harness/plugin.rs
@@ -0,0 +1,10 @@
+use crate::harness::HarnessState;
+use crate::PhysicsState;
+use crate::physics::PhysicsEvents;
+
+pub trait HarnessPlugin {
+ //FIXME: is run_callbacks needed?
+ fn run_callbacks(&mut self, physics: &mut PhysicsState, events: &PhysicsEvents, harness_state: &HarnessState, t: f32);
+ fn step(&mut self, physics: &mut PhysicsState);
+ fn profiling_string(&self) -> String;
+} \ No newline at end of file
diff --git a/src_testbed/lib.rs b/src_testbed/lib.rs
index 9b08330..daf364b 100644
--- a/src_testbed/lib.rs
+++ b/src_testbed/lib.rs
@@ -23,7 +23,7 @@ extern crate log;
pub use crate::engine::GraphicsManager;
pub use crate::physics::PhysicsState;
-pub use crate::plugin::HarnessPlugin;
+pub use crate::harness::plugin::HarnessPlugin;
pub use crate::plugin::TestbedPlugin;
pub use crate::testbed::Testbed;
@@ -34,7 +34,7 @@ pub mod harness;
#[cfg(feature = "other-backends")]
mod nphysics_backend;
pub mod objects;
-mod physics;
+pub mod physics;
#[cfg(all(feature = "dim3", feature = "other-backends"))]
mod physx_backend;
mod plugin;
diff --git a/src_testbed/plugin.rs b/src_testbed/plugin.rs
index 6da1404..811e33c 100644
--- a/src_testbed/plugin.rs
+++ b/src_testbed/plugin.rs
@@ -11,9 +11,3 @@ pub trait TestbedPlugin {
fn profiling_string(&self) -> String;
}
-pub trait HarnessPlugin {
- //FIXME: is run_callbacks needed?
- fn run_callbacks(&mut self, physics: &mut PhysicsState, t: f32);
- fn step(&mut self, physics: &mut PhysicsState);
- fn profiling_string(&self) -> String;
-}