rust/hwphysics/src/physics.rs
author alfadur
Wed, 28 Aug 2019 00:10:41 +0300
changeset 15369 0f2fd8d12734
parent 15282 478d5372eb4a
child 15380 6e3e5be8b2e2
permissions -rw-r--r--
fix tupo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15282
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
     1
use crate::common::{GearData, GearDataLookup, GearDataProcessor, GearId, Millis};
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     2
use fpnum::*;
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     3
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     4
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     5
pub struct PhysicsData {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     6
    pub position: FPPoint,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     7
    pub velocity: FPPoint,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     8
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
     9
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    10
impl GearData for PhysicsData {}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    11
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    12
impl PhysicsData {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    13
    pub fn new(position: FPPoint, velocity: FPPoint) -> Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    14
        Self { position, velocity }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    15
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    16
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    17
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    18
pub struct DynamicPhysicsCollection {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    19
    gear_ids: Vec<GearId>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    20
    positions: Vec<FPPoint>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    21
    velocities: Vec<FPPoint>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    22
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    23
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    24
impl DynamicPhysicsCollection {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    25
    fn new() -> Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    26
        Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    27
            gear_ids: Vec::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    28
            positions: Vec::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    29
            velocities: Vec::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    30
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    31
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    32
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    33
    fn len(&self) -> usize {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    34
        self.gear_ids.len()
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    35
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    36
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    37
    fn push(&mut self, gear_id: GearId, physics: PhysicsData) -> u16 {
15274
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
    38
        self.gear_ids.push(gear_id);
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    39
        self.positions.push(physics.position);
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    40
        self.velocities.push(physics.velocity);
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    41
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    42
        (self.gear_ids.len() - 1) as u16
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    43
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    44
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    45
    fn remove(&mut self, index: usize) -> Option<GearId> {
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    46
        self.gear_ids.swap_remove(index);
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    47
        self.positions.swap_remove(index);
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    48
        self.velocities.swap_remove(index);
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    49
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    50
        self.gear_ids.get(index).cloned()
15274
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
    51
    }
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
    52
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    53
    fn iter_pos_update(&mut self) -> impl Iterator<Item = (GearId, (&mut FPPoint, &FPPoint))> {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    54
        self.gear_ids
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    55
            .iter()
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    56
            .cloned()
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    57
            .zip(self.positions.iter_mut().zip(self.velocities.iter()))
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    58
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    59
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    60
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    61
pub struct StaticPhysicsCollection {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    62
    gear_ids: Vec<GearId>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    63
    positions: Vec<FPPoint>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    64
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    65
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    66
impl StaticPhysicsCollection {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    67
    fn new() -> Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    68
        Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    69
            gear_ids: Vec::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    70
            positions: Vec::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    71
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    72
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    73
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    74
    fn push(&mut self, gear_id: GearId, physics: PhysicsData) -> u16 {
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    75
        self.gear_ids.push(gear_id);
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    76
        self.positions.push(physics.position);
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    77
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    78
        (self.gear_ids.len() - 1) as u16
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    79
    }
15274
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
    80
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    81
    fn remove(&mut self, index: usize) -> Option<GearId> {
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    82
        self.gear_ids.swap_remove(index);
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    83
        self.positions.swap_remove(index);
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    84
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    85
        self.gear_ids.get(index).cloned()
15274
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
    86
    }
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    87
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    88
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    89
pub struct PhysicsProcessor {
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
    90
    gear_lookup: GearDataLookup<bool>,
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    91
    dynamic_physics: DynamicPhysicsCollection,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    92
    static_physics: StaticPhysicsCollection,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    93
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    94
    physics_cleanup: Vec<GearId>,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    95
    position_updates: PositionUpdates,
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    96
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    97
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    98
pub struct PositionUpdates {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
    99
    pub gear_ids: Vec<GearId>,
15260
775d7efa4e5c save full shifts to position updates
alfadur
parents: 15120
diff changeset
   100
    pub shifts: Vec<(FPPoint, FPPoint)>,
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   101
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   102
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   103
impl PositionUpdates {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   104
    pub fn new(capacity: usize) -> Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   105
        Self {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   106
            gear_ids: Vec::with_capacity(capacity),
15260
775d7efa4e5c save full shifts to position updates
alfadur
parents: 15120
diff changeset
   107
            shifts: Vec::with_capacity(capacity),
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   108
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   109
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   110
15260
775d7efa4e5c save full shifts to position updates
alfadur
parents: 15120
diff changeset
   111
    pub fn push(&mut self, gear_id: GearId, old_position: &FPPoint, new_position: &FPPoint) {
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   112
        self.gear_ids.push(gear_id);
15260
775d7efa4e5c save full shifts to position updates
alfadur
parents: 15120
diff changeset
   113
        self.shifts.push((*old_position, *new_position));
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   114
    }
15261
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   115
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   116
    pub fn iter(&self) -> impl Iterator<Item = (GearId, &FPPoint, &FPPoint)> {
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   117
        self.gear_ids
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   118
            .iter()
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   119
            .cloned()
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   120
            .zip(self.shifts.iter())
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   121
            .map(|(id, (from, to))| (id, from, to))
501dfa1c8deb update collision grid with position changes
alfadur
parents: 15260
diff changeset
   122
    }
15266
b58f98bbc120 clear intermediate result structures between iterations
alfadur
parents: 15261
diff changeset
   123
b58f98bbc120 clear intermediate result structures between iterations
alfadur
parents: 15261
diff changeset
   124
    pub fn clear(&mut self) {
b58f98bbc120 clear intermediate result structures between iterations
alfadur
parents: 15261
diff changeset
   125
        self.gear_ids.clear();
b58f98bbc120 clear intermediate result structures between iterations
alfadur
parents: 15261
diff changeset
   126
        self.shifts.clear();
b58f98bbc120 clear intermediate result structures between iterations
alfadur
parents: 15261
diff changeset
   127
    }
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   128
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   129
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   130
impl PhysicsProcessor {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   131
    pub fn new() -> Self {
15270
7446258fab98 add time events
alfadur
parents: 15266
diff changeset
   132
        Self {
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   133
            gear_lookup: GearDataLookup::new(),
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   134
            dynamic_physics: DynamicPhysicsCollection::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   135
            static_physics: StaticPhysicsCollection::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   136
            physics_cleanup: Vec::new(),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   137
            position_updates: PositionUpdates::new(0),
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   138
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   139
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   140
15275
66c987015f2d replace time with milliseconds
alfadur
parents: 15274
diff changeset
   141
    pub fn process(&mut self, time_step: Millis) -> &PositionUpdates {
66c987015f2d replace time with milliseconds
alfadur
parents: 15274
diff changeset
   142
        let fp_step = time_step.to_fixed();
15266
b58f98bbc120 clear intermediate result structures between iterations
alfadur
parents: 15261
diff changeset
   143
        self.position_updates.clear();
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   144
        for (gear_id, (pos, vel)) in self.dynamic_physics.iter_pos_update() {
15260
775d7efa4e5c save full shifts to position updates
alfadur
parents: 15120
diff changeset
   145
            let old_pos = *pos;
15275
66c987015f2d replace time with milliseconds
alfadur
parents: 15274
diff changeset
   146
            *pos += *vel * fp_step;
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   147
            if !vel.is_zero() {
15260
775d7efa4e5c save full shifts to position updates
alfadur
parents: 15120
diff changeset
   148
                self.position_updates.push(gear_id, &old_pos, pos)
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   149
            } else {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   150
                self.physics_cleanup.push(gear_id)
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   151
            }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   152
        }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   153
        &self.position_updates
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   154
    }
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   155
}
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   156
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   157
impl GearDataProcessor<PhysicsData> for PhysicsProcessor {
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   158
    fn add(&mut self, gear_id: GearId, gear_data: PhysicsData) {
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   159
        let is_dynamic = !gear_data.velocity.is_zero();
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   160
        let index = if is_dynamic {
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   161
            self.dynamic_physics.push(gear_id, gear_data)
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   162
        } else {
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   163
            self.static_physics.push(gear_id, gear_data)
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   164
        };
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   165
15282
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   166
        self.gear_lookup.add(gear_id, index, is_dynamic);
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   167
    }
15274
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
   168
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
   169
    fn remove(&mut self, gear_id: GearId) {
15282
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   170
        if let Some(entry) = self.gear_lookup.get(gear_id) {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   171
            let relocated_gear_id = if *entry.value() {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   172
                self.dynamic_physics.remove(entry.index() as usize)
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   173
            } else {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   174
                self.static_physics.remove(entry.index() as usize)
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   175
            };
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   176
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   177
            if let Some(id) = relocated_gear_id {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   178
                let index = entry.index();
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   179
                self.gear_lookup[id].set_index(index);
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   180
            }
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   181
        }
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   182
    }
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   183
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   184
    fn get(&mut self, gear_id: GearId) -> Option<PhysicsData> {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   185
        if let Some(entry) = self.gear_lookup.get(gear_id) {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   186
            let data = if *entry.value() {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   187
                PhysicsData {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   188
                    position: self.dynamic_physics.positions[entry.index() as usize],
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   189
                    velocity: self.dynamic_physics.velocities[entry.index() as usize],
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   190
                }
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   191
            } else {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   192
                PhysicsData {
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   193
                    position: self.static_physics.positions[entry.index() as usize],
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   194
                    velocity: FPPoint::zero(),
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   195
                }
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   196
            };
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   197
            Some(data)
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   198
        } else {
15282
478d5372eb4a implement empty gear lookup entries
alfadur
parents: 15281
diff changeset
   199
            None
15281
8095853811a6 add gear lookup to the physics processor
alfadur
parents: 15275
diff changeset
   200
        }
15274
42b710b0f883 add gear allocator
alfadur
parents: 15270
diff changeset
   201
    }
15120
febccab419b1 Apply dos2unix to rust sources
unc0rr
parents: 14716
diff changeset
   202
}