Skip to content

Commit 7289d61

Browse files
committedJan 5, 2015
Optionally specify propagateSunlight area in calcLighting
This fixes the Mapgen V5 calcLighting segfault
1 parent 00bca11 commit 7289d61

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed
 

‎src/mapgen.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void Mapgen::updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nm
202202
}
203203

204204

205-
void Mapgen::setLighting(v3s16 nmin, v3s16 nmax, u8 light)
205+
void Mapgen::setLighting(u8 light, v3s16 nmin, v3s16 nmax)
206206
{
207207
ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
208208
VoxelArea a(nmin, nmax);
@@ -241,6 +241,19 @@ void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light)
241241
}
242242

243243

244+
void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax)
245+
{
246+
ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);
247+
//TimeTaker t("updateLighting");
248+
249+
propagateSunlight(nmin, nmax);
250+
spreadLight(full_nmin, full_nmax);
251+
252+
//printf("updateLighting: %dms\n", t.stop());
253+
}
254+
255+
256+
244257
void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax)
245258
{
246259
ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG);

‎src/mapgen.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ class Mapgen {
154154
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
155155
void updateHeightmap(v3s16 nmin, v3s16 nmax);
156156
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
157-
void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
157+
158+
void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
158159
void lightSpread(VoxelArea &a, v3s16 p, u8 light);
159160

160161
void calcLighting(v3s16 nmin, v3s16 nmax);
162+
void calcLighting(v3s16 nmin, v3s16 nmax,
163+
v3s16 full_nmin, v3s16 full_nmax);
164+
161165
void propagateSunlight(v3s16 nmin, v3s16 nmax);
162166
void spreadLight(v3s16 nmin, v3s16 nmax);
163167

‎src/mapgen_v5.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ void MapgenV5::makeChunk(BlockMakeData *data)
289289
updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
290290

291291
// Calculate lighting
292-
if (flags & MG_LIGHT)
293-
calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0));
292+
if (flags & MG_LIGHT) {
293+
calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
294+
full_node_min, full_node_max);
295+
}
294296

295297
this->generating = false;
296298
}

‎src/script/lua_api/l_vmanip.cpp

+16-17
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,22 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
168168
EmergeManager *emerge = getServer(L)->getEmergeManager();
169169
ManualMapVoxelManipulator *vm = o->vm;
170170

171-
v3s16 p1 = lua_istable(L, 2) ? read_v3s16(L, 2) : vm->m_area.MinEdge;
172-
v3s16 p2 = lua_istable(L, 3) ? read_v3s16(L, 3) : vm->m_area.MaxEdge;
173-
sortBoxVerticies(p1, p2);
174-
if (!vm->m_area.contains(VoxelArea(p1, p2)))
171+
v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE;
172+
v3s16 fpmin = vm->m_area.MinEdge;
173+
v3s16 fpmax = vm->m_area.MaxEdge;
174+
v3s16 pmin = lua_istable(L, 2) ? read_v3s16(L, 2) : fpmin + yblock;
175+
v3s16 pmax = lua_istable(L, 3) ? read_v3s16(L, 3) : fpmax - yblock;
176+
177+
sortBoxVerticies(pmin, pmax);
178+
if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
175179
throw LuaError("Specified voxel area out of VoxelManipulator bounds");
176180

177181
Mapgen mg;
178182
mg.vm = vm;
179183
mg.ndef = ndef;
180184
mg.water_level = emerge->params.water_level;
181185

182-
// Mapgen::calcLighting assumes the coordinates of
183-
// the central chunk; correct for this
184-
mg.calcLighting(
185-
p1 + v3s16(1, 1, 1) * MAP_BLOCKSIZE,
186-
p2 - v3s16(1, 1, 1) * MAP_BLOCKSIZE);
186+
mg.calcLighting(pmin, pmax, fpmin, fpmax);
187187

188188
return 0;
189189
}
@@ -205,19 +205,18 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
205205

206206
ManualMapVoxelManipulator *vm = o->vm;
207207

208-
v3s16 p1 = lua_istable(L, 3) ? read_v3s16(L, 3) : vm->m_area.MinEdge;
209-
v3s16 p2 = lua_istable(L, 4) ? read_v3s16(L, 4) : vm->m_area.MaxEdge;
210-
sortBoxVerticies(p1, p2);
211-
if (!vm->m_area.contains(VoxelArea(p1, p2)))
208+
v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE;
209+
v3s16 pmin = lua_istable(L, 3) ? read_v3s16(L, 3) : vm->m_area.MinEdge + yblock;
210+
v3s16 pmax = lua_istable(L, 4) ? read_v3s16(L, 4) : vm->m_area.MaxEdge - yblock;
211+
212+
sortBoxVerticies(pmin, pmax);
213+
if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
212214
throw LuaError("Specified voxel area out of VoxelManipulator bounds");
213215

214216
Mapgen mg;
215217
mg.vm = vm;
216218

217-
mg.setLighting(
218-
p1 + v3s16(0, 1, 0) * MAP_BLOCKSIZE,
219-
p2 - v3s16(0, 1, 0) * MAP_BLOCKSIZE,
220-
light);
219+
mg.setLighting(light, pmin, pmax);
221220

222221
return 0;
223222
}

0 commit comments

Comments
 (0)
Please sign in to comment.