diff options
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/world.cpp b/src/world.cpp index dc35f46..e326bf3 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -19,27 +19,12 @@ world_t::world_t(void) perlin.generate(&prng, 32); } -void world_t::generate_tile(tile_t *tile, tile_index_t x) +// FIXME: rename +static cflags_t tiles[256] = {0}; + +void register_tile(uint8_t type, cflags_t cflags) { - float waterlevel, height; - - waterlevel = perlin.get(x, 1000.0f) * 0.3f + - perlin.get(x, 500.0f) * 0.1f; - - height = perlin.get(x, 40.0f) * 0.6f + - perlin.get(x, 20.0f) * 0.25f + - perlin.get(x, 10.0f) * 0.2f + - perlin.get(x, 4.0f) * 0.1f + - perlin.get(x, 1.0f) * 0.05f; - - if (height < waterlevel) - tile->type = TILE_NONE; - else if (height < waterlevel + 0.1) - tile->type = TILE_DIRT; - else if (perlin.get(x, 3.0f) > 0.0f) - tile->type = TILE_WALL; - else - tile->type = TILE_DIRT; + tiles[type] = cflags; } void world_t::generate(sector_t *sector, sector_index_t index, bool partial) @@ -50,10 +35,12 @@ void world_t::generate(sector_t *sector, sector_index_t index, bool partial) sector->bounds.v[1] = sector->bounds.v[0] + v2f_t(SECTOR_SIZE, SECTOR_SIZE); for (coord_t ly = 0; ly < SECTOR_SIZE; ly++) - for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) - generate_tile(sector->tiles + ly * SECTOR_SIZE + lx, - tile_index_t(index[0] * SECTOR_SIZE + lx, - index[1] * SECTOR_SIZE + ly)); + for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) { + tile_t *tile = sector->tiles + ly * SECTOR_SIZE + lx; + tile_index_t tile_index(index[0] * SECTOR_SIZE + lx, + index[1] * SECTOR_SIZE + ly); + generator(tile, tile_index, &perlin); + } sector->empty = false; @@ -98,7 +85,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 (get_tile(index)->type == TILE_DIRT) + if (tiles[get_tile(index)->type] & cmodel->cflags) continue; combined[0] = v2f_t(index) - cmodel_dims / 2; @@ -251,7 +238,8 @@ bool world_t::test_rect(const cmodel_t *cmodel, const entity_t *ignore) tile_t *tile; tile = sector->tiles + index[1] * SECTOR_SIZE + index[0]; - if (tile->type != TILE_DIRT) + + if (tiles[tile->type] & cmodel->cflags) return true; } @@ -376,6 +364,7 @@ trace_t world_t::trace(v2f_t start, v2f_t end, cflags_t cflags) trace_t trace_cmodel(v2f_t start, v2f_t end, const cmodel_t *cmodel) { // TODO + return {0}; } void world_t::debug_point(sf::Vector2f point) |