add HarnessState to callbacks, move HarnessPlugin to src_testbed/harness/plugin
This commit is contained in:
@@ -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 plugin in &mut self.plugins {
|
||||
plugin.run_callbacks(&mut self.physics, self.time)
|
||||
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.events,&self.state, self.time)
|
||||
}
|
||||
|
||||
self.events.poll_all();
|
||||
|
||||
self.time += self.physics.integration_parameters.dt();
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
|
||||
10
src_testbed/harness/plugin.rs
Normal file
10
src_testbed/harness/plugin.rs
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user