mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
Separate agent on_tick and removal, better world consistency
This commit is contained in:
parent
27f4f4a3b0
commit
1a9dcce608
1 changed files with 13 additions and 10 deletions
23
main.cc
23
main.cc
|
@ -48,6 +48,19 @@ main(int argc, char *argv[])
|
|||
while (true) {
|
||||
std::cout << "tick " << tick_id << '\n';
|
||||
|
||||
/* Drop disconnected agents. */
|
||||
|
||||
for (std::list<class agent *>::iterator agent = agents.begin(); agent != agents.end(); agent++)
|
||||
{
|
||||
next_agent:
|
||||
if ((*agent)->conn && (*agent)->conn->error) {
|
||||
delete *agent;
|
||||
agent = agents.erase(agent);
|
||||
if (agent != agents.end())
|
||||
goto next_agent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Accept new agents. */
|
||||
|
||||
int cfd = accept(lfd, NULL, NULL);
|
||||
|
@ -63,18 +76,8 @@ main(int argc, char *argv[])
|
|||
/* Run on_tick everywhere. */
|
||||
|
||||
map.on_tick();
|
||||
|
||||
for (std::list<class agent *>::iterator agent = agents.begin(); agent != agents.end(); agent++)
|
||||
{
|
||||
next_agent:
|
||||
(*agent)->on_tick();
|
||||
if ((*agent)->conn && (*agent)->conn->error) {
|
||||
delete *agent;
|
||||
agent = agents.erase(agent);
|
||||
if (agent != agents.end())
|
||||
goto next_agent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Finish a tick. */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue