]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_node.c
56c646e3757f711cb0ff16d47f32f92bb6f59c00
[dragonblocks_alpha.git] / src / client / client_node.c
1 #include "client/client.h"
2 #include "client/client_node.h"
3 #include "color.h"
4 #include "environment.h"
5 #include "node.h"
6 #include "perlin.h"
7
8 #define TILES_SIMPLE(path) {.paths = {path, NULL, NULL, NULL, NULL, NULL}, .indices = {0, 0, 0, 0, 0, 0}, .textures = {NULL}}
9 #define TILES_NONE {.paths = {NULL}, .indices = {0}, .textures = {NULL}}
10
11 static void render_grass(NodeArgsRender *args)
12 {
13         args->vertex.color = hsl_to_rgb((v3f32) {f32_mix(
14                 // hue values between .13 and .33 depending on humidity
15                 f32_mix(
16                         0.13f,
17                         0.33f,
18                         get_humidity(args->pos)
19                 ),
20                 // move towards .45 while temperature is between .3 and .0
21                 0.45f,
22                 f32_clamp(
23                         0.3f - get_temperature(args->pos),
24                         0.0f,
25                         0.3f
26                 ) / 0.3f
27         ), 1.0f, 0.5f});
28 }
29
30 static void render_stone(NodeArgsRender *args)
31 {
32         args->vertex.cube.textureCoordinates.x += noise2d(args->pos.x, args->pos.z, 0, seed + OFFSET_TEXTURE_OFFSET_S);
33         args->vertex.cube.textureCoordinates.y += noise2d(args->pos.x, args->pos.z, 0, seed + OFFSET_TEXTURE_OFFSET_T);
34 }
35
36 static void render_color(NodeArgsRender *args)
37 {
38         args->vertex.color = ((ColorData *) args->node->data)->color;
39 }
40
41 ClientNodeDef client_node_defs[NODE_UNLOADED] = {
42         // unknown
43         {
44                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/unknown.png"),
45                 .visibility = VISIBILITY_SOLID,
46                 .mipmap = true,
47                 .render = NULL,
48                 .pointable = true,
49                 .selection_color = {1.0f, 1.0f, 1.0f},
50                 .name = "Unknown",
51         },
52         // air
53         {
54                 .tiles = TILES_NONE,
55                 .visibility = VISIBILITY_NONE,
56                 .mipmap = true,
57                 .render = NULL,
58                 .pointable = false,
59                 .selection_color = {1.0f, 1.0f, 1.0f},
60                 .name = "Air",
61         },
62         // grass
63         {
64                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/grass.png"),
65                 .visibility = VISIBILITY_SOLID,
66                 .mipmap = true,
67                 .render = &render_grass,
68                 .pointable = true,
69                 .selection_color = {1.0f, 1.0f, 1.0f},
70                 .name = "Grass",
71         },
72         // dirt
73         {
74                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/dirt.png"),
75                 .visibility = VISIBILITY_SOLID,
76                 .mipmap = true,
77                 .render = NULL,
78                 .pointable = true,
79                 .selection_color = {1.0f, 1.0f, 1.0f},
80                 .name = "Dirt",
81         },
82         // stone
83         {
84                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/stone.png"),
85                 .visibility = VISIBILITY_SOLID,
86                 .mipmap = true,
87                 .render = &render_stone,
88                 .pointable = true,
89                 .selection_color = {1.0f, 1.0f, 1.0f},
90                 .name = "Stone",
91         },
92         // snow
93         {
94                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/snow.png"),
95                 .visibility = VISIBILITY_SOLID,
96                 .mipmap = true,
97                 .render = NULL,
98                 .pointable = true,
99                 .selection_color = {0.1f, 0.5f, 1.0f},
100                 .name = "Snow",
101         },
102         // oak wood
103         {
104                 .tiles = {
105                         .paths = {RESSOURCE_PATH "textures/oak_wood.png", RESSOURCE_PATH "textures/oak_wood_top.png", NULL, NULL, NULL, NULL},
106                         .indices = {0, 0, 0, 0, 1, 1},
107                         .textures = {NULL},
108                 },
109                 .visibility = VISIBILITY_SOLID,
110                 .mipmap = true,
111                 .render = &render_color,
112                 .pointable = true,
113                 .selection_color = {1.0f, 1.0f, 1.0f},
114                 .name = "Oak Wood",
115         },
116         // oak leaves
117         {
118                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/oak_leaves.png"),
119                 .visibility = VISIBILITY_SOLID,
120                 .mipmap = true,
121                 .render = &render_color,
122                 .pointable = true,
123                 .selection_color = {1.0f, 1.0f, 1.0f},
124                 .name = "Oak Leaves",
125         },
126         // pine wood
127         {
128                 .tiles = {
129                         .paths = {RESSOURCE_PATH "textures/pine_wood.png", RESSOURCE_PATH "textures/pine_wood_top.png", NULL, NULL, NULL, NULL},
130                         .indices = {0, 0, 0, 0, 1, 1},
131                         .textures = {NULL},
132                 },
133                 .visibility = VISIBILITY_SOLID,
134                 .mipmap = true,
135                 .render = &render_color,
136                 .pointable = true,
137                 .selection_color = {1.0f, 1.0f, 1.0f},
138                 .name = "Pine Wood",
139         },
140         // pine leaves
141         {
142                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/pine_leaves.png"),
143                 .visibility = VISIBILITY_CLIP,
144                 .mipmap = true,
145                 .render = &render_color,
146                 .pointable = true,
147                 .selection_color = {1.0f, 1.0f, 1.0f},
148                 .name = "Pine Leaves",
149         },
150         // palm wood
151         {
152                 .tiles = {
153                         .paths = {RESSOURCE_PATH "textures/palm_wood.png", RESSOURCE_PATH "textures/palm_wood_top.png", NULL, NULL, NULL, NULL},
154                         .indices = {0, 0, 0, 0, 1, 1},
155                         .textures = {NULL},
156                 },
157                 .visibility = VISIBILITY_SOLID,
158                 .mipmap = true,
159                 .render = &render_color,
160                 .pointable = true,
161                 .selection_color = {1.0f, 1.0f, 1.0f},
162                 .name = "Palm Wood",
163         },
164         // palm leaves
165         {
166                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/palm_leaves.png"),
167                 .visibility = VISIBILITY_SOLID,
168                 .mipmap = true,
169                 .render = &render_color,
170                 .pointable = true,
171                 .selection_color = {1.0f, 1.0f, 1.0f},
172                 .name = "Palm Leaves",
173         },
174         // sand
175         {
176                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/sand.png"),
177                 .visibility = VISIBILITY_SOLID,
178                 .mipmap = true,
179                 .render = NULL,
180                 .pointable = true,
181                 .selection_color = {1.0f, 1.0f, 1.0f},
182                 .name = "Sand",
183         },
184         // water
185         {
186                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/water.png"),
187                 .visibility = VISIBILITY_BLEND,
188                 .mipmap = true,
189                 .render = NULL,
190                 .pointable = false,
191                 .selection_color = {1.0f, 1.0f, 1.0f},
192                 .name = "Water",
193         },
194         // lava
195         {
196                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/lava.png"),
197                 .visibility = VISIBILITY_BLEND,
198                 .mipmap = true,
199                 .render = NULL,
200                 .pointable = false,
201                 .selection_color = {1.0f, 1.0f, 1.0f},
202                 .name = "Lava",
203         },
204         // vulcano_stone
205         {
206                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/vulcano_stone.png"),
207                 .visibility = VISIBILITY_SOLID,
208                 .mipmap = true,
209                 .render = NULL,
210                 .pointable = true,
211                 .selection_color = {1.0f, 1.0f, 1.0f},
212                 .name = "Vulcano Stone",
213         },
214 };
215
216 void client_node_init()
217 {
218         for (NodeType node = 0; node < NODE_UNLOADED; node++) {
219                 ClientNodeDef *def = &client_node_defs[node];
220
221                 if (def->visibility != VISIBILITY_NONE) {
222                         Texture *textures[6];
223
224                         for (int i = 0; i < 6; i++) {
225                                 char *path = def->tiles.paths[i];
226
227                                 if (path)
228                                         textures[i] = texture_load(path, def->mipmap);
229                                 else
230                                         break;
231                         }
232
233                         for (int i = 0; i < 6; i++)
234                                 def->tiles.textures[i] = textures[def->tiles.indices[i]];
235                 }
236         }
237 }