diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-08-20 13:30:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-20 13:30:50 +0200 |
commit | 1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3 (patch) | |
tree | 03dd0c39e323c7f0b1f06014ff30e74f429bfa01 /src/voxel.cpp | |
parent | 50669cd2822a11570ae462972194eeb2d585a8c1 (diff) | |
download | minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.tar.gz minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.tar.bz2 minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.zip |
Modernize source code: last part (#6285)
* Modernize source code: last par
* Use empty when needed
* Use emplace_back instead of push_back when needed
* For range-based loops
* Initializers fixes
* constructors, destructors default
* c++ C stl includes
Diffstat (limited to 'src/voxel.cpp')
-rw-r--r-- | src/voxel.cpp | 58 |
1 files changed, 10 insertions, 48 deletions
diff --git a/src/voxel.cpp b/src/voxel.cpp index 981bc5823..cd638183c 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -21,8 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "gettime.h" #include "nodedef.h" +#include "util/directiontables.h" #include "util/timetaker.h" -#include <string.h> // memcpy, memset +#include <cstring> // memcpy, memset /* Debug stuff @@ -32,11 +33,6 @@ u64 emerge_time = 0; u64 emerge_load_time = 0; u64 clearflag_time = 0; - -VoxelManipulator::VoxelManipulator() -{ -} - VoxelManipulator::~VoxelManipulator() { clear(); @@ -110,7 +106,7 @@ void VoxelManipulator::print(std::ostream &o, INodeDefManager *ndef, { if(ndef->get(m).light_source != 0) c = 'S'; - else if(ndef->get(m).light_propagates == false) + else if(!ndef->get(m).light_propagates) c = 'X'; else { @@ -322,23 +318,13 @@ void VoxelManipulator::clearFlag(u8 flags) void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, std::set<v3s16> & light_sources, INodeDefManager *nodemgr) { - v3s16 dirs[6] = { - v3s16(0,0,1), // back - v3s16(0,1,0), // top - v3s16(1,0,0), // right - v3s16(0,0,-1), // front - v3s16(0,-1,0), // bottom - v3s16(-1,0,0), // left - }; - 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++) - { + for (const v3s16 &dir : g_6dirs) { // Get the position of the neighbor node - v3s16 n2pos = p + dirs[i]; + v3s16 n2pos = p + dir; u32 n2i = m_area.index(n2pos); @@ -387,15 +373,6 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p, INodeDefManager *nodemgr) { - const v3s16 dirs[6] = { - v3s16(0,0,1), // back - v3s16(0,1,0), // top - v3s16(1,0,0), // right - v3s16(0,0,-1), // front - v3s16(0,-1,0), // bottom - v3s16(-1,0,0), // left - }; - VoxelArea voxel_area(p - v3s16(1,1,1), p + v3s16(1,1,1)); addArea(voxel_area); @@ -410,10 +387,9 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p, u8 newlight = diminish_light(oldlight); // Loop through 6 neighbors - for(u16 i=0; i<6; i++) - { + for (const auto &dir : g_6dirs) { // Get the position of the neighbor node - v3s16 n2pos = p + dirs[i]; + v3s16 n2pos = p + dir; u32 n2i = m_area.index(n2pos); @@ -457,25 +433,12 @@ const MapNode VoxelManipulator::ContentIgnoreNode = MapNode(CONTENT_IGNORE); void VoxelManipulator::spreadLight(enum LightBank bank, std::set<v3s16> & from_nodes, INodeDefManager *nodemgr) { - const v3s16 dirs[6] = { - v3s16(0,0,1), // back - v3s16(0,1,0), // top - v3s16(1,0,0), // right - v3s16(0,0,-1), // front - v3s16(0,-1,0), // bottom - v3s16(-1,0,0), // left - }; - if(from_nodes.empty()) return; std::set<v3s16> lighted_nodes; - for(std::set<v3s16>::iterator j = from_nodes.begin(); - j != from_nodes.end(); ++j) - { - v3s16 pos = *j; - + for (const v3s16 &pos : from_nodes) { VoxelArea voxel_area(pos - v3s16(1,1,1), pos + v3s16(1,1,1)); addArea(voxel_area); @@ -490,10 +453,9 @@ void VoxelManipulator::spreadLight(enum LightBank bank, u8 newlight = diminish_light(oldlight); // Loop through 6 neighbors - for(u16 i=0; i<6; i++) - { + for (const v3s16 &dir : g_6dirs) { // Get the position of the neighbor node - v3s16 n2pos = pos + dirs[i]; + v3s16 n2pos = pos + dir; try { |