diff options
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
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) |