summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2023-10-14 00:28:58 -0500
committercitrons <citrons@mondecitronne.com>2023-10-14 00:28:58 -0500
commitb7f85312f7e45d28dcd92efa8dd1a35149d9b3c9 (patch)
treece2087746f1436bdbaca2b3b40b83577e1f22013
parent0928b5cbbde02d4a6c58ca940040ae4a1c2ac2e4 (diff)
refactor world generation
-rw-r--r--generator.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/generator.c b/generator.c
index a52f9c2..e708856 100644
--- a/generator.c
+++ b/generator.c
@@ -32,23 +32,16 @@ void generate_chunk(world *w, chunk *c) {
SDL_memset(c->tiles, TILE_EMPTY, sizeof(c->tiles));
if (c->pos.y < 0) return;
- static float noise_params[CHUNK_DIM * CHUNK_DIM];
-
- for (int i = 0; i < CHUNK_DIM * CHUNK_DIM; i++) {
- float radius = SDL_pow(rand_float(), SPARSITY);
- if (rand_int() % 4 == 0) radius = -radius;
- radius *= (radius > 0) ? FULLNESS : CAVERNITY;
- if (c->pos.y == 0) {
- int y = i / CHUNK_DIM;
- if (y < 96) radius = 0;
- else if (radius > 0) radius *= 1.8;
- }
- noise_params[i] = radius;
- }
-
for (int y = 0; y < CHUNK_DIM; y++) {
for (int x = 0; x < CHUNK_DIM; x++) {
- float radius = noise_params[tile_index((SDL_Point) {x, y})];
+ float radius = SDL_pow(rand_float(), SPARSITY);
+ if (rand_int() % 4 == 0) radius = -radius;
+ radius *= (radius > 0) ? FULLNESS : CAVERNITY;
+ if (c->pos.y == 0) {
+ if (y < 96) radius = 0;
+ else if (radius > 0) radius *= 1.8;
+ }
+
tile t = radius > 0 ? TILE_WALL : TILE_EMPTY;
fill_circle(c->tiles, x, y, SDL_abs(radius), t);
}