Skip to content

Commit

Permalink
only show arrows on one-way roads
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Aug 11, 2023
1 parent adc7b64 commit c928c50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion egregoria/src/map/objects/road.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Road {
}

/// Returns lanes in left to right order from the source
pub fn lanes_iter(&self) -> impl DoubleEndedIterator<Item = (LaneID, LaneKind)> + '_ {
pub fn lanes_iter(&self) -> impl DoubleEndedIterator<Item = (LaneID, LaneKind)> + Clone + '_ {
self.lanes_forward
.iter()
.rev()
Expand Down
25 changes: 21 additions & 4 deletions native_app/src/rendering/map_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,32 @@ impl MapMeshHandler {

impl MapBuilders {
fn arrows(&mut self, road: &Road, lanes: &Lanes) {
let has_forward = road
.outgoing_lanes_from(road.src)
.iter()
.filter(|(_, kind)| kind.needs_arrows())
.count()
> 0;
let has_backward = road
.outgoing_lanes_from(road.dst)
.iter()
.filter(|(_, kind)| kind.needs_arrows())
.count()
> 0;
let is_two_way = has_forward && has_backward;

if is_two_way {
return;
}

let n_arrows = ((road.length() / 50.0) as i32).max(1);

let fade =
(road.length() - 5.0 - road.interface_from(road.src) - road.interface_from(road.dst))
.mul(0.2)
.clamp(0.0, 1.0);

let r_lanes = road.lanes_iter().filter(|(_, kind)| kind.needs_arrows());
let n_arrows = ((road.length() / 50.0) as i32).max(1);

for (id, _) in r_lanes {
for (id, _) in road.lanes_iter().filter(|(_, kind)| kind.needs_arrows()) {
let lane = &lanes[id];
let l = lane.points.length();
for i in 0..n_arrows {
Expand Down

0 comments on commit c928c50

Please sign in to comment.