From ff4929c650e6ed446b6faff9f6b0f078d0a3644c Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Mon, 9 Oct 2017 22:51:50 +0200 Subject: Initial work on entities. --- src/world.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/world.cpp') diff --git a/src/world.cpp b/src/world.cpp index dc25f66..9d9b97d 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -83,9 +83,30 @@ tile_t *world_t::get_tile(ssize_t x, ssize_t y) return sector->tiles + ty * SECTOR_SIZE + tx; } +static sector_index_t get_index(float x, float y) +{ + return sector_index_t(floor(x), floor(y)); +} + +void entity_t::link_to_sector(sector_t *sector) +{ + parents.push_back(sector); + sector->ents.insert(this); +} + void entity_t::link(world_t *world) { - // TODO + sector_index_t base; + sector_t *sector; + ssize_t dx, dy; + + // An entity gets linked to at least one sector. + base = get_index(bounds.left, bounds.top); + sector = world->get_sector(base); + link_to_sector(sector); + + // There might be more, though. + //for (dy = 0; dy < } void entity_t::unlink(void) -- cgit