[CSM] Don't Load the package library (#6944)
[oweals/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         TileSpec tile_liquid;
96         TileSpec tile_liquid_top;
97         content_t c_flowing;
98         content_t c_source;
99         video::SColor color_liquid_top;
100         struct NeighborData {
101                 f32 level;
102                 content_t content;
103                 bool is_same_liquid;
104                 bool top_is_same_liquid;
105         };
106         NeighborData liquid_neighbors[3][3];
107         f32 corner_levels[2][2];
108
109         void prepareLiquidNodeDrawing();
110         void getLiquidNeighborhood();
111         void calculateCornerLevels();
112         f32 getCornerLevel(int i, int k);
113         void drawLiquidSides();
114         void drawLiquidTop();
115
116 // raillike-specific
117         // name of the group that enables connecting to raillike nodes of different kind
118         static const std::string raillike_groupname;
119         int raillike_group;
120         bool isSameRail(v3s16 dir);
121
122 // plantlike-specific
123         PlantlikeStyle draw_style;
124         v3f offset;
125         int rotate_degree;
126         bool random_offset_Y;
127         int face_num;
128         float plant_height;
129
130         void drawPlantlikeQuad(float rotation, float quad_offset = 0,
131                 bool offset_top_only = false);
132         void drawPlantlike();
133
134 // firelike-specific
135         void drawFirelikeQuad(float rotation, float opening_angle,
136                 float offset_h, float offset_v = 0.0);
137
138 // drawtypes
139         void drawLiquidNode();
140         void drawGlasslikeNode();
141         void drawGlasslikeFramedNode();
142         void drawAllfacesNode();
143         void drawTorchlikeNode();
144         void drawSignlikeNode();
145         void drawPlantlikeNode();
146         void drawPlantlikeRootedNode();
147         void drawFirelikeNode();
148         void drawFencelikeNode();
149         void drawRaillikeNode();
150         void drawNodeboxNode();
151         void drawMeshNode();
152
153 // common
154         void errorUnknownDrawtype();
155         void drawNode();
156
157 public:
158         MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
159         void generate();
160         void renderSingle(content_t node);
161 };