summaryrefslogtreecommitdiff
path: root/src/mapblock.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-05-17 22:14:26 -0400
committerkwolekr <kwolekr@minetest.net>2015-05-17 22:14:26 -0400
commit46684beec185d13f89c4a91aaa5dd2148ebb0273 (patch)
tree3e4115131b71f7f00a232a59bdb2c61a440cc513 /src/mapblock.cpp
parent4c9a8a91c4988b3567a38af622a3eb0d0ec19f6b (diff)
downloadminetest-46684beec185d13f89c4a91aaa5dd2148ebb0273.tar.gz
minetest-46684beec185d13f89c4a91aaa5dd2148ebb0273.tar.bz2
minetest-46684beec185d13f89c4a91aaa5dd2148ebb0273.zip
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.
Diffstat (limited to 'src/mapblock.cpp')
-rw-r--r--src/mapblock.cpp48
1 files changed, 46 insertions, 2 deletions
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.