mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
agent::conn: Change to pointer, delete in ~agent()
This commit is contained in:
parent
1d15adac48
commit
a645ba5758
3 changed files with 11 additions and 8 deletions
8
agent.cc
8
agent.cc
|
@ -37,5 +37,11 @@ agent::on_tick(void)
|
|||
tile->tile_in_dir(0, 1).symbol(),
|
||||
tile->tile_in_dir(-1, 0).symbol(),
|
||||
};
|
||||
conn.senses(tick_id, around);
|
||||
conn->senses(tick_id, around);
|
||||
}
|
||||
|
||||
agent::~agent()
|
||||
{
|
||||
tile->on_agent_leave(*this);
|
||||
delete conn;
|
||||
};
|
||||
|
|
9
agent.h
9
agent.h
|
@ -9,9 +9,9 @@ class agent {
|
|||
public:
|
||||
int id;
|
||||
class tile *tile;
|
||||
class connection &conn;
|
||||
class connection *conn;
|
||||
|
||||
agent(int id_, class tile &tile_, class connection &conn_) : id (id_), tile (&tile_), conn (conn_)
|
||||
agent(int id_, class tile &tile_, class connection *conn_) : id (id_), tile (&tile_), conn (conn_)
|
||||
{
|
||||
put_at(tile_);
|
||||
};
|
||||
|
@ -20,10 +20,7 @@ public:
|
|||
|
||||
void on_tick(void);
|
||||
|
||||
~agent()
|
||||
{
|
||||
tile->on_agent_leave(*this);
|
||||
};
|
||||
~agent();
|
||||
|
||||
private:
|
||||
/* Just for initial placement. */
|
||||
|
|
2
main.cc
2
main.cc
|
@ -52,7 +52,7 @@ main(int argc, char *argv[])
|
|||
if (cfd >= 0) {
|
||||
class connection *conn = new class connection(cfd);
|
||||
class tile &agentpos = map.tile_at(random() % map.w, random() % map.h);
|
||||
agent = new class agent(0, agentpos, *conn);
|
||||
agent = new class agent(0, agentpos, conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue