-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmod.rs
84 lines (74 loc) · 2.89 KB
/
mod.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
//! The servers are the `amethyst_physics` interfaces, that is possible to use in order to control ary physics
//! engine that implements them.
//!
//! Each server controls a specific part of the physics engine, and they are:
//! - [World Server](trait.WorldPhysicsServerTrait.html)
//! - [RBody Server](trait.RBodyPhysicsServerTrait.html)
//! - [Area Server](trait.AreaPhysicsServerTrait.html)
//! - [Shape Server](trait.ShapePhysicsServerTrait.html)
//!
//! Is it possible to access them trough the `PhysicsWorld`.
pub use area_server::{AreaDesc, AreaPhysicsServerTrait, OverlapEvent};
pub use body_server::{BodyMode, ContactEvent, RBodyPhysicsServerTrait, RigidBodyDesc};
pub use joint_server::{JointDesc, JointPhysicsServerTrait, JointPosition};
pub use shape_server::{ShapeDesc, ShapePhysicsServerTrait};
pub use world_server::WorldPhysicsServerTrait;
/// This struct contains all the servers that can be used to control a `PhysicsEngine`.
///
/// The `PhysicsWorld` is safe to be sent through threads because internally each `Backend` make sure
/// to access each data in thread safe.
#[allow(missing_debug_implementations)]
pub struct PhysicsWorld<N> {
world_server: Box<dyn WorldPhysicsServerTrait<N>>,
rigid_body_server: Box<dyn RBodyPhysicsServerTrait<N>>,
area_server: Box<dyn AreaPhysicsServerTrait<N>>,
shape_server: Box<dyn ShapePhysicsServerTrait<N>>,
joint_server: Box<dyn JointPhysicsServerTrait<N>>,
}
impl<N> PhysicsWorld<N> {
/// Creates a new PhysicsWorld.
///
/// This function is called automatically by the `PhysicsBundle`.
pub fn new(
world_server: Box<dyn WorldPhysicsServerTrait<N>>,
rigid_body_server: Box<dyn RBodyPhysicsServerTrait<N>>,
area_server: Box<dyn AreaPhysicsServerTrait<N>>,
shape_server: Box<dyn ShapePhysicsServerTrait<N>>,
joint_server: Box<dyn JointPhysicsServerTrait<N>>,
) -> Self {
PhysicsWorld {
world_server,
rigid_body_server,
area_server,
shape_server,
joint_server,
}
}
/// Return world server.
pub fn world_server(&self) -> &dyn WorldPhysicsServerTrait<N> {
self.world_server.as_ref()
}
/// Return body server.
pub fn rigid_body_server(&self) -> &dyn RBodyPhysicsServerTrait<N> {
self.rigid_body_server.as_ref()
}
/// Return area server.
pub fn area_server(&self) -> &dyn AreaPhysicsServerTrait<N> {
self.area_server.as_ref()
}
/// Return shape server.
pub fn shape_server(&self) -> &dyn ShapePhysicsServerTrait<N> {
self.shape_server.as_ref()
}
/// Return joint server.
pub fn joint_server(&self) -> &dyn JointPhysicsServerTrait<N> {
self.joint_server.as_ref()
}
}
unsafe impl<N> Send for PhysicsWorld<N> {}
unsafe impl<N> Sync for PhysicsWorld<N> {}
mod area_server;
mod body_server;
mod joint_server;
mod shape_server;
mod world_server;