Precalculate mapblock relative size. This permit to remove many s16 calculs on runtime 2967/head
authornerzhul <loic.blot@unix-experience.fr>
Wed, 29 Jul 2015 08:49:40 +0000 (10:49 +0200)
committernerzhul <loic.blot@unix-experience.fr>
Wed, 29 Jul 2015 09:45:44 +0000 (11:45 +0200)
src/mapblock.cpp
src/mapblock.h

index 1d2e1e2501f0b79bc989f0aab20252b24248cd7b..43057f3a54fc5ece599d870bf098249bd3d65052 100644 (file)
@@ -69,6 +69,7 @@ static const char *modified_reason_strings[] = {
 MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
                m_parent(parent),
                m_pos(pos),
+               m_pos_relative(pos * MAP_BLOCKSIZE),
                m_gamedef(gamedef),
                m_modified(MOD_STATE_WRITE_NEEDED),
                m_modified_reason(MOD_REASON_INITIAL),
index 92ca4b485f5fc1c5826b5ca54d005655b45a91b8..ba33c01a2eef145f24803241c795de1f31d3ea56 100644 (file)
@@ -258,7 +258,7 @@ public:
 
        inline v3s16 getPosRelative()
        {
-               return m_pos * MAP_BLOCKSIZE;
+               return m_pos_relative;
        }
 
        inline core::aabbox3d<s16> getBox()
@@ -564,6 +564,14 @@ private:
        // Position in blocks on parent
        v3s16 m_pos;
 
+       /* This is the precalculated m_pos_relative value
+       * This caches the value, improving performance by removing 3 s16 multiplications
+       * at runtime on each getPosRelative call
+       * For a 5 minutes runtime with valgrind this removes 3 * 19M s16 multiplications
+       * The gain can be estimated in Release Build to 3 * 100M multiply operations for 5 mins
+       */
+       v3s16 m_pos_relative;
+
        IGameDef *m_gamedef;
 
        /*