]> git.lizzy.rs Git - minetest.git/blobdiff - src/voxel.h
Implement propagateSunlight for VoxelManipulator
[minetest.git] / src / voxel.h
index 6d1a318f1e9b9f505d1a849d150806664cc67b14..2373667560dbe2ca7e904bc027c2a5dc58a93282 100644 (file)
@@ -20,11 +20,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef VOXEL_HEADER
 #define VOXEL_HEADER
 
-#include "common_irrlicht.h"
+#include "irrlichttypes.h"
 #include <iostream>
 #include "debug.h"
 #include "mapnode.h"
 
+class INodeDefManager;
+
 // For VC++
 #undef min
 #undef max
@@ -331,6 +333,7 @@ enum VoxelPrintMode
        VOXELPRINT_NOTHING,
        VOXELPRINT_MATERIAL,
        VOXELPRINT_WATERPRESSURE,
+       VOXELPRINT_LIGHT_DAY,
 };
 
 class VoxelManipulator /*: public NodeContainer*/
@@ -362,11 +365,11 @@ class VoxelManipulator /*: public NodeContainer*/
 
                if(m_flags[m_area.index(p)] & VOXELFLAG_INEXISTENT)
                {
-                       dstream<<"EXCEPT: VoxelManipulator::getNode(): "
+                       /*dstream<<"EXCEPT: VoxelManipulator::getNode(): "
                                        <<"p=("<<p.X<<","<<p.Y<<","<<p.Z<<")"
                                        <<", index="<<m_area.index(p)
                                        <<", flags="<<(int)m_flags[m_area.index(p)]
-                                       <<" is inexistent"<<std::endl;
+                                       <<" is inexistent"<<std::endl;*/
                        throw InvalidPositionException
                        ("VoxelManipulator: getNode: inexistent");
                }
@@ -392,24 +395,37 @@ class VoxelManipulator /*: public NodeContainer*/
                        return MapNode(CONTENT_IGNORE);
                return m_data[m_area.index(p)];
        }
+       // Stuff explodes if non-emerged area is touched with this.
+       // Emerge first, and check VOXELFLAG_INEXISTENT if appropriate.
+       MapNode & getNodeRefUnsafe(v3s16 p)
+       {
+               return m_data[m_area.index(p)];
+       }
+       u8 & getFlagsRefUnsafe(v3s16 p)
+       {
+               return m_flags[m_area.index(p)];
+       }
+       bool exists(v3s16 p)
+       {
+               return m_area.contains(p) &&
+                       !(getFlagsRefUnsafe(p) & VOXELFLAG_INEXISTENT);
+       }
        MapNode & getNodeRef(v3s16 p)
        {
                emerge(p);
-
-               if(m_flags[m_area.index(p)] & VOXELFLAG_INEXISTENT)
+               if(getFlagsRefUnsafe(p) & VOXELFLAG_INEXISTENT)
                {
-                       dstream<<"EXCEPT: VoxelManipulator::getNode(): "
+                       /*dstream<<"EXCEPT: VoxelManipulator::getNode(): "
                                        <<"p=("<<p.X<<","<<p.Y<<","<<p.Z<<")"
                                        <<", index="<<m_area.index(p)
-                                       <<", flags="<<(int)m_flags[m_area.index(p)]
-                                       <<" is inexistent"<<std::endl;
+                                       <<", flags="<<(int)getFlagsRefUnsafe(p)
+                                       <<" is inexistent"<<std::endl;*/
                        throw InvalidPositionException
                        ("VoxelManipulator: getNode: inexistent");
                }
-
-               return m_data[m_area.index(p)];
+               return getNodeRefUnsafe(p);
        }
-       void setNode(v3s16 p, MapNode &n)
+       void setNode(v3s16 p, const MapNode &n)
        {
                emerge(p);
                
@@ -417,7 +433,8 @@ class VoxelManipulator /*: public NodeContainer*/
                m_flags[m_area.index(p)] &= ~VOXELFLAG_INEXISTENT;
                m_flags[m_area.index(p)] &= ~VOXELFLAG_NOT_LOADED;
        }
-       void setNodeNoRef(v3s16 p, MapNode n)
+       // TODO: Should be removed and replaced with setNode
+       void setNodeNoRef(v3s16 p, const MapNode &n)
        {
                setNode(p, n);
        }
@@ -453,12 +470,14 @@ class VoxelManipulator /*: public NodeContainer*/
                if(m_area.contains(p) == false)
                        return false;
                m_data[m_area.index(p)] = n;
+               return true;
        }
        bool setNodeNoEmerge(s32 i, MapNode n)
        {
                if(m_area.contains(i) == false)
                        return false;
                m_data[i] = n;
+               return true;
        }
        /*bool setContentNoEmerge(v3s16 p, u8 c)
        {
@@ -473,7 +492,8 @@ class VoxelManipulator /*: public NodeContainer*/
 
        virtual void clear();
 
-       void print(std::ostream &o, VoxelPrintMode mode=VOXELPRINT_MATERIAL);
+       void print(std::ostream &o, INodeDefManager *nodemgr,
+                       VoxelPrintMode mode=VOXELPRINT_MATERIAL);
        
        void addArea(VoxelArea area);
 
@@ -493,16 +513,18 @@ class VoxelManipulator /*: public NodeContainer*/
        */
 
        void clearFlag(u8 flag);
-       
+
+       // TODO: Move to voxelalgorithms.h
+
        void unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
-                       core::map<v3s16, bool> & light_sources);
+                       core::map<v3s16, bool> & light_sources, INodeDefManager *nodemgr);
        void unspreadLight(enum LightBank bank,
                        core::map<v3s16, u8> & from_nodes,
-                       core::map<v3s16, bool> & light_sources);
+                       core::map<v3s16, bool> & light_sources, INodeDefManager *nodemgr);
        
-       void spreadLight(enum LightBank bank, v3s16 p);
+       void spreadLight(enum LightBank bank, v3s16 p, INodeDefManager *nodemgr);
        void spreadLight(enum LightBank bank,
-                       core::map<v3s16, bool> & from_nodes);
+                       core::map<v3s16, bool> & from_nodes, INodeDefManager *nodemgr);
        
        /*
                Virtual functions