]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_node.c
832400dfbb38dd3cbfb35918846d7527b77df773
[dragonblocks_alpha.git] / src / client / client_node.c
1 #include "client/client.h"
2 #include "client/client_node.h"
3 #include "environment.h"
4 #include "node.h"
5 #include "perlin.h"
6 #include "util.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}}
9
10 static void render_grass(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
11 {
12         f32 hum_min, hum_max, temp_max;
13         hum_min = 0.13f;
14         hum_max = 0.33f;
15         temp_max = 0.45f;
16
17         f32 temp_f = clamp(0.3f - get_temperature(pos), 0.0f, 0.3f) / 0.3f;
18
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;
22 }
23
24 static void render_stone(v3s32 pos, unused MapNode *node, Vertex3D *vertex, unused int f, unused int v)
25 {
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);
28 }
29
30 static void render_wood(unused v3s32 pos, unused MapNode *node, Vertex3D *vertex, int f, unused int v)
31 {
32         vertex->color.h = f < 4 ? 0.1f : 0.11f;
33         vertex->color.s = 1.0f;
34         vertex->color.v = 1.0f;
35 }
36
37 ClientNodeDefintion client_node_definitions[NODE_UNLOADED] = {
38         // unknown
39         {
40                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/unknown.png"),
41                 .visibility = NV_SOLID,
42                 .render = NULL,
43         },
44         // air
45         {
46                 .tiles = TILES_NONE,
47                 .visibility = NV_NONE,
48                 .render = NULL,
49         },
50         // grass
51         {
52                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/grass.png"),
53                 .visibility = NV_SOLID,
54                 .render = &render_grass,
55         },
56         // dirt
57         {
58                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/dirt.png"),
59                 .visibility = NV_SOLID,
60                 .render = NULL,
61         },
62         // stone
63         {
64                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/stone.png"),
65                 .visibility = NV_SOLID,
66                 .render = &render_stone,
67         },
68         // snow
69         {
70                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/snow.png"),
71                 .visibility = NV_SOLID,
72                 .render = NULL,
73         },
74         // wood
75         {
76                 .tiles = {
77                         .paths = {RESSOURCEPATH "textures/wood.png", RESSOURCEPATH "textures/wood_top.png", NULL, NULL, NULL, NULL},
78                         .indices = {0, 0, 0, 0, 1, 1},
79                         .textures = {NULL},
80                 },
81                 .visibility = NV_SOLID,
82                 .render = &render_wood,
83         },
84         // sand
85         {
86                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/sand.png"),
87                 .visibility = NV_SOLID,
88                 .render = NULL,
89         },
90         // water
91         {
92                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/water.png"),
93                 .visibility = NV_TRANSPARENT,
94                 .render = NULL,
95         },
96         // lava
97         {
98                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/lava.png"),
99                 .visibility = NV_TRANSPARENT,
100                 .render = NULL,
101         },
102         // vulcano_stone
103         {
104                 .tiles = TILES_SIMPLE(RESSOURCEPATH "textures/vulcano_stone.png"),
105                 .visibility = NV_SOLID,
106                 .render = NULL,
107         },
108 };
109
110 void client_node_init()
111 {
112         for (Node node = NODE_UNKNOWN; node < NODE_UNLOADED; node++) {
113                 ClientNodeDefintion *def = &client_node_definitions[node];
114
115                 if (client_node_definitions[node].visibility != NV_NONE) {
116                         Texture *textures[6];
117
118                         for (int i = 0; i < 6; i++) {
119                                 char *path = def->tiles.paths[i];
120
121                                 if (path)
122                                         textures[i] = texture_get(path);
123                                 else
124                                         break;
125                         }
126
127                         for (int i = 0; i < 6; i++)
128                                 def->tiles.textures[i] = textures[def->tiles.indices[i]];
129                 }
130         }
131 }