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

mod common;
mod physics;
mod grid;
mod collision;

use fpnum::FPNum;
use land2d::Land2D;

use crate::{
    common::GearId,
    physics::{
        PhysicsProcessor,
        PhysicsData
    },
    collision::{
        CollisionProcessor,
        CollisionData,
        ContactData
    }
};

pub struct JoinedData {
    gear_id: GearId,
    physics: PhysicsData,
    collision: CollisionData,
    contact: ContactData
}

pub struct World {
    physics: PhysicsProcessor,
    collision: CollisionProcessor,
}

impl World {
    pub fn step(&mut self, time_step: FPNum, land: &Land2D<u32>) {
        let updates = self.physics.process(time_step);
        self.collision.process(land, &updates);
    }

    pub fn add_gear(&mut self, data: JoinedData) {
        self.physics.push(data.gear_id, data.physics);
        self.collision.push(data.gear_id, data.physics, data.collision);
    }
}

#[cfg(test)]
mod tests {

}