also spawn peds around an intersection

This commit is contained in:
Dustin Carlino 2019-04-16 13:06:01 -07:00
parent 615c33903b
commit 5ed6f2256e
7 changed files with 63 additions and 28 deletions

View File

@ -42,10 +42,11 @@ functionality
- In A/B Street, lanes and intersections have disjoint geometry.
![A/B Street](screenshots/moving_through_intersection.gif)
- This means that cars and pedestrians stop and queue at the correct position before crossing an intersection.
This means that cars and pedestrians stop and queue at the correct position before crossing the intersection.
(gif of stuff moving thru intersection, including peds)
- The intersection geometry is calculated automatically. In some cases, it works quite well. Other times, the result is very confusing and inaccurate.
(OSM and abst examples)

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 KiB

View File

@ -1,5 +0,0 @@
# Videos
ffmpeg -f x11grab -r 25 -s 1920x1080 -i :0.0 -vcodec huffyuv raw.avi
ffmpeg -ss 10.0 -t 5.0 -i raw.avi -f gif -filter_complex "[0:v] fps=12,scale=1024:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" screencast.gif

View File

@ -58,3 +58,14 @@ npm install prettier --save-dev --save-exact
Use https://github.com/joeyespo/grip to render. Doesn't seem to work with the
graphviz image.
## Videos
```
# Fullscreen
ffmpeg -f x11grab -r 25 -s 1920x1080 -i :0.0 -vcodec huffyuv raw.avi
# Default window
ffmpeg -f x11grab -r 25 -s 1024x768 -i :0.0+28,92 -vcodec huffyuv raw.avi
ffmpeg -ss 10.0 -t 5.0 -i raw.avi -f gif -filter_complex "[0:v] fps=12,scale=1024:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" screencast.gif
```

View File

@ -72,9 +72,9 @@ impl SpawnAgent {
Some(ID::Intersection(i)) => {
if ctx
.input
.contextual_action(Key::Z, "spawn cars around this intersection")
.contextual_action(Key::Z, "spawn agents around this intersection")
{
spawn_cars_around(i, ctx);
spawn_agents_around(i, ctx);
}
}
None => {
@ -247,32 +247,48 @@ impl BlockingPlugin for SpawnAgent {
}
}
fn spawn_cars_around(i: IntersectionID, ctx: &mut PluginCtx) {
fn spawn_agents_around(i: IntersectionID, ctx: &mut PluginCtx) {
let map = &ctx.primary.map;
let sim = &mut ctx.primary.sim;
let mut rng = ctx.primary.current_flags.sim_flags.make_rng();
for l in &map.get_i(i).incoming_lanes {
let lane = map.get_l(*l);
if !lane.is_driving() {
continue;
}
for _ in 0..10 {
let vehicle = Scenario::rand_car(&mut rng);
sim.schedule_trip(
// TODO +1?
sim.time(),
TripSpec::CarAppearing(
Position::new(
lane.id,
Scenario::rand_dist(&mut rng, vehicle.length, lane.length()),
if lane.is_driving() {
for _ in 0..10 {
let vehicle = Scenario::rand_car(&mut rng);
sim.schedule_trip(
// TODO +1?
sim.time(),
TripSpec::CarAppearing(
Position::new(
lane.id,
Scenario::rand_dist(&mut rng, vehicle.length, lane.length()),
),
vehicle,
DrivingGoal::ParkNear(map.all_buildings().choose(&mut rng).unwrap().id),
),
vehicle,
DrivingGoal::ParkNear(map.all_buildings().choose(&mut rng).unwrap().id),
),
map,
);
map,
);
}
} else if lane.is_sidewalk() {
for _ in 0..5 {
sim.schedule_trip(
sim.time(),
TripSpec::JustWalking(
SidewalkSpot::suddenly_appear(
lane.id,
Scenario::rand_dist(&mut rng, 0.1 * lane.length(), 0.9 * lane.length()),
map,
),
SidewalkSpot::building(
map.all_buildings().choose(&mut rng).unwrap().id,
map,
),
),
map,
);
}
}
}

View File

@ -280,6 +280,16 @@ impl SidewalkSpot {
})
}
}
pub fn suddenly_appear(l: LaneID, dist: Distance, map: &Map) -> SidewalkSpot {
let lane = map.get_l(l);
assert!(lane.is_sidewalk());
assert!(dist <= lane.length());
SidewalkSpot {
sidewalk_pos: Position::new(l, dist),
connection: SidewalkPOI::SuddenlyAppear,
}
}
}
// Point of interest, that is
@ -291,6 +301,7 @@ pub enum SidewalkPOI {
Border(IntersectionID),
// The equivalent position on the nearest driving/bike lane
BikeRack(Position),
SuddenlyAppear,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]

View File

@ -157,6 +157,7 @@ impl WalkingSimState {
);
scheduler.push(ped.state.get_end_time(), Command::UpdatePed(ped.id));
}
SidewalkPOI::SuddenlyAppear => unreachable!(),
}
} else {
if let PathStep::Turn(t) = ped.path.current_step() {