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 void render_grass(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
12 f32 hum_min, hum_max, temp_max;
17 f32 temp_f = clamp(0.3f - get_temperature(pos), 0.0f, 0.3f) / 0.3f;
19 vertex->color.h = (get_humidity(pos) * (hum_max - hum_min) + hum_min) * (1.0f - temp_f) + temp_max * temp_f;
20 vertex->color.s = 1.0f;
21 vertex->color.v = 1.0f;
24 static void render_stone(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
26 vertex->textureCoordinates.s += noise2d(pos.x, pos.z, 0, seed + SO_TEXTURE_OFFSET_S);
27 vertex->textureCoordinates.t += noise2d(pos.x, pos.z, 0, seed + SO_TEXTURE_OFFSET_T);
30 static void render_wood(unused v3s32 pos, unused MapNode *node, Vertex3D *vertex, int f, unused int v)
32 vertex->color.h = f < 4 ? 0.1f : 0.11f;
33 vertex->color.s = 1.0f;
34 vertex->color.v = 1.0f;
37 ClientNodeDefintion client_node_definitions[NODE_UNLOADED] = {
40 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/unknown.png"),
41 .visibility = NV_SOLID,
47 .visibility = NV_NONE,
52 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/grass.png"),
53 .visibility = NV_SOLID,
54 .render = &render_grass,
58 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/dirt.png"),
59 .visibility = NV_SOLID,
64 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/stone.png"),
65 .visibility = NV_SOLID,
66 .render = &render_stone,
70 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/snow.png"),
71 .visibility = NV_SOLID,
77 .paths = {RESSOURCEPATH "textures/wood.png", RESSOURCEPATH "textures/wood_top.png", NULL, NULL, NULL, NULL},
78 .indices = {0, 0, 0, 0, 1, 1},
81 .visibility = NV_SOLID,
82 .render = &render_wood,
86 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/sand.png"),
87 .visibility = NV_SOLID,
92 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/water.png"),
93 .visibility = NV_TRANSPARENT,
98 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/lava.png"),
99 .visibility = NV_TRANSPARENT,
104 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/vulcano_stone.png"),
105 .visibility = NV_SOLID,
110 void client_node_init()
112 for (Node node = NODE_UNKNOWN; node < NODE_UNLOADED; node++) {
113 ClientNodeDefintion *def = &client_node_definitions[node];
115 if (client_node_definitions[node].visibility != NV_NONE) {
116 Texture *textures[6];
118 for (int i = 0; i < 6; i++) {
119 char *path = def->tiles.paths[i];
122 textures[i] = texture_get(path);
127 for (int i = 0; i < 6; i++)
128 def->tiles.textures[i] = textures[def->tiles.indices[i]];