X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fvoxel.h;h=58ad39be4a890d7f1fe6fe4ab1db6519dd4a024f;hb=d1df09841d0eac7a88f638676b80ec848522cca5;hp=bed35b57e87a43acc9818995a4a24b91a07c37d9;hpb=6a1670dbc31cc0e44178bbd9ad34ff0d5981a060;p=dragonfireclient.git diff --git a/src/voxel.h b/src/voxel.h index bed35b57e..58ad39be4 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -22,12 +22,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes.h" #include "irr_v3d.h" -#include #include #include "debug.h" +#include "exceptions.h" #include "mapnode.h" #include #include +#include class INodeDefManager; @@ -79,9 +80,9 @@ class VoxelArea Modifying methods */ - void addArea(VoxelArea &a) + void addArea(const VoxelArea &a) { - if(getExtent() == v3s16(0,0,0)) + if (hasEmptyExtent()) { *this = a; return; @@ -93,9 +94,9 @@ class VoxelArea if(a.MaxEdge.Y > MaxEdge.Y) MaxEdge.Y = a.MaxEdge.Y; if(a.MaxEdge.Z > MaxEdge.Z) MaxEdge.Z = a.MaxEdge.Z; } - void addPoint(v3s16 p) + void addPoint(const v3s16 &p) { - if(getExtent() == v3s16(0,0,0)) + if(hasEmptyExtent()) { MinEdge = p; MaxEdge = p; @@ -110,7 +111,7 @@ class VoxelArea } // Pad with d nodes - void pad(v3s16 d) + void pad(const v3s16 &d) { MinEdge -= d; MaxEdge += d; @@ -136,6 +137,15 @@ class VoxelArea { return MaxEdge - MinEdge + v3s16(1,1,1); } + + /* Because MaxEdge and MinEdge are included in the voxel area an empty extent + * is not represented by (0, 0, 0), but instead (-1, -1, -1) + */ + bool hasEmptyExtent() const + { + return MaxEdge - MinEdge == v3s16(-1, -1, -1); + } + s32 getVolume() const { v3s16 e = getExtent(); @@ -145,7 +155,7 @@ class VoxelArea { // No area contains an empty area // NOTE: Algorithms depend on this, so do not change. - if(a.getExtent() == v3s16(0,0,0)) + if(a.hasEmptyExtent()) return false; return( @@ -203,7 +213,7 @@ class VoxelArea return; } - assert(contains(a)); + assert(contains(a)); // pre-condition // Take back area, XY inclusive { @@ -319,10 +329,10 @@ class VoxelArea v3s16 MaxEdge; }; -// Hasn't been copied from source (emerged) -#define VOXELFLAG_NOT_LOADED (1<<0) -// Checked as being inexistent in source -#define VOXELFLAG_INEXISTENT (1<<1) +// unused +#define VOXELFLAG_UNUSED (1<<0) +// no data about that node +#define VOXELFLAG_NO_DATA (1<<1) // Algorithm-dependent #define VOXELFLAG_CHECKED1 (1<<2) // Algorithm-dependent @@ -355,8 +365,8 @@ class VoxelManipulator /*: public NodeContainer*/ } bool isValidPosition(v3s16 p) { - emerge(p); - return !(m_flags[m_area.index(p)] & VOXELFLAG_INEXISTENT); + addArea(p); + return !(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA); }*/ /* @@ -365,9 +375,10 @@ class VoxelManipulator /*: public NodeContainer*/ */ MapNode getNode(v3s16 p) { - emerge(p); + VoxelArea voxel_area(p); + addArea(voxel_area); - if(m_flags[m_area.index(p)] & VOXELFLAG_INEXISTENT) + if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) { /*dstream<<"EXCEPT: VoxelManipulator::getNode(): " <<"p=("<