From d406ac994b8092c5bd2dc32eda1a2eafbf95a30c Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Fri, 21 Nov 2014 14:43:29 +1000 Subject: [PATCH] Optimise functions from CNodeDefManager and VoxelManipulator CNodeDefManager::get() VoxelManipulator::addArea() --- src/mapblock_mesh.cpp | 5 +++-- src/nodedef.cpp | 14 ++++++-------- src/voxel.cpp | 11 +++++++---- src/voxel.h | 20 ++++++++++++-------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 3324dd2b6..193fea328 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -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"); diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 51e71a052..deb08fda9 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -389,8 +389,8 @@ public: 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 &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()); } diff --git a/src/voxel.cpp b/src/voxel.cpp index 19f2deb32..13711d1a1 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -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); diff --git a/src/voxel.h b/src/voxel.h index 033ad3e45..53b6edbc7 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -80,7 +80,7 @@ public: Modifying methods */ - void addArea(VoxelArea &a) + void addArea(const VoxelArea &a) { if(getExtent() == v3s16(0,0,0)) { @@ -94,7 +94,7 @@ public: 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 @@ public: } // Pad with d nodes - void pad(v3s16 d) + void pad(const v3s16 &d) { MinEdge -= d; MaxEdge += d; @@ -366,7 +366,8 @@ public: */ 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 @@ public: } 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 @@ public: } 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 @@ public: } 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 @@ public: 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