aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrezural <rezural@protonmail.com>2021-06-28 11:05:55 +1000
committerSébastien Crozet <sebastien@crozet.re>2021-07-08 10:07:42 +0200
commit7c249c873d28b4fa03023bff6fe3bf5df7a1cee9 (patch)
treede9c0095da5449e6e438284c572e48164e3f93cb
parent62d6b0651b35b5b354c18b386d8a4e2c9669fd2f (diff)
downloadrapier-7c249c873d28b4fa03023bff6fe3bf5df7a1cee9.tar.gz
rapier-7c249c873d28b4fa03023bff6fe3bf5df7a1cee9.tar.bz2
rapier-7c249c873d28b4fa03023bff6fe3bf5df7a1cee9.zip
enable clear_graphics and run_callbacks agin
update plugin signature to recieve bevy structs, add Arc<Mutex<>> around gfx_components, we we can get shared mutable access add prefab_meshes() access function Remove Arc<Mutex<>>
-rw-r--r--src_testbed/graphics.rs12
-rw-r--r--src_testbed/objects/node.rs1
-rw-r--r--src_testbed/plugin.rs30
-rw-r--r--src_testbed/testbed.rs57
4 files changed, 72 insertions, 28 deletions
diff --git a/src_testbed/graphics.rs b/src_testbed/graphics.rs
index 060798c..0682f63 100644
--- a/src_testbed/graphics.rs
+++ b/src_testbed/graphics.rs
@@ -195,9 +195,9 @@ impl GraphicsManager {
.cloned()
.unwrap_or_else(|| self.alloc_color(materials, handle, !body.is_dynamic()));
- self.add_with_color(
+ let _ = self.add_with_color(
commands, meshes, materials, components, handle, bodies, colliders, color,
- )
+ );
}
pub fn add_with_color(
@@ -210,8 +210,7 @@ impl GraphicsManager {
bodies: &RigidBodySet,
colliders: &ColliderSet,
color: Point3<f32>,
- ) {
- // let body = bodies.get(handle).unwrap();
+ ) -> Vec<EntityWithGraphics> {
let mut new_nodes = Vec::new();
for collider_handle in bodies[handle].colliders() {
@@ -246,7 +245,10 @@ impl GraphicsManager {
// }
let nodes = self.b2sn.entry(handle).or_insert_with(Vec::new);
- nodes.append(&mut new_nodes);
+
+ nodes.append(&mut new_nodes.clone());
+
+ new_nodes
}
pub fn add_collider(
diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs
index 9acc62e..a7d39fd 100644
--- a/src_testbed/objects/node.rs
+++ b/src_testbed/objects/node.rs
@@ -17,6 +17,7 @@ use {
rapier::geometry::{Ball, Cuboid},
};
+#[derive(Clone, Debug)]
pub struct EntityWithGraphics {
pub entity: Entity,
pub color: Point3<f32>,
diff --git a/src_testbed/plugin.rs b/src_testbed/plugin.rs
index 8603880..24a91dd 100644
--- a/src_testbed/plugin.rs
+++ b/src_testbed/plugin.rs
@@ -1,12 +1,32 @@
-use crate::harness::RunState;
+use crate::harness::Harness;
use crate::physics::PhysicsState;
+use crate::GraphicsManager;
+use bevy::prelude::{Assets, Commands, Mesh, Query, StandardMaterial, Transform};
use na::Point3;
pub trait TestbedPlugin {
- fn init_graphics(&mut self, gen_color: &mut dyn FnMut() -> Point3<f32>);
- fn clear_graphics(&mut self);
- fn run_callbacks(&mut self, physics: &mut PhysicsState, run_state: &RunState);
+ fn init_graphics(
+ &mut self,
+ graphics: &mut GraphicsManager,
+ commands: &mut Commands,
+ meshes: &mut Assets<Mesh>,
+ materials: &mut Assets<StandardMaterial>,
+ components: &mut Query<(&mut Transform,)>,
+ harness: &mut Harness,
+
+ gen_color: &mut dyn FnMut() -> Point3<f32>,
+ );
+ fn clear_graphics(&mut self, graphics: &mut GraphicsManager, commands: &mut Commands);
+ fn run_callbacks(&mut self, harness: &mut Harness);
fn step(&mut self, physics: &mut PhysicsState);
- fn draw(&mut self);
+ fn draw(
+ &mut self,
+ graphics: &mut GraphicsManager,
+ commands: &mut Commands,
+ meshes: &mut Assets<Mesh>,
+ materials: &mut Assets<StandardMaterial>,
+ components: &mut Query<(&mut Transform,)>,
+ harness: &mut Harness,
+ );
fn profiling_string(&self) -> String;
}
diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs
index 6f022f2..8b23e02 100644
--- a/src_testbed/testbed.rs
+++ b/src_testbed/testbed.rs
@@ -942,6 +942,7 @@ fn update_testbed(
let selected_example = state.selected_example;
let manager = &mut *graphics;
let meshes = &mut *meshes;
+
let graphics_context = TestbedGraphics {
manager: &mut *manager,
commands: &mut commands,
@@ -950,6 +951,7 @@ fn update_testbed(
components: &mut gfx_components,
camera: &mut cameras.iter_mut().next().unwrap().2,
};
+
let mut testbed = Testbed {
graphics: Some(graphics_context),
state: &mut *state,
@@ -997,9 +999,9 @@ fn update_testbed(
if let Ok(w) = snapshot.restore() {
clear(&mut commands, &mut state, &mut graphics, &mut plugins);
- // for plugin in &mut plugins {
- // plugin.clear_graphics(window);
- // }
+ for plugin in &mut plugins.0 {
+ plugin.clear_graphics(&mut graphics, &mut commands);
+ }
// set_world(w.3, w.4, w.5);
harness.physics.broad_phase = w.1;
@@ -1028,10 +1030,18 @@ fn update_testbed(
);
}
- // for plugin in &mut plugins {
- // let graphics = &mut graphics;
- // plugin.init_graphics(window, &mut || graphics.next_color());
- // }
+ for plugin in &mut plugins.0 {
+ let next_color = graphics.next_color();
+ plugin.init_graphics(
+ &mut graphics,
+ &mut commands,
+ meshes,
+ materials,
+ &mut gfx_components,
+ &mut harness,
+ &mut || next_color,
+ );
+ }
}
if example_changed
@@ -1071,6 +1081,7 @@ fn update_testbed(
for _ in 0..state.nsteps {
if state.selected_backend == RAPIER_BACKEND {
let graphics = &mut graphics;
+
let mut testbed_graphics = TestbedGraphics {
manager: &mut *graphics,
commands: &mut commands,
@@ -1137,9 +1148,9 @@ fn update_testbed(
}
}
- // for plugin in &mut plugins.0 {
- // plugin.run_callbacks(window, &mut harness.physics, &harness.state);
- // }
+ for plugin in &mut plugins.0 {
+ plugin.run_callbacks(&mut harness);
+ }
}
}
@@ -1157,15 +1168,25 @@ fn update_testbed(
}
}
- let physics = &harness.physics;
- graphics.draw(&physics.bodies, &physics.colliders, &mut gfx_components);
+ graphics.draw(
+ &harness.physics.bodies,
+ &harness.physics.colliders,
+ &mut gfx_components,
+ );
for plugin in &mut plugins.0 {
- plugin.draw();
+ plugin.draw(
+ &mut graphics,
+ &mut commands,
+ meshes,
+ materials,
+ &mut gfx_components,
+ &mut harness,
+ );
}
if state.flags.contains(TestbedStateFlags::CONTACT_POINTS) {
- draw_contacts(&physics.narrow_phase, &physics.colliders);
+ draw_contacts(&harness.physics.narrow_phase, &harness.physics.colliders);
}
if state.running == RunMode::Step {
@@ -1177,14 +1198,14 @@ fn clear(
commands: &mut Commands,
state: &mut TestbedState,
graphics: &mut GraphicsManager,
- _plugins: &mut Plugins,
+ plugins: &mut Plugins,
) {
state.can_grab_behind_ground = false;
graphics.clear(commands);
- // for plugin in plugins.0.drain(..) {
- // plugin.clear_graphics();
- // }
+ for mut plugin in plugins.0.drain(..) {
+ plugin.clear_graphics(graphics, commands);
+ }
}
#[cfg(feature = "dim2")]