X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fvoxel.cpp;h=1299a5296da9c5eef0d25e243b6f2ca721f5e052;hb=7289d61e99625b46eb2c4d6b90a2a5de42f207e6;hp=19f2deb3279445e51d7e3b3ab95f77761c6c6f28;hpb=8ad83767cfccc2d1a42bdc4af087ec013d7554a0;p=minetest.git diff --git a/src/voxel.cpp b/src/voxel.cpp index 19f2deb32..1299a5296 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -46,21 +46,15 @@ VoxelManipulator::VoxelManipulator(): VoxelManipulator::~VoxelManipulator() { clear(); - if(m_data) - delete[] m_data; - if(m_flags) - delete[] m_flags; } void VoxelManipulator::clear() { // Reset area to volume=0 m_area = VoxelArea(); - if(m_data) - delete[] m_data; + delete[] m_data; m_data = NULL; - if(m_flags) - delete[] m_flags; + delete[] m_flags; m_flags = NULL; } @@ -142,7 +136,7 @@ void VoxelManipulator::print(std::ostream &o, INodeDefManager *ndef, } } -void VoxelManipulator::addArea(VoxelArea area) +void VoxelManipulator::addArea(const VoxelArea &area) { // Cancel if requested area has zero volume if(area.getExtent() == v3s16(0,0,0)) @@ -180,7 +174,9 @@ void VoxelManipulator::addArea(VoxelArea area) dstream<|'''''' dest mod '''''''' + * dest <---------------------------------------------> + * + * dest_mod (it's essentially a modulus) is added to the destination index + * after every full iteration of the y span. + * + * This method falls under the category "linear array and incrementing + * index". + */ + + s32 src_step = src_area.getExtent().X; + s32 dest_step = m_area.getExtent().X; + s32 dest_mod = m_area.index(to_pos.X, to_pos.Y, to_pos.Z + 1) + - m_area.index(to_pos.X, to_pos.Y, to_pos.Z) + - dest_step * size.Y; + + s32 i_src = src_area.index(from_pos.X, from_pos.Y, from_pos.Z); + s32 i_local = m_area.index(to_pos.X, to_pos.Y, to_pos.Z); + + for (s16 z = 0; z < size.Z; z++) { + for (s16 y = 0; y < size.Y; y++) { + memcpy(&m_data[i_local], &src[i_src], size.X * sizeof(*m_data)); + memset(&m_flags[i_local], 0, size.X); + i_src += src_step; + i_local += dest_step; + } + i_local += dest_mod; } } @@ -310,7 +339,8 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, v3s16(-1,0,0), // left }; - addArea(VoxelArea(p - v3s16(1,1,1), p + v3s16(1,1,1))); + VoxelArea voxel_area(p - v3s16(1,1,1), p + v3s16(1,1,1)); + addArea(voxel_area); // Loop through 6 neighbors for(u16 i=0; i<6; i++) @@ -384,7 +414,7 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, std::map & from_nodes, std::set & light_sources, INodeDefManager *nodemgr) { - if(from_nodes.size() == 0) + if(from_nodes.empty()) return; for(std::map::iterator j = from_nodes.begin(); @@ -515,7 +545,8 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p, v3s16(-1,0,0), // left }; - addArea(VoxelArea(p - v3s16(1,1,1), p + v3s16(1,1,1))); + VoxelArea voxel_area(p - v3s16(1,1,1), p + v3s16(1,1,1)); + addArea(voxel_area); u32 i = m_area.index(p); @@ -609,7 +640,7 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16(-1,0,0), // left }; - if(from_nodes.size() == 0) + if(from_nodes.empty()) return; std::set lighted_nodes; @@ -619,7 +650,8 @@ void VoxelManipulator::spreadLight(enum LightBank bank, { v3s16 pos = *j; - addArea(VoxelArea(pos - v3s16(1,1,1), pos + v3s16(1,1,1))); + VoxelArea voxel_area(pos - v3s16(1,1,1), pos + v3s16(1,1,1)); + addArea(voxel_area); u32 i = m_area.index(pos); @@ -681,7 +713,7 @@ void VoxelManipulator::spreadLight(enum LightBank bank, <<" for "< 0) + if(!lighted_nodes.empty()) spreadLight(bank, lighted_nodes, nodemgr); } #endif