rust/hwphysics/src/lib.rs
changeset 15279 42b710b0f883
parent 15275 7446258fab98
child 15280 66c987015f2d
equal deleted inserted replaced
15278:bfd185ad03e7 15279:42b710b0f883
     8 use integral_geometry::Size;
     8 use integral_geometry::Size;
     9 use land2d::Land2D;
     9 use land2d::Land2D;
    10 
    10 
    11 use crate::{
    11 use crate::{
    12     collision::{CollisionData, CollisionProcessor, ContactData},
    12     collision::{CollisionData, CollisionProcessor, ContactData},
    13     common::{GearData, GearDataAggregator, GearDataProcessor, GearId},
    13     common::{GearAllocator, GearData, GearDataAggregator, GearDataProcessor, GearId},
    14     physics::{PhysicsData, PhysicsProcessor},
    14     physics::{PhysicsData, PhysicsProcessor},
    15     time::TimeProcessor,
    15     time::TimeProcessor,
    16 };
    16 };
    17 
    17 
    18 pub struct JoinedData {
    18 pub struct JoinedData {
    21     collision: CollisionData,
    21     collision: CollisionData,
    22     contact: ContactData,
    22     contact: ContactData,
    23 }
    23 }
    24 
    24 
    25 pub struct World {
    25 pub struct World {
       
    26     allocator: GearAllocator,
    26     physics: PhysicsProcessor,
    27     physics: PhysicsProcessor,
    27     collision: CollisionProcessor,
    28     collision: CollisionProcessor,
    28     time: TimeProcessor,
    29     time: TimeProcessor,
    29 }
    30 }
    30 
    31 
    42 processor_map!(CollisionData => collision);
    43 processor_map!(CollisionData => collision);
    43 
    44 
    44 impl World {
    45 impl World {
    45     pub fn new(world_size: Size) -> Self {
    46     pub fn new(world_size: Size) -> Self {
    46         Self {
    47         Self {
       
    48             allocator: GearAllocator::new(),
    47             physics: PhysicsProcessor::new(),
    49             physics: PhysicsProcessor::new(),
    48             collision: CollisionProcessor::new(world_size),
    50             collision: CollisionProcessor::new(world_size),
    49             time: TimeProcessor::new(),
    51             time: TimeProcessor::new(),
    50         }
    52         }
       
    53     }
       
    54 
       
    55     #[inline]
       
    56     pub fn new_gear(&mut self) -> Option<GearId> {
       
    57         self.allocator.alloc()
       
    58     }
       
    59 
       
    60     #[inline]
       
    61     pub fn delete_gear(&mut self, gear_id: GearId) {
       
    62         self.physics.remove(gear_id);
       
    63         self.collision.remove(gear_id);
       
    64         self.time.cancel(gear_id);
       
    65         self.allocator.free(gear_id)
    51     }
    66     }
    52 
    67 
    53     pub fn step(&mut self, time_step: FPNum, land: &Land2D<u32>) {
    68     pub fn step(&mut self, time_step: FPNum, land: &Land2D<u32>) {
    54         let updates = self.physics.process(time_step);
    69         let updates = self.physics.process(time_step);
    55         let collision = self.collision.process(land, &updates);
    70         let collision = self.collision.process(land, &updates);