Skip to content

Commit 6929206

Browse files
Craig Robbinskwolekr
Craig Robbins
authored andcommittedJul 30, 2014
Fix issue 1527
#1527
1 parent 1734540 commit 6929206

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed
 

‎src/script/lua_api/l_vmanip.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3131
int LuaVoxelManip::gc_object(lua_State *L)
3232
{
3333
LuaVoxelManip *o = *(LuaVoxelManip **)(lua_touserdata(L, 1));
34-
if (!o->is_mapgen_vm)
35-
delete o;
36-
34+
delete o;
35+
3736
return 0;
3837
}
3938

4039
int LuaVoxelManip::l_read_from_map(lua_State *L)
4140
{
4241
LuaVoxelManip *o = checkobject(L, 1);
4342
ManualMapVoxelManipulator *vm = o->vm;
44-
43+
4544
v3s16 bp1 = getNodeBlockPos(read_v3s16(L, 2));
4645
v3s16 bp2 = getNodeBlockPos(read_v3s16(L, 3));
4746
sortBoxVerticies(bp1, bp2);
48-
47+
4948
vm->initialEmerge(bp1, bp2);
50-
49+
5150
push_v3s16(L, vm->m_area.MinEdge);
5251
push_v3s16(L, vm->m_area.MaxEdge);
53-
52+
5453
return 2;
5554
}
5655

@@ -60,39 +59,39 @@ int LuaVoxelManip::l_get_data(lua_State *L)
6059

6160
LuaVoxelManip *o = checkobject(L, 1);
6261
ManualMapVoxelManipulator *vm = o->vm;
63-
62+
6463
int volume = vm->m_area.getVolume();
65-
64+
6665
lua_newtable(L);
6766
for (int i = 0; i != volume; i++) {
6867
lua_Integer cid = vm->m_data[i].getContent();
6968
lua_pushinteger(L, cid);
7069
lua_rawseti(L, -2, i + 1);
7170
}
72-
71+
7372
return 1;
7473
}
7574

7675
int LuaVoxelManip::l_set_data(lua_State *L)
7776
{
7877
NO_MAP_LOCK_REQUIRED;
79-
78+
8079
LuaVoxelManip *o = checkobject(L, 1);
8180
ManualMapVoxelManipulator *vm = o->vm;
82-
81+
8382
if (!lua_istable(L, 2))
8483
return 0;
85-
84+
8685
int volume = vm->m_area.getVolume();
8786
for (int i = 0; i != volume; i++) {
8887
lua_rawgeti(L, 2, i + 1);
8988
content_t c = lua_tointeger(L, -1);
90-
89+
9190
vm->m_data[i].setContent(c);
9291

9392
lua_pop(L, 1);
9493
}
95-
94+
9695
return 0;
9796
}
9897

@@ -103,7 +102,7 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
103102

104103
vm->blitBackAll(&o->modified_blocks);
105104

106-
return 0;
105+
return 0;
107106
}
108107

