Skip to content

Commit

Permalink
remove physics module
Browse files Browse the repository at this point in the history
replace with transportation since it was used for that anyway
  • Loading branch information
Uriopass committed Jan 11, 2024
1 parent 8fae1f6 commit 38510e0
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 158 deletions.
28 changes: 18 additions & 10 deletions native_app/src/audio/car_sounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -36,7 +36,7 @@ impl CarSounds {
}

pub fn update(&mut self, sim: &Simulation, uiworld: &mut UiWorld, ctx: &mut AudioContext) {
let coworld = sim.read::<CollisionWorld>();
let transport_grid = sim.read::<TransportGrid>();
let campos = uiworld.read::<Camera>().eye();
let cambox = AABB::new(campos.xy(), campos.xy()).expand(100.0);

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions native_app/src/gui/windows/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -356,12 +356,12 @@ fn draw_spline(tess: &mut Tesselator<true>, mut sp: Spline3) {
tess.draw_circle(sp.to - sp.to_derivative, 0.7);
}

fn debug_coworld(tess: &mut Tesselator<true>, sim: &Simulation, _: &UiWorld) -> Option<()> {
let coworld = sim.read::<CollisionWorld>();
fn debug_transport_grid(tess: &mut Tesselator<true>, sim: &Simulation, _: &UiWorld) -> Option<()> {
let transport_grid = sim.read::<TransportGrid>();

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(())
Expand Down
11 changes: 5 additions & 6 deletions simulation/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -73,7 +72,7 @@ pub fn init() {
register_resource::<GameTime, Bincode>("game_time", || {
GameTime::new(0.0, SECONDS_PER_DAY as f64 + 10.0 * SECONDS_PER_HOUR as f64)
});
register_resource::<CollisionWorld, Bincode>("coworld", || CollisionWorld::new(100));
register_resource::<TransportGrid, Bincode>("transport_grid", || TransportGrid::new(100));
register_resource::<RandProvider, Bincode>("randprovider", || RandProvider::new(RNG_SEED));
register_resource_default::<Dispatcher, Bincode>("dispatcher");
register_resource_default::<Replay, JSON>("replay");
Expand Down
3 changes: 0 additions & 3 deletions simulation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions simulation/src/map_dynamic/router.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -264,7 +264,7 @@ fn walk_inside(body: HumanID, h: &mut HumanEnt, cbuf: &ParCommandBuffer<HumanEnt
fn walk_outside(body: HumanID, pos: Vec3, cbuf: &ParCommandBuffer<HumanEnt>, loc: &mut Location) {
*loc = Location::Outside;
cbuf.exec_ent(body, move |sim| {
let coll = put_pedestrian_in_coworld(&mut sim.write::<CollisionWorld>(), pos);
let coll = put_pedestrian_in_transport_grid(&mut sim.write::<TransportGrid>(), pos);
let h = unwrap_ret!(sim.world.humans.get_mut(body));
h.trans.position = pos;
h.collider = Some(coll);
Expand Down
91 changes: 0 additions & 91 deletions simulation/src/physics/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion simulation/src/souls/human.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
Loading

0 comments on commit 38510e0

Please sign in to comment.