LuaVoxelManip: Fix minor bug with set_lighting, remove coordinate params for light and liquid updates

This commit is contained in:
kwolekr 2013-06-29 22:22:25 -04:00
parent 848c3fe51a
commit 067888d549
4 changed files with 35 additions and 31 deletions

@ -1563,13 +1563,11 @@ methods:
- update_map(): Update map after writing chunk back to map. - update_map(): Update map after writing chunk back to map.
^ To be used only by VoxelManip objects created by the mod itself; not a VoxelManip that was ^ To be used only by VoxelManip objects created by the mod itself; not a VoxelManip that was
^ retrieved from minetest.get_mapgen_object ^ retrieved from minetest.get_mapgen_object
- set_lighting(p1, p2, light): Set the lighting in the region formed by p1 and p2 to light - set_lighting(light): Set the lighting within the VoxelManip
^ light is a table containing two integer fields ranging from 0 to 15, day and night ^ light is a table, {day=<0...15>, night=<0...15>}
^ To be used only by a VoxelManip object from minetest.get_mapgen_object; otherwise, set lighting will ^ To be used only by a VoxelManip object from minetest.get_mapgen_object
^ be ignored - calc_lighting(): Calculate lighting within the VoxelManip
- calc_lighting(p1, p2): Calculate lighting in the region formed by p1 and p2 ^ To be used only by a VoxelManip object from minetest.get_mapgen_object
^ To be used only by a VoxelManip object from minetest.get_mapgen_object; otherwise, calculated lighting
^ will be ignored
- update_liquids(): Update liquid flow - update_liquids(): Update liquid flow
VoxelArea: A helper class for voxel areas VoxelArea: A helper class for voxel areas

@ -591,7 +591,7 @@ int ModApiEnvMod::l_get_mapgen_object(lua_State *L)
ManualMapVoxelManipulator *vm = mg->vm; ManualMapVoxelManipulator *vm = mg->vm;
// VoxelManip object // VoxelManip object
LuaVoxelManip *o = new LuaVoxelManip(vm, false); LuaVoxelManip *o = new LuaVoxelManip(vm, true);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o; *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, "VoxelManip"); luaL_getmetatable(L, "VoxelManip");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);

