From caf8d2a9d16a313bbc86a27ad0642efc76852e9f Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Sat, 7 Feb 2015 17:52:56 +1000 Subject: [PATCH] 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) --- src/mapblock.cpp | 29 ++++++++++++----------------- src/mapnode.cpp | 16 ++++++++++++++++ src/mapnode.h | 8 ++++++++ 3 files changed, 36 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; iget(*this); + bool isEqual; + + if (f.param_type == CPT_LIGHT) { + u8 day = MYMAX(f.light_source, param1 & 0x0f); + u8 night = MYMAX(f.light_source, (param1 >> 4) & 0x0f); + isEqual = day == night; + } else { + isEqual = true; + } + + return isEqual; +} + u8 MapNode::getLight(enum LightBank bank, INodeDefManager *nodemgr) const { // Select the brightest of [light source, propagated light] diff --git a/src/mapnode.h b/src/mapnode.h index 82c53e7d4..b7d9f3acd 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -192,6 +192,14 @@ struct MapNode } void setLight(enum LightBank bank, u8 a_light, INodeDefManager *nodemgr); + + /** + * Check if the light value for night differs from the light value for day. + * + * @return If the light values are equal, returns true; otherwise false + */ + bool isLightDayNightEq(INodeDefManager *nodemgr) const; + u8 getLight(enum LightBank bank, INodeDefManager *nodemgr) const; /**