Skip to content

Commit

Permalink
rename position -> pos
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jan 11, 2024
1 parent 38510e0 commit 3fc6388
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 76 deletions.
6 changes: 3 additions & 3 deletions egui-inspect/src/impls/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ impl Inspect<LinearColor> for LinearColor {

impl Inspect<Transform> 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;
<Vec3 as Inspect<Vec3>>::render(&position, "position", ui, &InspectArgs::default());
<Vec3 as Inspect<Vec3>>::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 = <Vec3 as Inspect<Vec3>>::render_mut(
&mut position,
Expand All @@ -93,7 +93,7 @@ impl Inspect<Transform> for Transform {
&InspectArgs::default(),
);
t.dir = direction.normalize();
t.position = position;
t.pos = position;
changed
}
}
Expand Down
19 changes: 8 additions & 11 deletions geom/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -15,17 +15,14 @@ impl Transform {
Self::new(Vec3::ZERO)
}

pub fn new<T: Into<Vec3>>(position: T) -> Self {
let position = position.into();
Self {
position,
dir: Vec3::X,
}
pub fn new<T: Into<Vec3>>(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]
Expand All @@ -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),
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/windows/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub fn debug_parking(tess: &mut Tesselator<true>, 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(())
Expand Down
11 changes: 4 additions & 7 deletions native_app/src/rendering/entity_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand All @@ -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,
};
Expand All @@ -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,
});
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/map/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions simulation/src/map/objects/parking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/map_dynamic/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

/*
Expand Down
12 changes: 3 additions & 9 deletions simulation/src/map_dynamic/itinerary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
20 changes: 10 additions & 10 deletions simulation/src/map_dynamic/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ fn walk_outside(body: HumanID, pos: Vec3, cbuf: &ParCommandBuffer<HumanEnt>, loc
cbuf.exec_ent(body, move |sim| {
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.trans.pos = pos;
h.collider = Some(coll);
});
}
Expand All @@ -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,
};
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 2 additions & 4 deletions simulation/src/souls/desire/buyfood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
Expand Down
12 changes: 3 additions & 9 deletions simulation/src/souls/freight_station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion simulation/src/souls/human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions simulation/src/transportation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/transportation/pedestrian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions simulation/src/transportation/road.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -319,7 +319,7 @@ fn calc_front_dist<'a>(
neighs: impl Iterator<Item = (Vec2, &'a TransportState)>,
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();
Expand Down
3 changes: 1 addition & 2 deletions simulation/src/transportation/testing_vehicles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 3fc6388

Please sign in to comment.