From 46684beec185d13f89c4a91aaa5dd2148ebb0273 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sun, 17 May 2015 22:14:26 -0400 Subject: Record MapBlock modification reasons as flags instead of strings This improves performance of MapBlock::raiseModified by a factor of 6. Also, clean up mapblock.h a bit and inline small functions. --- src/mapblock.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src/mapblock.cpp') diff --git a/src/mapblock.cpp b/src/mapblock.cpp index ca80c39d7..7ad67c589 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -38,6 +38,30 @@ with this program; if not, write to the Free Software Foundation, Inc., #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" +static const char *modified_reason_strings[] = { + "initial", + "reallocate", + "setIsUnderground", + "setLightingExpired", + "setGenerated", + "setNode", + "setNodeNoCheck", + "setTimestamp", + "NodeMetaRef::reportMetadataChange", + "clearAllObjects", + "Timestamp expired (step)", + "addActiveObjectRaw", + "removeRemovedObjects/remove", + "removeRemovedObjects/deactivate", + "Stored list cleared in activateObjects due to overflow", + "deactivateFarObjects: Static data moved in", + "deactivateFarObjects: Static data moved out", + "deactivateFarObjects: Static data changed considerably", + "finishBlockMake: expireDayNightDiff" + "unknown", +}; + + /* MapBlock */ @@ -47,8 +71,7 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy): m_pos(pos), m_gamedef(gamedef), m_modified(MOD_STATE_WRITE_NEEDED), - m_modified_reason("initial"), - m_modified_reason_too_long(false), + m_modified_reason(MOD_REASON_INITIAL), is_underground(false), m_lighting_expired(true), m_day_night_differs(false), @@ -112,6 +135,27 @@ MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position) return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X]; } +std::string MapBlock::getModifiedReasonString() +{ + std::string reason; + + const u32 ubound = MYMIN(sizeof(m_modified_reason) * CHAR_BIT, + ARRLEN(modified_reason_strings)); + + for (u32 i = 0; i != ubound; i++) { + if ((m_modified_reason & (1 << i)) == 0) + continue; + + reason += modified_reason_strings[i]; + reason += ", "; + } + + if (reason.length() > 2) + reason.resize(reason.length() - 2); + + return reason; +} + /* Propagates sunlight down through the block. Doesn't modify nodes that are not affected by sunlight. -- cgit v1.2.3