Browse Source

Don't collect other agents' position for worldview

This is a huge performance improvement (drops ~90% of execution time)
with the current SimpleAgent implementation, because a SimpleAgent
that is not It will not even look at other agents' positions.
main
Adrian Heine 3 years ago
parent
commit
894ebbd736
  1. 4
      src/agent.rs
  2. 5
      src/world.rs

4
src/agent.rs

@ -26,12 +26,12 @@ impl From<(Distance, Distance)> for Direction {
pub type AgentId = usize;
pub struct WorldView {
pub struct WorldView<'o> {
pub self_id: AgentId,
pub tagged: AgentId,
pub tagged_by: Option<AgentId>,
pub bounds_distance: (Distance, Distance, Distance, Distance),
pub other_agents: Vec<(Direction, AgentId)>,
pub other_agents: &'o mut dyn Iterator<Item = (Direction, AgentId)>,
}
#[derive(Debug)]

5
src/world.rs

@ -58,7 +58,7 @@ impl ActualWorld {
tagged_by: self.state.tagged_by,
tagged: self.state.tagged,
bounds_distance: (pos.y, self.size.x - pos.x, self.size.y - pos.y, pos.x),
other_agents: self
other_agents: &mut self
.state
.agent_positions
.iter()
@ -71,8 +71,7 @@ impl ActualWorld {
},
*id,
)
})
.collect(),
}),
}),
)
})

Loading…
Cancel
Save