Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Optimise functions from CNodeDefManager and VoxelManipulator
CNodeDefManager::get()
VoxelManipulator::addArea()
- Loading branch information
Showing
with
28 additions
and
22 deletions.
-
+3
−2
src/mapblock_mesh.cpp
-
+6
−8
src/nodedef.cpp
-
+7
−4
src/voxel.cpp
-
+12
−8
src/voxel.h
|
@@ -65,8 +65,9 @@ void MeshMakeData::fill(MapBlock *block) |
|
|
|
|
|
// Allocate this block + neighbors |
|
|
m_vmanip.clear(); |
|
|
m_vmanip.addArea(VoxelArea(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE, |
|
|
blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1))); |
|
|
VoxelArea voxel_area(blockpos_nodes - v3s16(1,1,1) * MAP_BLOCKSIZE, |
|
|
blockpos_nodes + v3s16(1,1,1) * MAP_BLOCKSIZE*2-v3s16(1,1,1)); |
|
|
m_vmanip.addArea(voxel_area); |
|
|
|
|
|
{ |
|
|
//TimeTaker timer("copy central block data"); |
|
|
|
@@ -389,8 +389,8 @@ class CNodeDefManager: public IWritableNodeDefManager { |
|
|
virtual ~CNodeDefManager(); |
|
|
void clear(); |
|
|
virtual IWritableNodeDefManager *clone(); |
|
|
virtual const ContentFeatures& get(content_t c) const; |
|
|
virtual const ContentFeatures& get(const MapNode &n) const; |
|
|
inline virtual const ContentFeatures& get(content_t c) const; |
|
|
inline virtual const ContentFeatures& get(const MapNode &n) const; |
|
|
virtual bool getId(const std::string &name, content_t &result) const; |
|
|
virtual content_t getId(const std::string &name) const; |
|
|
virtual void getIds(const std::string &name, std::set<content_t> &result) const; |
|
@@ -530,16 +530,14 @@ IWritableNodeDefManager *CNodeDefManager::clone() |
|
|
} |
|
|
|
|
|
|
|
|
const ContentFeatures& CNodeDefManager::get(content_t c) const |
|
|
inline const ContentFeatures& CNodeDefManager::get(content_t c) const |
|
|
{ |
|
|
if (c < m_content_features.size()) |
|
|
return m_content_features[c]; |
|
|
else |
|
|
return m_content_features[CONTENT_UNKNOWN]; |
|
|
return c < m_content_features.size() |
|
|
? m_content_features[c] : m_content_features[CONTENT_UNKNOWN]; |
|
|
} |
|
|
|
|
|
|
|
|
const ContentFeatures& CNodeDefManager::get(const MapNode &n) const |
|
|
inline const ContentFeatures& CNodeDefManager::get(const MapNode &n) const |
|
|
{ |
|
|
return get(n.getContent()); |
|
|
} |
|
|
|
@@ -142,7 +142,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)) |
|
@@ -310,7 +310,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++) |
|
@@ -515,7 +516,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); |
|
|
|
|
@@ -619,7 +621,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); |
|
|
|
|
|
|
@@ -80,7 +80,7 @@ class VoxelArea |
|
|
Modifying methods |
|
|
*/ |
|
|
|
|
|
void addArea(VoxelArea &a) |
|
|
void addArea(const VoxelArea &a) |
|
|
{ |
|
|
if(getExtent() == v3s16(0,0,0)) |
|
|
{ |
|
@@ -94,7 +94,7 @@ 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)) |
|
|
{ |
|
@@ -111,7 +111,7 @@ class VoxelArea |
|
|
} |
|
|
|
|
|
// Pad with d nodes |
|
|
void pad(v3s16 d) |
|
|
void pad(const v3s16 &d) |
|
|
{ |
|
|
MinEdge -= d; |
|
|
MaxEdge += d; |
|
@@ -366,7 +366,8 @@ class VoxelManipulator /*: public NodeContainer*/ |
|
|
*/ |
|
|
MapNode getNode(v3s16 p) |
|
|
{ |
|
|
addArea(p); |
|
|
VoxelArea voxel_area(p); |
|
|
addArea(voxel_area); |
|
|
|
|
|
if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) |
|
|
{ |
|
@@ -383,7 +384,8 @@ class VoxelManipulator /*: public NodeContainer*/ |
|
|
} |
|
|
MapNode getNodeNoEx(v3s16 p) |
|
|
{ |
|
|
addArea(p); |
|
|
VoxelArea voxel_area(p); |
|
|
addArea(voxel_area); |
|
|
|
|
|
if(m_flags[m_area.index(p)] & VOXELFLAG_NO_DATA) |
|
|
{ |
|
@@ -417,7 +419,8 @@ class VoxelManipulator /*: public NodeContainer*/ |
|
|
} |
|
|
MapNode & getNodeRef(v3s16 p) |
|
|
{ |
|
|
addArea(p); |
|
|
VoxelArea voxel_area(p); |
|
|
addArea(voxel_area); |
|
|
if(getFlagsRefUnsafe(p) & VOXELFLAG_NO_DATA) |
|
|
{ |
|
|
/*dstream<<"EXCEPT: VoxelManipulator::getNode(): " |
|
@@ -432,7 +435,8 @@ class VoxelManipulator /*: public NodeContainer*/ |
|
|
} |
|
|
void setNode(v3s16 p, const MapNode &n) |
|
|
{ |
|
|
addArea(p); |
|
|
VoxelArea voxel_area(p); |
|
|
addArea(voxel_area); |
|
|
|
|
|
m_data[m_area.index(p)] = n; |
|
|
m_flags[m_area.index(p)] &= ~VOXELFLAG_NO_DATA; |
|
@@ -499,7 +503,7 @@ class VoxelManipulator /*: public NodeContainer*/ |
|
|
void print(std::ostream &o, INodeDefManager *nodemgr, |
|
|
VoxelPrintMode mode=VOXELPRINT_MATERIAL); |
|
|
|
|
|
void addArea(VoxelArea area); |
|
|
void addArea(const VoxelArea &area); |
|
|
|
|
|
/* |
|
|
Copy data and set flags to 0 |
|
|