Move tool stuff to tool.{h,cpp}
[oweals/minetest.git] / src / map.cpp
index e2ac5a2315a9990a748cfe3e7df3cce2db4afae9..b70b76b71ef2efa24a5b3666cc12a646ad9d88d9 100644 (file)
@@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "log.h"
 #include "profiler.h"
+#include "mapnode_contentfeatures.h"
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
 
@@ -1773,7 +1774,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
                /*
                        update the current node
                 */
-               bool flow_down_enabled = (flowing_down && ((n0.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK));
+               //bool flow_down_enabled = (flowing_down && ((n0.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK));
                if (content_features(new_node_content).liquid_type == LIQUID_FLOWING) {
                        // set level to last 3 bits, flowing down bit to 4th bit
                        n0.param2 = (flowing_down ? LIQUID_FLOW_DOWN_MASK : 0x00) | (new_node_level & LIQUID_LEVEL_MASK);
@@ -1835,7 +1836,7 @@ NodeMetadata* Map::getNodeMetadata(v3s16 p)
                                <<std::endl;
                return NULL;
        }
-       NodeMetadata *meta = block->m_node_metadata.get(p_rel);
+       NodeMetadata *meta = block->m_node_metadata->get(p_rel);
        return meta;
 }
 
@@ -1855,7 +1856,7 @@ void Map::setNodeMetadata(v3s16 p, NodeMetadata *meta)
                                <<std::endl;
                return;
        }
-       block->m_node_metadata.set(p_rel, meta);
+       block->m_node_metadata->set(p_rel, meta);
 }
 
 void Map::removeNodeMetadata(v3s16 p)
@@ -1869,7 +1870,7 @@ void Map::removeNodeMetadata(v3s16 p)
                                <<std::endl;
                return;
        }
-       block->m_node_metadata.remove(p_rel);
+       block->m_node_metadata->remove(p_rel);
 }
 
 void Map::nodeMetadataStep(float dtime,
@@ -1894,7 +1895,7 @@ void Map::nodeMetadataStep(float dtime,
                for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
                {
                        MapBlock *block = *i;
-                       bool changed = block->m_node_metadata.step(dtime);
+                       bool changed = block->m_node_metadata->step(dtime);
                        if(changed)
                                changed_blocks[block->getPos()] = block;
                }
@@ -3613,7 +3614,7 @@ void ClientMap::OnRegisterSceneNode()
        ISceneNode::OnRegisterSceneNode();
 }
 
-static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step,
+static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
                float start_off, float end_off, u32 needed_count)
 {
        float d0 = (float)BS * p0.getDistanceFrom(p1);
@@ -3637,6 +3638,7 @@ static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step,
                        if(count >= needed_count)
                                return true;
                }
+               step *= stepfac;
        }
        return false;
 }
@@ -3785,9 +3787,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
 
                        blocks_in_range++;
                        
-                       // This block is in range. Reset usage timer.
-                       block->resetUsageTimer();
-
 #if 1
                        /*
                                Update expired mesh (used for day/night change)
@@ -3843,39 +3842,43 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
                                Occlusion culling
                        */
 
-                       v3s16 cpn = v3s16(block->getPos() * MAP_BLOCKSIZE)
-                                       + v3s16(MAP_BLOCKSIZE)/2;
-                       float step = BS*2;
-                       float startoff = BS*3;
+                       v3s16 cpn = block->getPos() * MAP_BLOCKSIZE;
+                       cpn += v3s16(MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2, MAP_BLOCKSIZE/2);
+                       float step = BS*1;
+                       float stepfac = 1.1;
+                       float startoff = BS*1;
                        float endoff = -BS*MAP_BLOCKSIZE*1.42*1.42;
                        v3s16 spn = cam_pos_nodes + v3s16(0,0,0);
                        s16 bs2 = MAP_BLOCKSIZE/2 + 1;
                        u32 needed_count = 1;
                        if(
                                isOccluded(this, spn, cpn + v3s16(0,0,0),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(bs2,bs2,bs2),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(bs2,bs2,-bs2),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(bs2,-bs2,bs2),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(bs2,-bs2,-bs2),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(-bs2,bs2,bs2),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(-bs2,bs2,-bs2),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,bs2),
-                                               step, startoff, endoff, needed_count) &&
+                                               step, stepfac, startoff, endoff, needed_count) &&
                                isOccluded(this, spn, cpn + v3s16(-bs2,-bs2,-bs2),
-                                               step, startoff, endoff, needed_count)
+                                               step, stepfac, startoff, endoff, needed_count)
                        )
                        {
                                blocks_occlusion_culled++;
                                continue;
                        }
                        
+                       // This block is in range. Reset usage timer.
+                       block->resetUsageTimer();
+
                        /*
                                Ignore if mesh doesn't exist
                        */