@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
int LuaVoxelManip::gc_object(lua_State *L) int LuaVoxelManip::gc_object(lua_State *L)
{ {
LuaVoxelManip *o = *(LuaVoxelManip **)(lua_touserdata(L, 1)); LuaVoxelManip *o = *(LuaVoxelManip **)(lua_touserdata(L, 1));
if (o->do_gc) if (!o->is_mapgen_vm)
delete o; delete o;
return 0; return 0;
@ -111,10 +111,12 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
int LuaVoxelManip::l_update_liquids(lua_State *L) int LuaVoxelManip::l_update_liquids(lua_State *L)
{ {
LuaVoxelManip *o = checkobject(L, 1); LuaVoxelManip *o = checkobject(L, 1);
if (!o->is_mapgen_vm)
return 0;
ManualMapVoxelManipulator *vm = o->vm;
INodeDefManager *ndef = STACK_TO_SERVER(L)->getNodeDefManager(); INodeDefManager *ndef = STACK_TO_SERVER(L)->getNodeDefManager();
Map *map = &(get_scriptapi(L)->getEnv()->getMap()); Map *map = &(get_scriptapi(L)->getEnv()->getMap());
ManualMapVoxelManipulator *vm = o->vm;
Mapgen mg; Mapgen mg;
mg.vm = vm; mg.vm = vm;
@ -131,20 +133,20 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1); LuaVoxelManip *o = checkobject(L, 1);
v3s16 p1 = read_v3s16(L, 2); if (!o->is_mapgen_vm)
v3s16 p2 = read_v3s16(L, 3); return 0;
sortBoxVerticies(p1, p2);
ManualMapVoxelManipulator *vm = o->vm;
INodeDefManager *ndef = STACK_TO_SERVER(L)->getNodeDefManager(); INodeDefManager *ndef = STACK_TO_SERVER(L)->getNodeDefManager();
EmergeManager *emerge = STACK_TO_SERVER(L)->getEmergeManager(); EmergeManager *emerge = STACK_TO_SERVER(L)->getEmergeManager();
ManualMapVoxelManipulator *vm = o->vm;
Mapgen mg; Mapgen mg;
mg.vm = vm; mg.vm = vm;
mg.ndef = ndef; mg.ndef = ndef;
mg.water_level = emerge->params->water_level; mg.water_level = emerge->params->water_level;
mg.calcLighting(p1, p2); mg.calcLighting(vm->m_area.MinEdge + v3s16(0, 1, 0) * MAP_BLOCKSIZE,
vm->m_area.MaxEdge - v3s16(0, 1, 0) * MAP_BLOCKSIZE);
return 0; return 0;
} }
@ -154,23 +156,24 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1); LuaVoxelManip *o = checkobject(L, 1);
v3s16 p1 = read_v3s16(L, 2); if (!o->is_mapgen_vm)
v3s16 p2 = read_v3s16(L, 3);
sortBoxVerticies(p1, p2);
u8 light;
if (!lua_istable(L, 4))
return 0; return 0;
light = getintfield_default(L, 4, "day", 0); if (!lua_istable(L, 2))
light |= getintfield_default(L, 4, "night", 0); return 0;
u8 light;
light = (getintfield_default(L, 4, "day", 0) & 0x0F);
light |= (getintfield_default(L, 4, "night", 0) & 0x0F) << 8;
ManualMapVoxelManipulator *vm = o->vm; ManualMapVoxelManipulator *vm = o->vm;
Mapgen mg; Mapgen mg;
mg.vm = vm; mg.vm = vm;
mg.setLighting(p1, p2, light); mg.setLighting(vm->m_area.MinEdge + v3s16(0, 1, 0) * MAP_BLOCKSIZE,
vm->m_area.MaxEdge - v3s16(0, 1, 0) * MAP_BLOCKSIZE,
light);
return 0; return 0;
} }
@ -178,6 +181,8 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
int LuaVoxelManip::l_update_map(lua_State *L) int LuaVoxelManip::l_update_map(lua_State *L)
{ {
LuaVoxelManip *o = checkobject(L, 1); LuaVoxelManip *o = checkobject(L, 1);
if (o->is_mapgen_vm)
return 0;
// TODO: Optimize this by using Mapgen::calcLighting() instead // TODO: Optimize this by using Mapgen::calcLighting() instead
std::map<v3s16, MapBlock *> lighting_mblocks; std::map<v3s16, MapBlock *> lighting_mblocks;
@ -202,15 +207,16 @@ int LuaVoxelManip::l_update_map(lua_State *L)
return 0; return 0;
} }
LuaVoxelManip::LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool dogc) LuaVoxelManip::LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mg_vm)
{ {
this->vm = mmvm; this->vm = mmvm;
this->do_gc = dogc; this->is_mapgen_vm = is_mg_vm;
} }
LuaVoxelManip::LuaVoxelManip(Map *map) LuaVoxelManip::LuaVoxelManip(Map *map)
{ {
vm = new ManualMapVoxelManipulator(map); this->vm = new ManualMapVoxelManipulator(map);
this->is_mapgen_vm = false;
} }
LuaVoxelManip::~LuaVoxelManip() LuaVoxelManip::~LuaVoxelManip()

@ -36,7 +36,7 @@ class LuaVoxelManip
private: private:
ManualMapVoxelManipulator *vm; ManualMapVoxelManipulator *vm;
std::map<v3s16, MapBlock *> modified_blocks; std::map<v3s16, MapBlock *> modified_blocks;
bool do_gc; bool is_mapgen_vm;
static const char className[]; static const char className[];
static const luaL_reg methods[]; static const luaL_reg methods[];
@ -54,7 +54,7 @@ private:
static int l_set_lighting(lua_State *L); static int l_set_lighting(lua_State *L);
public: public:
LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool dogc); LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm);
LuaVoxelManip(Map *map); LuaVoxelManip(Map *map);
~LuaVoxelManip(); ~LuaVoxelManip();