Skip to content

Commit c50bb7e

Browse files
committed
rustfmt
1 parent 953e4e3 commit c50bb7e

File tree

2 files changed

+93
-59
lines changed

2 files changed

+93
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
22
**/*.rs.bk
33
*.iml
4+
/.idea
45
cargo.lock

src/lib.rs

Lines changed: 92 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
extern crate amethyst;
2-
pub extern crate nphysics3d as nphysics;
32
pub extern crate ncollide3d as ncollide;
3+
pub extern crate nphysics3d as nphysics;
44

55
use self::ncollide::events::ContactEvent;
6-
use self::nphysics::math::{Inertia, Point, Velocity, Vector};
6+
use self::nphysics::math::{Inertia, Point, Vector, Velocity};
77
use self::nphysics::object::{Body, BodyHandle, RigidBody};
8-
use amethyst::ecs::*;
9-
use amethyst::ecs::prelude::*;
10-
use amethyst::core::{GlobalTransform, Time};
11-
use amethyst::core::nalgebra::try_convert;
128
use amethyst::core::nalgebra::base::Matrix3;
9+
use amethyst::core::nalgebra::try_convert;
10+
use amethyst::core::{GlobalTransform, Time};
11+
use amethyst::ecs::prelude::*;
12+
use amethyst::ecs::*;
1313
use amethyst::shrev::EventChannel;
1414

1515
pub type World = self::nphysics::world::World<f32>;
@@ -74,7 +74,7 @@ pub struct Dumb3dPhysicsSystem {
7474
physics_bodies_reader_id: Option<ReaderId<ComponentEvent>>,
7575
}
7676

77-
impl <'a> System<'a> for Dumb3dPhysicsSystem {
77+
impl<'a> System<'a> for Dumb3dPhysicsSystem {
7878
type SystemData = (
7979
WriteExpect<'a, World>,
8080
Write<'a, EventChannel<ContactEvent>>,
@@ -102,32 +102,48 @@ impl <'a> System<'a> for Dumb3dPhysicsSystem {
102102

103103
// Get change flag events for transforms, removing deleted ones from the physics world.
104104
{
105-
let events = transforms.channel().read(
106-
&mut self.transforms_reader_id.as_mut().unwrap());
105+
let events = transforms
106+
.channel()
107+
.read(&mut self.transforms_reader_id.as_mut().unwrap());
107108
for event in events {
108109
match event {
109-
ComponentEvent::Modified(id) => { self.modified_transforms.add(*id); },
110-
ComponentEvent::Inserted(id) => { self.inserted_transforms.add(*id); },
110+
ComponentEvent::Modified(id) => {
111+
self.modified_transforms.add(*id);
112+
}
113+
ComponentEvent::Inserted(id) => {
114+
self.inserted_transforms.add(*id);
115+
}
111116
ComponentEvent::Removed(id) => {
112-
physical_world.remove_bodies(&[
113-
physics_bodies.get(entities.entity(*id)).unwrap().handle().unwrap() ]);
114-
},
117+
physical_world.remove_bodies(&[physics_bodies
118+
.get(entities.entity(*id))
119+
.unwrap()
120+
.handle()
121+
.unwrap()]);
122+
}
115123
};
116124
}
117125
}
118126

119127
// Get change flag events for physics bodies, removing deleted ones from the physics world.
120128
{
121-
let events = physics_bodies.channel().read(
122-
&mut self.physics_bodies_reader_id.as_mut().unwrap());
129+
let events = physics_bodies
130+
.channel()
131+
.read(&mut self.physics_bodies_reader_id.as_mut().unwrap());
123132
for event in events {
124133
match event {
125-
ComponentEvent::Modified(id) => { self.modified_physics_bodies.add(*id); },
126-
ComponentEvent::Inserted(id) => { self.inserted_physics_bodies.add(*id); },
134+
ComponentEvent::Modified(id) => {
135+
self.modified_physics_bodies.add(*id);
136+
}
137+
ComponentEvent::Inserted(id) => {
138+
self.inserted_physics_bodies.add(*id);
139+
}
127140
ComponentEvent::Removed(id) => {
128-
physical_world.remove_bodies(&[
129-
physics_bodies.get(entities.entity(*id)).unwrap().handle().unwrap() ]);
130-
},
141+
physical_world.remove_bodies(&[physics_bodies
142+
.get(entities.entity(*id))
143+
.unwrap()
144+
.handle()
145+
.unwrap()]);
146+
}
131147
};
132148
}
133149
}
@@ -140,53 +156,60 @@ impl <'a> System<'a> for Dumb3dPhysicsSystem {
140156
&self.modified_transforms
141157
| &self.inserted_transforms
142158
| &self.modified_physics_bodies
143-
| &self.inserted_physics_bodies
144-
).join() {
145-
146-
if self.inserted_transforms.contains(id)
147-
|| self.inserted_physics_bodies.contains(id) {
159+
| &self.inserted_physics_bodies,
160+
)
161+
.join()
162+
{
163+
if self.inserted_transforms.contains(id) || self.inserted_physics_bodies.contains(id) {
148164
match body {
149165
PhysicsBody::RigidBody(ref mut rigid_body) => {
150166
if rigid_body.handle.is_some()
151-
&& physical_world.rigid_body(rigid_body.handle.unwrap()).is_some() {
152-
physical_world.remove_bodies(&[ rigid_body.handle.unwrap() ]);
167+
&& physical_world
168+
.rigid_body(rigid_body.handle.unwrap())
169+
.is_some()
170+
{
171+
physical_world.remove_bodies(&[rigid_body.handle.unwrap()]);
153172
}
154173

155174
rigid_body.handle = Some(physical_world.add_rigid_body(
156175
try_convert(transform.0).unwrap(),
157176
Inertia::new(rigid_body.mass, rigid_body.angular_mass),
158-
rigid_body.center_of_mass));
177+
rigid_body.center_of_mass,
178+
));
159179

160-
let mut physical_body = physical_world.rigid_body_mut(
161-
rigid_body.handle.unwrap()).unwrap();
180+
let mut physical_body = physical_world
181+
.rigid_body_mut(rigid_body.handle.unwrap())
182+
.unwrap();
162183

163184
physical_body.set_velocity(rigid_body.velocity);
164-
},
185+
}
165186
PhysicsBody::Multibody(x) => {
166187
// TODO
167-
},
188+
}
168189
PhysicsBody::Ground(x) => {
169190
// TODO
170-
},
191+
}
171192
}
172193
} else if self.modified_transforms.contains(id)
173-
|| self.modified_physics_bodies.contains(id) {
194+
|| self.modified_physics_bodies.contains(id)
195+
{
174196
match body {
175197
PhysicsBody::RigidBody(ref mut rigid_body) => {
176-
let mut physical_body = physical_world.rigid_body_mut(
177-
rigid_body.handle.unwrap()).unwrap();
198+
let mut physical_body = physical_world
199+
.rigid_body_mut(rigid_body.handle.unwrap())
200+
.unwrap();
178201

179202
physical_body.set_position(try_convert(transform.0).unwrap());
180203
physical_body.set_velocity(rigid_body.velocity);
181204

182205
// if you changed the mass properties at all... too bad!
183-
},
206+
}
184207
PhysicsBody::Multibody(x) => {
185208
// TODO
186-
},
209+
}
187210
PhysicsBody::Ground(x) => {
188211
// TODO
189-
},
212+
}
190213
}
191214
}
192215
}
@@ -200,22 +223,25 @@ impl <'a> System<'a> for Dumb3dPhysicsSystem {
200223
//contact_events.iter_write(physical_world.contact_events());
201224

202225
// Apply the updated values of the simulated world to our Components
203-
for (mut transform, mut body) in (&mut transforms,&mut physics_bodies).join() {
226+
for (mut transform, mut body) in (&mut transforms, &mut physics_bodies).join() {
204227
let updated_body = physical_world.body(body.handle().unwrap());
205228

206229
if updated_body.is_ground() || !updated_body.is_active() || updated_body.is_static() {
207230
continue;
208231
}
209232

210233
match (body, updated_body) {
211-
(PhysicsBody::RigidBody(ref mut rigid_body), Body::RigidBody(ref updated_rigid_body)) => {
234+
(
235+
PhysicsBody::RigidBody(ref mut rigid_body),
236+
Body::RigidBody(ref updated_rigid_body),
237+
) => {
212238
updated_rigid_body.position();
213239
rigid_body.velocity = *updated_rigid_body.velocity();
214240
let inertia = updated_rigid_body.inertia();
215241
rigid_body.mass = inertia.linear;
216242
rigid_body.angular_mass = inertia.angular;
217243
rigid_body.center_of_mass = updated_rigid_body.center_of_mass();
218-
},
244+
}
219245
(PhysicsBody::Multibody(multibody), Body::Multibody(updated_multibody)) => {
220246
match updated_multibody.links().next() {
221247
Some(link) => link.position(),
@@ -234,7 +260,8 @@ impl <'a> System<'a> for Dumb3dPhysicsSystem {
234260
fn setup(&mut self, res: &mut Resources) {
235261
Self::SystemData::setup(res);
236262

237-
res.entry::<Gravity>().or_insert_with(|| Gravity::new(0.0, -9.80665, 0.0));
263+
res.entry::<Gravity>()
264+
.or_insert_with(|| Gravity::new(0.0, -9.80665, 0.0));
238265
res.entry::<World>().or_insert_with(|| World::new());
239266

240267
let mut transform_storage: WriteStorage<GlobalTransform> = SystemData::fetch(&res);
@@ -247,14 +274,14 @@ impl <'a> System<'a> for Dumb3dPhysicsSystem {
247274

248275
#[cfg(test)]
249276
mod tests {
250-
use amethyst::{GameData, StateData, SimpleState, GameDataBuilder, Application};
277+
use super::*;
251278
use amethyst::assets::Handle;
279+
use amethyst::core::nalgebra::Vector3;
280+
use amethyst::core::transform::bundle::TransformBundle;
281+
use amethyst::core::Transform;
252282
use amethyst::prelude::Builder;
253283
use amethyst::renderer::*;
254-
use amethyst::core::Transform;
255-
use amethyst::core::transform::bundle::TransformBundle;
256-
use amethyst::core::nalgebra::Vector3;
257-
use super::*;
284+
use amethyst::{Application, GameData, GameDataBuilder, SimpleState, StateData};
258285

259286
struct GameState;
260287

@@ -265,11 +292,14 @@ mod tests {
265292
data.world.register::<Handle<Texture>>();
266293

267294
// Create a texture for using.
268-
let texture = data.world.read_resource::<amethyst::assets::Loader>()
295+
let texture = data
296+
.world
297+
.read_resource::<amethyst::assets::Loader>()
269298
.load_from_data::<Texture, ()>(
270299
[170.0, 170.0, 255.0, 1.0].into(),
271300
(),
272-
&data.world.read_resource());
301+
&data.world.read_resource(),
302+
);
273303

274304
// Get resolution of the screen.
275305
let (x, y) = {
@@ -283,16 +313,18 @@ mod tests {
283313
camera_transform.yaw_local(-3.142);
284314

285315
// Add Camera
286-
data.world.create_entity()
316+
data.world
317+
.create_entity()
287318
.with(Camera::standard_3d(x, y))
288319
.with(camera_transform)
289320
.build();
290321
}
291322

292323
// Add Light
293324
data.world.add_resource(AmbientColor(Rgba::from([0.01; 3])));
294-
data.world.create_entity()
295-
.with(Light::Point(PointLight{
325+
data.world
326+
.create_entity()
327+
.with(Light::Point(PointLight {
296328
intensity: 3.0,
297329
color: Rgba::white(),
298330
radius: 5.0,
@@ -302,7 +334,8 @@ mod tests {
302334
.build();
303335

304336
// Add Sphere (todo: add many, add rigidbodies and colliders)
305-
data.world.create_entity()
337+
data.world
338+
.create_entity()
306339
.with(Shape::Sphere(32, 32).generate::<Vec<PosNormTex>>(None))
307340
.with(texture)
308341
.with(GlobalTransform::default())
@@ -318,17 +351,17 @@ mod tests {
318351
.with_basic_renderer(
319352
"./resources/display.ron",
320353
DrawShaded::<PosNormTex>::new(),
321-
false)?
354+
false,
355+
)?
322356
.with_bundle(TransformBundle::new())?
323357
.with(Dumb3dPhysicsSystem::default(), "physics", &[]);
324358

325-
let mut application
326-
= Application::new("./", GameState, game_data,);
359+
let mut application = Application::new("./", GameState, game_data);
327360

328361
assert_eq!(application.is_ok(), true);
329362

330363
application.ok().unwrap().run();
331364

332365
Ok(())
333366
}
334-
}
367+
}

0 commit comments

Comments
 (0)