-
Notifications
You must be signed in to change notification settings - Fork 1
/
component.rs
88 lines (76 loc) · 2.47 KB
/
component.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use specs::prelude::*;
#[derive(Component)]
#[storage(VecStorage)]
pub struct Airjump(pub bool);
#[derive(Component, Default)]
#[storage(NullStorage)]
pub struct AirjumpRestorer;
#[derive(Component)]
#[storage(VecStorage)]
pub struct Control {
pub gamepad_id: usize,
/// Which part of the controller controls
pub parts: [bool; 2],
}
// pub struct CollisionSound {
// sound: TODO
// }
#[derive(Component)]
#[storage(VecStorage)]
pub struct Image(pub f32, pub ::Image);
#[derive(Clone)]
pub struct RigidBody(::nphysics2d::object::BodyHandle);
impl ::specs::Component for RigidBody {
type Storage = ::retained_storage::RetainedStorage<Self, ::specs::VecStorage<Self>>;
}
#[allow(unused)]
impl RigidBody {
pub fn safe_insert<'a>(
entity: ::specs::Entity,
position: ::nphysics2d::math::Isometry<f32>,
local_inertia: ::nphysics2d::math::Inertia<f32>,
local_center_of_mass: ::nphysics2d::math::Point<f32>,
status: ::nphysics2d::object::BodyStatus,
bodies_handle: &mut ::specs::WriteStorage<'a, ::component::RigidBody>,
physic_world: &mut ::resource::PhysicWorld,
bodies_map: &mut ::resource::BodiesMap,
) -> Self {
let body_handle =
physic_world.add_rigid_body(position, local_inertia, local_center_of_mass);
{
let mut rigid_body = physic_world.rigid_body_mut(body_handle).unwrap();
rigid_body.set_status(status);
rigid_body
.activation_status_mut()
.set_deactivation_threshold(None);
}
bodies_map.insert(body_handle, entity);
bodies_handle.insert(entity, RigidBody(body_handle));
RigidBody(body_handle)
}
pub fn handle(&self) -> ::nphysics2d::object::BodyHandle {
self.0
}
#[inline]
#[allow(unused)]
pub fn get<'a>(
&'a self,
physic_world: &'a ::resource::PhysicWorld,
) -> &'a ::nphysics2d::object::RigidBody<f32> {
physic_world
.rigid_body(self.0)
.expect("Rigid body in specs does not exist in physic world")
}
#[inline]
pub fn get_mut<'a>(
&self,
physic_world: &'a mut ::resource::PhysicWorld,
) -> &'a mut ::nphysics2d::object::RigidBody<f32> {
physic_world
.rigid_body_mut(self.0)
.expect("Rigid body in specs does not exist in physic world")
}
}
#[derive(Deref, DerefMut, Component)]
#[storage(VecStorage)]
pub struct Contactor(pub Vec<Entity>);