Skip to content

Commit 9c642f8

Browse files
author
BERGER Thierry
committed
Split set_world and set_world_owner method.
In order to avoid breaking changes, examples don't need modifications to compile and work!
1 parent 098927c commit 9c642f8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

examples2d/balls2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use nphysics2d::object::{BodyHandle, Material};
99
use nphysics2d::volumetric::Volumetric;
1010
use nphysics2d::world::World;
1111
use nphysics_testbed2d::Testbed;
12-
use nphysics_testbed2d::WorldOwnerExclusive;
1312

1413
const COLLIDER_MARGIN: f32 = 0.01;
1514

@@ -81,7 +80,7 @@ fn main() {
8180
/*
8281
* Set up the testbed.
8382
*/
84-
let mut testbed = Testbed::new(Box::new(WorldOwnerExclusive::new(world)));
83+
let mut testbed = Testbed::new(world);
8584
testbed.look_at(Point2::new(0.0, -2.5), 95.0);
8685
testbed.run();
8786
}

nphysics_testbed2d/src/testbed.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ pub struct WorldOwnerExclusive {
7878
world: World<f32>
7979
}
8080

81-
impl WorldOwnerExclusive {
82-
pub fn new(world: World<f32>) -> WorldOwnerExclusive {
83-
WorldOwnerExclusive {world}
84-
}
85-
}
86-
8781
impl WorldOwner for WorldOwnerExclusive {
8882
fn get_mut<'a: 'b, 'b>(&'a mut self) -> Box<DerefMut<Target = World<f32>> + 'b> {
8983
Box::new(&mut self.world)
9084
}
9185
}
9286

87+
impl From<World<f32>> for WorldOwnerExclusive {
88+
fn from(world: World<f32>) -> Self {
89+
WorldOwnerExclusive {world}
90+
}
91+
}
92+
9393
pub struct Testbed {
9494
window: Option<Box<Window>>,
9595
graphics: GraphicsManager,
@@ -136,10 +136,13 @@ impl Testbed {
136136
}
137137
}
138138

139-
pub fn new(world: Box<WorldOwner>) -> Testbed {
139+
pub fn new(world: World<f32>) -> Testbed {
140+
Testbed::new_with_world_owner(Box::new(WorldOwnerExclusive::from(world)))
141+
}
142+
pub fn new_with_world_owner(world_owner: Box<WorldOwner>) -> Testbed {
140143
let mut res = Testbed::new_empty();
141144

142-
res.set_world(world);
145+
res.set_world_owner(world_owner);
143146

144147
res
145148
}
@@ -156,7 +159,11 @@ impl Testbed {
156159
self.hide_counters = false;
157160
}
158161

159-
pub fn set_world(&mut self, world: Box<WorldOwner>) {
162+
pub fn set_world(&mut self, world: World<f32>) {
163+
self.set_world_owner(Box::new(WorldOwnerExclusive::from(world)));
164+
}
165+
166+
pub fn set_world_owner(&mut self, world: Box<WorldOwner>) {
160167
self.world = world;
161168
let mut world = self.world.get_mut();
162169
world.enable_performance_counters();

0 commit comments

Comments
 (0)