Skip to content

Commit

Permalink
Optionally specify propagateSunlight area in calcLighting
Browse files Browse the repository at this point in the history
This fixes the Mapgen V5 calcLighting segfault
  • Loading branch information
kwolekr committed Jan 5, 2015
1 parent 00bca11 commit 7289d61
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
15 changes: 14 additions & 1 deletion src/mapgen.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/mapgen.h
Expand Up @@ -154,10 +154,14 @@ class Mapgen {
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);

Expand Down
6 changes: 4 additions & 2 deletions src/mapgen_v5.cpp
Expand Up @@ -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;
}
Expand Down
33 changes: 16 additions & 17 deletions src/script/lua_api/l_vmanip.cpp
Expand Up @@ -168,22 +168,22 @@ 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;
mg.vm = vm;
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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 7289d61

Please sign in to comment.