]> git.lizzy.rs Git - minetest.git/blob - src/content_mapblock.h
Fix liquid bottoms not being rendered
[minetest.git] / src / content_mapblock.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "nodedef.h"
23 #include <IMeshManipulator.h>
24
25 struct MeshMakeData;
26 struct MeshCollector;
27
28 struct LightPair {
29         u8 lightA;
30         u8 lightB;
31
32         LightPair() = default;
33         explicit LightPair(u16 value) : lightA(value & 0xff), lightB(value >> 8) {}
34         LightPair(u8 valueA, u8 valueB) : lightA(valueA), lightB(valueB) {}
35         LightPair(float valueA, float valueB) :
36                 lightA(core::clamp(core::round32(valueA), 0, 255)),
37                 lightB(core::clamp(core::round32(valueB), 0, 255)) {}
38         operator u16() const { return lightA | lightB << 8; }
39 };
40
41 struct LightFrame {
42         f32 lightsA[8];
43         f32 lightsB[8];
44 };
45
46 class MapblockMeshGenerator
47 {
48 public:
49         MeshMakeData *data;
50         MeshCollector *collector;
51
52         INodeDefManager *nodedef;
53         scene::IMeshManipulator *meshmanip;
54
55 // options
56         bool enable_mesh_cache;
57
58 // current node
59         v3s16 blockpos_nodes;
60         v3s16 p;
61         v3f origin;
62         MapNode n;
63         const ContentFeatures *f;
64         LightPair light;
65         LightFrame frame;
66         video::SColor color;
67         TileSpec tile;
68         float scale;
69
70 // lighting
71         void getSmoothLightFrame();
72         LightPair blendLight(const v3f &vertex_pos);
73         video::SColor blendLightColor(const v3f &vertex_pos);
74         video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
75
76         void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY,
77                 u8 reset_flags = 0, bool special = false);
78         void getTile(int index, TileSpec *tile);
79         void getTile(v3s16 direction, TileSpec *tile);
80         void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false);
81
82 // face drawing
83         void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0),
84                 float vertical_tiling = 1.0);
85
86 // cuboid drawing!
87         void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount,
88                 const LightPair *lights , const f32 *txc);
89         void generateCuboidTextureCoords(aabb3f const &box, f32 *coords);
90         void drawAutoLightedCuboid(aabb3f box, const f32 *txc = NULL,
91                 TileSpec *tiles = NULL, int tile_count = 0);
92
93 // liquid-specific
94         bool top_is_same_liquid;
95         bool draw_liquid_bottom;
96         TileSpec tile_liquid;
97         TileSpec tile_liquid_top;
98         content_t c_flowing;
99         content_t c_source;
100         video::SColor color_liquid_top;
101         struct NeighborData {
102                 f32 level;
103                 content_t content;
104                 bool is_same_liquid;
105                 bool top_is_same_liquid;
106         };
107         NeighborData liquid_neighbors[3][3];
108         f32 corner_levels[2][2];
109
110         void prepareLiquidNodeDrawing();
111         void getLiquidNeighborhood();
112         void calculateCornerLevels();
113         f32 getCornerLevel(int i, int k);
114         void drawLiquidSides();
115         void drawLiquidTop();
116         void drawLiquidBottom();
117
118 // raillike-specific
119         // name of the group that enables connecting to raillike nodes of different kind
120         static const std::string raillike_groupname;
121         int raillike_group;
122         bool isSameRail(v3s16 dir);
123
124 // plantlike-specific
125         PlantlikeStyle draw_style;
126         v3f offset;
127         int rotate_degree;
128         bool random_offset_Y;
129         int face_num;
130         float plant_height;
131
132         void drawPlantlikeQuad(float rotation, float quad_offset = 0,
133                 bool offset_top_only = false);
134         void drawPlantlike();
135
136 // firelike-specific
137         void drawFirelikeQuad(float rotation, float opening_angle,
138                 float offset_h, float offset_v = 0.0);
139
140 // drawtypes
141         void drawLiquidNode();
142         void drawGlasslikeNode();
143         void drawGlasslikeFramedNode();
144         void drawAllfacesNode();
145         void drawTorchlikeNode();
146         void drawSignlikeNode();
147         void drawPlantlikeNode();
148         void drawPlantlikeRootedNode();
149         void drawFirelikeNode();
150         void drawFencelikeNode();
151         void drawRaillikeNode();
152         void drawNodeboxNode();
153         void drawMeshNode();
154
155 // common
156         void errorUnknownDrawtype();
157         void drawNode();
158
159 public:
160         MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
161         void generate();
162         void renderSingle(content_t node);
163 };