mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 15:33:44 +03:00
move person counters to population panel
This commit is contained in:
parent
1259b42ab5
commit
d7886fa85b
@ -72,7 +72,7 @@ impl State for ABTestMode {
|
||||
diff.lines.len()
|
||||
)));
|
||||
}
|
||||
let (finished, unfinished, by_mode, _, _) = app.primary.sim.num_trips();
|
||||
let (finished, unfinished, by_mode) = app.primary.sim.num_trips();
|
||||
txt.add(Line(format!("Finished trips: {}", finished)));
|
||||
txt.add(Line(format!("Unfinished trips: {}", unfinished)));
|
||||
txt.add(Line(format!(
|
||||
|
@ -402,7 +402,7 @@ impl Overlays {
|
||||
.maybe_cb(
|
||||
"population map",
|
||||
Box::new(|ctx, app| {
|
||||
app.overlay = Overlays::population_map(ctx, app, None);
|
||||
app.overlay = Overlays::population_map(ctx, app, Some(HeatmapOptions::new()));
|
||||
Some(maybe_unzoom(ctx, app))
|
||||
}),
|
||||
);
|
||||
@ -1030,7 +1030,7 @@ impl Overlays {
|
||||
batch.push(Color::RED.alpha(0.8), circle.translate(pt.x(), pt.y()));
|
||||
}
|
||||
}
|
||||
let controls = population_controls(ctx, opts.as_ref());
|
||||
let controls = population_controls(ctx, app, opts.as_ref());
|
||||
Overlays::PopulationMap(app.primary.sim.time(), opts, ctx.upload(batch), controls)
|
||||
}
|
||||
}
|
||||
@ -1049,37 +1049,52 @@ fn maybe_unzoom(ctx: &EventCtx, app: &mut App) -> Transition {
|
||||
}
|
||||
|
||||
// This function sounds more ominous than it should.
|
||||
fn population_controls(ctx: &mut EventCtx, opts: Option<&HeatmapOptions>) -> Composite {
|
||||
fn population_controls(ctx: &mut EventCtx, app: &App, opts: Option<&HeatmapOptions>) -> Composite {
|
||||
let (total_ppl, ppl_in_bldg, ppl_off_map) = app.primary.sim.num_ppl();
|
||||
|
||||
let mut col = vec![
|
||||
Widget::row(vec![
|
||||
Line("Population").roboto_bold().draw(ctx),
|
||||
// TODO Only bold the first part
|
||||
Line(format!("Population: {}", prettyprint_usize(total_ppl)))
|
||||
.roboto_bold()
|
||||
.draw(ctx),
|
||||
Btn::text_fg("X")
|
||||
.build(ctx, "close", hotkey(Key::Escape))
|
||||
.align_right(),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
Widget::draw_svg(ctx, "../data/system/assets/tools/home.svg"),
|
||||
prettyprint_usize(ppl_in_bldg).draw_text(ctx),
|
||||
format!("Off-map: {}", prettyprint_usize(ppl_off_map)).draw_text(ctx),
|
||||
])
|
||||
.centered(),
|
||||
Widget::checkbox(ctx, "Show heatmap", None, opts.is_some()),
|
||||
];
|
||||
if let Some(ref o) = opts {
|
||||
// TODO Display the value...
|
||||
col.push(Widget::row(vec![
|
||||
"Resolution (meters)".draw_text(ctx),
|
||||
"Resolution (meters)".draw_text(ctx).margin(5),
|
||||
Widget::slider({
|
||||
let mut slider = Slider::horizontal(ctx, 100.0, 25.0);
|
||||
// 1 to 100m
|
||||
slider.set_percent(ctx, (o.resolution - 1.0) / 99.0);
|
||||
slider
|
||||
})
|
||||
.named("resolution"),
|
||||
.named("resolution")
|
||||
.align_right()
|
||||
.centered_vert(),
|
||||
]));
|
||||
col.push(Widget::row(vec![
|
||||
"Diffusion (num of passes)".draw_text(ctx),
|
||||
"Diffusion (num of passes)".draw_text(ctx).margin(5),
|
||||
Widget::slider({
|
||||
let mut slider = Slider::horizontal(ctx, 100.0, 25.0);
|
||||
// 0 to 10
|
||||
slider.set_percent(ctx, (o.num_passes as f64) / 10.0);
|
||||
slider
|
||||
})
|
||||
.named("passes"),
|
||||
.named("passes")
|
||||
.align_right()
|
||||
.centered_vert(),
|
||||
]));
|
||||
|
||||
col.push(Widget::dropdown(
|
||||
@ -1090,7 +1105,7 @@ fn population_controls(ctx: &mut EventCtx, opts: Option<&HeatmapOptions>) -> Com
|
||||
));
|
||||
}
|
||||
|
||||
Composite::new(Widget::col(col).bg(colors::PANEL_BG))
|
||||
Composite::new(Widget::col(col).padding(5).bg(colors::PANEL_BG))
|
||||
.aligned(HorizontalAlignment::Right, VerticalAlignment::Center)
|
||||
.build(ctx)
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ impl AgentMeter {
|
||||
pub fn new(ctx: &mut EventCtx, app: &App, show_score: Option<ScoreCard>) -> AgentMeter {
|
||||
use abstutil::prettyprint_usize;
|
||||
|
||||
let (finished, unfinished, by_mode, ppl_in_bldg, ppl_off_map) = app.primary.sim.num_trips();
|
||||
let (finished, unfinished, by_mode) = app.primary.sim.num_trips();
|
||||
|
||||
let mut rows = vec![
|
||||
"Active agents".draw_text(ctx),
|
||||
@ -372,17 +372,6 @@ impl AgentMeter {
|
||||
prettyprint_usize(by_mode[&TripMode::Transit]).draw_text(ctx),
|
||||
])
|
||||
.centered(),
|
||||
// TODO Not sure about this one yet
|
||||
if app.opts.dev {
|
||||
Widget::row(vec![
|
||||
Widget::draw_svg(ctx, "../data/system/assets/tools/home.svg"),
|
||||
prettyprint_usize(ppl_in_bldg).draw_text(ctx),
|
||||
format!("Off-map: {}", prettyprint_usize(ppl_off_map)).draw_text(ctx),
|
||||
])
|
||||
.centered()
|
||||
} else {
|
||||
Widget::nothing()
|
||||
},
|
||||
// Separator
|
||||
Widget::draw_batch(
|
||||
ctx,
|
||||
|
@ -699,7 +699,7 @@ impl Sim {
|
||||
|
||||
let dt_real = Duration::realtime_elapsed(last_print);
|
||||
if dt_real >= Duration::seconds(1.0) {
|
||||
let (finished, unfinished, _, _, _) = self.num_trips();
|
||||
let (finished, unfinished, _) = self.num_trips();
|
||||
println!(
|
||||
"{}: {} trips finished, {} unfinished, speed = {:.2}x, {}",
|
||||
self.time(),
|
||||
@ -851,11 +851,14 @@ impl Sim {
|
||||
self.time == Time::START_OF_DAY && self.is_done()
|
||||
}
|
||||
|
||||
// (number of finished trips, number of unfinished trips, number of active by mode, number of
|
||||
// people in buildings, number of people off map)
|
||||
pub fn num_trips(&self) -> (usize, usize, BTreeMap<TripMode, usize>, usize, usize) {
|
||||
// (number of finished trips, number of unfinished trips, number of active by mode)
|
||||
pub fn num_trips(&self) -> (usize, usize, BTreeMap<TripMode, usize>) {
|
||||
self.trips.num_trips()
|
||||
}
|
||||
// (total number of people, just in buildings, just off map)
|
||||
pub fn num_ppl(&self) -> (usize, usize, usize) {
|
||||
self.trips.num_ppl()
|
||||
}
|
||||
|
||||
pub fn count_trips_involving_bldg(&self, b: BuildingID) -> TripCount {
|
||||
self.trips.count_trips_involving_bldg(b, self.time)
|
||||
|
@ -557,9 +557,7 @@ impl TripManager {
|
||||
}
|
||||
}
|
||||
|
||||
// (finished trips, unfinished trips, active trips by the trip's current mode, people in
|
||||
// buildings, people off map)
|
||||
pub fn num_trips(&self) -> (usize, usize, BTreeMap<TripMode, usize>, usize, usize) {
|
||||
pub fn num_trips(&self) -> (usize, usize, BTreeMap<TripMode, usize>) {
|
||||
let mut cnt = Counter::new();
|
||||
for a in self.active_trip_mode.keys() {
|
||||
cnt.inc(TripMode::from_agent(*a));
|
||||
@ -568,6 +566,13 @@ impl TripManager {
|
||||
.into_iter()
|
||||
.map(|k| (k, cnt.get(k)))
|
||||
.collect();
|
||||
(
|
||||
self.trips.len() - self.unfinished_trips,
|
||||
self.unfinished_trips,
|
||||
per_mode,
|
||||
)
|
||||
}
|
||||
pub fn num_ppl(&self) -> (usize, usize, usize) {
|
||||
let mut ppl_in_bldg = 0;
|
||||
let mut ppl_off_map = 0;
|
||||
for p in &self.people {
|
||||
@ -582,13 +587,7 @@ impl TripManager {
|
||||
PersonState::Limbo => {}
|
||||
}
|
||||
}
|
||||
(
|
||||
self.trips.len() - self.unfinished_trips,
|
||||
self.unfinished_trips,
|
||||
per_mode,
|
||||
ppl_in_bldg,
|
||||
ppl_off_map,
|
||||
)
|
||||
(self.people.len(), ppl_in_bldg, ppl_off_map)
|
||||
}
|
||||
|
||||
pub fn is_done(&self) -> bool {
|
||||
|
Loading…
Reference in New Issue
Block a user