diff --git a/sim/src/render.rs b/sim/src/render.rs index 0a2e6b5426..3990f0892e 100644 --- a/sim/src/render.rs +++ b/sim/src/render.rs @@ -37,7 +37,7 @@ impl Sim { } pub fn get_draw_ped(&self, id: PedestrianID, map: &Map) -> Option { - self.walking_state.get_draw_ped(id, map) + self.walking_state.get_draw_ped(id, map, self.time) } // TODO maybe just DrawAgent instead? should caller care? @@ -56,10 +56,10 @@ impl Sim { } pub fn get_draw_peds_on_lane(&self, l: LaneID, map: &Map) -> Vec { - self.walking_state.get_draw_peds_on_lane(l, map) + self.walking_state.get_draw_peds_on_lane(l, map, self.time) } pub fn get_draw_peds_on_turn(&self, t: TurnID, map: &Map) -> Vec { - self.walking_state.get_draw_peds_on_turn(t, map) + self.walking_state.get_draw_peds_on_turn(t, map, self.time) } } diff --git a/sim/src/sim.rs b/sim/src/sim.rs index 73f74d3e56..3c2f3aa0bc 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -404,9 +404,10 @@ impl Sim { .driving_state .get_draw_car(id, self.time, map) .map(|c| c.front), - Some(AgentID::Pedestrian(id)) => { - self.walking_state.get_draw_ped(id, map).map(|p| p.pos) - } + Some(AgentID::Pedestrian(id)) => self + .walking_state + .get_draw_ped(id, map, self.time) + .map(|p| p.pos), None => None, }; if let Some(pt) = pt { diff --git a/sim/src/walking.rs b/sim/src/walking.rs index 903b8cb5d8..51b55a349b 100644 --- a/sim/src/walking.rs +++ b/sim/src/walking.rs @@ -306,9 +306,23 @@ impl Pedestrian { Ok(()) } - fn get_pos(&self, map: &Map) -> Pt2D { + fn get_pos(&self, map: &Map, now: Tick) -> Pt2D { if let Some(ref fp) = self.front_path { map.get_b(fp.bldg).front_path.line.dist_along(fp.dist_along) + } else if let Some(ref bp) = self.bike_parking { + let (base_pos, angle) = self.on.dist_along(self.dist_along, map); + let progress: f64 = + ((now - bp.started_at).as_time() / TIME_TO_PREPARE_BIKE).value_unsafe; + assert!(progress >= 0.0 && progress <= 1.0); + let project_away_ratio = if bp.is_parking { + progress + } else { + 1.0 - progress + }; + // TODO how many lanes away? and we're assuming the equivalent dist_along is + // perpendicular + use map_model::LANE_THICKNESS; + base_pos.project_away(project_away_ratio * LANE_THICKNESS, angle.rotate_degs(90.0)) } else { self.on.dist_along(self.dist_along, map).0 } @@ -518,28 +532,43 @@ impl WalkingSimState { } } - pub fn get_draw_ped(&self, id: PedestrianID, map: &Map) -> Option { + pub fn get_draw_ped( + &self, + id: PedestrianID, + map: &Map, + now: Tick, + ) -> Option { let ped = self.peds.get(&id)?; Some(DrawPedestrianInput { id, - pos: ped.get_pos(map), + pos: ped.get_pos(map, now), waiting_for_turn: ped.waiting_for_turn(), preparing_bike: ped.bike_parking.is_some(), }) } - pub fn get_draw_peds_on_lane(&self, l: LaneID, map: &Map) -> Vec { + pub fn get_draw_peds_on_lane( + &self, + l: LaneID, + map: &Map, + now: Tick, + ) -> Vec { let mut result = Vec::new(); for id in self.peds_per_sidewalk.get_vec(&l).unwrap_or(&Vec::new()) { - result.push(self.get_draw_ped(*id, map).unwrap()); + result.push(self.get_draw_ped(*id, map, now).unwrap()); } result } - pub fn get_draw_peds_on_turn(&self, t: TurnID, map: &Map) -> Vec { + pub fn get_draw_peds_on_turn( + &self, + t: TurnID, + map: &Map, + now: Tick, + ) -> Vec { let mut result = Vec::new(); for id in self.peds_per_turn.get_vec(&t).unwrap_or(&Vec::new()) { - result.push(self.get_draw_ped(*id, map).unwrap()); + result.push(self.get_draw_ped(*id, map, now).unwrap()); } result }