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.
This commit is contained in:
Adrian Heine 2021-07-23 10:25:28 +02:00
parent 449644ade6
commit 894ebbd736
2 changed files with 4 additions and 5 deletions

View file

@ -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)]

View file

@ -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(),
}),
}),
)
})