1 #include "client/client.h"
2 #include "client/client_node.h"
3 #include "environment.h"
7 #define TILES_SIMPLE(path) {.paths = {path, NULL, NULL, NULL, NULL, NULL}, .indices = {0, 0, 0, 0, 0, 0}, .textures = {NULL}}
8 #define TILES_NONE {.paths = {NULL}, .indices = {0}, .textures = {NULL}}
10 static f64 clamp(f64 v, f64 min, f64 max)
12 return v < min ? min : v > max ? max : v;
15 static void render_grass(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
17 f32 wet_min, wet_max, temp_max;
22 f32 temp_f = clamp(0.3f - get_temperature(pos), 0.0f, 0.3f) / 0.3f;
24 vertex->color.h = (get_wetness(pos) * (wet_max - wet_min) + wet_min) * (1.0f - temp_f) + temp_max * temp_f;
25 vertex->color.s = 1.0f;
26 vertex->color.v = 1.0f;
29 static void render_stone(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
31 vertex->textureCoordinates.s += smooth2d(U32(pos.x), U32(pos.z), 0, seed + SO_TEXTURE_OFFSET_S);
32 vertex->textureCoordinates.t += smooth2d(U32(pos.x), U32(pos.z), 0, seed + SO_TEXTURE_OFFSET_T);
35 static void render_wood(unused v3s32 pos, unused MapNode *node, Vertex3D *vertex, int f, unused int v)
37 vertex->color.h = f < 4 ? 0.1f : 0.11f;
38 vertex->color.s = 1.0f;
39 vertex->color.v = 1.0f;
42 ClientNodeDefintion client_node_definitions[NODE_UNLOADED] = {
45 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/invalid.png"),
46 .visibility = NV_SOLID,
52 .visibility = NV_NONE,
57 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/grass.png"),
58 .visibility = NV_SOLID,
59 .render = &render_grass,
63 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/dirt.png"),
64 .visibility = NV_SOLID,
69 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/stone.png"),
70 .visibility = NV_SOLID,
71 .render = &render_stone,
75 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/snow.png"),
76 .visibility = NV_SOLID,
82 .paths = {RESSOURCEPATH "textures/wood.png", RESSOURCEPATH "textures/wood_top.png", NULL, NULL, NULL, NULL},
83 .indices = {0, 0, 0, 0, 1, 1},
86 .visibility = NV_SOLID,
87 .render = &render_wood,
91 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/sand.png"),
92 .visibility = NV_SOLID,
97 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/water.png"),
98 .visibility = NV_TRANSPARENT,
103 void client_node_init()
105 for (Node node = NODE_INVALID; node < NODE_UNLOADED; node++) {
106 ClientNodeDefintion *def = &client_node_definitions[node];
108 if (client_node_definitions[node].visibility != NV_NONE) {
109 Texture *textures[6];
111 for (int i = 0; i < 6; i++) {
112 char *path = def->tiles.paths[i];
115 textures[i] = texture_get(path);
120 for (int i = 0; i < 6; i++)
121 def->tiles.textures[i] = textures[def->tiles.indices[i]];