LocalPlayer::accelerateHorizontal: cleanups
[oweals/minetest.git] / src / voxelalgorithms.cpp
index 40f8595a752144a7e0ec25f5aa9b52d52ccfaf9a..74c165dd345e928a0065bef0584bd43200b3cb9b 100644 (file)
@@ -1402,16 +1402,13 @@ void repair_block_light(ServerMap *map, MapBlock *block,
                modified_blocks);
 }
 
-VoxelLineIterator::VoxelLineIterator(
-       const v3f &start_position,
-       const v3f &line_vector) :
+VoxelLineIterator::VoxelLineIterator(const v3f &start_position, const v3f &line_vector) :
        m_start_position(start_position),
-       m_line_vector(line_vector),
-       m_next_intersection_multi(10000.0f, 10000.0f, 10000.0f),
-       m_intersection_multi_inc(10000.0f, 10000.0f, 10000.0f),
-       m_step_directions(1.0f, 1.0f, 1.0f)
+       m_line_vector(line_vector)
 {
        m_current_node_pos = floatToInt(m_start_position, 1);
+       m_start_node_pos = m_current_node_pos;
+       m_last_index = getIndex(floatToInt(start_position + line_vector, 1));
 
        if (m_line_vector.X > 0) {
                m_next_intersection_multi.X = (floorf(m_start_position.X - 0.5) + 1.5
@@ -1445,14 +1442,11 @@ VoxelLineIterator::VoxelLineIterator(
                m_intersection_multi_inc.Z = -1 / m_line_vector.Z;
                m_step_directions.Z = -1;
        }
-
-       m_has_next = (m_next_intersection_multi.X <= 1)
-               || (m_next_intersection_multi.Y <= 1)
-               || (m_next_intersection_multi.Z <= 1);
 }
 
 void VoxelLineIterator::next()
 {
+       m_current_index++;
        if ((m_next_intersection_multi.X < m_next_intersection_multi.Y)
                        && (m_next_intersection_multi.X < m_next_intersection_multi.Z)) {
                m_next_intersection_multi.X += m_intersection_multi_inc.X;
@@ -1464,10 +1458,13 @@ void VoxelLineIterator::next()
                m_next_intersection_multi.Z += m_intersection_multi_inc.Z;
                m_current_node_pos.Z += m_step_directions.Z;
        }
+}
 
-       m_has_next = (m_next_intersection_multi.X <= 1)
-                       || (m_next_intersection_multi.Y <= 1)
-                       || (m_next_intersection_multi.Z <= 1);
+s16 VoxelLineIterator::getIndex(v3s16 voxel){
+       return
+               abs(voxel.X - m_start_node_pos.X) +
+               abs(voxel.Y - m_start_node_pos.Y) +
+               abs(voxel.Z - m_start_node_pos.Z);
 }
 
 } // namespace voxalgo