mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
show route by trip, not agent
This commit is contained in:
parent
afa52e4bad
commit
9660794467
@ -2,61 +2,60 @@ use colors::Colors;
|
||||
use dimensioned::si;
|
||||
use ezgui::GfxCtx;
|
||||
use map_model::{Trace, LANE_THICKNESS};
|
||||
use objects::{Ctx, ID};
|
||||
use objects::Ctx;
|
||||
use piston::input::Key;
|
||||
use plugins::{Plugin, PluginCtx};
|
||||
use sim::AgentID;
|
||||
use sim::TripID;
|
||||
use std::f64;
|
||||
|
||||
pub enum ShowRouteState {
|
||||
Empty,
|
||||
Active(AgentID, Trace),
|
||||
Active(TripID, Trace),
|
||||
}
|
||||
|
||||
impl Plugin for ShowRouteState {
|
||||
fn event(&mut self, ctx: PluginCtx) -> bool {
|
||||
let (input, sim, map, selected) = (
|
||||
ctx.input,
|
||||
&ctx.primary.sim,
|
||||
&ctx.primary.map,
|
||||
ctx.primary.current_selection,
|
||||
);
|
||||
|
||||
let maybe_agent = match self {
|
||||
ShowRouteState::Empty => match selected {
|
||||
Some(ID::Car(id)) => {
|
||||
if input.key_pressed(Key::R, "show this car's route") {
|
||||
Some(AgentID::Car(id))
|
||||
let maybe_trip = match self {
|
||||
ShowRouteState::Empty => ctx
|
||||
.primary
|
||||
.current_selection
|
||||
.and_then(|id| id.agent_id())
|
||||
.and_then(|agent| ctx.primary.sim.agent_to_trip(agent))
|
||||
.and_then(|trip| {
|
||||
if ctx
|
||||
.input
|
||||
.key_pressed(Key::R, &format!("show {}'s route", trip))
|
||||
{
|
||||
Some(trip)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Some(ID::Pedestrian(id)) => {
|
||||
if input.key_pressed(Key::R, "show this pedestrian's route") {
|
||||
Some(AgentID::Pedestrian(id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
ShowRouteState::Active(agent, _) => {
|
||||
if input.key_pressed(Key::Return, "stop showing route") {
|
||||
}),
|
||||
ShowRouteState::Active(trip, _) => {
|
||||
if ctx.input.key_pressed(Key::Return, "stop showing route") {
|
||||
None
|
||||
} else {
|
||||
Some(*agent)
|
||||
Some(*trip)
|
||||
}
|
||||
}
|
||||
};
|
||||
if let Some(agent) = maybe_agent {
|
||||
// Trace along the entire route by passing in max distance
|
||||
match sim.trace_route(agent, map, f64::MAX * si::M) {
|
||||
Some(trace) => {
|
||||
*self = ShowRouteState::Active(agent, trace);
|
||||
}
|
||||
None => {
|
||||
*self = ShowRouteState::Empty;
|
||||
if let Some(trip) = maybe_trip {
|
||||
if let Some(agent) = ctx.primary.sim.trip_to_agent(trip) {
|
||||
// Trace along the entire route by passing in max distance
|
||||
if let Some(trace) =
|
||||
ctx.primary
|
||||
.sim
|
||||
.trace_route(agent, &ctx.primary.map, f64::MAX * si::M)
|
||||
{
|
||||
*self = ShowRouteState::Active(trip, trace);
|
||||
} else {
|
||||
warn!("{} has no trace right now", agent);
|
||||
}
|
||||
} else {
|
||||
warn!(
|
||||
"{} has no agent associated right now; is the trip done?",
|
||||
trip
|
||||
);
|
||||
}
|
||||
} else {
|
||||
*self = ShowRouteState::Empty;
|
||||
|
@ -384,7 +384,7 @@ impl Sim {
|
||||
|
||||
// TODO dont toggle state in debug_car
|
||||
pub fn debug_trip(&mut self, id: TripID) {
|
||||
match self.trips_state.current_mode(id) {
|
||||
match self.trips_state.trip_to_agent(id) {
|
||||
Some(AgentID::Car(id)) => self.debug_car(id),
|
||||
Some(AgentID::Pedestrian(id)) => self.debug_ped(id),
|
||||
None => println!("{} doesn't exist", id),
|
||||
@ -395,9 +395,13 @@ impl Sim {
|
||||
self.trips_state.agent_to_trip(id)
|
||||
}
|
||||
|
||||
pub fn trip_to_agent(&self, id: TripID) -> Option<AgentID> {
|
||||
self.trips_state.trip_to_agent(id)
|
||||
}
|
||||
|
||||
pub fn get_canonical_point_for_trip(&self, id: TripID, map: &Map) -> Option<Pt2D> {
|
||||
// Don't unwrap(); the trip might be registered before the agent has started.
|
||||
match self.trips_state.current_mode(id) {
|
||||
match self.trips_state.trip_to_agent(id) {
|
||||
Some(AgentID::Car(id)) => self
|
||||
.driving_state
|
||||
.get_draw_car(id, self.time, map)
|
||||
|
@ -226,7 +226,7 @@ impl TripManager {
|
||||
self.active_trip_mode.keys().cloned().collect()
|
||||
}
|
||||
|
||||
pub fn current_mode(&self, id: TripID) -> Option<AgentID> {
|
||||
pub fn trip_to_agent(&self, id: TripID) -> Option<AgentID> {
|
||||
let trip = self.trips.get(id.0)?;
|
||||
match trip.legs[0] {
|
||||
TripLeg::Walk(_) => Some(AgentID::Pedestrian(trip.ped)),
|
||||
|
Loading…
Reference in New Issue
Block a user