aboutsummaryrefslogtreecommitdiff
path: root/src/pipeline/collision_pipeline.rs
blob: 074ba7521549dbb71d94b8271b2064f8572b90b8 (plain)
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
//! Physics pipeline structures.

use crate::data::{ComponentSet, ComponentSetMut};
use crate::dynamics::{
    IslandManager, JointSet, RigidBodyActivation, RigidBodyColliders, RigidBodyDominance,
    RigidBodyIds, RigidBodyType, RigidBodyVelocity,
};
use crate::geometry::{BroadPhase, BroadPhasePairEvent, ColliderPair, ColliderShape, NarrowPhase};
use crate::math::Real;
use crate::pipeline::{EventHandler, PhysicsHooks};

/// The collision pipeline, responsible for performing collision detection between colliders.
///
/// This structure only contains temporary data buffers. It can be dropped and replaced by a fresh
/// copy at any time. For performance reasons it is recommended to reuse the same physics pipeline
/// instance to benefit from the cached data.
// NOTE: this contains only workspace data, so there is no point in making this serializable.
pub struct CollisionPipeline {
    broadphase_collider_pairs: Vec<ColliderPair>,
    broad_phase_events: Vec<BroadPhasePairEvent>,
    empty_joints: JointSet,
}

#[allow(dead_code)]
fn check_pipeline_send_sync() {
    fn do_test<T: Sync>() {}
    do_test::<CollisionPipeline>();
}

impl CollisionPipeline {
    /// Initializes a new physics pipeline.
    pub fn new() -> CollisionPipeline {
        CollisionPipeline {
            broadphase_collider_pairs: Vec::new(),
            broad_phase_events: Vec::new(),
            empty_joints: JointSet::new(),
        }
    }

    /// Executes one step of the collision detection.
    pub fn step<Bodies, Colliders>(
        &mut self,
        _prediction_distance: Real,
        _broad_phase: &mut BroadPhase,
        _narrow_phase: &mut NarrowPhase,
        _islands: &mut IslandManager,
        _bodies: &mut Bodies,
        _colliders: &mut Colliders,
        _hooks: &dyn PhysicsHooks<Bodies, Colliders>,
        _events: &dyn EventHandler,
    ) where
        Bodies: ComponentSetMut<RigidBodyIds>
            + ComponentSetMut<RigidBodyActivation>
            + ComponentSet<RigidBodyColliders>
            + ComponentSetMut<RigidBodyVelocity>
            + ComponentSet<RigidBodyDominance>
            + ComponentSet<RigidBodyType>,
        Colliders: ComponentSetMut<ColliderShape>,
    {
        unimplemented!()
    }
}