summaryrefslogtreecommitdiff
path: root/src/mapblock.cpp
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2015-02-07 17:52:56 +1000
committerLoic Blot <loic.blot@unix-experience.fr>2015-02-10 16:23:37 +0100
commitcaf8d2a9d16a313bbc86a27ad0642efc76852e9f (patch)
tree9787d5960dc11c3fbe37ab05efb103fcbb3dcddc /src/mapblock.cpp
parentbb59a8543d44b566d8b39fd4727d552a8d4f3e90 (diff)
downloadminetest-caf8d2a9d16a313bbc86a27ad0642efc76852e9f.tar.gz
minetest-caf8d2a9d16a313bbc86a27ad0642efc76852e9f.tar.bz2
minetest-caf8d2a9d16a313bbc86a27ad0642efc76852e9f.zip
Increase MapBlock::actuallyUpdateDayNightDiff() performance by 2-8x. ok @celeron55
Before patch, function consumes up to ~8% of the main server loop. After, ~0% (below level of 2 places of significance)
Diffstat (limited to 'src/mapblock.cpp')
-rw-r--r--src/mapblock.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/mapblock.cpp b/src/mapblock.cpp
index ecd9a016b..a05b7a4da 100644
--- a/src/mapblock.cpp
+++ b/src/mapblock.cpp
@@ -330,47 +330,42 @@ void MapBlock::copyFrom(VoxelManipulator &dst)
void MapBlock::actuallyUpdateDayNightDiff()
{
INodeDefManager *nodemgr = m_gamedef->ndef();
+
// Running this function un-expires m_day_night_differs
m_day_night_differs_expired = false;
- if(data == NULL)
- {
+ if (data == NULL) {
m_day_night_differs = false;
return;
}
- bool differs = false;
+ bool differs;
/*
Check if any lighting value differs
*/
- for(u32 i=0; i<MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++)
- {
+ for (u32 i = 0; i < MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++) {
MapNode &n = data[i];
- if(n.getLight(LIGHTBANK_DAY, nodemgr) != n.getLight(LIGHTBANK_NIGHT, nodemgr))
- {
- differs = true;
+
+ differs = !n.isLightDayNightEq(nodemgr);
+ if (differs)
break;
- }
}
/*
If some lighting values differ, check if the whole thing is
- just air. If it is, differ = false
+ just air. If it is just air, differs = false
*/
- if(differs)
- {
+ if (differs) {
bool only_air = true;
- for(u32 i=0; i<MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++)
- {
+ for (u32 i = 0; i < MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++) {
MapNode &n = data[i];
- if(n.getContent() != CONTENT_AIR)
- {
+ if (n.getContent() != CONTENT_AIR) {
only_air = false;
break;
}
}
- if(only_air)
+ if (only_air)
differs = false;
}