]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_node.c
Add node selection box
[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 ClientNodeDefinition client_node_definitions[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         },
51         // air
52         {
53                 .tiles = TILES_NONE,
54                 .visibility = VISIBILITY_NONE,
55                 .mipmap = true,
56                 .render = NULL,
57                 .pointable = false,
58                 .selection_color = {1.0f, 1.0f, 1.0f},
59         },
60         // grass
61         {
62                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/grass.png"),
63                 .visibility = VISIBILITY_SOLID,
64                 .mipmap = true,
65                 .render = &render_grass,
66                 .pointable = true,
67                 .selection_color = {1.0f, 1.0f, 1.0f},
68         },
69         // dirt
70         {
71                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/dirt.png"),
72                 .visibility = VISIBILITY_SOLID,
73                 .mipmap = true,
74                 .render = NULL,
75                 .pointable = true,
76                 .selection_color = {1.0f, 1.0f, 1.0f},
77         },
78         // stone
79         {
80                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/stone.png"),
81                 .visibility = VISIBILITY_SOLID,
82                 .mipmap = true,
83                 .render = &render_stone,
84                 .pointable = true,
85                 .selection_color = {1.0f, 1.0f, 1.0f},
86         },
87         // snow
88         {
89                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/snow.png"),
90                 .visibility = VISIBILITY_SOLID,
91                 .mipmap = true,
92                 .render = NULL,
93                 .pointable = true,
94                 .selection_color = {0.1f, 0.5f, 1.0f},
95         },
96         // oak wood
97         {
98                 .tiles = {
99                         .paths = {RESSOURCE_PATH "textures/oak_wood.png", RESSOURCE_PATH "textures/oak_wood_top.png", NULL, NULL, NULL, NULL},
100                         .indices = {0, 0, 0, 0, 1, 1},
101                         .textures = {NULL},
102                 },
103                 .visibility = VISIBILITY_SOLID,
104                 .mipmap = true,
105                 .render = &render_color,
106                 .pointable = true,
107                 .selection_color = {1.0f, 1.0f, 1.0f},
108         },
109         // oak leaves
110         {
111                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/oak_leaves.png"),
112                 .visibility = VISIBILITY_SOLID,
113                 .mipmap = true,
114                 .render = &render_color,
115                 .pointable = true,
116                 .selection_color = {1.0f, 1.0f, 1.0f},
117         },
118         // pine wood
119         {
120                 .tiles = {
121                         .paths = {RESSOURCE_PATH "textures/pine_wood.png", RESSOURCE_PATH "textures/pine_wood_top.png", NULL, NULL, NULL, NULL},
122                         .indices = {0, 0, 0, 0, 1, 1},
123                         .textures = {NULL},
124                 },
125                 .visibility = VISIBILITY_SOLID,
126                 .mipmap = true,
127                 .render = &render_color,
128                 .pointable = true,
129                 .selection_color = {1.0f, 1.0f, 1.0f},
130         },
131         // pine leaves
132         {
133                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/pine_leaves.png"),
134                 .visibility = VISIBILITY_CLIP,
135                 .mipmap = true,
136                 .render = &render_color,
137                 .pointable = true,
138                 .selection_color = {1.0f, 1.0f, 1.0f},
139         },
140         // palm wood
141         {
142                 .tiles = {
143                         .paths = {RESSOURCE_PATH "textures/palm_wood.png", RESSOURCE_PATH "textures/palm_wood_top.png", NULL, NULL, NULL, NULL},
144                         .indices = {0, 0, 0, 0, 1, 1},
145                         .textures = {NULL},
146                 },
147                 .visibility = VISIBILITY_SOLID,
148                 .mipmap = true,
149                 .render = &render_color,
150                 .pointable = true,
151                 .selection_color = {1.0f, 1.0f, 1.0f},
152         },
153         // palm leaves
154         {
155                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/palm_leaves.png"),
156                 .visibility = VISIBILITY_SOLID,
157                 .mipmap = true,
158                 .render = &render_color,
159                 .pointable = true,
160                 .selection_color = {1.0f, 1.0f, 1.0f},
161         },
162         // sand
163         {
164                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/sand.png"),
165                 .visibility = VISIBILITY_SOLID,
166                 .mipmap = true,
167                 .render = NULL,
168                 .pointable = true,
169                 .selection_color = {1.0f, 1.0f, 1.0f},
170         },
171         // water
172         {
173                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/water.png"),
174                 .visibility = VISIBILITY_BLEND,
175                 .mipmap = true,
176                 .render = NULL,
177                 .pointable = false,
178                 .selection_color = {1.0f, 1.0f, 1.0f},
179         },
180         // lava
181         {
182                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/lava.png"),
183                 .visibility = VISIBILITY_BLEND,
184                 .mipmap = true,
185                 .render = NULL,
186                 .pointable = false,
187                 .selection_color = {1.0f, 1.0f, 1.0f},
188         },
189         // vulcano_stone
190         {
191                 .tiles = TILES_SIMPLE(RESSOURCE_PATH "textures/vulcano_stone.png"),
192                 .visibility = VISIBILITY_SOLID,
193                 .mipmap = true,
194                 .render = NULL,
195                 .pointable = true,
196                 .selection_color = {1.0f, 1.0f, 1.0f},
197         },
198 };
199
200 void client_node_init()
201 {
202         for (NodeType node = NODE_UNKNOWN; node < NODE_UNLOADED; node++) {
203                 ClientNodeDefinition *def = &client_node_definitions[node];
204
205                 if (def->visibility != VISIBILITY_NONE) {
206                         Texture *textures[6];
207
208                         for (int i = 0; i < 6; i++) {
209                                 char *path = def->tiles.paths[i];
210
211                                 if (path)
212                                         textures[i] = texture_load(path, def->mipmap);
213                                 else
214                                         break;
215                         }
216
217                         for (int i = 0; i < 6; i++)
218                                 def->tiles.textures[i] = textures[def->tiles.indices[i]];
219                 }
220         }
221 }