Optionally specify propagateSunlight area in calcLighting

This fixes the Mapgen V5 calcLighting segfault
This commit is contained in:
kwolekr 2015-01-05 01:18:53 -05:00
parent 00bca11f59
commit 7289d61e99
4 changed files with 39 additions and 21 deletions

@ -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);

@ -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);

@ -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;
}

@ -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;
}