Cleanup various headers to reduce compilation times (#6255)
[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 #ifndef CONTENT_MAPBLOCK_HEADER
21 #define CONTENT_MAPBLOCK_HEADER
22
23 #include "nodedef.h"
24 #include <IMeshManipulator.h>
25
26 struct MeshMakeData;
27 struct MeshCollector;
28
29 struct LightFrame
30 {
31         f32 lightsA[8];
32         f32 lightsB[8];
33 };
34
35 class MapblockMeshGenerator
36 {
37 public:
38         MeshMakeData *data;
39         MeshCollector *collector;
40
41         INodeDefManager *nodedef;
42         scene::IMeshManipulator *meshmanip;
43
44 // options
45         bool enable_mesh_cache;
46
47 // current node
48         v3s16 blockpos_nodes;
49         v3s16 p;
50         v3f origin;
51         MapNode n;
52         const ContentFeatures *f;
53         u16 light;
54         LightFrame frame;
55         video::SColor color;
56         TileSpec tile;
57         float scale;
58
59 // lighting
60         void getSmoothLightFrame();
61         u16 blendLight(const v3f &vertex_pos);
62         video::SColor blendLightColor(const v3f &vertex_pos);
63         video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
64
65         void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY,
66                 u8 reset_flags = 0, bool special = false);
67         void getTile(v3s16 direction, TileSpec *tile);
68         void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false);
69
70 // face drawing
71         void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0),
72                 float vertical_tiling = 1.0);
73
74 // cuboid drawing!
75         void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount,
76                 const u16 *lights , const f32 *txc);
77         void generateCuboidTextureCoords(aabb3f const &box, f32 *coords);
78         void drawAutoLightedCuboid(aabb3f box, const f32 *txc = NULL,
79                 TileSpec *tiles = NULL, int tile_count = 0);
80
81 // liquid-specific
82         bool top_is_same_liquid;
83         TileSpec tile_liquid;
84         TileSpec tile_liquid_top;
85         content_t c_flowing;
86         content_t c_source;
87         video::SColor color_liquid_top;
88         struct NeighborData {
89                 f32 level;
90                 content_t content;
91                 bool is_same_liquid;
92                 bool top_is_same_liquid;
93         };
94         NeighborData liquid_neighbors[3][3];
95         f32 corner_levels[2][2];
96
97         void prepareLiquidNodeDrawing();
98         void getLiquidNeighborhood();
99         void calculateCornerLevels();
100         f32 getCornerLevel(int i, int k);
101         void drawLiquidSides();
102         void drawLiquidTop();
103
104 // raillike-specific
105         // name of the group that enables connecting to raillike nodes of different kind
106         static const std::string raillike_groupname;
107         int raillike_group;
108         bool isSameRail(v3s16 dir);
109
110 // plantlike-specific
111         PlantlikeStyle draw_style;
112         v3f offset;
113         int rotate_degree;
114         bool random_offset_Y;
115         int face_num;
116         float plant_height;
117
118         void drawPlantlikeQuad(float rotation, float quad_offset = 0,
119                 bool offset_top_only = false);
120         void drawPlantlike();
121
122 // firelike-specific
123         void drawFirelikeQuad(float rotation, float opening_angle,
124                 float offset_h, float offset_v = 0.0);
125
126 // drawtypes
127         void drawLiquidNode();
128         void drawGlasslikeNode();
129         void drawGlasslikeFramedNode();
130         void drawAllfacesNode();
131         void drawTorchlikeNode();
132         void drawSignlikeNode();
133         void drawPlantlikeNode();
134         void drawPlantlikeRootedNode();
135         void drawFirelikeNode();
136         void drawFencelikeNode();
137         void drawRaillikeNode();
138         void drawNodeboxNode();
139         void drawMeshNode();
140
141 // common
142         void errorUnknownDrawtype();
143         void drawNode();
144
145 public:
146         MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
147         void generate();
148 };
149
150 #endif