Fixes for using std:vector in ABMHander and further perf improvements
authorLars Hofhansl <larsh@apache.org>
Wed, 4 Jan 2017 19:11:55 +0000 (11:11 -0800)
committersfan5 <sfan5@live.de>
Wed, 4 Jan 2017 20:37:29 +0000 (21:37 +0100)
src/environment.cpp
src/mapblock.h
src/mapnode.h

index 5eb9d9770ee3d0eb6c5664ffd68cc4c007b0843b..a0cf9dca5dbbb9d08ca265cda641d202da5da1ba 100644 (file)
@@ -827,7 +827,7 @@ public:
                                {
                                        content_t c = *k;
                                        if (c >= m_aabms.size())
-                                               m_aabms.resize(c + 256, (std::vector<ActiveABM> *) NULL);
+                                               m_aabms.resize(c + 256, NULL);
                                        if (!m_aabms[c])
                                                m_aabms[c] = new std::vector<ActiveABM>;
                                        m_aabms[c]->push_back(aabm);
@@ -872,7 +872,7 @@ public:
        }
        void apply(MapBlock *block)
        {
-               if(m_aabms.empty())
+               if(m_aabms.empty() || block->isDummy())
                        return;
 
                ServerMap *map = &m_env->getServerMap();
@@ -886,13 +886,13 @@ public:
                for(p0.Y=0; p0.Y<MAP_BLOCKSIZE; p0.Y++)
                for(p0.Z=0; p0.Z<MAP_BLOCKSIZE; p0.Z++)
                {
-                       MapNode n = block->getNodeNoEx(p0);
+                       const MapNode &n = block->getNodeUnsafe(p0);
                        content_t c = n.getContent();
-                       v3s16 p = p0 + block->getPosRelative();
 
-                       if (!m_aabms[c])
+                       if (c >= m_aabms.size() || !m_aabms[c])
                                continue;
 
+                       v3s16 p = p0 + block->getPosRelative();
                        for(std::vector<ActiveABM>::iterator
                                        i = m_aabms[c]->begin(); i != m_aabms[c]->end(); ++i) {
                                if(myrand() % i->chance != 0)
index 5adfcf3fb56deff54bbecbec0001f9411a88ff75..c737b4c3760956d04beb259b080c82969ad812b7 100644 (file)
@@ -305,8 +305,7 @@ public:
        inline MapNode getNodeNoEx(v3s16 p)
        {
                bool is_valid;
-               MapNode node = getNode(p.X, p.Y, p.Z, &is_valid);
-               return is_valid ? node : MapNode(CONTENT_IGNORE);
+               return getNode(p.X, p.Y, p.Z, &is_valid);
        }
 
        inline void setNode(s16 x, s16 y, s16 z, MapNode & n)
@@ -341,6 +340,22 @@ public:
                return getNodeNoCheck(p.X, p.Y, p.Z, valid_position);
        }
 
+       ////
+       //// Non-checking, unsafe variants of the above
+       //// MapBlock must be loaded by another function in the same scope/function
+       //// Caller must ensure that this is not a dummy block (by calling isDummy())
+       ////
+
+       inline const MapNode &getNodeUnsafe(s16 x, s16 y, s16 z)
+       {
+               return data[z * zstride + y * ystride + x];
+       }
+
+       inline const MapNode &getNodeUnsafe(v3s16 &p)
+       {
+               return getNodeUnsafe(p.X, p.Y, p.Z);
+       }
+
        inline void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n)
        {
                if (data == NULL)
@@ -512,7 +527,6 @@ public:
 
        void serializeNetworkSpecific(std::ostream &os, u16 net_proto_version);
        void deSerializeNetworkSpecific(std::istream &is);
-
 private:
        /*
                Private methods
index a3c20e8ffea300bb9ec18e96e85e75bb99fb4f7e..ae0245cfe3ee707f162bce7b265fb915d755fd46 100644 (file)
@@ -143,11 +143,6 @@ struct MapNode
        MapNode()
        { }
 
-       MapNode(const MapNode & n)
-       {
-               *this = n;
-       }
-
        MapNode(content_t content, u8 a_param1=0, u8 a_param2=0)
                : param0(content),
                  param1(a_param1),