From 3fc6388887e965839c37337c0f9ffb207fa7f4bb Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Thu, 11 Jan 2024 13:21:11 +0100 Subject: [PATCH] rename position -> pos --- egui-inspect/src/impls/geometry.rs | 6 +++--- geom/src/transform.rs | 19 ++++++++---------- native_app/src/gui/windows/debug.rs | 2 +- native_app/src/rendering/entity_render.rs | 11 ++++------ simulation/src/map/map.rs | 2 +- simulation/src/map/objects/parking.rs | 4 ++-- simulation/src/map_dynamic/dispatch.rs | 2 +- simulation/src/map_dynamic/itinerary.rs | 12 +++-------- simulation/src/map_dynamic/router.rs | 20 +++++++++---------- simulation/src/souls/desire/buyfood.rs | 6 ++---- simulation/src/souls/freight_station.rs | 12 +++-------- simulation/src/souls/human.rs | 2 +- simulation/src/transportation/mod.rs | 4 ++-- simulation/src/transportation/pedestrian.rs | 2 +- simulation/src/transportation/road.rs | 8 ++++---- .../src/transportation/testing_vehicles.rs | 3 +-- simulation/src/transportation/train.rs | 4 ++-- simulation/src/transportation/vehicle.rs | 2 +- simulation/src/world.rs | 10 +++++----- 19 files changed, 55 insertions(+), 76 deletions(-) diff --git a/egui-inspect/src/impls/geometry.rs b/egui-inspect/src/impls/geometry.rs index 991bd4aa..a1e0bf11 100644 --- a/egui-inspect/src/impls/geometry.rs +++ b/egui-inspect/src/impls/geometry.rs @@ -71,14 +71,14 @@ impl Inspect for LinearColor { impl Inspect for Transform { fn render(t: &Self, _: &'static str, ui: &mut egui::Ui, _: &InspectArgs) { - let position = t.position; + let position = t.pos; let direction = t.dir; >::render(&position, "position", ui, &InspectArgs::default()); >::render(&direction, "direction", ui, &InspectArgs::default()); } fn render_mut(t: &mut Self, _: &'static str, ui: &mut egui::Ui, _: &InspectArgs) -> bool { - let mut position = t.position; + let mut position = t.pos; let mut direction = t.dir; let mut changed = >::render_mut( &mut position, @@ -93,7 +93,7 @@ impl Inspect for Transform { &InspectArgs::default(), ); t.dir = direction.normalize(); - t.position = position; + t.pos = position; changed } } diff --git a/geom/src/transform.rs b/geom/src/transform.rs index a7bcd1e4..cb79343f 100644 --- a/geom/src/transform.rs +++ b/geom/src/transform.rs @@ -5,7 +5,7 @@ const UP: Vec3 = Vec3::Z; #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Transform { - pub position: Vec3, + pub pos: Vec3, pub dir: Vec3, } @@ -15,17 +15,14 @@ impl Transform { Self::new(Vec3::ZERO) } - pub fn new>(position: T) -> Self { - let position = position.into(); - Self { - position, - dir: Vec3::X, - } + pub fn new>(pos: T) -> Self { + let pos = pos.into(); + Self { pos, dir: Vec3::X } } #[inline] - pub fn new_dir(position: Vec3, dir: Vec3) -> Self { - Self { position, dir } + pub fn new_dir(pos: Vec3, dir: Vec3) -> Self { + Self { pos, dir } } #[inline] @@ -47,7 +44,7 @@ impl Transform { x: x.w(0.0), y: y.w(0.0), z: z.w(0.0), - w: self.position.w(1.0), + w: self.pos.w(1.0), } } @@ -58,7 +55,7 @@ impl Transform { #[inline] pub fn project(&self, point: Vec3) -> Vec3 { - point.rotate_up(self.dir) + self.position + point.rotate_up(self.dir) + self.pos } } diff --git a/native_app/src/gui/windows/debug.rs b/native_app/src/gui/windows/debug.rs index cf6e03db..752b8fe6 100644 --- a/native_app/src/gui/windows/debug.rs +++ b/native_app/src/gui/windows/debug.rs @@ -442,7 +442,7 @@ pub fn debug_parking(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) }; tess.set_color(color); - tess.draw_circle(spot.trans.position.up(0.5), 2.0); + tess.draw_circle(spot.trans.pos.up(0.5), 2.0); } Some(()) diff --git a/native_app/src/rendering/entity_render.rs b/native_app/src/rendering/entity_render.rs index b942eff8..0de48481 100644 --- a/native_app/src/rendering/entity_render.rs +++ b/native_app/src/rendering/entity_render.rs @@ -43,7 +43,7 @@ impl InstancedRender { for v in sim.world().vehicles.values() { let trans = &v.trans; let instance = MeshInstance { - pos: trans.position, + pos: trans.pos, dir: trans.dir, tint: v.vehicle.tint.into(), }; @@ -61,7 +61,7 @@ impl InstancedRender { for wagon in sim.world().wagons.values() { let trans = &wagon.trans; let instance = MeshInstance { - pos: trans.position, + pos: trans.pos, dir: trans.dir, tint: LinearColor::WHITE, }; @@ -82,10 +82,7 @@ impl InstancedRender { for p in sim.world().humans.values() { if matches!(p.location, Location::Outside) { self.pedestrians.instances.push(MeshInstance { - pos: p - .trans - .position - .up(0.5 + 0.4 * p.pedestrian.walk_anim.cos()), + pos: p.trans.pos.up(0.5 + 0.4 * p.pedestrian.walk_anim.cos()), dir: p.trans.dir.xy().z0(), tint: LinearColor::WHITE, }); @@ -106,7 +103,7 @@ impl InstancedRender { let s = 7.0; self.path_not_found.push( - trans.position + off * 3.0 * V3::Y + 3.0 * V3::Z, + trans.pos + off * 3.0 * V3::Y + 3.0 * V3::Z, Vec3::X, LinearColor::RED.a(r), (s, s), diff --git a/simulation/src/map/map.rs b/simulation/src/map/map.rs index 523102b8..113339af 100644 --- a/simulation/src/map/map.rs +++ b/simulation/src/map/map.rs @@ -745,7 +745,7 @@ impl Map { .lanes() .get(lane)? .points - .project_segment_dir(spot.trans.position); + .project_segment_dir(spot.trans.pos); Some(pos - dir * 4.0) } diff --git a/simulation/src/map/objects/parking.rs b/simulation/src/map/objects/parking.rs index cd6f824f..e43413d8 100644 --- a/simulation/src/map/objects/parking.rs +++ b/simulation/src/map/objects/parking.rs @@ -72,7 +72,7 @@ impl ParkingSpots { if let Some(spots) = self.lane_spots.remove(lane) { for spot_id in spots { let spot = unwrap_cont!(self.spots.get(spot_id)); - self.reuse_spot.insert(spot.trans.position.xy(), spot_id); + self.reuse_spot.insert(spot.trans.pos.xy(), spot_id); } } } @@ -154,7 +154,7 @@ impl ParkingSpots { let lspots = self.lane_spots.get(lane)?; let (closest, _) = lspots.iter().copied().enumerate().min_by_key(|&(_, x)| { let p = unwrap_ret!(spots.get(x), OrderedFloat(f32::INFINITY)); - OrderedFloat(p.trans.position.distance2(near)) + OrderedFloat(p.trans.pos.distance2(near)) })?; let closest = closest as i32; diff --git a/simulation/src/map_dynamic/dispatch.rs b/simulation/src/map_dynamic/dispatch.rs index 47711633..f89337f0 100644 --- a/simulation/src/map_dynamic/dispatch.rs +++ b/simulation/src/map_dynamic/dispatch.rs @@ -88,7 +88,7 @@ impl Dispatcher { .or_insert_with(|| DispatchOne::new(DispatchKind::FreightTrain.lane_kind())); world.trains.iter().for_each(|(ent, train)| { - disp_trains.register(DispatchID::FreightTrain(ent), map, train.trans.position); + disp_trains.register(DispatchID::FreightTrain(ent), map, train.trans.pos); }); /* diff --git a/simulation/src/map_dynamic/itinerary.rs b/simulation/src/map_dynamic/itinerary.rs index 843a366d..c211000b 100644 --- a/simulation/src/map_dynamic/itinerary.rs +++ b/simulation/src/map_dynamic/itinerary.rs @@ -420,25 +420,19 @@ pub fn itinerary_update(world: &mut World, resources: &mut Resources) { world.query_it_trans_speed().for_each( |(it, trans, speed): (&mut Itinerary, &mut Transform, f32)| { - trans.position = it.update( - trans.position, - speed * time.realdelta, - tick, - time.seconds, - map, - ); + trans.pos = it.update(trans.pos, speed * time.realdelta, tick, time.seconds, map); }, ); world.trains.values_mut().for_each(|train| { - train.leader.past.push(train.trans.position); + train.leader.past.push(train.trans.pos); }); world.wagons.values_mut().for_each(|wagon| { let leader = &unwrap_ret!(world.trains.get(wagon.itfollower.leader)).leader; let (pos, dir) = wagon.itfollower.head.update(&leader.past); let (pos2, dir2) = wagon.itfollower.tail.update(&leader.past); - wagon.trans.position = (pos + pos2) * 0.5; + wagon.trans.pos = (pos + pos2) * 0.5; wagon.trans.dir = (dir + dir2).try_normalize().unwrap_or(dir); }); } diff --git a/simulation/src/map_dynamic/router.rs b/simulation/src/map_dynamic/router.rs index 1b9ebdb2..980d6de3 100644 --- a/simulation/src/map_dynamic/router.rs +++ b/simulation/src/map_dynamic/router.rs @@ -124,17 +124,17 @@ pub fn routing_update_system(world: &mut World, resources: &mut Resources) { let itin: &Itinerary = &h.it; let pos = match h.location { - Location::Outside => trans.position, + Location::Outside => trans.pos, Location::Vehicle(id) => world .vehicles .get(id) - .map(|x| x.trans.position) - .unwrap_or_else(|| trans.position), + .map(|x| x.trans.pos) + .unwrap_or_else(|| trans.pos), Location::Building(id) => map .buildings() .get(id) .map(|b| b.door_pos) - .unwrap_or_else(|| trans.position), + .unwrap_or_else(|| trans.pos), }; let mut cur_step_over = true; @@ -172,7 +172,7 @@ pub fn routing_update_system(world: &mut World, resources: &mut Resources) { RoutingStep::GetInVehicle(vehicle) => world .vehicles .get(vehicle) - .map(|v| v.trans.position.is_close(pos, 3.0)) + .map(|v| v.trans.pos.is_close(pos, 3.0)) .unwrap_or(true), RoutingStep::GetOutVehicle(_) => true, RoutingStep::GetInBuilding(build) => map @@ -229,7 +229,7 @@ pub fn routing_update_system(world: &mut World, resources: &mut Resources) { .vehicles .get(vehicle) .map(|v| v.trans) - .map(|vtrans| vtrans.position + vtrans.dir.cross(Vec3::Z) * 2.0) + .map(|vtrans| vtrans.pos + vtrans.dir.cross(Vec3::Z) * 2.0) .unwrap_or(pos); walk_outside(body, pos, cbuf_human, &mut h.location); } @@ -266,7 +266,7 @@ fn walk_outside(body: HumanID, pos: Vec3, cbuf: &ParCommandBuffer, loc cbuf.exec_ent(body, move |sim| { 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.trans.pos = pos; h.collider = Some(coll); }); } @@ -282,8 +282,8 @@ fn park(map: &Map, vehicle: &mut VehicleEnt, spot_resa: SpotReservation) { }; let s = Spline3 { - from: trans.position, - to: spot.trans.position, + from: trans.pos, + to: spot.trans.pos, from_derivative: trans.dir * 2.0, to_derivative: spot.trans.dir * 2.0, }; @@ -358,7 +358,7 @@ impl Router { }; if !matches!(loc, Location::Vehicle(_)) { - if let Some(pos) = cars.get(car).map(|x| x.trans.position) { + if let Some(pos) = cars.get(car).map(|x| x.trans.pos) { steps.push(RoutingStep::WalkTo(pos)); steps.push(RoutingStep::GetInVehicle(car)); steps.push(RoutingStep::Unpark(car)); diff --git a/simulation/src/souls/desire/buyfood.rs b/simulation/src/souls/desire/buyfood.rs index 2941cc7c..123fa1ce 100644 --- a/simulation/src/souls/desire/buyfood.rs +++ b/simulation/src/souls/desire/buyfood.rs @@ -69,7 +69,7 @@ impl BuyFood { use HumanDecisionKind::*; match self.state { BuyFoodState::Empty => { - let pos = trans.position; + let pos = trans.pos; let bread = self.bread; cbuf.exec_on(id, move |market: &mut Market| { market.buy(SoulID::Human(id), pos.xy(), bread, 1) @@ -79,9 +79,7 @@ impl BuyFood { } BuyFoodState::WaitingForTrade => { for trade in bought.0.entry(self.bread).or_default().drain(..) { - if let Some(b) = - find_trade_place(trade.seller, trans.position.xy(), binfos, map) - { + if let Some(b) = find_trade_place(trade.seller, trans.pos.xy(), binfos, map) { self.state = BuyFoodState::BoughtAt(b); } } diff --git a/simulation/src/souls/freight_station.rs b/simulation/src/souls/freight_station.rs index a3a3c425..d1717335 100644 --- a/simulation/src/souls/freight_station.rs +++ b/simulation/src/souls/freight_station.rs @@ -104,7 +104,7 @@ pub fn freight_station_system(world: &mut World, resources: &mut Resources) { let bpos = map.buildings[ext].obb.center().z(0.0); *itin = if let Some(r) = - Itinerary::route(tick, train.trans.position, bpos, &map, PathKind::Rail) + Itinerary::route(tick, train.trans.pos, bpos, &map, PathKind::Rail) { r } else { @@ -134,7 +134,7 @@ pub fn freight_station_system(world: &mut World, resources: &mut Resources) { continue; } - let destination = pos.position + pos.dir * 75.0 - pos.dir.perp_up() * 40.0; + let destination = pos.pos + pos.dir * 75.0 - pos.dir.perp_up() * 40.0; let Some(DispatchID::FreightTrain(trainid)) = dispatch.query( &map, @@ -147,13 +147,7 @@ pub fn freight_station_system(world: &mut World, resources: &mut Resources) { let train = world.trains.get_mut(trainid).unwrap(); train.it = unwrap_or!( - Itinerary::route( - tick, - train.trans.position, - destination, - &map, - PathKind::Rail, - ), + Itinerary::route(tick, train.trans.pos, destination, &map, PathKind::Rail,), continue ); diff --git a/simulation/src/souls/human.rs b/simulation/src/souls/human.rs index 5e762451..34b563b1 100644 --- a/simulation/src/souls/human.rs +++ b/simulation/src/souls/human.rs @@ -183,7 +183,7 @@ pub fn update_decision( decision.wait -= 1; return; } - let pos = trans.position; + let pos = trans.pos; decision.wait = (30.0 + common::rand::rand2(pos.x, pos.y) * 50.0) as u8; if !decision.kind.update(router, binfos, map, cbuf_freight) { return; diff --git a/simulation/src/transportation/mod.rs b/simulation/src/transportation/mod.rs index ec8813ab..38279e62 100644 --- a/simulation/src/transportation/mod.rs +++ b/simulation/src/transportation/mod.rs @@ -91,11 +91,11 @@ pub fn transport_grid_synchronize(world: &mut World, resources: &mut Resources) 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()); + transport_grid.set_position(coll.0, trans.pos.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; + po.height = trans.pos.z; if let Some(v) = v { po.flag = v.flag; } diff --git a/simulation/src/transportation/pedestrian.rs b/simulation/src/transportation/pedestrian.rs index 900dd773..351a9a51 100644 --- a/simulation/src/transportation/pedestrian.rs +++ b/simulation/src/transportation/pedestrian.rs @@ -116,7 +116,7 @@ pub fn calc_decision( None => return (0.0, trans.dir), }; - let position = trans.position; + let position = trans.pos; let delta_pos: Vec3 = objective - position; let dir_to_pos = match delta_pos.try_normalize() { diff --git a/simulation/src/transportation/road.rs b/simulation/src/transportation/road.rs index 9566a5d9..d0cafe7d 100644 --- a/simulation/src/transportation/road.rs +++ b/simulation/src/transportation/road.rs @@ -58,7 +58,7 @@ pub fn vehicle_decision( ) { let danger_length = (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 neighbors = cow.query_around(trans.pos.xy(), 12.0 + danger_length); let objs = neighbors.map(|(id, pos)| (pos, cow.get(id).expect("Handle not in transport grid").1)); @@ -159,7 +159,7 @@ fn physics( return; } VehicleState::RoadToPark(spline, t, _) => { - trans.position = spline.get(t); + trans.pos = spline.get(t); trans.dir = spline.derivative(t).normalize(); return; } @@ -220,7 +220,7 @@ pub fn calc_decision<'a>( let (front_dist, flag) = calc_front_dist(vehicle, trans, self_obj, it, neighs, cutoff); - let position = trans.position; + let position = trans.pos; let dir_to_pos = unwrap_or!( (objective - position).try_normalize(), return default_return @@ -319,7 +319,7 @@ fn calc_front_dist<'a>( neighs: impl Iterator, cutoff: f32, ) -> (f32, u64) { - let position = trans.position; + let position = trans.pos; let direction = trans.dir; let pos2 = position.xy(); let dir2 = trans.dir.xy(); diff --git a/simulation/src/transportation/testing_vehicles.rs b/simulation/src/transportation/testing_vehicles.rs index 2d256595..bcbda110 100644 --- a/simulation/src/transportation/testing_vehicles.rs +++ b/simulation/src/transportation/testing_vehicles.rs @@ -35,8 +35,7 @@ pub fn random_vehicles_update(world: &mut World, res: &mut Resources) { } let rng = common::hash_u64((tick.0, v_id)); - if let Some(it) = - Itinerary::random_route(rng, v.trans.position, *tick, &map, PathKind::Vehicle) + if let Some(it) = Itinerary::random_route(rng, v.trans.pos, *tick, &map, PathKind::Vehicle) { v.it = it; } diff --git a/simulation/src/transportation/train.rs b/simulation/src/transportation/train.rs index 802b36cc..8acf4e75 100644 --- a/simulation/src/transportation/train.rs +++ b/simulation/src/transportation/train.rs @@ -325,7 +325,7 @@ pub fn locomotive_system(world: &mut World, resources: &mut Resources) { let desired_dir = t.it.get_point() .and_then(|x| { - let d = x - t.trans.position; + let d = x - t.trans.pos; if d.mag2() < 0.5 { return None; } @@ -432,7 +432,7 @@ pub fn locomotive_desired_speed( } if on_last_lane { - if let Some(howfar) = t.it.end_pos().map(|term| term.distance(t.trans.position)) { + if let Some(howfar) = t.it.end_pos().map(|term| term.distance(t.trans.pos)) { if howfar + 0.1 <= stop_dist { return 0.0; } diff --git a/simulation/src/transportation/vehicle.rs b/simulation/src/transportation/vehicle.rs index 8e18569a..79464617 100644 --- a/simulation/src/transportation/vehicle.rs +++ b/simulation/src/transportation/vehicle.rs @@ -47,7 +47,7 @@ pub struct Vehicle { #[must_use] pub fn put_vehicle_in_transport_grid(sim: &Simulation, w: f32, trans: Transform) -> Transporter { Transporter(sim.write::().insert( - trans.position.xy(), + trans.pos.xy(), TransportState { dir: trans.dir.xy(), radius: w * 0.5, diff --git a/simulation/src/world.rs b/simulation/src/world.rs index 9dcf3ed4..d19060b2 100644 --- a/simulation/src/world.rs +++ b/simulation/src/world.rs @@ -236,7 +236,7 @@ impl World { } pub fn pos(&self, id: E) -> Option { - self.get(id).map(|x| E::trans(x).position) + self.get(id).map(|x| E::trans(x).pos) } pub fn trans(&self, id: E) -> Option { @@ -255,10 +255,10 @@ impl World { #[rustfmt::skip] pub fn query_selectable_pos(&self) -> impl Iterator + '_ { chain(( - self.humans .iter().map(|(id, x)| (AnyEntity::HumanID(id), x.trans.position.xy())), - self.vehicles.iter().map(|(id, x)| (AnyEntity::VehicleID(id), x.trans.position.xy())), - self.trains .iter().map(|(id, x)| (AnyEntity::TrainID(id), x.trans.position.xy())), - self.wagons .iter().map(|(id, x)| (AnyEntity::WagonID(id), x.trans.position.xy())), + self.humans .iter().map(|(id, x)| (AnyEntity::HumanID(id), x.trans.pos.xy())), + self.vehicles.iter().map(|(id, x)| (AnyEntity::VehicleID(id), x.trans.pos.xy())), + self.trains .iter().map(|(id, x)| (AnyEntity::TrainID(id), x.trans.pos.xy())), + self.wagons .iter().map(|(id, x)| (AnyEntity::WagonID(id), x.trans.pos.xy())), )) }