Accept new agents at the beginning of tick

This commit is contained in:
Petr Baudis 2011-11-27 00:24:05 +01:00
parent f33f7c1d61
commit 6f038434f9

20
main.cc
View file

@ -46,6 +46,16 @@ main(int argc, char *argv[])
while (true) {
std::cout << "tick " << tick_id << '\n';
int cfd = accept(lfd, NULL, NULL);
if (cfd >= 0) {
class connection *conn = new class connection(cfd);
class tile *agentpos;
do {
agentpos = &map.tile_at(random() % map.w, random() % map.h);
} while (agentpos->agent);
agents.push_back(new class agent(0, *agentpos, conn));
}
map.on_tick();
for (std::list<class agent *>::iterator agent = agents.begin(); agent != agents.end(); agent++)
@ -60,16 +70,6 @@ next_agent:
}
}
int cfd = accept(lfd, NULL, NULL);
if (cfd >= 0) {
class connection *conn = new class connection(cfd);
class tile *agentpos;
do {
agentpos = &map.tile_at(random() % map.w, random() % map.h);
} while (agentpos->agent);
agents.push_back(new class agent(0, *agentpos, conn));
}
map.print_map();
std::cout << '\n';
usleep(1000000);