]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_mapblock.h
Use a settings object for the main settings
[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 #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(bool flowing);
97         void getLiquidNeighborhood(bool flowing);
98         void resetCornerLevels();
99         void calculateCornerLevels();
100         f32 getCornerLevel(int i, int k);
101         void drawLiquidSides(bool flowing);
102         void drawLiquidTop(bool flowing);
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
117         void drawPlantlikeQuad(float rotation, float quad_offset = 0,
118                 bool offset_top_only = false);
119
120 // firelike-specific
121         void drawFirelikeQuad(float rotation, float opening_angle,
122                 float offset_h, float offset_v = 0.0);
123
124 // drawtypes
125         void drawLiquidNode(bool flowing);
126         void drawGlasslikeNode();
127         void drawGlasslikeFramedNode();
128         void drawAllfacesNode();
129         void drawTorchlikeNode();
130         void drawSignlikeNode();
131         void drawPlantlikeNode();
132         void drawFirelikeNode();
133         void drawFencelikeNode();
134         void drawRaillikeNode();
135         void drawNodeboxNode();
136         void drawMeshNode();
137
138 // common
139         void errorUnknownDrawtype();
140         void drawNode();
141
142 public:
143         MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
144         void generate();
145 };
146
147 #endif