From 4a229dc6e067cc840a32bcff361532755fccac19 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Sun, 2 Feb 2014 20:19:13 -0500 Subject: [PATCH] experimenting --- src/main.c | 2 +- src/world.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index a0b622861..ad0e38a7e 100644 --- a/src/main.c +++ b/src/main.c @@ -2416,7 +2416,7 @@ void handle_movement(double dt) { if (!g->typing) { float m = dt * 1.0; g->ortho = glfwGetKey(g->window, CRAFT_KEY_ORTHO) ? 64 : 0; - g->fov = glfwGetKey(g->window, CRAFT_KEY_ZOOM) ? 15 : 65; + g->fov = glfwGetKey(g->window, CRAFT_KEY_ZOOM) ? 15 : 60; if (glfwGetKey(g->window, CRAFT_KEY_FORWARD)) sz--; if (glfwGetKey(g->window, CRAFT_KEY_BACKWARD)) sz++; if (glfwGetKey(g->window, CRAFT_KEY_LEFT)) sx--; diff --git a/src/world.c b/src/world.c index 8ca739821..415aa8ba9 100644 --- a/src/world.c +++ b/src/world.c @@ -2,7 +2,7 @@ #include "noise.h" #include "world.h" -void create_world(int p, int q, world_func func, void *arg) { +void create_world1(int p, int q, world_func func, void *arg) { int pad = 1; for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) { for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) { @@ -75,3 +75,112 @@ void create_world(int p, int q, world_func func, void *arg) { } } } + +void biome0(int x, int z, int flag, world_func func, void *arg) { + float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2); + float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2); + int mh = g * 32 + 16; + int h = f * mh; + int w = 1; + int t = 12; + if (h <= t) { + h = t; + w = 2; + } + // sand and grass terrain + for (int y = 0; y < h; y++) { + func(x, y, z, w * flag, arg); + } + if (w == 1) { + if (SHOW_PLANTS) { + // grass + if (simplex2(-x * 0.1, z * 0.1, 4, 0.8, 2) > 0.6) { + func(x, h, z, 17 * flag, arg); + } + // flowers + if (simplex2(x * 0.05, -z * 0.05, 4, 0.8, 2) > 0.7) { + int w = 18 + simplex2(x * 0.1, z * 0.1, 4, 0.8, 2) * 7; + func(x, h, z, w * flag, arg); + } + } + // trees + int ok = 0;//SHOW_TREES; + // if (dx - 4 < 0 || dz - 4 < 0 || + // dx + 4 >= CHUNK_SIZE || dz + 4 >= CHUNK_SIZE) + // { + // ok = 0; + // } + if (ok && simplex2(x, z, 6, 0.5, 2) > 0.84) { + for (int y = h + 3; y < h + 8; y++) { + for (int ox = -3; ox <= 3; ox++) { + for (int oz = -3; oz <= 3; oz++) { + int d = (ox * ox) + (oz * oz) + + (y - (h + 4)) * (y - (h + 4)); + if (d < 11) { + func(x + ox, y, z + oz, 15, arg); + } + } + } + } + for (int y = h; y < h + 7; y++) { + func(x, y, z, 5, arg); + } + } + } + // clouds + if (SHOW_CLOUDS) { + for (int y = 64; y < 72; y++) { + if (simplex3( + x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75) + { + func(x, y, z, 16 * flag, arg); + } + } + } +} + +void biome1(int x, int z, int flag, world_func func, void *arg) { + int lo = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2) * 8 + 8; + int hi = simplex2(-x * 0.01, -z * 0.01, 4, 0.5, 2) * 32 + 32; + int lookup[] = {3, 6, 11, 12, 13}; + for (int y = 0; y < lo; y++) { + func(x, y, z, 6 * flag, arg); + } + for (int y = lo; y < hi; y++) { + int i = simplex3(-x * 0.01, -y * 0.01, -z * 0.01, 4, 0.5, 2) * 10; + int w = lookup[i % 5]; + if (simplex3(x * 0.01, y * 0.01, z * 0.01, 4, 0.5, 2) > 0.5) { + func(x, y, z, w * flag, arg); + } + } + if (SHOW_CLOUDS) { + for (int y = 64; y < 72; y++) { + if (simplex3( + x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75) + { + func(x, y, z, 16 * flag, arg); + } + } + } +} + +void create_world2(int p, int q, world_func func, void *arg) { + int pad = 1; + for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) { + for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) { + int flag = 1; + if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) { + flag = -1; + } + int x = p * CHUNK_SIZE + dx; + int z = q * CHUNK_SIZE + dz; + int i = simplex2(-x * 0.001, -z * 0.001, 8, 0.5, 2) * 2; + if (i == 0) biome0(x, z, flag, func, arg); + else biome1(x, z, flag, func, arg); + } + } +} + +void create_world(int p, int q, world_func func, void *arg) { + create_world2(p, q, func, arg); +}