diff options
author | sapier <Sapier at GMX dot net> | 2014-06-07 02:52:58 +0200 |
---|---|---|
committer | sapier <Sapier at GMX dot net> | 2014-06-23 00:13:41 +0200 |
commit | 56bf867874bda0a5fc4d34415984241a52083b3b (patch) | |
tree | 508533262260bfa530654796e5a91be0d17808f3 | |
parent | 496cb115b11fcf55b70abbf2c527f65ddf42cc75 (diff) | |
download | minetest-56bf867874bda0a5fc4d34415984241a52083b3b.tar.gz minetest-56bf867874bda0a5fc4d34415984241a52083b3b.tar.bz2 minetest-56bf867874bda0a5fc4d34415984241a52083b3b.zip |
Use memset for flag initialization (compiler optimization is way better)
use temp variables instead of recalculating array index
-rw-r--r-- | src/voxel.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/voxel.cpp b/src/voxel.cpp index 4b523b596..0d8b55163 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -183,11 +183,10 @@ void VoxelManipulator::addArea(VoxelArea area) // Allocate and clear new data MapNode *new_data = new MapNode[new_size]; + assert(new_data); u8 *new_flags = new u8[new_size]; - for(s32 i=0; i<new_size; i++) - { - new_flags[i] = VOXELFLAG_NOT_LOADED; - } + assert(new_flags); + memset(new_flags, VOXELFLAG_NOT_LOADED, new_size); // Copy old data @@ -195,11 +194,13 @@ void VoxelManipulator::addArea(VoxelArea area) for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++) for(s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++) { + unsigned int old_index = m_area.index(x,y,z); // If loaded, copy data and flags - if((m_flags[m_area.index(x,y,z)] & VOXELFLAG_NOT_LOADED) == false) + if((m_flags[old_index] & VOXELFLAG_NOT_LOADED) == false) { - new_data[new_area.index(x,y,z)] = m_data[m_area.index(x,y,z)]; - new_flags[new_area.index(x,y,z)] = m_flags[m_area.index(x,y,z)]; + unsigned int new_index = new_area.index(x,y,z); + new_data[new_index] = m_data[old_index]; + new_flags[new_index] = m_flags[old_index]; } } |