diff options
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/world.cpp b/src/world.cpp index c18a7ab..511de12 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -43,10 +43,9 @@ void world_t::generate_tile(tile_t *tile, tile_index_t x) void world_t::generate(sector_t *sector, sector_index_t index) { sector->index = index; - sector->bounds.left = index[0] * SECTOR_SIZE; - sector->bounds.top = index[1] * SECTOR_SIZE; - sector->bounds.width = SECTOR_SIZE; - sector->bounds.height = SECTOR_SIZE; + + sector->bounds.v[0] = (v2f_t)index * SECTOR_SIZE; + sector->bounds.v[1].broadcast(SECTOR_SIZE); std::cout << "generating " << index << "\n"; @@ -71,26 +70,26 @@ sector_t *world_t::get_sector(sector_index_t index) return sector; } -tile_t *world_t::get_tile(ssize_t x, ssize_t y) +tile_t *world_t::get_tile(tile_index_t index) { - sector_index_t index; + sector_index_t sector_index; sector_t *sector; - ssize_t tx, ty; + int64_t tx, ty; - index[0] = divide_rmi(x, (ssize_t)SECTOR_SIZE, &tx); - index[1] = divide_rmi(y, (ssize_t)SECTOR_SIZE, &ty); - sector = get_sector(index); + sector_index[0] = divide_rmi(index[0], (int64_t)SECTOR_SIZE, &tx); + sector_index[1] = divide_rmi(index[1], (int64_t)SECTOR_SIZE, &ty); + sector = get_sector(sector_index); return sector->tiles + ty * SECTOR_SIZE + tx; } -std::list<sector_t*> world_t::get_sectors(sf::FloatRect rect) +std::list<sector_t*> world_t::get_sectors(rectf_t rect) { sector_index_t base, upper; std::list<sector_t*> list; - base = sector_index_at(v2f_t(rect.left, rect.top)); - upper = sector_index_at(v2f_t(rect.left + rect.width, rect.top + rect.height)); + base = sector_index_at(rect.v[0]); + upper = sector_index_at(rect.v[1]); for (int64_t y = base[1]; y <= upper[1]; y++) for (int64_t x = base[0]; x <= upper[0]; x++) { @@ -101,7 +100,7 @@ std::list<sector_t*> world_t::get_sectors(sf::FloatRect rect) return list; } -std::list<entity_t*> world_t::get_render_entities(sf::FloatRect rect) +std::list<entity_t*> world_t::get_entities(rectf_t rect) { static size_t cookie = 0; std::list<entity_t*> list; @@ -113,7 +112,7 @@ std::list<entity_t*> world_t::get_render_entities(sf::FloatRect rect) if (ent->cookie == cookie) continue; - if (!rect.intersects(ent->render_bounds)) + if (!rect.intersects(ent->bounds)) continue; ent->cookie = cookie; @@ -124,7 +123,7 @@ std::list<entity_t*> world_t::get_render_entities(sf::FloatRect rect) return list; } -std::list<entity_t*> world_t::get_entities(sf::FloatRect rect) +std::list<entity_t*> world_t::get_render_entities(rectf_t rect) { static size_t cookie = 0; std::list<entity_t*> list; @@ -136,7 +135,7 @@ std::list<entity_t*> world_t::get_entities(sf::FloatRect rect) if (ent->cookie == cookie) continue; - if (!rect.intersects(ent->bounds)) + if (!rect.intersects(ent->render_bounds)) continue; ent->cookie = cookie; @@ -173,12 +172,12 @@ void entity_t::link(world_t *world) //total.bounds.width = std::max(bounds.width, render_bounds.width); //total.bounds.height = std::max(bounds.height, render_bounds.height); - fx = floor(bounds.left); - fy = floor(bounds.top); + fx = floor(bounds[0][0]); + fy = floor(bounds[0][1]); base = sector_index_at(v2f_t(fx, fy)); - xlip = bounds.left + bounds.width - (base[0] + 1) * SECTOR_SIZE; - ylip = bounds.top + bounds.height - (base[1] + 1) * SECTOR_SIZE; + xlip = bounds[1][0] - (base[0] + 1) * SECTOR_SIZE; + ylip = bounds[1][1] - (base[1] + 1) * SECTOR_SIZE; if (xlip > 0.0f) xsecs = ceil(xlip / SECTOR_SIZE) + 1; |