diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/voxel.cpp | 177 |
1 files changed, 0 insertions, 177 deletions
diff --git a/src/voxel.cpp b/src/voxel.cpp index 15624feed..b85ba8666 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -770,183 +770,6 @@ find_again: return true; } -bool VoxelManipulator::flowWater(v3s16 removed_pos, - core::map<v3s16, u8> &active_nodes, - int recursion_depth, bool debugprint, - int *counter, int counterlimit) -{ - v3s16 dirs[6] = { - v3s16(0,1,0), // top - v3s16(-1,0,0), // left - v3s16(1,0,0), // right - v3s16(0,0,-1), // front - v3s16(0,0,1), // back - v3s16(0,-1,0), // bottom - }; - - recursion_depth++; - - v3s16 p; - - // Randomize horizontal order - static s32 cs = 0; - if(cs < 3) - cs++; - else - cs = 0; - s16 s1 = (cs & 1) ? 1 : -1; - s16 s2 = (cs & 2) ? 1 : -1; - //dstream<<"s1="<<s1<<", s2="<<s2<<std::endl; - - { - TimeTaker timer1("flowWater pre", g_device, &flowwater_pre_time); - - // Load neighboring nodes - emerge(VoxelArea(removed_pos - v3s16(1,1,1), removed_pos + v3s16(1,1,1))); - - // Ignore incorrect removed_pos - { - u8 f = m_flags[m_area.index(removed_pos)]; - // Ignore inexistent or checked node - if(f & (VOXELFLAG_INEXISTENT | VOXELFLAG_CHECKED)) - return false; - MapNode &n = m_data[m_area.index(removed_pos)]; - // Water can move only to air - if(n.d != MATERIAL_AIR) - return false; - } - - s32 i; - for(i=0; i<6; i++) - { - p = removed_pos + v3s16(s1*dirs[i].X, dirs[i].Y, s2*dirs[i].Z); - - u8 f = m_flags[m_area.index(p)]; - // Inexistent or checked nodes can't move - if(f & (VOXELFLAG_INEXISTENT | VOXELFLAG_CHECKED)) - continue; - MapNode &n = m_data[m_area.index(p)]; - // Only liquid nodes can move - if(material_liquid(n.d) == false) - continue; - // If block is at top, select it always - if(i == 0) - { - break; - } - // If block is at bottom, select it if it has enough pressure - if(i == 5) - { - if(n.pressure >= 3) - break; - continue; - } - // Else block is at some side. Select it if it has enough pressure - if(n.pressure >= 2) - { - break; - } - } - - // If there is nothing to move, return - if(i==6) - return false; - - // Switch nodes at p and removed_pos - u8 m = m_data[m_area.index(p)].d; - u8 f = m_flags[m_area.index(p)]; - m_data[m_area.index(p)].d = m_data[m_area.index(removed_pos)].d; - m_flags[m_area.index(p)] = m_flags[m_area.index(removed_pos)]; - m_data[m_area.index(removed_pos)].d = m; - m_flags[m_area.index(removed_pos)] = f; - - // Mark removed_pos checked - m_flags[m_area.index(removed_pos)] |= VOXELFLAG_CHECKED; - // If block was dropped from surface, increase pressure - if(i == 0 && m_data[m_area.index(removed_pos)].pressure == 1) - { - m_data[m_area.index(removed_pos)].pressure = 2; - } - - /*if(debugprint) - { - dstream<<"VoxelManipulator::flowWater(): Moved bubble:"<<std::endl; - print(dstream, VOXELPRINT_WATERPRESSURE); - }*/ - - // Update pressure - VoxelArea a; - a.addPoint(p - v3s16(1,1,1)); - a.addPoint(p + v3s16(1,1,1)); - a.addPoint(removed_pos - v3s16(1,1,1)); - a.addPoint(removed_pos + v3s16(1,1,1)); - updateAreaWaterPressure(a, active_nodes); - - /*if(debugprint) - { - dstream<<"VoxelManipulator::flowWater(): Pressure updated:"<<std::endl; - print(dstream, VOXELPRINT_WATERPRESSURE); - //std::cin.get(); - }*/ - - if(debugprint) - { - dstream<<"VoxelManipulator::flowWater(): step done:"<<std::endl; - print(dstream, VOXELPRINT_WATERPRESSURE); - //std::cin.get(); - } - - }//timer1 - - // Flow water to the newly created empty position - flowWater(p, active_nodes, recursion_depth, - debugprint, counter, counterlimit); - -find_again: - // Try flowing water to empty positions around removed_pos. - // They are checked in reverse order compared to the previous loop. - for(s32 i=5; i>=0; i--) - { - //v3s16 p = removed_pos + dirs[i]; - p = removed_pos + v3s16(s1*dirs[i].X, dirs[i].Y, s2*dirs[i].Z); - - u8 f = m_flags[m_area.index(p)]; - // Water can't move to inexistent nodes - if(f & VOXELFLAG_INEXISTENT) - continue; - MapNode &n = m_data[m_area.index(p)]; - // Water can only move to air - if(n.d != MATERIAL_AIR) - continue; - - // Flow water to node - bool moved = - flowWater(p, active_nodes, recursion_depth, - debugprint, counter, counterlimit); - - if(moved) - { - // Search again from all neighbors - goto find_again; - } - } - - if(counter != NULL) - { - (*counter)++; - if((*counter) % 10 == 0) - dstream<<"flowWater(): moved "<<(*counter)<<" nodes" - <<std::endl; - - if(counterlimit != -1 && (*counter) > counterlimit) - { - dstream<<"Counter limit reached; returning"<<std::endl; - throw ProcessingLimitException("flowWater counterlimit reached"); - } - } - - return true; -} void VoxelManipulator::flowWater( core::map<v3s16, u8> &active_nodes, |