From a44122dc7336640c4f20cd9845f26e38a55ec1cd Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 17 Dec 2017 08:12:13 +0000 Subject: Improve decos: more variations and fewer patterns. --- src/common.hpp | 3 ++- src/game/assets.cpp | 2 ++ src/game/decos.cpp | 10 ++++++++++ src/game/game.hpp | 8 ++++++-- src/game/worldgen.cpp | 41 ++++++++++++++++++++++++++++++++--------- src/world.cpp | 18 ++++++++++++++---- 6 files changed, 66 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/common.hpp b/src/common.hpp index e8f531a..5510f95 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -109,7 +109,8 @@ namespace world { public: procgen::perlin_noise_t perlin; - void (*generator)(world_t *world, sector_index_t index, sector_t *sector, void *data) = 0; + void (*generator)(world_t *world, sector_index_t index, sector_t *sector, + bool gen_tiles, bool gen_decos, void *data) = 0; void *generator_data = 0; world_t(void); diff --git a/src/game/assets.cpp b/src/game/assets.cpp index 6751435..e4d6475 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -29,6 +29,8 @@ void load(void) deco.stone.load("assets/deco/stone_", 1); deco.eyething.load("assets/deco/eyething_", 2); + deco.spike.load("assets/deco/spike_", 1); + deco.spike_small.load("assets/deco/spike_small_", 1); world::register_tile(TILE_DIRT, 0); render::register_tile(TILE_DIRT, "assets/tiles/dirt.png"); diff --git a/src/game/decos.cpp b/src/game/decos.cpp index 07e6b10..9027ee0 100644 --- a/src/game/decos.cpp +++ b/src/game/decos.cpp @@ -23,6 +23,16 @@ static const struct { &assets::deco.eyething, {-0.4f, +0.1f}, {+0.4f, +0.4f}, CF_SOLID, {-0.4f, -1.2f}, {+0.4f, +0.4f}, 0.3 + }, + { + &assets::deco.spike, + {-0.4f, +0.1f}, {+0.4f, +0.4f}, CF_SOLID, + {-0.4f, -1.2f}, {+0.4f, +0.4f}, 0.0 + }, + { + &assets::deco.spike_small, + {-0.2f, +0.1f}, {+0.2f, +0.2f}, 0, + {-0.2f, -0.6f}, {+0.2f, +0.2f}, 0.0 } }; diff --git a/src/game/game.hpp b/src/game/game.hpp index 7b0674c..d055aa5 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -24,7 +24,8 @@ namespace game { extern size_t selection_cookie; - void worldgen(world::world_t *world, world::sector_index_t index, world::sector_t *sector, void *data); + void worldgen(world::world_t *world, world::sector_index_t index, world::sector_t *sector, + bool gen_tiles, bool gen_decos, void *data); namespace assets { typedef struct { @@ -49,6 +50,7 @@ namespace game { typedef struct { render::animated_texture_t stone, eyething; + render::animated_texture_t spike, spike_small; } deco_assets_t; extern soldier_assets_t soldier; @@ -250,7 +252,9 @@ namespace game { typedef enum { DECO_STONE, DECO_STONE_SMALL, - DECO_EYETHING + DECO_EYETHING, + DECO_SPIKE, + DECO_SPIKE_SMALL } deco_type_t; class deco_t : public game::entity_t { diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp index 18a98b5..6ade1a6 100644 --- a/src/game/worldgen.cpp +++ b/src/game/worldgen.cpp @@ -4,29 +4,37 @@ namespace game { using namespace world; -void add_decoration(world_t *world, state_t *game, v2f_t x, float noise) +void add_decoration(world_t *world, state_t *game, v2f_t x) { + float noise; deco_t *deco; deco_type_t type; v2f_t center, offset; - if (noise < 0.3) + noise = world->perlin.get(x, 0.53213f) + world->perlin.get(x, 0.12994f); + noise = fabs(noise / 2); + + if (noise < 0.16) return; offset[0] = world->perlin.get(x, 0.17331f); offset[1] = world->perlin.get(x, 0.19571f); center = x + v2f_t(0.5f, 0.5f) + offset.norm() * 0.1; - if (noise > 0.5) { + if (noise > 0.39) { unit_nest_t *nest = new unit_nest_t(game); nest->place(world, center); return; } - if (noise > 0.40) + if (noise > 0.36) type = DECO_EYETHING; - else if (noise > 0.35) + else if (noise > 0.33) type = DECO_STONE; + else if (noise > 0.26) + type = DECO_SPIKE; + else if (noise > 0.20) + type = DECO_SPIKE_SMALL; else type = DECO_STONE_SMALL; @@ -35,10 +43,14 @@ void add_decoration(world_t *world, state_t *game, v2f_t x, float noise) deco->place(world, x); } -void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data) +void worldgen(world_t *world, sector_index_t index, sector_t *sector, + bool gen_tiles, bool gen_decos, void *data) { state_t *game = (game::state_t*)data; + if (!gen_tiles) + goto decos; + for (coord_t ly = 0; ly < SECTOR_SIZE; ly++) for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) { tile_t *tile = sector->tiles + ly * SECTOR_SIZE + lx; @@ -46,7 +58,6 @@ void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data index[1] * SECTOR_SIZE + ly); v2f_t x; float waterlevel, height; - float deco_noise; x = v2f_t(index) * SECTOR_SIZE + v2f_t(lx, ly); @@ -67,11 +78,23 @@ void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data tile->type = TILE_STONE; else tile->type = TILE_DIRT; + } - deco_noise = world->perlin.get(x, 0.125559f); +decos: + if (!gen_decos) + return; + + for (coord_t ly = 0; ly < 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); + v2f_t x; + + x = v2f_t(index) * SECTOR_SIZE + v2f_t(lx, ly); if (tile->type == TILE_DIRT) - add_decoration(world, game, x, deco_noise); + add_decoration(world, game, x); } } diff --git a/src/world.cpp b/src/world.cpp index a41b793..7256aee 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -29,17 +29,26 @@ void register_tile(uint8_t type, cflags_t cflags) void world_t::generate(sector_t *sector, sector_index_t index, bool partial) { + 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); - sector->empty = false; - generator(this, index, sector, generator_data); + if (sector->empty) { + if (partial) + gen_tiles = true; + else + gen_tiles = gen_decos = true; + } else + gen_decos = true; - if (partial) - return; + sector->empty = false; + generator(this, index, sector, gen_tiles, gen_decos, generator_data); + // Unused, for now. + /* for (coord_t ly = 0; ly < SECTOR_SIZE; ly++) for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) { tile_t *tile; @@ -58,6 +67,7 @@ void world_t::generate(sector_t *sector, sector_index_t index, bool partial) tile->neighbors |= (1 << i); } } + */ } bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore, -- cgit