3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
22 #include "irrlichttypes_extrabloated.h"
23 #include "client/tile.h"
36 struct MinimapMapblock;
40 VoxelManipulator m_vmanip;
41 v3s16 m_blockpos = v3s16(-1337, -1337, -1337);
42 v3s16 m_crack_pos_relative = v3s16(-1337, -1337, -1337);
43 bool m_smooth_lighting = false;
47 bool m_use_tangent_vertices;
49 MeshMakeData(Client *client, bool use_shaders, bool use_tangent_vertices = false);
52 Copy block data manually (to allow optimizations by the caller)
54 void fillBlockDataBegin(const v3s16 &blockpos);
55 void fillBlockData(const v3s16 &block_offset, MapNode *data);
58 Copy central data directly from block, and other data from
61 void fill(MapBlock *block);
64 Set up with only a single node at (1,1,1)
66 void fillSingleNode(MapNode *node);
69 Set the (node) position of a crack
71 void setCrack(int crack_level, v3s16 crack_pos);
74 Enable or disable smooth lighting
76 void setSmoothLighting(bool smooth_lighting);
80 Holds a mesh for a mapblock.
82 Besides the SMesh*, this contains information used for animating
83 the vertex positions, colors and texture coordinates of the mesh.
85 - cracks [implemented]
86 - day/night transitions [implemented]
87 - animated flowing liquids [not implemented]
88 - animating vertex positions for e.g. axles [not implemented]
93 // Builds the mesh given
94 MapBlockMesh(MeshMakeData *data, v3s16 camera_offset);
97 // Main animation function, parameters:
98 // faraway: whether the block is far away from the camera (~50 nodes)
99 // time: the global animation time, 0 .. 60 (repeats every minute)
100 // daynight_ratio: 0 .. 1000
101 // crack: -1 .. CRACK_ANIMATION_LENGTH-1 (-1 for off)
102 // Returns true if anything has been changed.
103 bool animate(bool faraway, float time, int crack, u32 daynight_ratio);
105 scene::IMesh *getMesh() { return m_mesh[0]; }
107 scene::IMesh *getMesh(u8 layer) { return m_mesh[layer]; }
109 MinimapMapblock *moveMinimapMapblock()
111 MinimapMapblock *p = m_minimap_mapblock;
112 m_minimap_mapblock = NULL;
116 bool isAnimationForced() const { return m_animation_force_timer == 0; }
118 void decreaseAnimationForceTimer()
120 if (m_animation_force_timer > 0)
121 m_animation_force_timer--;
124 void updateCameraOffset(v3s16 camera_offset);
127 scene::IMesh *m_mesh[MAX_TILE_LAYERS];
128 MinimapMapblock *m_minimap_mapblock;
129 ITextureSource *m_tsrc;
130 IShaderSource *m_shdrsrc;
132 bool m_enable_shaders;
133 bool m_use_tangent_vertices;
136 // Must animate() be called before rendering?
137 bool m_has_animation;
138 int m_animation_force_timer;
140 // Animation info: cracks
141 // Last crack value passed to animate()
143 // Maps mesh and mesh buffer (i.e. material) indices to base texture names
144 std::map<std::pair<u8, u32>, std::string> m_crack_materials;
146 // Animation info: texture animationi
147 // Maps mesh and mesh buffer indices to TileSpecs
148 // Keys are pairs of (mesh index, buffer index in the mesh)
149 std::map<std::pair<u8, u32>, TileLayer> m_animation_tiles;
150 std::map<std::pair<u8, u32>, int> m_animation_frames; // last animation frame
151 std::map<std::pair<u8, u32>, int> m_animation_frame_offsets;
153 // Animation info: day/night transitions
154 // Last daynight_ratio value passed to animate()
155 u32 m_last_daynight_ratio;
156 // For each mesh and mesh buffer, stores pre-baked colors
157 // of sunlit vertices
158 // Keys are pairs of (mesh index, buffer index in the mesh)
159 std::map<std::pair<u8, u32>, std::map<u32, video::SColor>> m_daynight_diffs;
161 // Camera offset info -> do we have to translate the mesh?
162 v3s16 m_camera_offset;
166 * Encodes light of a node.
167 * The result is not the final color, but a
168 * half-baked vertex color.
169 * You have to multiply the resulting color
170 * with the node's color.
172 * \param light the first 8 bits are day light,
173 * the last 8 bits are night light
174 * \param emissive_light amount of light the surface emits,
175 * from 0 to LIGHT_SUN.
177 video::SColor encode_light(u16 light, u8 emissive_light);
179 // Compute light at node
180 u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef);
182 MapNode n, MapNode n2, const v3s16 &face_dir, const NodeDefManager *ndef);
183 u16 getSmoothLightSolid(const v3s16 &p, const v3s16 &face_dir, const v3s16 &corner,
185 u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData *data);
188 * Returns the sunlight's color from the current
191 void get_sunlight_color(video::SColorf *sunlight, u32 daynight_ratio);
194 * Gives the final SColor shown on screen.
196 * \param result output color
197 * \param light first 8 bits are day light, second 8 bits are
200 void final_color_blend(video::SColor *result, u16 light, u32 daynight_ratio);
203 * Gives the final SColor shown on screen.
205 * \param result output color
206 * \param data the half-baked vertex color
207 * \param dayLight color of the sunlight
209 void final_color_blend(video::SColor *result, const video::SColor &data,
210 const video::SColorf &dayLight);
212 // Retrieves the TileSpec of a face of a node
213 // Adds MATERIAL_FLAG_CRACK if the node is cracked
214 // TileSpec should be passed as reference due to the underlying TileFrame and its vector
215 // TileFrame vector copy cost very much to client
216 void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data,
218 void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *data,