From 38510e02ea84c6b31a45470902a0779ac147f5c6 Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Thu, 11 Jan 2024 13:19:58 +0100 Subject: [PATCH] remove physics module replace with transportation since it was used for that anyway --- native_app/src/audio/car_sounds.rs | 28 +++--- native_app/src/gui/windows/debug.rs | 12 +-- simulation/src/init.rs | 11 ++- simulation/src/lib.rs | 3 - simulation/src/map_dynamic/router.rs | 6 +- simulation/src/physics/mod.rs | 91 ------------------- simulation/src/souls/human.rs | 2 +- simulation/src/transportation/mod.rs | 96 +++++++++++++++++++-- simulation/src/transportation/pedestrian.rs | 15 ++-- simulation/src/transportation/road.rs | 27 +++--- simulation/src/transportation/train.rs | 3 +- simulation/src/transportation/vehicle.rs | 14 +-- simulation/src/world.rs | 15 ++-- 13 files changed, 165 insertions(+), 158 deletions(-) delete mode 100644 simulation/src/physics/mod.rs diff --git a/native_app/src/audio/car_sounds.rs b/native_app/src/audio/car_sounds.rs index 257a8e56..7a650ba0 100644 --- a/native_app/src/audio/car_sounds.rs +++ b/native_app/src/audio/car_sounds.rs @@ -4,7 +4,7 @@ use engine::{AudioContext, Gain, GainControl}; use flat_spatial::grid::GridHandle; use geom::{Camera, AABB}; use oddio::{Cycle, Mixed, Seek, Speed, SpeedControl}; -use simulation::physics::CollisionWorld; +use simulation::transportation::TransportGrid; use simulation::Simulation; use slotmapd::SecondaryMap; @@ -36,7 +36,7 @@ impl CarSounds { } pub fn update(&mut self, sim: &Simulation, uiworld: &mut UiWorld, ctx: &mut AudioContext) { - let coworld = sim.read::(); + let transport_grid = sim.read::(); let campos = uiworld.read::().eye(); let cambox = AABB::new(campos.xy(), campos.xy()).expand(100.0); @@ -50,7 +50,7 @@ impl CarSounds { let mut to_remove = vec![]; for (h, _) in &self.sounds { - if let Some((pos, _)) = coworld.get(h) { + if let Some((pos, _)) = transport_grid.get(h) { if pos.z0().is_close(campos, HEAR_RADIUS) { continue; } @@ -70,14 +70,17 @@ impl CarSounds { } // Gather - for (h, _) in coworld.query_around( + for (h, _) in transport_grid.query_around( campos.xy(), (HEAR_RADIUS * HEAR_RADIUS - campos.z * campos.z) .max(0.0) .sqrt(), ) { - let (pos, obj) = coworld.get(h).unwrap(); - if !matches!(obj.group, simulation::physics::PhysicsGroup::Vehicles) { + let (pos, obj) = transport_grid.get(h).unwrap(); + if !matches!( + obj.group, + simulation::transportation::TransportationGroup::Vehicles + ) { continue; } @@ -120,7 +123,7 @@ impl CarSounds { // Update for (h, cs) in &mut self.sounds { - let (pos, obj) = coworld.get(h).unwrap(); // Unwrap ok: checked it existed before + let (pos, obj) = transport_grid.get(h).unwrap(); // Unwrap ok: checked it existed before let his_speed = (obj.speed * obj.dir).z0(); let dir_to_me = (campos - pos.z(campos.z * 0.5)).normalize(); @@ -140,10 +143,15 @@ impl CarSounds { } if campos.z < 1000.0 { - let cars_on_screen = coworld + let cars_on_screen = transport_grid .query_aabb(cambox.ll, cambox.ur) - .filter_map(|(h, _)| coworld.get(h)) - .filter(|(_, obj)| matches!(obj.group, simulation::physics::PhysicsGroup::Vehicles)) + .filter_map(|(h, _)| transport_grid.get(h)) + .filter(|(_, obj)| { + matches!( + obj.group, + simulation::transportation::TransportationGroup::Vehicles + ) + }) .count(); if let Some(ref mut s) = self.generic_car_sound { s.set_amplitude_ratio( diff --git a/native_app/src/gui/windows/debug.rs b/native_app/src/gui/windows/debug.rs index 2e9d1fd5..cf6e03db 100644 --- a/native_app/src/gui/windows/debug.rs +++ b/native_app/src/gui/windows/debug.rs @@ -4,7 +4,7 @@ use crate::game_loop::Timings; use crate::gui::InspectedEntity; use crate::uiworld::UiWorld; use simulation::map_dynamic::ParkingManagement; -use simulation::physics::CollisionWorld; +use simulation::transportation::TransportGrid; use simulation::utils::time::{GameTime, Tick, SECONDS_PER_DAY}; use simulation::{Simulation, TrainID}; @@ -39,7 +39,7 @@ impl Default for DebugObjs { (false, "Debug train reservations", debug_trainreservations), (false, "Debug connectivity", debug_connectivity), (false, "Debug spatialmap", debug_spatialmap), - (false, "Debug collision world", debug_coworld), + (false, "Debug transport grid", debug_transport_grid), (false, "Debug splines", debug_spline), (false, "Debug lots", debug_lots), (false, "Debug road points", debug_road_points), @@ -356,12 +356,12 @@ fn draw_spline(tess: &mut Tesselator, mut sp: Spline3) { tess.draw_circle(sp.to - sp.to_derivative, 0.7); } -fn debug_coworld(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { - let coworld = sim.read::(); +fn debug_transport_grid(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { + let transport_grid = sim.read::(); tess.set_color(Color::new(0.8, 0.8, 0.9, 0.5)); - for h in coworld.handles() { - let (pos, obj) = coworld.get(h)?; + for h in transport_grid.handles() { + let (pos, obj) = transport_grid.get(h)?; tess.draw_circle(pos.z(obj.height + 0.1), 3.0); } Some(()) diff --git a/simulation/src/init.rs b/simulation/src/init.rs index f0bb9c75..8679f888 100644 --- a/simulation/src/init.rs +++ b/simulation/src/init.rs @@ -5,7 +5,6 @@ use crate::map_dynamic::{ BuildingInfos, Dispatcher, ParkingManagement, }; use crate::multiplayer::MultiplayerState; -use crate::physics::coworld_synchronize; use crate::souls::freight_station::freight_station_system; use crate::souls::goods_company::{company_system, GoodsCompanyRegistry}; use crate::souls::human::update_decision_system; @@ -15,14 +14,14 @@ use crate::transportation::testing_vehicles::{random_vehicles_update, RandomVehi use crate::transportation::train::{ locomotive_system, train_reservations_update, TrainReservations, }; +use crate::transportation::{transport_grid_synchronize, TransportGrid}; use crate::utils::resources::Resources; use crate::utils::time::Tick; use crate::world::{CompanyEnt, FreightStationEnt, HumanEnt, TrainEnt, VehicleEnt, WagonEnt}; use crate::World; use crate::{ - add_souls_to_empty_buildings, utils, CollisionWorld, GameTime, ParCommandBuffer, RandProvider, - Replay, RunnableSystem, Simulation, SimulationOptions, RNG_SEED, SECONDS_PER_DAY, - SECONDS_PER_HOUR, + add_souls_to_empty_buildings, utils, GameTime, ParCommandBuffer, RandProvider, Replay, + RunnableSystem, Simulation, SimulationOptions, RNG_SEED, SECONDS_PER_DAY, SECONDS_PER_HOUR, }; use common::saveload::{Bincode, Encoder, JSON}; use serde::de::DeserializeOwned; @@ -33,7 +32,7 @@ pub fn init() { register_system("update_decision_system", update_decision_system); register_system("company_system", company_system); register_system("pedestrian_decision_system", pedestrian_decision_system); - register_system("coworld_synchronize", coworld_synchronize); + register_system("transport_grid_synchronize", transport_grid_synchronize); register_system("locomotive_system", locomotive_system); register_system("vehicle_decision_system", vehicle_decision_system); register_system("vehicle_state_update_system", vehicle_state_update_system); @@ -73,7 +72,7 @@ pub fn init() { register_resource::("game_time", || { GameTime::new(0.0, SECONDS_PER_DAY as f64 + 10.0 * SECONDS_PER_HOUR as f64) }); - register_resource::("coworld", || CollisionWorld::new(100)); + register_resource::("transport_grid", || TransportGrid::new(100)); register_resource::("randprovider", || RandProvider::new(RNG_SEED)); register_resource_default::("dispatcher"); register_resource_default::("replay"); diff --git a/simulation/src/lib.rs b/simulation/src/lib.rs index 0b3edfa1..6b904e58 100644 --- a/simulation/src/lib.rs +++ b/simulation/src/lib.rs @@ -3,8 +3,6 @@ use crate::map::{BuildingKind, Map}; use crate::map_dynamic::{Itinerary, ItineraryLeader}; -use crate::physics::CollisionWorld; -use crate::physics::Speed; use crate::souls::add_souls_to_empty_buildings; use crate::souls::goods_company::GoodsCompanyRegistry; use crate::utils::resources::{Ref, RefMut, Resources}; @@ -40,7 +38,6 @@ pub mod init; pub mod map; pub mod map_dynamic; pub mod multiplayer; -pub mod physics; pub mod souls; #[cfg(test)] mod tests; diff --git a/simulation/src/map_dynamic/router.rs b/simulation/src/map_dynamic/router.rs index 6327daa5..1b9ebdb2 100644 --- a/simulation/src/map_dynamic/router.rs +++ b/simulation/src/map_dynamic/router.rs @@ -1,7 +1,7 @@ use crate::map::{BuildingID, Map, PathKind}; use crate::map_dynamic::{Itinerary, ParkingManagement, ParkingReserveError, SpotReservation}; -use crate::physics::CollisionWorld; -use crate::transportation::{put_pedestrian_in_coworld, unpark, Location, VehicleState}; +use crate::transportation::TransportGrid; +use crate::transportation::{put_pedestrian_in_transport_grid, unpark, Location, VehicleState}; use crate::utils::resources::Resources; use crate::world::{HumanEnt, HumanID, VehicleEnt, VehicleID}; use crate::{ParCommandBuffer, World}; @@ -264,7 +264,7 @@ fn walk_inside(body: HumanID, h: &mut HumanEnt, cbuf: &ParCommandBuffer, loc: &mut Location) { *loc = Location::Outside; cbuf.exec_ent(body, move |sim| { - let coll = put_pedestrian_in_coworld(&mut sim.write::(), pos); + let coll = put_pedestrian_in_transport_grid(&mut sim.write::(), pos); let h = unwrap_ret!(sim.world.humans.get_mut(body)); h.trans.position = pos; h.collider = Some(coll); diff --git a/simulation/src/physics/mod.rs b/simulation/src/physics/mod.rs deleted file mode 100644 index 5148f7ab..00000000 --- a/simulation/src/physics/mod.rs +++ /dev/null @@ -1,91 +0,0 @@ -use crate::transportation::Vehicle; -use crate::utils::resources::Resources; -use crate::{Simulation, World}; -use egui_inspect::Inspect; -use egui_inspect::InspectVec2Rotation; -use flat_spatial::grid::GridHandle; -use geom::Transform; -use geom::Vec2; -use serde::{Deserialize, Serialize}; -use std::fmt::{Debug, Formatter}; - -#[derive(Clone, Default, Serialize, Deserialize)] -#[repr(transparent)] -pub struct Speed(pub f32); - -impl Debug for Speed { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{:.1}m/s", self.0) - } -} - -debug_inspect_impl!(Speed); - -#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub enum PhysicsGroup { - Unknown, - Vehicles, - Pedestrians, -} - -debug_inspect_impl!(PhysicsGroup); - -#[derive(Copy, Clone, Serialize, Deserialize, Inspect)] -pub struct PhysicsObject { - #[inspect(proxy_type = "InspectVec2Rotation")] - pub dir: Vec2, - pub speed: f32, - pub radius: f32, - pub height: f32, - pub group: PhysicsGroup, - pub flag: u64, -} - -impl Default for PhysicsObject { - fn default() -> Self { - Self { - dir: Vec2::X, - speed: 0.0, - radius: 1.0, - height: 0.0, - group: PhysicsGroup::Unknown, - flag: 0, - } - } -} - -pub type CollisionWorld = flat_spatial::Grid; - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -pub struct Collider(pub GridHandle); - -debug_inspect_impl!(Collider); - -impl Collider { - pub fn destroy(self) -> impl FnOnce(&mut Simulation) { - move |sim| { - let cw = &mut sim.write::(); - cw.remove_maintain(self.0); - } - } -} - -pub fn coworld_synchronize(world: &mut World, resources: &mut Resources) { - profiling::scope!("physics::coworld_synchronize"); - let mut coworld = resources.write::(); - - world.query_trans_speed_coll_vehicle().for_each( - |(trans, kin, coll, v): (&Transform, &Speed, Collider, Option<&Vehicle>)| { - coworld.set_position(coll.0, trans.position.xy()); - let (_, po) = coworld.get_mut(coll.0).unwrap(); // Unwrap ok: handle is deleted only when entity is deleted too - po.dir = trans.dir.xy(); - po.speed = kin.0; - po.height = trans.position.z; - if let Some(v) = v { - po.flag = v.flag; - } - }, - ); - - coworld.maintain(); -} diff --git a/simulation/src/souls/human.rs b/simulation/src/souls/human.rs index 8a178e1d..5e762451 100644 --- a/simulation/src/souls/human.rs +++ b/simulation/src/souls/human.rs @@ -1,8 +1,8 @@ use crate::economy::{Bought, ItemRegistry, Market}; use crate::map::BuildingID; use crate::map_dynamic::{BuildingInfos, Destination, Itinerary, Router}; -use crate::physics::Speed; use crate::souls::desire::{BuyFood, Home, Work}; +use crate::transportation::Speed; use crate::transportation::{ random_pedestrian_shirt_color, spawn_parked_vehicle, Location, Pedestrian, VehicleKind, }; diff --git a/simulation/src/transportation/mod.rs b/simulation/src/transportation/mod.rs index e23d6aae..ec8813ab 100644 --- a/simulation/src/transportation/mod.rs +++ b/simulation/src/transportation/mod.rs @@ -1,16 +1,24 @@ -use crate::map::BuildingID; +use std::fmt::{Debug, Formatter}; + +use flat_spatial::grid::GridHandle; use serde::{Deserialize, Serialize}; +use egui_inspect::InspectVec2Rotation; +use geom::{Transform, Vec2}; +pub use pedestrian::*; +pub use vehicle::*; + +use crate::map::BuildingID; +use crate::utils::resources::Resources; +use crate::world::VehicleID; +use crate::{Simulation, World}; + pub mod pedestrian; pub mod road; pub mod testing_vehicles; pub mod train; mod vehicle; -use crate::world::VehicleID; -pub use pedestrian::*; -pub use vehicle::*; - #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum Location { Outside, @@ -18,3 +26,81 @@ pub enum Location { Building(BuildingID), } debug_inspect_impl!(Location); + +#[derive(Clone, Default, Serialize, Deserialize)] +#[repr(transparent)] +pub struct Speed(pub f32); +debug_inspect_impl!(Speed); + +impl Debug for Speed { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:.1}m/s", self.0) + } +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum TransportationGroup { + Unknown, + Vehicles, + Pedestrians, +} +debug_inspect_impl!(TransportationGroup); + +#[derive(Copy, Clone, Serialize, Deserialize, Inspect)] +pub struct TransportState { + #[inspect(proxy_type = "InspectVec2Rotation")] + pub dir: Vec2, + pub speed: f32, + pub radius: f32, + pub height: f32, + pub group: TransportationGroup, + pub flag: u64, +} + +impl Default for TransportState { + fn default() -> Self { + Self { + dir: Vec2::X, + speed: 0.0, + radius: 1.0, + height: 0.0, + group: TransportationGroup::Unknown, + flag: 0, + } + } +} + +pub type TransportGrid = flat_spatial::Grid; + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +pub struct Transporter(pub GridHandle); +debug_inspect_impl!(Transporter); + +impl Transporter { + pub fn destroy(self) -> impl FnOnce(&mut Simulation) { + move |sim| { + let cw = &mut sim.write::(); + cw.remove_maintain(self.0); + } + } +} + +pub fn transport_grid_synchronize(world: &mut World, resources: &mut Resources) { + profiling::scope!("physics::transport_grid_synchronize"); + let mut transport_grid = resources.write::(); + + world.query_trans_speed_coll_vehicle().for_each( + |(trans, kin, coll, v): (&Transform, &Speed, Transporter, Option<&Vehicle>)| { + transport_grid.set_position(coll.0, trans.position.xy()); + let (_, po) = transport_grid.get_mut(coll.0).unwrap(); // Unwrap ok: handle is deleted only when entity is deleted too + po.dir = trans.dir.xy(); + po.speed = kin.0; + po.height = trans.position.z; + if let Some(v) = v { + po.flag = v.flag; + } + }, + ); + + transport_grid.maintain(); +} diff --git a/simulation/src/transportation/pedestrian.rs b/simulation/src/transportation/pedestrian.rs index 71407a1a..900dd773 100644 --- a/simulation/src/transportation/pedestrian.rs +++ b/simulation/src/transportation/pedestrian.rs @@ -1,5 +1,7 @@ use crate::map_dynamic::Itinerary; -use crate::physics::{Collider, CollisionWorld, PhysicsGroup, PhysicsObject, Speed}; +use crate::transportation::{ + Speed, TransportGrid, TransportState, TransportationGroup, Transporter, +}; use crate::utils::rand_provider::RandProvider; use crate::utils::resources::Resources; use crate::utils::time::GameTime; @@ -16,12 +18,15 @@ pub struct Pedestrian { const PED_SIZE: f32 = 0.5; -pub fn put_pedestrian_in_coworld(coworld: &mut CollisionWorld, pos: Vec3) -> Collider { - Collider(coworld.insert( +pub fn put_pedestrian_in_transport_grid( + transport_grid: &mut TransportGrid, + pos: Vec3, +) -> Transporter { + Transporter(transport_grid.insert( pos.xy(), - PhysicsObject { + TransportState { radius: PED_SIZE * 0.6, - group: PhysicsGroup::Pedestrians, + group: TransportationGroup::Pedestrians, ..Default::default() }, )) diff --git a/simulation/src/transportation/road.rs b/simulation/src/transportation/road.rs index e9f44b5c..9566a5d9 100644 --- a/simulation/src/transportation/road.rs +++ b/simulation/src/transportation/road.rs @@ -1,7 +1,8 @@ use crate::map::{Map, TrafficBehavior, Traversable, TraverseKind}; use crate::map_dynamic::{Itinerary, OBJECTIVE_OK_DIST}; -use crate::physics::Speed; -use crate::physics::{Collider, CollisionWorld, PhysicsGroup, PhysicsObject}; +use crate::transportation::{ + Speed, TransportGrid, TransportState, TransportationGroup, Transporter, +}; use crate::transportation::{Vehicle, VehicleState, TIME_TO_PARK}; use crate::utils::resources::Resources; use crate::utils::time::GameTime; @@ -39,15 +40,15 @@ pub fn vehicle_decision_system(world: &mut World, resources: &mut Resources) { pub fn vehicle_decision( map: &Map, time: &GameTime, - cow: &CollisionWorld, + cow: &TransportGrid, me: VehicleID, it: &mut Itinerary, trans: &mut Transform, kin: &mut Speed, vehicle: &mut Vehicle, - collider: &Collider, + collider: &Transporter, ) { - let (_, self_obj) = cow.get(collider.0).expect("Handle not in collision world"); + let (_, self_obj) = cow.get(collider.0).expect("Handle not in transport grid"); let mut desired_speed = 0.0; let mut desired_dir = Vec3::ZERO; @@ -59,7 +60,7 @@ pub fn vehicle_decision( (self_obj.speed.powi(2) / (2.0 * vehicle.kind.deceleration())).min(100.0); let neighbors = cow.query_around(trans.position.xy(), 12.0 + danger_length); let objs = - neighbors.map(|(id, pos)| (pos, cow.get(id).expect("Handle not in collision world").1)); + neighbors.map(|(id, pos)| (pos, cow.get(id).expect("Handle not in transport grid").1)); let (s, d) = calc_decision(me, vehicle, map, time, trans, self_obj, it, objs); desired_speed = s; @@ -107,7 +108,7 @@ pub fn vehicle_state_update( vehicle: &mut Vehicle, trans: &mut Transform, kin: &mut Speed, - coll: &mut Option, + coll: &mut Option, ) { match vehicle.state { VehicleState::RoadToPark(_, ref mut t, _) => { @@ -146,7 +147,7 @@ fn physics( kin: &mut Speed, vehicle: &mut Vehicle, time: &GameTime, - obj: &PhysicsObject, + obj: &TransportState, map: &Map, desired_speed: f32, desired_dir: Vec3, @@ -200,9 +201,9 @@ pub fn calc_decision<'a>( map: &Map, time: &GameTime, trans: &Transform, - self_obj: &PhysicsObject, + self_obj: &TransportState, it: &Itinerary, - neighs: impl Iterator, + neighs: impl Iterator, ) -> (f32, Vec3) { let default_return = (0.0, trans.dir); if vehicle.wait_time > 0.0 { @@ -313,9 +314,9 @@ pub fn calc_decision<'a>( fn calc_front_dist<'a>( vehicle: &mut Vehicle, trans: &Transform, - self_obj: &PhysicsObject, + self_obj: &TransportState, it: &Itinerary, - neighs: impl Iterator, + neighs: impl Iterator, cutoff: f32, ) -> (f32, u64) { let position = trans.position; @@ -358,7 +359,7 @@ fn calc_front_dist<'a>( let dist_to_side = towards_vec.perp_dot(dir2).abs(); - let is_vehicle = matches!(nei_physics_obj.group, PhysicsGroup::Vehicles); + let is_vehicle = matches!(nei_physics_obj.group, TransportationGroup::Vehicles); let cos_direction_angle = nei_physics_obj.dir.dot(dir2); diff --git a/simulation/src/transportation/train.rs b/simulation/src/transportation/train.rs index e41306d8..802b36cc 100644 --- a/simulation/src/transportation/train.rs +++ b/simulation/src/transportation/train.rs @@ -1,8 +1,9 @@ use crate::map::{IntersectionID, LaneID, Map, TraverseKind}; use crate::map_dynamic::ItineraryFollower; +use crate::transportation::Speed; use crate::utils::resources::Resources; use crate::world::{TrainEnt, TrainID, WagonEnt}; -use crate::{GameTime, Itinerary, ItineraryLeader, Simulation, Speed, World}; +use crate::{GameTime, Itinerary, ItineraryLeader, Simulation, World}; use egui_inspect::Inspect; use geom::{PolyLine3, Polyline3Queue, Transform, Vec3}; use ordered_float::OrderedFloat; diff --git a/simulation/src/transportation/vehicle.rs b/simulation/src/transportation/vehicle.rs index 8e40c195..8e18569a 100644 --- a/simulation/src/transportation/vehicle.rs +++ b/simulation/src/transportation/vehicle.rs @@ -1,5 +1,5 @@ use crate::map_dynamic::{Itinerary, ParkingManagement, SpotReservation}; -use crate::physics::{Collider, CollisionWorld, PhysicsGroup, PhysicsObject}; +use crate::transportation::{TransportGrid, TransportState, TransportationGroup, Transporter}; use crate::utils::rand_provider::RandProvider; use crate::utils::time::GameInstant; use crate::world::{VehicleEnt, VehicleID}; @@ -45,13 +45,13 @@ pub struct Vehicle { } #[must_use] -pub fn put_vehicle_in_coworld(sim: &Simulation, w: f32, trans: Transform) -> Collider { - Collider(sim.write::().insert( +pub fn put_vehicle_in_transport_grid(sim: &Simulation, w: f32, trans: Transform) -> Transporter { + Transporter(sim.write::().insert( trans.position.xy(), - PhysicsObject { + TransportState { dir: trans.dir.xy(), radius: w * 0.5, - group: PhysicsGroup::Vehicles, + group: TransportationGroup::Vehicles, ..Default::default() }, )) @@ -117,7 +117,7 @@ pub fn unpark(sim: &mut Simulation, vehicle: VehicleID) { log::warn!("Trying to unpark {:?} that wasn't parked", vehicle); } - let coll = put_vehicle_in_coworld(sim, w, trans); + let coll = put_vehicle_in_transport_grid(sim, w, trans); let v = unwrap_ret!(sim.world.vehicles.get_mut(vehicle)); v.collider = Some(coll); @@ -167,7 +167,7 @@ pub fn make_vehicle_entity( let mut collider = None; if mk_collider { - collider = Some(put_vehicle_in_coworld(sim, w, trans)); + collider = Some(put_vehicle_in_transport_grid(sim, w, trans)); } sim.world.insert(VehicleEnt { trans, diff --git a/simulation/src/world.rs b/simulation/src/world.rs index d7661ecf..9dcf3ed4 100644 --- a/simulation/src/world.rs +++ b/simulation/src/world.rs @@ -3,13 +3,14 @@ use crate::map_dynamic::{ DispatchID, Dispatcher, Itinerary, ItineraryFollower, ItineraryLeader, ParkingManagement, Router, }; -use crate::physics::{Collider, CollisionWorld, Speed}; use crate::souls::desire::{BuyFood, Home, Work}; use crate::souls::freight_station::FreightStation; use crate::souls::goods_company::GoodsCompany; use crate::souls::human::{HumanDecision, PersonalInfo}; use crate::transportation::train::{Locomotive, LocomotiveReservation, RailWagon}; -use crate::transportation::{Location, Pedestrian, Vehicle, VehicleKind, VehicleState}; +use crate::transportation::{ + Location, Pedestrian, Speed, TransportGrid, Transporter, Vehicle, VehicleKind, VehicleState, +}; use crate::utils::par_command_buffer::SimDrop; use crate::utils::resources::Resources; use crate::{impl_entity, impl_trans, SoulID}; @@ -59,13 +60,13 @@ pub struct VehicleEnt { pub speed: Speed, pub vehicle: Vehicle, pub it: Itinerary, - pub collider: Option, + pub collider: Option, } impl SimDrop for VehicleEnt { fn sim_drop(mut self, id: VehicleID, res: &mut Resources) { if let Some(collider) = self.collider { - res.write::().remove_maintain(collider.0); + res.write::().remove_maintain(collider.0); } if let VehicleState::Parked(resa) | VehicleState::RoadToPark(_, _, resa) = @@ -87,7 +88,7 @@ pub struct HumanEnt { pub speed: Speed, pub location: Location, pub pedestrian: Pedestrian, - pub collider: Option, + pub collider: Option, pub router: Router, pub it: Itinerary, @@ -104,7 +105,7 @@ pub struct HumanEnt { impl SimDrop for HumanEnt { fn sim_drop(mut self, id: HumanID, res: &mut Resources) { if let Some(collider) = self.collider { - res.write::().remove_maintain(collider.0); + res.write::().remove_maintain(collider.0); } res.write::().remove(SoulID::Human(id)); @@ -276,7 +277,7 @@ impl World { #[rustfmt::skip] pub fn query_trans_speed_coll_vehicle( &self, - ) -> impl Iterator)> { + ) -> impl Iterator)> { chain(( self.vehicles.values().filter_map(|x| { x.collider.map(|coll| (&x.trans, &x.speed, coll, Some(&x.vehicle))) }), self.humans .values().filter_map(|x| { x.collider.map(|coll| (&x.trans, &x.speed, coll, None)) }),