@@ -31,26 +31,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
31
31
int LuaVoxelManip::gc_object (lua_State *L)
32
32
{
33
33
LuaVoxelManip *o = *(LuaVoxelManip **)(lua_touserdata (L, 1 ));
34
- if (!o->is_mapgen_vm )
35
- delete o;
36
-
34
+ delete o;
35
+
37
36
return 0 ;
38
37
}
39
38
40
39
int LuaVoxelManip::l_read_from_map (lua_State *L)
41
40
{
42
41
LuaVoxelManip *o = checkobject (L, 1 );
43
42
ManualMapVoxelManipulator *vm = o->vm ;
44
-
43
+
45
44
v3s16 bp1 = getNodeBlockPos (read_v3s16 (L, 2 ));
46
45
v3s16 bp2 = getNodeBlockPos (read_v3s16 (L, 3 ));
47
46
sortBoxVerticies (bp1, bp2);
48
-
47
+
49
48
vm->initialEmerge (bp1, bp2);
50
-
49
+
51
50
push_v3s16 (L, vm->m_area .MinEdge );
52
51
push_v3s16 (L, vm->m_area .MaxEdge );
53
-
52
+
54
53
return 2 ;
55
54
}
56
55
@@ -60,39 +59,39 @@ int LuaVoxelManip::l_get_data(lua_State *L)
60
59
61
60
LuaVoxelManip *o = checkobject (L, 1 );
62
61
ManualMapVoxelManipulator *vm = o->vm ;
63
-
62
+
64
63
int volume = vm->m_area .getVolume ();
65
-
64
+
66
65
lua_newtable (L);
67
66
for (int i = 0 ; i != volume; i++) {
68
67
lua_Integer cid = vm->m_data [i].getContent ();
69
68
lua_pushinteger (L, cid);
70
69
lua_rawseti (L, -2 , i + 1 );
71
70
}
72
-
71
+
73
72
return 1 ;
74
73
}
75
74
76
75
int LuaVoxelManip::l_set_data (lua_State *L)
77
76
{
78
77
NO_MAP_LOCK_REQUIRED;
79
-
78
+
80
79
LuaVoxelManip *o = checkobject (L, 1 );
81
80
ManualMapVoxelManipulator *vm = o->vm ;
82
-
81
+
83
82
if (!lua_istable (L, 2 ))
84
83
return 0 ;
85
-
84
+
86
85
int volume = vm->m_area .getVolume ();
87
86
for (int i = 0 ; i != volume; i++) {
88
87
lua_rawgeti (L, 2 , i + 1 );
89
88
content_t c = lua_tointeger (L, -1 );
90
-
89
+
91
90
vm->m_data [i].setContent (c);
92
91
93
92
lua_pop (L, 1 );
94
93
}
95
-
94
+
96
95
return 0 ;
97
96
}
98
97
@@ -103,7 +102,7 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
103
102
104
103
vm->blitBackAll (&o->modified_blocks );
105
104
106
- return 0 ;
105
+ return 0 ;
107
106
}
108
107
109
108
int LuaVoxelManip::l_update_liquids (lua_State *L)
@@ -131,7 +130,7 @@ int LuaVoxelManip::l_update_liquids(lua_State *L)
131
130
int LuaVoxelManip::l_calc_lighting (lua_State *L)
132
131
{
133
132
NO_MAP_LOCK_REQUIRED;
134
-
133
+
135
134
LuaVoxelManip *o = checkobject (L, 1 );
136
135
if (!o->is_mapgen_vm )
137
136
return 0 ;
@@ -150,7 +149,7 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
150
149
mg.vm = vm;
151
150
mg.ndef = ndef;
152
151
mg.water_level = emerge->params .water_level ;
153
-
152
+
154
153
mg.calcLighting (p1, p2);
155
154
156
155
return 0 ;
@@ -159,20 +158,20 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
159
158
int LuaVoxelManip::l_set_lighting (lua_State *L)
160
159
{
161
160
NO_MAP_LOCK_REQUIRED;
162
-
161
+
163
162
LuaVoxelManip *o = checkobject (L, 1 );
164
163
if (!o->is_mapgen_vm )
165
164
return 0 ;
166
-
165
+
167
166
if (!lua_istable (L, 2 ))
168
167
return 0 ;
169
168
170
169
u8 light;
171
170
light = (getintfield_default (L, 2 , " day" , 0 ) & 0x0F );
172
171
light |= (getintfield_default (L, 2 , " night" , 0 ) & 0x0F ) << 4 ;
173
-
172
+
174
173
ManualMapVoxelManipulator *vm = o->vm ;
175
-
174
+
176
175
v3s16 p1 = lua_istable (L, 3 ) ? read_v3s16 (L, 3 ) :
177
176
vm->m_area .MinEdge + v3s16 (0 , 1 , 0 ) * MAP_BLOCKSIZE;
178
177
v3s16 p2 = lua_istable (L, 4 ) ? read_v3s16 (L, 4 ) :
@@ -181,7 +180,7 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
181
180
182
181
Mapgen mg;
183
182
mg.vm = vm;
184
-
183
+
185
184
mg.setLighting (p1, p2, light);
186
185
187
186
return 0 ;
@@ -276,7 +275,7 @@ int LuaVoxelManip::l_update_map(lua_State *L)
276
275
LuaVoxelManip *o = checkobject (L, 1 );
277
276
if (o->is_mapgen_vm )
278
277
return 0 ;
279
-
278
+
280
279
Environment *env = getEnv (L);
281
280
if (!env)
282
281
return 0 ;
@@ -286,9 +285,9 @@ int LuaVoxelManip::l_update_map(lua_State *L)
286
285
// TODO: Optimize this by using Mapgen::calcLighting() instead
287
286
std::map<v3s16, MapBlock *> lighting_mblocks;
288
287
std::map<v3s16, MapBlock *> *mblocks = &o->modified_blocks ;
289
-
288
+
290
289
lighting_mblocks.insert (mblocks->begin (), mblocks->end ());
291
-
290
+
292
291
map->updateLighting (lighting_mblocks, *mblocks);
293
292
294
293
MapEditEvent event;
@@ -297,12 +296,12 @@ int LuaVoxelManip::l_update_map(lua_State *L)
297
296
it = mblocks->begin ();
298
297
it != mblocks->end (); ++it)
299
298
event.modified_blocks .insert (it->first );
300
-
299
+
301
300
map->dispatchEvent (&event);
302
301
303
302
mblocks->clear ();
304
303
305
- return 0 ;
304
+ return 0 ;
306
305
}
307
306
308
307
LuaVoxelManip::LuaVoxelManip (ManualMapVoxelManipulator *mmvm, bool is_mg_vm)
@@ -319,22 +318,23 @@ LuaVoxelManip::LuaVoxelManip(Map *map)
319
318
320
319
LuaVoxelManip::~LuaVoxelManip ()
321
320
{
322
- delete vm;
321
+ if (!is_mapgen_vm)
322
+ delete vm;
323
323
}
324
324
325
325
// LuaVoxelManip()
326
326
// Creates an LuaVoxelManip and leaves it on top of stack
327
327
int LuaVoxelManip::create_object (lua_State *L)
328
328
{
329
329
NO_MAP_LOCK_REQUIRED;
330
-
330
+
331
331
Environment *env = getEnv (L);
332
332
if (!env)
333
333
return 0 ;
334
-
334
+
335
335
Map *map = &(env->getMap ());
336
336
LuaVoxelManip *o = new LuaVoxelManip (map);
337
-
337
+
338
338
*(void **)(lua_newuserdata (L, sizeof (void *))) = o;
339
339
luaL_getmetatable (L, className);
340
340
lua_setmetatable (L, -2 );
@@ -344,13 +344,13 @@ int LuaVoxelManip::create_object(lua_State *L)
344
344
LuaVoxelManip *LuaVoxelManip::checkobject (lua_State *L, int narg)
345
345
{
346
346
NO_MAP_LOCK_REQUIRED;
347
-
347
+
348
348
luaL_checktype (L, narg, LUA_TUSERDATA);
349
349
350
350
void *ud = luaL_checkudata (L, narg, className);
351
351
if (!ud)
352
352
luaL_typerror (L, narg, className);
353
-
353
+
354
354
return *(LuaVoxelManip **)ud; // unbox pointer
355
355
}
356
356
0 commit comments