diff options
-rw-r--r-- | src/mapgen.cpp | 15 | ||||
-rw-r--r-- | src/mapgen.h | 6 | ||||
-rw-r--r-- | src/mapgen_v5.cpp | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 33 |
4 files changed, 39 insertions, 21 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp index d61e56819..3f83d2178 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -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); diff --git a/src/mapgen.h b/src/mapgen.h index 2ac66d354..eace02e2c 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -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); diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index 16fe4be5d..e220455bf 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -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; } diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index f64b94af1..54689c84c 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -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; } |