109108
int LuaVoxelManip::l_update_liquids(lua_State *L)
@@ -131,7 +130,7 @@ int LuaVoxelManip::l_update_liquids(lua_State *L)
131130
int LuaVoxelManip::l_calc_lighting(lua_State *L)
132131
{
133132
NO_MAP_LOCK_REQUIRED;
134-
133+
135134
LuaVoxelManip *o = checkobject(L, 1);
136135
if (!o->is_mapgen_vm)
137136
return 0;
@@ -150,7 +149,7 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
150149
mg.vm = vm;
151150
mg.ndef = ndef;
152151
mg.water_level = emerge->params.water_level;
153-
152+
154153
mg.calcLighting(p1, p2);
155154

156155
return 0;
@@ -159,20 +158,20 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
159158
int LuaVoxelManip::l_set_lighting(lua_State *L)
160159
{
161160
NO_MAP_LOCK_REQUIRED;
162-
161+
163162
LuaVoxelManip *o = checkobject(L, 1);
164163
if (!o->is_mapgen_vm)
165164
return 0;
166-
165+
167166
if (!lua_istable(L, 2))
168167
return 0;
169168

170169
u8 light;
171170
light = (getintfield_default(L, 2, "day", 0) & 0x0F);
172171
light |= (getintfield_default(L, 2, "night", 0) & 0x0F) << 4;
173-
172+
174173
ManualMapVoxelManipulator *vm = o->vm;
175-
174+
176175
v3s16 p1 = lua_istable(L, 3) ? read_v3s16(L, 3) :
177176
vm->m_area.MinEdge + v3s16(0, 1, 0) * MAP_BLOCKSIZE;
178177
v3s16 p2 = lua_istable(L, 4) ? read_v3s16(L, 4) :
@@ -181,7 +180,7 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
181180

182181
Mapgen mg;
183182
mg.vm = vm;
184-
183+
185184
mg.setLighting(p1, p2, light);
186185

187186
return 0;
@@ -276,7 +275,7 @@ int LuaVoxelManip::l_update_map(lua_State *L)
276275
LuaVoxelManip *o = checkobject(L, 1);
277276
if (o->is_mapgen_vm)
278277
return 0;
279-
278+
280279
Environment *env = getEnv(L);
281280
if (!env)
282281
return 0;
@@ -286,9 +285,9 @@ int LuaVoxelManip::l_update_map(lua_State *L)
286285
// TODO: Optimize this by using Mapgen::calcLighting() instead
287286
std::map<v3s16, MapBlock *> lighting_mblocks;
288287
std::map<v3s16, MapBlock *> *mblocks = &o->modified_blocks;
289-
288+
290289
lighting_mblocks.insert(mblocks->begin(), mblocks->end());
291-
290+
292291
map->updateLighting(lighting_mblocks, *mblocks);
293292

294293
MapEditEvent event;
@@ -297,12 +296,12 @@ int LuaVoxelManip::l_update_map(lua_State *L)
297296
it = mblocks->begin();
298297
it != mblocks->end(); ++it)
299298
event.modified_blocks.insert(it->first);
300-
299+
301300
map->dispatchEvent(&event);
302301

303302
mblocks->clear();
304303

305-
return 0;
304+
return 0;
306305
}
307306

308307
LuaVoxelManip::LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mg_vm)
@@ -319,22 +318,23 @@ LuaVoxelManip::LuaVoxelManip(Map *map)
319318

320319
LuaVoxelManip::~LuaVoxelManip()
321320
{
322-
delete vm;
321+
if (!is_mapgen_vm)
322+
delete vm;
323323
}
324324

325325
// LuaVoxelManip()
326326
// Creates an LuaVoxelManip and leaves it on top of stack
327327
int LuaVoxelManip::create_object(lua_State *L)
328328
{
329329
NO_MAP_LOCK_REQUIRED;
330-
330+
331331
Environment *env = getEnv(L);
332332
if (!env)
333333
return 0;
334-
334+
335335
Map *map = &(env->getMap());
336336
LuaVoxelManip *o = new LuaVoxelManip(map);
337-
337+
338338
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
339339
luaL_getmetatable(L, className);
340340
lua_setmetatable(L, -2);
@@ -344,13 +344,13 @@ int LuaVoxelManip::create_object(lua_State *L)
344344
LuaVoxelManip *LuaVoxelManip::checkobject(lua_State *L, int narg)
345345
{
346346
NO_MAP_LOCK_REQUIRED;
347-
347+
348348
luaL_checktype(L, narg, LUA_TUSERDATA);
349349

350350
void *ud = luaL_checkudata(L, narg, className);
351351
if (!ud)
352352
luaL_typerror(L, narg, className);
353-
353+
354354
return *(LuaVoxelManip **)ud; // unbox pointer
355355
}
356356

0 commit comments

Comments
 (0)
Please sign in to comment.