From 47a593b5197393d8f8cdfe18b1aa46b8bc1f3fb6 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 12 Dec 2010 14:33:13 +0200 Subject: starting to separate "material" to "content" and "tile" --- src/voxel.cpp | 199 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 143 insertions(+), 56 deletions(-) (limited to 'src/voxel.cpp') diff --git a/src/voxel.cpp b/src/voxel.cpp index b85ba8666..cdd41a14f 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -335,23 +335,26 @@ int VoxelManipulator::getWaterPressure(v3s16 p, s16 &highest_y, int recur_count) if(p.Y > highest_y) highest_y = p.Y; - recur_count++; - if(recur_count > 30) + /*if(recur_count > 1000) throw ProcessingLimitException - ("getWaterPressure recur_count limit reached"); + ("getWaterPressure recur_count limit reached");*/ + + if(recur_count > 10000) + return -1; + + recur_count++; 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,0,-1), // front + v3s16(1,0,0), // right + v3s16(-1,0,0), // left v3s16(0,-1,0), // bottom }; // Load neighboring nodes - // TODO: A bigger area would be better - emerge(VoxelArea(p - v3s16(1,1,1), p + v3s16(1,1,1))); + emerge(VoxelArea(p - v3s16(1,1,1), p + v3s16(1,1,1)), 1); s32 i; for(i=0; i<6; i++) @@ -367,14 +370,14 @@ int VoxelManipulator::getWaterPressure(v3s16 p, s16 &highest_y, int recur_count) continue; int pr; - - // If at surface - /*if(n.pressure == 1) + + // If at ocean surface + if(n.pressure == 1 && n.d == MATERIAL_OCEAN) { pr = 1; } // Otherwise recurse more - else*/ + else { pr = getWaterPressure(p2, highest_y, recur_count); if(pr == -1) @@ -410,10 +413,21 @@ void VoxelManipulator::spreadWaterPressure(v3s16 p, int pr, core::map &active_nodes, int recur_count) { + //if(recur_count > 10000) + /*throw ProcessingLimitException + ("spreadWaterPressure recur_count limit reached");*/ + if(recur_count > 10) + return; recur_count++; - if(recur_count > 10000) - throw ProcessingLimitException - ("spreadWaterPressure recur_count limit reached"); + + /*dstream<<"spreadWaterPressure: p=(" + < &active_nodes, int recursion_depth, bool debugprint, - int *counter, int counterlimit) + u32 stoptime) { 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(-1,0,0), // left + v3s16(1,0,0), // right v3s16(0,-1,0), // bottom }; recursion_depth++; v3s16 p; + bool from_ocean = false; // Randomize horizontal order static s32 cs = 0; @@ -625,7 +645,7 @@ bool VoxelManipulator::flowWater(v3s16 removed_pos, 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))); + emerge(VoxelArea(removed_pos - v3s16(1,1,1), removed_pos + v3s16(1,1,1)), 4); // Ignore incorrect removed_pos { @@ -660,11 +680,13 @@ bool VoxelManipulator::flowWater(v3s16 removed_pos, // If block is at bottom, select it if it has enough pressure if(i == 5) { + //if(n.pressure >= PRESERVE_WATER_VOLUME ? 3 : 2) if(n.pressure >= 3) break; continue; } // Else block is at some side. Select it if it has enough pressure + //if(n.pressure >= PRESERVE_WATER_VOLUME ? 2 : 1) if(n.pressure >= 2) { break; @@ -675,22 +697,47 @@ bool VoxelManipulator::flowWater(v3s16 removed_pos, if(i==6) return false; - // Switch nodes at p and removed_pos + /* + Move water and bubble + */ + 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)]; + + if(m == MATERIAL_OCEAN) + from_ocean = true; + + // Move air bubble if not taking water from ocean + if(from_ocean == false) + { + 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; } + /* + NOTE: This does not work as-is + if(m == MATERIAL_OCEAN) + { + // If block was raised to surface, increase pressure of + // source node + if(i == 5 && m_data[m_area.index(p)].pressure == 1) + { + m_data[m_area.index(p)].pressure = 2; + } + }*/ + /*if(debugprint) { dstream<<"VoxelManipulator::flowWater(): Moved bubble:"<getTimer()->getRealTime(); + if(timenow >= stoptime || + (stoptime < 0x80000000 && timenow > 0x80000000)) + { + dstream<<"flowWater: stoptime reached"<=0; i--) @@ -745,7 +810,9 @@ find_again: // Flow water to node bool moved = flowWater(p, active_nodes, recursion_depth, - debugprint, counter, counterlimit); + debugprint, stoptime); + /*flowWater(p, active_nodes, recursion_depth, + debugprint, counter, counterlimit);*/ if(moved) { @@ -754,27 +821,13 @@ find_again: } } - if(counter != NULL) - { - (*counter)++; - if((*counter) % 10 == 0) - dstream<<"flowWater(): moved "<<(*counter)<<" nodes" - < counterlimit) - { - dstream<<"Counter limit reached; returning"< &active_nodes, int recursion_depth, bool debugprint, - int counterlimit) + u32 timelimit) { addarea_time = 0; emerge_time = 0; @@ -783,25 +836,53 @@ void VoxelManipulator::flowWater( updateareawaterpressure_time = 0; flowwater_pre_time = 0; + if(active_nodes.size() == 0) + { + dstream<<"flowWater: no active nodes"<::Iterator i = active_nodes.getIterator().getNode(); for(s32 j=0; j::Node *n = i.getNode(); + + // Decrement index if less than 0. + // This keeps us in existing indices always. + if(k > 0) + k--; #endif v3s16 p = n->getKey(); active_nodes.remove(p); flowWater(p, active_nodes, recursion_depth, - debugprint, &counter, counterlimit); + debugprint, stoptime); } } @@ -836,11 +920,14 @@ void VoxelManipulator::flowWater( v3s16 e = m_area.getExtent(); s32 v = m_area.getVolume(); - dstream<<"flowWater (active): moved "<