rust/hwphysics/src/lib.rs
author alfadur
Fri, 09 Nov 2018 01:05:34 +0300
changeset 14178 a4c17cfaa4c9
parent 14144 165e43c3ed59
child 14179 abbb74b9cb62
permissions -rw-r--r--
split hwphysics into modules
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
     1
mod common;
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
     2
mod physics;
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
     3
mod grid;
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
     4
mod collision;
14144
165e43c3ed59 pull land into collision detector
alfadur
parents: 14059
diff changeset
     5
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
     6
use fpnum::FPNum;
14144
165e43c3ed59 pull land into collision detector
alfadur
parents: 14059
diff changeset
     7
use land2d::Land2D;
14059
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
     8
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
     9
use crate::{
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    10
    common::GearId,
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    11
    physics::{
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    12
        PhysicsProcessor,
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    13
        PhysicsData
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    14
    },
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    15
    collision::{
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    16
        CollisionProcessor,
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    17
        CollisionData,
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    18
        ContactData
14059
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    19
    }
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    20
};
14059
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    21
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    22
pub struct JoinedData {
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    23
    gear_id: GearId,
14059
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    24
    physics: PhysicsData,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    25
    collision: CollisionData,
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    26
    contact: ContactData
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    27
}
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
pub struct World {
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    30
    physics: PhysicsProcessor,
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    31
    collision: CollisionProcessor,
14059
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    32
}
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    33
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    34
impl World {
14144
165e43c3ed59 pull land into collision detector
alfadur
parents: 14059
diff changeset
    35
    pub fn step(&mut self, time_step: FPNum, land: &Land2D<u32>) {
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    36
        let updates = self.physics.process(time_step);
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    37
        self.collision.process(land, &updates);
14144
165e43c3ed59 pull land into collision detector
alfadur
parents: 14059
diff changeset
    38
    }
165e43c3ed59 pull land into collision detector
alfadur
parents: 14059
diff changeset
    39
14059
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    40
    pub fn add_gear(&mut self, data: JoinedData) {
14178
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    41
        self.physics.push(data.gear_id, data.physics);
a4c17cfaa4c9 split hwphysics into modules
alfadur
parents: 14144
diff changeset
    42
        self.collision.push(data.gear_id, data.physics, data.collision);
14059
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    43
    }
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    44
}
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
#[cfg(test)]
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    47
mod tests {
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    48
c6745a1c827a start a physics engine to try out this data oriented thing everyone seems to be talking about
alfadur
parents:
diff changeset
    49
}