summaryrefslogtreecommitdiff
path: root/src/game/worldgen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/worldgen.cpp')
-rw-r--r--src/game/worldgen.cpp78
1 files changed, 58 insertions, 20 deletions
diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp
index 62c8a5e..74a07c7 100644
--- a/src/game/worldgen.cpp
+++ b/src/game/worldgen.cpp
@@ -2,28 +2,66 @@
namespace game {
-void worldgen(world::tile_t *tile, world::tile_index_t x,
- procgen::perlin_noise_t *perlin)
+using namespace world;
+
+void add_decoration(world_t *world, state_t *game, v2f_t x, float noise)
{
- 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_WATER;
- else if (height < waterlevel + 0.1)
- tile->type = TILE_DIRT;
- else if (perlin->get(x, 3.0f) > 0.0f)
- tile->type = TILE_STONE;
+ deco_t *deco;
+ deco_type_t type;
+
+ if (noise < 0.3)
+ return;
+
+ if (noise > 0.45)
+ type = DECO_EYETHING;
+ else if (noise > 0.35)
+ type = DECO_STONE;
else
- tile->type = TILE_DIRT;
+ type = DECO_STONE_SMALL;
+
+ deco = new deco_t(game, type);
+ deco->spawn(world, x);
+ deco->phase_shift = noise * 500.0;
+}
+
+void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data)
+{
+ state_t *game = (game::state_t*)data;
+
+ 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;
+ float waterlevel, height;
+ float deco_noise;
+
+ x = v2f_t(index) * SECTOR_SIZE + v2f_t(lx, ly);
+
+ waterlevel = world->perlin.get(x, 1000.0f) * 0.3f +
+ world->perlin.get(x, 500.0f) * 0.1f;
+
+ height = world->perlin.get(x, 40.0f) * 0.6f +
+ world->perlin.get(x, 20.0f) * 0.25f +
+ world->perlin.get(x, 10.0f) * 0.2f +
+ world->perlin.get(x, 4.0f) * 0.1f +
+ world->perlin.get(x, 1.0f) * 0.05f;
+
+ if (height < waterlevel)
+ tile->type = TILE_WATER;
+ else if (height < waterlevel + 0.1)
+ tile->type = TILE_DIRT;
+ else if (world->perlin.get(x, 3.0f) > 0.0f)
+ tile->type = TILE_STONE;
+ else
+ tile->type = TILE_DIRT;
+
+ deco_noise = world->perlin.get(x, 0.125559f);
+
+ if (tile->type == TILE_DIRT)
+ add_decoration(world, game, x, deco_noise);
+ }
}
}