2 #include "client/client.h"
3 #include "client/client_node.h"
4 #include "common/color.h"
5 #include "common/environment.h"
6 #include "common/node.h"
7 #include "common/perlin.h"
9 #define TILES_SIMPLE(path) {.paths = {path, NULL, NULL, NULL, NULL, NULL}, .indices = {0, 0, 0, 0, 0, 0}, .textures = {NULL}}
10 #define TILES_NONE {.paths = {NULL}, .indices = {0}, .textures = {NULL}}
12 static void render_grass(NodeArgsRender *args)
14 args->vertex.color = hsl_to_rgb((v3f32) {f32_mix(
15 // hue values between .13 and .33 depending on humidity
19 get_humidity(args->pos)
21 // move towards .45 while temperature is between .3 and .0
24 0.3f - get_temperature(args->pos),
31 static void render_stone(NodeArgsRender *args)
33 args->vertex.cube.textureCoordinates.x += noise2d(args->pos.x, args->pos.z, 0, seed + OFFSET_TEXTURE_OFFSET_S);
34 args->vertex.cube.textureCoordinates.y += noise2d(args->pos.x, args->pos.z, 0, seed + OFFSET_TEXTURE_OFFSET_T);
37 static void render_color(NodeArgsRender *args)
39 args->vertex.color = ((ColorData *) args->node->data)->color;
42 ClientNodeDef client_node_def[COUNT_NODE] = {
45 .tiles = TILES_SIMPLE(ASSET_PATH "textures/unknown.png"),
46 .visibility = VISIBILITY_SOLID,
50 .selection_color = {1.0f, 1.0f, 1.0f},
56 .visibility = VISIBILITY_NONE,
60 .selection_color = {1.0f, 1.0f, 1.0f},
65 .tiles = TILES_SIMPLE(ASSET_PATH "textures/grass.png"),
66 .visibility = VISIBILITY_SOLID,
68 .render = &render_grass,
70 .selection_color = {1.0f, 1.0f, 1.0f},
75 .tiles = TILES_SIMPLE(ASSET_PATH "textures/dirt.png"),
76 .visibility = VISIBILITY_SOLID,
80 .selection_color = {1.0f, 1.0f, 1.0f},
85 .tiles = TILES_SIMPLE(ASSET_PATH "textures/stone.png"),
86 .visibility = VISIBILITY_SOLID,
88 .render = &render_stone,
90 .selection_color = {1.0f, 1.0f, 1.0f},
95 .tiles = TILES_SIMPLE(ASSET_PATH "textures/snow.png"),
96 .visibility = VISIBILITY_SOLID,
100 .selection_color = {0.1f, 0.5f, 1.0f},
106 .paths = {ASSET_PATH "textures/oak_wood.png", ASSET_PATH "textures/oak_wood_top.png", NULL, NULL, NULL, NULL},
107 .indices = {0, 0, 0, 0, 1, 1},
110 .visibility = VISIBILITY_SOLID,
112 .render = &render_color,
114 .selection_color = {1.0f, 1.0f, 1.0f},
119 .tiles = TILES_SIMPLE(ASSET_PATH "textures/oak_leaves.png"),
120 .visibility = VISIBILITY_SOLID,
122 .render = &render_color,
124 .selection_color = {1.0f, 1.0f, 1.0f},
125 .name = "Oak Leaves",
130 .paths = {ASSET_PATH "textures/pine_wood.png", ASSET_PATH "textures/pine_wood_top.png", NULL, NULL, NULL, NULL},
131 .indices = {0, 0, 0, 0, 1, 1},
134 .visibility = VISIBILITY_SOLID,
136 .render = &render_color,
138 .selection_color = {1.0f, 1.0f, 1.0f},
143 .tiles = TILES_SIMPLE(ASSET_PATH "textures/pine_leaves.png"),
144 .visibility = VISIBILITY_CLIP,
146 .render = &render_color,
148 .selection_color = {1.0f, 1.0f, 1.0f},
149 .name = "Pine Leaves",
154 .paths = {ASSET_PATH "textures/palm_wood.png", ASSET_PATH "textures/palm_wood_top.png", NULL, NULL, NULL, NULL},
155 .indices = {0, 0, 0, 0, 1, 1},
158 .visibility = VISIBILITY_SOLID,
160 .render = &render_color,
162 .selection_color = {1.0f, 1.0f, 1.0f},
167 .tiles = TILES_SIMPLE(ASSET_PATH "textures/palm_leaves.png"),
168 .visibility = VISIBILITY_SOLID,
170 .render = &render_color,
172 .selection_color = {1.0f, 1.0f, 1.0f},
173 .name = "Palm Leaves",
177 .tiles = TILES_SIMPLE(ASSET_PATH "textures/sand.png"),
178 .visibility = VISIBILITY_SOLID,
182 .selection_color = {1.0f, 1.0f, 1.0f},
187 .tiles = TILES_SIMPLE(ASSET_PATH "textures/water.png"),
188 .visibility = VISIBILITY_BLEND,
192 .selection_color = {1.0f, 1.0f, 1.0f},
197 .tiles = TILES_SIMPLE(ASSET_PATH "textures/lava.png"),
198 .visibility = VISIBILITY_BLEND,
202 .selection_color = {1.0f, 1.0f, 1.0f},
207 .tiles = TILES_SIMPLE(ASSET_PATH "textures/vulcano_stone.png"),
208 .visibility = VISIBILITY_SOLID,
212 .selection_color = {1.0f, 1.0f, 1.0f},
213 .name = "Vulcano Stone",
217 void client_node_init()
219 for (NodeType node = 0; node < COUNT_NODE; node++) {
220 ClientNodeDef *def = &client_node_def[node];
222 if (def->visibility != VISIBILITY_NONE) {
223 Texture *textures[6];
225 for (int i = 0; i < 6; i++) {
226 char *path = def->tiles.paths[i];
229 textures[i] = texture_load(path, def->mipmap);
234 for (int i = 0; i < 6; i++)
235 def->tiles.textures[i] = textures[def->tiles.indices[i]];
240 void client_node_delete(TerrainNode *node)
242 switch (node->type) {
252 void client_node_deserialize(TerrainNode *node, Blob buffer)
254 switch (node->type) {
256 ColorData_read(&buffer, node->data = malloc(sizeof(ColorData)));