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.
20 #ifndef VOXELALGORITHMS_HEADER
21 #define VOXELALGORITHMS_HEADER
25 #include "util/container.h"
35 // TODO: Move unspreadLight and spreadLight from VoxelManipulator to here
37 void setLight(VoxelManipulator &v, VoxelArea a, u8 light,
38 INodeDefManager *ndef);
40 void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
41 enum LightBank bank, INodeDefManager *ndef,
42 std::set<v3s16> & light_sources,
43 std::map<v3s16, u8> & unlight_from);
45 struct SunlightPropagateResult
47 bool bottom_sunlight_valid;
49 SunlightPropagateResult(bool bottom_sunlight_valid_):
50 bottom_sunlight_valid(bottom_sunlight_valid_)
54 SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
55 bool inexistent_top_provides_sunlight,
56 std::set<v3s16> & light_sources,
57 INodeDefManager *ndef);
60 * Updates the lighting on the map.
61 * The result will be correct only if
62 * no nodes were changed except the given ones.
63 * Before calling this procedure make sure that all new nodes on
64 * the map have zero light level!
66 * \param oldnodes contains the MapNodes that were replaced by the new
67 * MapNodes and their positions
68 * \param modified_blocks output, contains all map blocks that
69 * the function modified
71 void update_lighting_nodes(
73 std::vector<std::pair<v3s16, MapNode> > &oldnodes,
74 std::map<v3s16, MapBlock*> &modified_blocks);
77 * Updates borders of the given mapblock.
78 * Only updates if the block was marked with incomplete
79 * lighting and the neighbor is also loaded.
81 * \param block the block to update
82 * \param modified_blocks output, contains all map blocks that
83 * the function modified
85 void update_block_border_lighting(Map *map, MapBlock *block,
86 std::map<v3s16, MapBlock*> &modified_blocks);
89 * Copies back nodes from a voxel manipulator
90 * to the map and updates lighting.
91 * For server use only.
93 * \param modified_blocks output, contains all map blocks that
94 * the function modified
96 void blit_back_with_light(ServerMap *map, MMVManip *vm,
97 std::map<v3s16, MapBlock*> *modified_blocks);
100 * Corrects the light in a map block.
101 * For server use only.
103 * \param block the block to update
105 void repair_block_light(ServerMap *map, MapBlock *block,
106 std::map<v3s16, MapBlock*> *modified_blocks);
109 * This class iterates trough voxels that intersect with
110 * a line. The collision detection does not see nodeboxes,
111 * every voxel is a cube and is returned.
112 * This iterator steps to all nodes exactly once.
114 struct VoxelLineIterator
117 //! Starting position of the line in world coordinates.
118 v3f m_start_position;
119 //! Direction and length of the line in world coordinates.
122 * Each component stores the next smallest positive number, by
123 * which multiplying the line's vector gives a vector that ends
124 * on the intersection of two nodes.
126 v3f m_next_intersection_multi = v3f(10000.0f, 10000.0f, 10000.0f);
128 * Each component stores the smallest positive number, by which
129 * m_next_intersection_multi's components can be increased.
131 v3f m_intersection_multi_inc = v3f(10000.0f, 10000.0f, 10000.0f);
133 * Direction of the line. Each component can be -1 or 1 (if a
134 * component of the line's vector is 0, then there will be 1).
136 v3s16 m_step_directions = v3s16(1, 1, 1);
137 //! Position of the current node.
138 v3s16 m_current_node_pos;
139 //! If true, the next node will intersect the line, too.
143 * Creates a voxel line iterator with the given line.
144 * @param start_position starting point of the line
145 * in voxel coordinates
146 * @param line_vector length and direction of the
147 * line in voxel coordinates. start_position+line_vector
148 * is the end of the line
150 VoxelLineIterator(const v3f &start_position,const v3f &line_vector);
153 * Steps to the next voxel.
154 * Updates m_current_node_pos and
155 * m_previous_node_pos.
156 * Note that it works even if hasNext() is false,
157 * continuing the line as a ray.
162 * Returns true if the next voxel intersects the given line.
164 inline bool hasNext() const { return m_has_next; }
167 } // namespace voxalgo