Optionally specify propagateSunlight area in calcLighting
authorkwolekr <kwolekr@minetest.net>
Mon, 5 Jan 2015 06:18:53 +0000 (01:18 -0500)
committerkwolekr <kwolekr@minetest.net>
Mon, 5 Jan 2015 06:20:36 +0000 (01:20 -0500)
This fixes the Mapgen V5 calcLighting segfault

src/mapgen.cpp
src/mapgen.h
src/mapgen_v5.cpp
src/script/lua_api/l_vmanip.cpp

index d61e56819aa3469be6fb6ab8ca49aaf8e116a7a1..3f83d21785757042960442886586453e4ca42f32 100644 (file)
@@ -202,7 +202,7 @@ void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nm
 }
 
 
-void Mapgen::setLighting(v3s16 nmin, v3s16 nmax, u8 light)
+void Mapgen::setLighting(u8 light, v3s16 nmin, v3s16 nmax)
 {
        ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
        VoxelArea a(nmin, nmax);
@@ -241,6 +241,19 @@ void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light)
 }
 
 
+void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax)
+{
+       ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
+       //TimeTaker t("updateLighting");
+
+       propagateSunlight(nmin, nmax);
+       spreadLight(full_nmin, full_nmax);
+
+       //printf("updateLighting: %dms\n", t.stop());
+}
+
+
+
 void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax)
 {
        ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
index 2ac66d354c8f4038a29e0469c6d0210ae1019896..eace02e2c676bcdd2f69c60de29b358d97c872fa 100644 (file)
@@ -154,10 +154,14 @@ public:
        s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
        void updateHeightmap(v3s16 nmin, v3s16 nmax);
        void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
-       void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
+
+       void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
        void lightSpread(VoxelArea &a, v3s16 p, u8 light);
 
        void calcLighting(v3s16 nmin, v3s16 nmax);
+       void calcLighting(v3s16 nmin, v3s16 nmax,
+               v3s16 full_nmin, v3s16 full_nmax);
+
        void propagateSunlight(v3s16 nmin, v3s16 nmax);
        void spreadLight(v3s16 nmin, v3s16 nmax);
 
index 16fe4be5d4ed84b2476269bcdc4ba378dc1f437a..e220455bf71af1841ba81c383335d4a527ea9690 100644 (file)
@@ -289,8 +289,10 @@ void MapgenV5::makeChunk(BlockMakeData *data)
        updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
 
        // Calculate lighting
-       if (flags & MG_LIGHT)
-               calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0));
+       if (flags & MG_LIGHT) {
+               calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
+                       full_node_min, full_node_max);
+       }
 
        this->generating = false;
 }
index f64b94af183c7c4509f2f5f4dec3b8428a20ba4e..54689c84cb588bf819044a46c85023feed0774bc 100644 (file)
@@ -168,10 +168,14 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
        EmergeManager *emerge = getServer(L)->getEmergeManager();
        ManualMapVoxelManipulator *vm = o->vm;
 
-       v3s16 p1 = lua_istable(L, 2) ? read_v3s16(L, 2) : vm->m_area.MinEdge;
-       v3s16 p2 = lua_istable(L, 3) ? read_v3s16(L, 3) : vm->m_area.MaxEdge;
-       sortBoxVerticies(p1, p2);
-       if (!vm->m_area.contains(VoxelArea(p1, p2)))
+       v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE;
+       v3s16 fpmin  = vm->m_area.MinEdge;
+       v3s16 fpmax  = vm->m_area.MaxEdge;
+       v3s16 pmin   = lua_istable(L, 2) ? read_v3s16(L, 2) : fpmin + yblock;
+       v3s16 pmax   = lua_istable(L, 3) ? read_v3s16(L, 3) : fpmax - yblock;
+
+       sortBoxVerticies(pmin, pmax);
+       if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
                throw LuaError("Specified voxel area out of VoxelManipulator bounds");
 
        Mapgen mg;
@@ -179,11 +183,7 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
        mg.ndef        = ndef;
        mg.water_level = emerge->params.water_level;
 
-       // Mapgen::calcLighting assumes the coordinates of
-       // the central chunk; correct for this
-       mg.calcLighting(
-               p1 + v3s16(1, 1, 1) * MAP_BLOCKSIZE,
-               p2 - v3s16(1, 1, 1) * MAP_BLOCKSIZE);
+       mg.calcLighting(pmin, pmax, fpmin, fpmax);
 
        return 0;
 }
@@ -205,19 +205,18 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
 
        ManualMapVoxelManipulator *vm = o->vm;
 
-       v3s16 p1 = lua_istable(L, 3) ? read_v3s16(L, 3) : vm->m_area.MinEdge;
-       v3s16 p2 = lua_istable(L, 4) ? read_v3s16(L, 4) : vm->m_area.MaxEdge;
-       sortBoxVerticies(p1, p2);
-       if (!vm->m_area.contains(VoxelArea(p1, p2)))
+       v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE;
+       v3s16 pmin = lua_istable(L, 3) ? read_v3s16(L, 3) : vm->m_area.MinEdge + yblock;
+       v3s16 pmax = lua_istable(L, 4) ? read_v3s16(L, 4) : vm->m_area.MaxEdge - yblock;
+
+       sortBoxVerticies(pmin, pmax);
+       if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
                throw LuaError("Specified voxel area out of VoxelManipulator bounds");
 
        Mapgen mg;
        mg.vm = vm;
 
-       mg.setLighting(
-               p1 + v3s16(0, 1, 0) * MAP_BLOCKSIZE,
-               p2 - v3s16(0, 1, 0) * MAP_BLOCKSIZE,
-               light);
+       mg.setLighting(light, pmin, pmax);
 
        return 0;
 }