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