]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapblock.h
Increase performance of getLight() by at least 2x
[dragonfireclient.git] / src / mapblock.h
index d56d93ddae8e41c5ee0b776f0411fa9445ac9fc2..fa56f331865385e4e276caba9e98982085059e74 100644 (file)
@@ -1,6 +1,6 @@
 /*
-Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -20,18 +20,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef MAPBLOCK_HEADER
 #define MAPBLOCK_HEADER
 
-#include <jmutex.h>
-#include <jmutexautolock.h>
-#include <exception>
+#include <set>
 #include "debug.h"
-#include "irrlichttypes.h"
 #include "irr_v3d.h"
-#include "irr_aabb3d.h"
 #include "mapnode.h"
 #include "exceptions.h"
-#include "serialization.h"
 #include "constants.h"
-#include "voxel.h"
 #include "staticobject.h"
 #include "nodemetadata.h"
 #include "nodetimer.h"
@@ -42,6 +36,7 @@ class Map;
 class NodeMetadataList;
 class IGameDef;
 class MapBlockMesh;
+class VoxelManipulator;
 
 #define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff
 
@@ -256,37 +251,39 @@ class MapBlock /*: public NodeContainer*/
                Regular MapNode get-setters
        */
        
+       bool isValidPosition(s16 x, s16 y, s16 z)
+       {
+               return data != NULL
+                               && x >= 0 && x < MAP_BLOCKSIZE
+                               && y >= 0 && y < MAP_BLOCKSIZE
+                               && z >= 0 && z < MAP_BLOCKSIZE;
+       }
+
        bool isValidPosition(v3s16 p)
        {
-               if(data == NULL)
-                       return false;
-               return (p.X >= 0 && p.X < MAP_BLOCKSIZE
-                               && p.Y >= 0 && p.Y < MAP_BLOCKSIZE
-                               && p.Z >= 0 && p.Z < MAP_BLOCKSIZE);
+               return isValidPosition(p.X, p.Y, p.Z);
        }
 
-       MapNode getNode(s16 x, s16 y, s16 z)
+       MapNode getNode(s16 x, s16 y, s16 z, bool *valid_position)
        {
-               if(data == NULL)
-                       throw InvalidPositionException();
-               if(x < 0 || x >= MAP_BLOCKSIZE) throw InvalidPositionException();
-               if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException();
-               if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException();
+               *valid_position = isValidPosition(x, y, z);
+
+               if (!*valid_position)
+                       return MapNode(CONTENT_IGNORE);
+
                return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
        }
        
-       MapNode getNode(v3s16 p)
+       MapNode getNode(v3s16 p, bool *valid_position)
        {
-               return getNode(p.X, p.Y, p.Z);
+               return getNode(p.X, p.Y, p.Z, valid_position);
        }
        
        MapNode getNodeNoEx(v3s16 p)
        {
-               try{
-                       return getNode(p.X, p.Y, p.Z);
-               }catch(InvalidPositionException &e){
-                       return MapNode(CONTENT_IGNORE);
-               }
+               bool is_valid;
+               MapNode node = getNode(p.X, p.Y, p.Z, &is_valid);
+               return is_valid ? node : MapNode(CONTENT_IGNORE);
        }
        
        void setNode(s16 x, s16 y, s16 z, MapNode & n)
@@ -309,16 +306,18 @@ class MapBlock /*: public NodeContainer*/
                Non-checking variants of the above
        */
 
-       MapNode getNodeNoCheck(s16 x, s16 y, s16 z)
+       MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position)
        {
-               if(data == NULL)
-                       throw InvalidPositionException();
+               *valid_position = data != NULL;
+               if(!valid_position)
+                       return MapNode(CONTENT_IGNORE);
+
                return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
        }
        
-       MapNode getNodeNoCheck(v3s16 p)
+       MapNode getNodeNoCheck(v3s16 p, bool *valid_position)
        {
-               return getNodeNoCheck(p.X, p.Y, p.Z);
+               return getNodeNoCheck(p.X, p.Y, p.Z, valid_position);
        }
        
        void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n)
@@ -339,9 +338,8 @@ class MapBlock /*: public NodeContainer*/
                is not valid on this MapBlock.
        */
        bool isValidPositionParent(v3s16 p);
-       MapNode getNodeParent(v3s16 p);
+       MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL);
        void setNodeParent(v3s16 p, MapNode & n);
-       MapNode getNodeParentNoEx(v3s16 p);
 
        void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node)
        {
@@ -352,7 +350,7 @@ class MapBlock /*: public NodeContainer*/
        }
 
        // See comments in mapblock.cpp
-       bool propagateSunlight(core::map<v3s16, bool> & light_sources,
+       bool propagateSunlight(std::set<v3s16> & light_sources,
                        bool remove_light=false, bool *black_air_left=NULL);
        
        // Copies data to VoxelManipulator to getPosRelative()
@@ -478,6 +476,9 @@ class MapBlock /*: public NodeContainer*/
        // unknown blocks from id-name mapping to wndef
        void deSerialize(std::istream &is, u8 version, bool disk);
 
+       void serializeNetworkSpecific(std::ostream &os, u16 net_proto_version);
+       void deSerializeNetworkSpecific(std::istream &is);
+
 private:
        /*
                Private methods
@@ -510,13 +511,12 @@ class MapBlock /*: public NodeContainer*/
 
 #ifndef SERVER // Only on client
        MapBlockMesh *mesh;
-       //JMutex mesh_mutex;
 #endif
        
        NodeMetadataList m_node_metadata;
        NodeTimerList m_node_timers;
        StaticObjectList m_static_objects;
-       
+
 private:
        /*
                Private member variables