]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_mapblock.h
C++ modernize: Pragma once (#6264)
[dragonfireclient.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 LightFrame
29 {
30         f32 lightsA[8];
31         f32 lightsB[8];
32 };
33
34 class MapblockMeshGenerator
35 {
36 public:
37         MeshMakeData *data;
38         MeshCollector *collector;
39
40         INodeDefManager *nodedef;
41         scene::IMeshManipulator *meshmanip;
42
43 // options
44         bool enable_mesh_cache;
45
46 // current node
47         v3s16 blockpos_nodes;
48         v3s16 p;
49         v3f origin;
50         MapNode n;
51         const ContentFeatures *f;
52         u16 light;
53         LightFrame frame;
54         video::SColor color;
55         TileSpec tile;
56         float scale;
57
58 // lighting
59         void getSmoothLightFrame();
60         u16 blendLight(const v3f &vertex_pos);
61         video::SColor blendLightColor(const v3f &vertex_pos);
62         video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
63
64         void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY,
65                 u8 reset_flags = 0, bool special = false);
66         void getTile(v3s16 direction, TileSpec *tile);
67         void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false);
68
69 // face drawing
70         void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0),
71                 float vertical_tiling = 1.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         float plant_height;
116
117         void drawPlantlikeQuad(float rotation, float quad_offset = 0,
118                 bool offset_top_only = false);
119         void drawPlantlike();
120
121 // firelike-specific
122         void drawFirelikeQuad(float rotation, float opening_angle,
123                 float offset_h, float offset_v = 0.0);
124
125 // drawtypes
126         void drawLiquidNode();
127         void drawGlasslikeNode();
128         void drawGlasslikeFramedNode();
129         void drawAllfacesNode();
130         void drawTorchlikeNode();
131         void drawSignlikeNode();
132         void drawPlantlikeNode();
133         void drawPlantlikeRootedNode();
134         void drawFirelikeNode();
135         void drawFencelikeNode();
136         void drawRaillikeNode();
137         void drawNodeboxNode();
138         void drawMeshNode();
139
140 // common
141         void errorUnknownDrawtype();
142         void drawNode();
143
144 public:
145         MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
146         void generate();
147 };