From 297524c8ec41b585c4812494791772406653e479 Mon Sep 17 00:00:00 2001 From: PaweÅ‚ Redman Date: Tue, 19 Dec 2017 19:27:06 +0100 Subject: Introduce tall tiles. Some features are still missing but the commit is large enough as it is. TODO: render layers and fix minor artifacts. --- src/world.cpp | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/world.cpp') diff --git a/src/world.cpp b/src/world.cpp index 5c2d7b3..6a0ba97 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -27,50 +27,50 @@ void register_tile(uint8_t type, cflags_t cflags) tiles[type] = cflags; } -void world_t::generate(sector_t *sector, sector_index_t index, bool partial) +void world_t::generate(sector_t *sector, sector_index_t index, sector_level_t level) { bool gen_tiles = false, gen_decos = false; sector->index = index; - sector->bounds.v[0] = (v2f_t)index * SECTOR_SIZE; sector->bounds.v[1] = sector->bounds.v[0] + v2f_t(SECTOR_SIZE, SECTOR_SIZE); - if (sector->empty) { - if (partial) + if (sector->level == SECTOR_EMPTY) { + if (level == SECTOR_PARTIAL) gen_tiles = true; - else + else if (level == SECTOR_FULL) gen_tiles = gen_decos = true; - } else + } else if (sector->level == SECTOR_PARTIAL) gen_decos = true; - sector->empty = false; + sector->level = level; generator(this, index, sector, gen_tiles, gen_decos, generator_data); stats.sectors++; stats.tiles += SECTOR_SIZE * SECTOR_SIZE; - // Unused, for now. - /* - for (coord_t ly = 0; ly < SECTOR_SIZE; ly++) - for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) { + if (sector->level < SECTOR_FULL) + return; + + for (coord_t ty = 0; ty < SECTOR_SIZE; ty++) + for (coord_t tx = 0; tx < SECTOR_SIZE; tx++) { tile_t *tile; + tile_index_t local(tx, ty); - tile = sector->tiles + ly * SECTOR_SIZE + lx; + tile = sector->tiles + ty * SECTOR_SIZE + tx; tile->neighbors = 0; for (size_t i = 0; i < 8; i++) { tile_index_t neighbor_index; tile_t *neighbor; - neighbor_index = index * SECTOR_SIZE + tile_index_t(lx, ly) + neighbor_offsets[i]; - neighbor = get_tile(neighbor_index, true); + neighbor_index = index * SECTOR_SIZE + local + neighbor_offsets[i]; + neighbor = get_tile(neighbor_index, SECTOR_PARTIAL); if (neighbor->type == tile->type) tile->neighbors |= (1 << i); } } - */ } bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore, @@ -91,7 +91,7 @@ bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore index = finder.base + tile_index_t(x, y); - if (!(tiles[get_tile(index)->type] & cmodel->cflags)) + if (!(tiles[get_tile(index, SECTOR_FULL)->type] & cmodel->cflags)) continue; combined[0] = v2f_t(index) - cmodel_dims / 2; @@ -129,19 +129,19 @@ bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore return true; } -sector_t *world_t::get_sector(sector_index_t index, bool partial) +sector_t *world_t::get_sector(sector_index_t index, sector_level_t level) { sector_t *sector; sector = §ors[index]; - if (sector->empty) - generate(sector, index, partial); + if (sector->level < level) + generate(sector, index, level); return sector; } -tile_t *world_t::get_tile(tile_index_t index, bool partial) +tile_t *world_t::get_tile(tile_index_t index, sector_level_t level) { sector_index_t sector_index; sector_t *sector; @@ -149,12 +149,12 @@ tile_t *world_t::get_tile(tile_index_t index, bool partial) 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, partial); + sector = get_sector(sector_index, level); return sector->tiles + ty * SECTOR_SIZE + tx; } -std::list world_t::get_sectors(rectf_t rect) +std::list world_t::get_sectors(rectf_t rect, sector_level_t level) { sector_index_t base, upper; std::list list; @@ -165,7 +165,7 @@ std::list world_t::get_sectors(rectf_t rect) for (int64_t y = base[1]; y <= upper[1]; y++) for (int64_t x = base[0]; x <= upper[0]; x++) { sector_index_t index(x, y); - list.push_back(get_sector(index)); + list.push_back(get_sector(index, level)); } return list; @@ -179,7 +179,7 @@ std::list world_t::get_entities(rectf_t rect, cflags_t cflags) cookie++; - for (sector_t *sector : get_sectors(rect)) + for (sector_t *sector : get_sectors(rect, SECTOR_FULL)) for (entity_t *ent : sector->ents) { if (ent->cookie == cookie) continue; @@ -204,7 +204,7 @@ std::list world_t::get_render_entities(rectf_t rect) cookie++; - for (sector_t *sector : get_sectors(rect)) + for (sector_t *sector : get_sectors(rect, SECTOR_FULL)) for (entity_t *ent : sector->ents) { if (ent->cookie == cookie) continue; @@ -224,7 +224,7 @@ bool world_t::test_rect(const cmodel_t *cmodel, const entity_t *ignore) { cookie++; - for (sector_t *sector : get_sectors(cmodel->bounds)) { + for (sector_t *sector : get_sectors(cmodel->bounds, SECTOR_FULL)) { rect_t bounds; tile_index_t index; @@ -338,7 +338,7 @@ trace_t world_t::trace(v2f_t start, v2f_t end, cflags_t cflags) index = (tile_index_t(x.floor()) ^ transforms_index[quad]) + offsets_index[quad]; - if (tiles[get_tile(index, false)->type] & cflags) { + if (tiles[get_tile(index, SECTOR_FULL)->type] & cflags) { res.hit = true; res.end = x ^ transforms[quad]; res.frac = (x - start).len() / (end - start).len(); @@ -423,7 +423,7 @@ void entity_t::link(world_t *world_) sector_index_t index = base + sector_index_t(x, y); sector_t *sector; - sector = world->get_sector(index); + sector = world->get_sector(index, SECTOR_FULL); link_to_sector(sector); } -- cgit