Navigation Menu

Skip to content

Commit

Permalink
Optimise functions from CNodeDefManager and VoxelManipulator
Browse files Browse the repository at this point in the history
CNodeDefManager::get()
VoxelManipulator::addArea()
  • Loading branch information
Zeno- committed Nov 21, 2014
1 parent ea40497 commit d406ac9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/mapblock_mesh.cpp
Expand Up @@ -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");
Expand Down
14 changes: 6 additions & 8 deletions src/nodedef.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
11 changes: 7 additions & 4 deletions src/voxel.cpp
Expand Up @@ -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))
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
20 changes: 12 additions & 8 deletions src/voxel.h
Expand Up @@ -80,7 +80,7 @@ class VoxelArea
Modifying methods
*/

void addArea(VoxelArea &a)
void addArea(const VoxelArea &a)
{
if(getExtent() == v3s16(0,0,0))
{
Expand All @@ -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))
{
Expand All @@ -111,7 +111,7 @@ class VoxelArea
}

// Pad with d nodes
void pad(v3s16 d)
void pad(const v3s16 &d)
{
MinEdge -= d;
MaxEdge += d;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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(): "
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d406ac9

Please sign in to comment.