]> git.lizzy.rs Git - dragonblocks_alpha.git/blobdiff - src/client/client_node.c
refactoring
[dragonblocks_alpha.git] / src / client / client_node.c
index 18283ebbdc69495cdd9696622741904efd1edd65..970059074e5bf7338a20fbe633d90abff8c0d6d4 100644 (file)
 #include "client/client.h"
 #include "client/client_node.h"
+#include "color.h"
 #include "environment.h"
 #include "node.h"
 #include "perlin.h"
-#include "util.h"
+
 #define TILES_SIMPLE(path) {.paths = {path, NULL, NULL, NULL, NULL, NULL}, .indices = {0, 0, 0, 0, 0, 0}, .textures = {NULL}}
 #define TILES_NONE {.paths = {NULL}, .indices = {0}, .textures = {NULL}}
 
-static f32 hue_to_rgb(f32 p, f32 q, f32 t)
-{
-    if (t < 0.0f)
-        t += 1.0f;
-
-    if (t > 1.0f)
-        t -= 1.0f;
-
-    if (t < 1.0f / 6.0f)
-        return p + (q - p) * 6.0f * t;
-
-    if (t < 1.0f / 2.0f)
-        return q;
-
-    if (t < 2.0f / 3.0f)
-        return p + (q - p) * (2.0f / 3.0f - t) * 6.0f;
-
-    return p;
-}
-
-static Vertex3DColor hsl_to_rgb(v3f32 hsl)
+static void render_grass(NodeArgsRender *args)
 {
-       Vertex3DColor rgb;
-
-    if (hsl.y == 0.0f) {
-               rgb = (Vertex3DColor) {hsl.z, hsl.z, hsl.z};
-    } else {
-        f32 q = hsl.z < 0.5f ? hsl.z * (1.0f + hsl.y) : hsl.z + hsl.y - hsl.z * hsl.y;
-        f32 p = 2.0f * hsl.z - q;
-
-        rgb.r = hue_to_rgb(p, q, hsl.x + 1.0f / 3.0f);
-        rgb.g = hue_to_rgb(p, q, hsl.x);
-        rgb.b = hue_to_rgb(p, q, hsl.x - 1.0f / 3.0f);
-    }
-
-    return rgb;
-}
-
-static void render_grass(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
-{
-       f32 hum_min, hum_max, temp_max;
-       hum_min = 0.13f;
-       hum_max = 0.33f;
-       temp_max = 0.45f;
-
-       f32 temp_f = f64_clamp(0.3f - get_temperature(pos), 0.0f, 0.3f) / 0.3f;
-
-       vertex->color = hsl_to_rgb((v3f32) {(get_humidity(pos) * (hum_max - hum_min) + hum_min) * (1.0f - temp_f) + temp_max * temp_f, 1.0f, 0.5f});
+       args->vertex.color = hsl_to_rgb((v3f32) {f32_mix(
+               // hue values between .13 and .33 depending on humidity
+               f32_mix(
+                       0.13f,
+                       0.33f,
+                       get_humidity(args->pos)
+               ),
+               // move towards .45 while temperature is between .3 and .0
+               0.45f,
+               f32_clamp(
+                       0.3f - get_temperature(args->pos),
+                       0.0f,
+                       0.3f
+               ) / 0.3f
+       ), 1.0f, 0.5f});
 }
 
-static void render_stone(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
+static void render_stone(NodeArgsRender *args)
 {
-       vertex->textureCoordinates.s += noise2d(pos.x, pos.z, 0, seed + SO_TEXTURE_OFFSET_S);
-       vertex->textureCoordinates.t += noise2d(pos.x, pos.z, 0, seed + SO_TEXTURE_OFFSET_T);
+       args->vertex.cube.textureCoordinates.x += noise2d(args->pos.x, args->pos.z, 0, seed + SO_TEXTURE_OFFSET_S);
+       args->vertex.cube.textureCoordinates.y += noise2d(args->pos.x, args->pos.z, 0, seed + SO_TEXTURE_OFFSET_T);
 }
 
-static void render_hsl(unused v3s32 pos, MapNode *node, Vertex3D *vertex, unused int f, unused int v)
+static void render_color(NodeArgsRender *args)
 {
-       vertex->color = hsl_to_rgb(((HSLData *) node->data)->color);
+       args->vertex.color = ((ColorData *) args->node->data)->color;
 }
 
 ClientNodeDefinition client_node_definitions[NODE_UNLOADED] = {
        // unknown
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/unknown.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
                .render = NULL,
        },
        // air
        {
                .tiles = TILES_NONE,
-               .visibility = NV_NONE,
+               .visibility = VISIBILITY_NONE,
                .mipmap = true,
                .render = NULL,
        },
        // grass
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/grass.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
                .render = &render_grass,
        },
        // dirt
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/dirt.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
                .render = NULL,
        },
        // stone
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/stone.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
                .render = &render_stone,
        },
        // snow
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/snow.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
                .render = NULL,
        },
@@ -118,16 +88,16 @@ ClientNodeDefinition client_node_definitions[NODE_UNLOADED] = {
                        .indices = {0, 0, 0, 0, 1, 1},
                        .textures = {NULL},
                },
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
-               .render = &render_hsl,
+               .render = &render_color,
        },
        // oak leaves
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/oak_leaves.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
-               .render = &render_hsl,
+               .render = &render_color,
        },
        // pine wood
        {
@@ -136,16 +106,16 @@ ClientNodeDefinition client_node_definitions[NODE_UNLOADED] = {
                        .indices = {0, 0, 0, 0, 1, 1},
                        .textures = {NULL},
                },
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
-               .render = &render_hsl,
+               .render = &render_color,
        },
        // pine leaves
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/pine_leaves.png"),
-               .visibility = NV_CLIP,
+               .visibility = VISIBILITY_CLIP,
                .mipmap = true,
-               .render = &render_hsl,
+               .render = &render_color,
        },
        // palm wood
        {
@@ -154,42 +124,42 @@ ClientNodeDefinition client_node_definitions[NODE_UNLOADED] = {
                        .indices = {0, 0, 0, 0, 1, 1},
                        .textures = {NULL},
                },
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
-               .render = &render_hsl,
+               .render = &render_color,
        },
        // palm leaves
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/palm_leaves.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
-               .render = &render_hsl,
+               .render = &render_color,
        },
        // sand
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/sand.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
                .render = NULL,
        },
        // water
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/water.png"),
-               .visibility = NV_BLEND,
+               .visibility = VISIBILITY_BLEND,
                .mipmap = true,
                .render = NULL,
        },
        // lava
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/lava.png"),
-               .visibility = NV_BLEND,
+               .visibility = VISIBILITY_BLEND,
                .mipmap = true,
                .render = NULL,
        },
        // vulcano_stone
        {
                .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/vulcano_stone.png"),
-               .visibility = NV_SOLID,
+               .visibility = VISIBILITY_SOLID,
                .mipmap = true,
                .render = NULL,
        },
@@ -197,10 +167,10 @@ ClientNodeDefinition client_node_definitions[NODE_UNLOADED] = {
 
 void client_node_init()
 {
-       for (Node node = NODE_UNKNOWN; node < NODE_UNLOADED; node++) {
+       for (NodeType node = NODE_UNKNOWN; node < NODE_UNLOADED; node++) {
                ClientNodeDefinition *def = &client_node_definitions[node];
 
-               if (def->visibility != NV_NONE) {
+               if (def->visibility != VISIBILITY_NONE) {
                        Texture *textures[6];
 
                        for (int i = 0; i < 6; i++) {