]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Add temperature factor that determines snow coverage and partly grass color
authorElias Fleckenstein <eliasfleckenstein@web.de>
Thu, 19 Aug 2021 13:55:28 +0000 (15:55 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Thu, 19 Aug 2021 13:55:28 +0000 (15:55 +0200)
src/biome.c
src/biome.h
src/client/client_node.c
src/client/client_player.c
src/client/client_player.h
src/server/mapgen.c

index 54444fba2ba001dea8504e46946c54c3273444d6..ca84e1516ad442bd152efd00eb3dc2fb27715d14 100644 (file)
@@ -7,3 +7,8 @@ f64 get_wetness(v3s32 pos)
 {
        return smooth2d((((u32) 1 << 31) + pos.x) / 128.0, (((u32) 1 << 31) + pos.z) / 128.0, 0, seed + SO_WETNESS) * 0.5 + 0.5;
 }
+
+f64 get_temperature(v3s32 pos)
+{
+       return smooth2d((((u32) 1 << 31) + pos.x) / 128.0, (((u32) 1 << 31) + pos.z) / 128.0, 0, seed + SO_TEMPERATURE) * 0.5 + 0.5 - (f64) (pos.y - 100) * 0.01;
+}
index 7fe388d59b4713821358eccc34ed195865630d07..f0361aae9ff07d9634c0a485cde54b56946de7e9 100644 (file)
@@ -13,9 +13,11 @@ typedef enum
        SO_WETNESS,
        SO_TEXTURE_OFFSET_S,
        SO_TEXTURE_OFFSET_T,
+       SO_TEMPERATURE,
 } SeedOffset;
 
 f64 get_wetness(v3s32 pos);
+f64 get_temperature(v3s32 pos);
 
 extern int seed;
 
index 434d8b62291b1840bb5ff7324b37ff3109476ca8..9fdec059b7ef1488fbbb1ba8cd1cf6f8169becbe 100644 (file)
@@ -4,13 +4,21 @@
 #include "node.h"
 #include "perlin.h"
 
+static f64 clamp(f64 v, f64 min, f64 max)
+{
+       return v < min ? min : v > max ? max : v;
+}
+
 static void render_state_biome(v3s32 pos, __attribute__((unused)) MapNode *node, Vertex3D *vertex)
 {
-       double min, max;
-       min = 0.15;
-       max = 0.45;
+       f32 wet_min, wet_max, temp_max;
+       wet_min = 0.13f;
+       wet_max = 0.33f;
+       temp_max = 0.45f;
+
+       f32 temp_f = clamp(0.3f - get_temperature(pos), 0.0f, 0.3f) / 0.3f;
 
-       vertex->color.h = get_wetness(pos) * (max - min) + min;
+       vertex->color.h = (get_wetness(pos) * (wet_max - wet_min) + wet_min) * (1.0f - temp_f) + temp_max * temp_f;
        vertex->color.s = 1.0f;
        vertex->color.v = 1.0f;
 }
index 43974a03e013b63ebe17f85a4f8e7caeca64ecda..9ae694b5ef400623fcee7c4468660e89981982ca 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include "biome.h"
 #include "client/camera.h"
 #include "client/client.h"
 #include "client/client_map.h"
@@ -18,10 +19,12 @@ static void update_pos()
        client_player.obj->pos = (v3f32) {client_player.pos.x, client_player.pos.y, client_player.pos.z};
        object_transform(client_player.obj);
 
-       char pos_text[BUFSIZ];
-       sprintf(pos_text, "(%.1f %.1f %.1f)", client_player.pos.x, client_player.pos.y, client_player.pos.z);
+       v3s32 node_pos = {client_player.pos.x, client_player.pos.y, client_player.pos.z};
 
-       hud_change_text(client_player.pos_display, pos_text);
+       char info_text[BUFSIZ];
+       sprintf(info_text, "(%.1f %.1f %.1f) wetness: %.2f temperature: %.2f", client_player.pos.x, client_player.pos.y, client_player.pos.z, get_wetness(node_pos), get_temperature(node_pos));
+
+       hud_change_text(client_player.info_hud, info_text);
 }
 
 // get absolute player bounding box
@@ -87,7 +90,7 @@ void client_player_deinit()
        pthread_rwlock_destroy(&client_player.rwlock);
 }
 
-// create mesh object and hud display
+// create mesh object and info hud
 void client_player_add_to_scene()
 {
        client_player.obj = object_create();
@@ -104,7 +107,7 @@ void client_player_add_to_scene()
                }
        }
 
-       client_player.pos_display = hud_add((HUDElementDefinition) {
+       client_player.info_hud = hud_add((HUDElementDefinition) {
                .type = HUD_TEXT,
                .pos = {-1.0f, -1.0f, 0.0f},
                .offset = {2, 2 + 16 + 2 + 16 + 2},
index 9554a6821c024dba836a31cb53466a97cafaf46c..96725caeedaf2fba90410e1cc08e6dc92e837563 100644 (file)
@@ -16,7 +16,7 @@ extern struct ClientPlayer
        f64 eye_height;                         // eye height above feet
        pthread_rwlock_t rwlock;        // used to protect the above properties
        Object *obj;                            // 3D mesh object (currently always invisible), not thread safe
-       HUDElement *pos_display;        // display position on HUD, not thread safe
+       HUDElement *info_hud;           // display position, temperature and wetness on HUD, not thread safe
 } client_player;
 
 void client_player_init();                             // ClientPlayer singleton constructor
index 9b14b9b17cebfeb2a75d64102cb8c73846646e0c..1bd12c271907492ca0c4a5457d6dbdc9105a5a66 100644 (file)
@@ -47,10 +47,10 @@ void mapgen_generate_block(MapBlock *block, List *changed_blocks)
                                        node = is_mountain ? NODE_STONE : NODE_DIRT;
                                else if (diff < 0)
                                        node = is_mountain ? NODE_STONE : NODE_GRASS;
-                               else if (diff < 1)
-                                       node = (is_mountain && ay > 256) ? NODE_SNOW : NODE_AIR;
+                               else if (diff < 1 && get_temperature((v3s32) {block->pos.x * MAPBLOCK_SIZE + x, block->pos.y * MAPBLOCK_SIZE + y, block->pos.z * MAPBLOCK_SIZE + z}) < 0.0)
+                                       node = NODE_SNOW;
 
-                               if (! is_mountain && diff == 0 && (smooth2d(x + block->pos.x * 16, z + block->pos.z * 16, 0, seed + SO_BOULDER_CENTER) * 0.5 + 0.5) < 0.0001f) {
+                               if (! is_mountain && diff == 0 && (smooth2d(x + block->pos.x * 16, z + block->pos.z * 16, 0, seed + SO_BOULDER_CENTER) * 0.5 + 0.5) < 0.0001) {
                                        for (s8 bx = -1; bx <= 1; bx++) {
                                                for (s8 by = -1; by <= 1; by++) {
                                                        for (s8 bz = -1; bz <= 1; bz++) {