mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
Accept new agents at the beginning of tick
This commit is contained in:
parent
f33f7c1d61
commit
6f038434f9
1 changed files with 10 additions and 10 deletions
20
main.cc
20
main.cc
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue