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