separated thinking and action handling in two different loop

This commit is contained in:
Lendemor 2016-06-04 19:15:18 +02:00
parent f762f199ca
commit 025113a218
2 changed files with 7 additions and 3 deletions

View File

@ -49,7 +49,7 @@ void Dude::update(BehaviorFunction func)
{ {
func(&m_action, m_memory, (Info*)this); func(&m_action, m_memory, (Info*)this);
m_receivedComData = false; m_receivedComData = false;
memcpy(m_com_data.data, 0, COM_SIZE); memset(m_com_data.data, 0, COM_SIZE);
} }
PixelType Dude::getNear(Dir d) const PixelType Dude::getNear(Dir d) const

View File

@ -34,10 +34,14 @@ void Simulation::update()
std::random_shuffle(m_dudes.begin(), m_dudes.end()); std::random_shuffle(m_dudes.begin(), m_dudes.end());
for (unsigned int i=0; i<m_dudes.size(); ++i){ for (unsigned int i=0; i<m_dudes.size(); ++i){
Dude *dude = m_dudes[i]; Dude *dude = m_dudes[i];
if (dude->isAlive()){ if (dude->isAlive())
m_teams[dude->getTeam()].update(dude); //get action for this dude from behavior function in team m_teams[dude->getTeam()].update(dude); //get action for this dude from behavior function in team
}
for (unsigned int i=0; i<m_dudes.size(); ++i){
Dude *dude = m_dudes[i];
if (dude->isAlive())
handleAction(dude); handleAction(dude);
}
} }
resolveBattles(); resolveBattles();