mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
starting a plugin to scrape agents...
This commit is contained in:
parent
5bc9992fc0
commit
29e1f3f6c0
@ -8,6 +8,7 @@ fn convert_twice() {
|
||||
elevation: "../data/input/N47W122.hgt".to_string(),
|
||||
traffic_signals: "../data/input/TrafficSignals.shp".to_string(),
|
||||
parcels: "../data/seattle_parcels.abst".to_string(),
|
||||
parking_shapes: "../data/shapes/blockface".to_string(),
|
||||
gtfs: "../data/input/google_transit_2018_18_08".to_string(),
|
||||
neighborhoods: "../data/input/neighborhoods.geojson".to_string(),
|
||||
output: "".to_string(),
|
||||
|
@ -18,6 +18,8 @@ if each plugin should sort of declare a dependency on a live sim or if at a
|
||||
higher level, the list of plugins should change?
|
||||
|
||||
Some initial steps:
|
||||
- make a plugin that asks for all Draw stuff every tick and just saves it
|
||||
= make a plugin that asks for all Draw stuff every tick and just saves it
|
||||
- activate the time travel plugin and have keys to go back/forward
|
||||
- supply the Draw{Car,Ped} stuff from the time travel plugin, not the sim
|
||||
- deactivate lots of other plugins while in this mode
|
||||
- make sim ctrl a proper plugin
|
||||
|
@ -23,6 +23,7 @@ pub mod show_route;
|
||||
pub mod sim_controls;
|
||||
pub mod steep;
|
||||
pub mod stop_sign_editor;
|
||||
pub mod time_travel;
|
||||
pub mod traffic_signal_editor;
|
||||
pub mod turn_cycler;
|
||||
pub mod warp;
|
||||
|
54
editor/src/plugins/time_travel.rs
Normal file
54
editor/src/plugins/time_travel.rs
Normal file
@ -0,0 +1,54 @@
|
||||
use plugins::{Plugin, PluginCtx};
|
||||
use map_model::Map;
|
||||
use std::collections::BTreeMap;
|
||||
use sim::{CarID, DrawCarInput, PedestrianID, DrawPedestrianInput, Sim, AgentID};
|
||||
|
||||
pub struct TimeTravel {
|
||||
state_per_tick: Vec<StateAtTime>,
|
||||
}
|
||||
|
||||
struct StateAtTime {
|
||||
cars: BTreeMap<CarID, DrawCarInput>,
|
||||
peds: BTreeMap<PedestrianID, DrawPedestrianInput>,
|
||||
}
|
||||
|
||||
impl TimeTravel {
|
||||
pub fn new() -> TimeTravel {
|
||||
TimeTravel {
|
||||
state_per_tick: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn record_state(&mut self, sim: &Sim, map: &Map) {
|
||||
// Record state for this tick, if needed.
|
||||
let tick = sim.time.to_inner() as usize;
|
||||
if tick + 1 == self.state_per_tick.len() {
|
||||
return;
|
||||
}
|
||||
assert_eq!(tick, self.state_per_tick.len());
|
||||
|
||||
let mut state = StateAtTime {
|
||||
cars: BTreeMap::new(),
|
||||
peds: BTreeMap::new(),
|
||||
};
|
||||
for agent in sim.active_agents().into_iter() {
|
||||
match agent {
|
||||
AgentID::Car(id) => {
|
||||
state.cars.insert(id, sim.get_draw_car(id, map).unwrap());
|
||||
}
|
||||
AgentID::Pedestrian(id) => {
|
||||
state.peds.insert(id, sim.get_draw_ped(id, map).unwrap());
|
||||
}
|
||||
};
|
||||
}
|
||||
self.state_per_tick.push(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for TimeTravel {
|
||||
fn event(&mut self, ctx: PluginCtx) -> bool {
|
||||
self.record_state(&ctx.primary.sim, &ctx.primary.map);
|
||||
|
||||
false
|
||||
}
|
||||
}
|
@ -257,6 +257,7 @@ impl PerMapUI {
|
||||
Box::new(plugins::map_edits::EditsManager::new()),
|
||||
Box::new(plugins::chokepoints::ChokepointsFinder::new()),
|
||||
Box::new(neighborhood_summary),
|
||||
Box::new(plugins::time_travel::TimeTravel::new()),
|
||||
],
|
||||
};
|
||||
(state, plugins)
|
||||
|
@ -18,6 +18,10 @@ pub type Acceleration = si::MeterPerSecond2<f64>;
|
||||
pub struct Tick(u32);
|
||||
|
||||
impl Tick {
|
||||
pub fn to_inner(&self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn zero() -> Tick {
|
||||
Tick(0)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user