rust/hwphysics/src/lib.rs
author alfadur
Thu, 01 Nov 2018 21:30:21 +0300
changeset 14080 c6745a1c827a
child 14165 165e43c3ed59
permissions -rw-r--r--
start a physics engine to try out this data oriented thing everyone seems to be talking about
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14080
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     1
use fpnum::*;
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     2
use integral_geometry::{
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     3
    Point, Size, GridIndex
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     4
};
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     5
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     6
type Index = u16;
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     7
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     8
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     9
struct PhysicsData {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    10
    position: FPPoint,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    11
    velocity: FPPoint,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    12
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    13
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    14
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    15
struct CollisionData {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    16
    bounds: CircleBounds
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    17
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    18
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    19
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    20
struct ContactData {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    21
    elasticity: FPNum,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    22
    friction: FPNum
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    23
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    24
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    25
pub struct PhysicsCollection {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    26
    positions: Vec<FPPoint>,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    27
    velocities: Vec<FPPoint>
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    28
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    29
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    30
impl PhysicsCollection {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    31
    fn push(&mut self, data: PhysicsData) {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    32
        self.positions.push(data.position);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    33
        self.velocities.push(data.velocity);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    34
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    35
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    36
    fn iter_mut_pos(&mut self) -> impl Iterator<Item = (&mut FPPoint, &FPPoint)> {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    37
        self.positions.iter_mut().zip(self.velocities.iter())
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    38
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    39
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    40
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    41
pub struct JoinedData {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    42
    physics: PhysicsData,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    43
    collision: CollisionData,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    44
    contact: ContactData
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    45
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    46
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    47
pub struct World {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    48
    enabled_physics: PhysicsCollection,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    49
    disabled_physics: Vec<PhysicsData>,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    50
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    51
    collision: Vec<CollisionData>,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    52
    grid: Grid,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    53
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    54
    physics_cleanup: Vec<PhysicsData>,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    55
    collision_output: Vec<(Index, Index)>
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    56
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    57
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    58
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    59
struct CircleBounds {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    60
    center: FPPoint,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    61
    radius: FPNum
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    62
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    63
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    64
impl CircleBounds {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    65
    fn intersects(&self, other: &CircleBounds) -> bool {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    66
        (other.center - self.center).is_in_range(self.radius + other.radius)
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    67
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    68
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    69
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    70
fn fppoint_round(point: &FPPoint) -> Point {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    71
    Point::new(point.x().round() as i32, point.y().round() as i32)
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    72
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    73
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    74
struct GridBin {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    75
    refs: Vec<Index>,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    76
    static_entries: Vec<CircleBounds>,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    77
    dynamic_entries: Vec<CircleBounds>
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    78
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    79
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    80
impl GridBin {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    81
    fn new() -> Self {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    82
        Self {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    83
            refs: vec![],
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    84
            static_entries: vec![],
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    85
            dynamic_entries: vec![]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    86
        }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    87
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    88
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    89
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    90
const GRID_BIN_SIZE: usize = 256;
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    91
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    92
struct Grid {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    93
    bins: Vec<GridBin>,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    94
    space_size: Size,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    95
    bins_count: Size,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    96
    index: GridIndex
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    97
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    98
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    99
impl Grid {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   100
    fn new(size: Size) -> Self {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   101
        assert!(size.is_power_of_two());
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   102
        let bins_count =
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   103
            Size::new(size.width / GRID_BIN_SIZE,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   104
                      size.height / GRID_BIN_SIZE);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   105
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   106
        Self {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   107
            bins: (0..bins_count.area()).map(|_| GridBin::new()).collect(),
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   108
            space_size: size,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   109
            bins_count,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   110
            index: Size::square(GRID_BIN_SIZE).to_grid_index()
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   111
        }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   112
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   113
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   114
    fn bin_index(&self, position: &FPPoint) -> Point {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   115
        self.index.map(fppoint_round(position))
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   116
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   117
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   118
    fn lookup_bin(&mut self, position: &FPPoint) -> &mut GridBin {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   119
        let index = self.bin_index(position);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   120
        &mut self.bins[index.x as usize * self.bins_count.width + index.y as usize]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   121
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   122
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   123
    fn insert_static(&mut self, index: Index, position: &FPPoint, bounds: &CircleBounds) {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   124
        self.lookup_bin(position).static_entries.push(*bounds)
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   125
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   126
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   127
    fn insert_dynamic(&mut self, index: Index, position: &FPPoint, bounds: &CircleBounds) {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   128
        self.lookup_bin(position).dynamic_entries.push(*bounds)
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   129
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   130
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   131
    fn check_collisions(&self, collisions: &mut Vec<(Index, Index)>) {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   132
        for bin in &self.bins {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   133
            for bounds in &bin.dynamic_entries {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   134
                for other in &bin.dynamic_entries {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   135
                    if bounds.intersects(other) && bounds != other {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   136
                        collisions.push((0, 0))
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   137
                    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   138
                }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   139
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   140
                for other in &bin.static_entries {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   141
                    if bounds.intersects(other) {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   142
                        collisions.push((0, 0))
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   143
                    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   144
                }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   145
            }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   146
        }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   147
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   148
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   149
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   150
impl World {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   151
    pub fn step(&mut self, time_step: FPNum) {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   152
        for (pos, vel) in self.enabled_physics.iter_mut_pos() {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   153
            *pos += *vel
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   154
        }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   155
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   156
        self.grid.check_collisions(&mut self.collision_output);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   157
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   158
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   159
    pub fn add_gear(&mut self, data: JoinedData) {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   160
        if data.physics.velocity == FPPoint::zero() {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   161
            self.disabled_physics.push(data.physics);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   162
            self.grid.insert_static(0, &data.physics.position, &data.collision.bounds);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   163
        } else {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   164
            self.enabled_physics.push(data.physics);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   165
            self.grid.insert_dynamic(0, &data.physics.position, &data.collision.bounds);
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   166
        }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   167
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   168
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   169
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   170
#[cfg(test)]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   171
mod tests {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   172
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
   173
}