diff options
author | kwolekr <kwolekr@minetest.net> | 2013-06-29 22:22:25 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-06-29 22:23:00 -0400 |
commit | 067888d54943d301c45843858c763d4f81db215d (patch) | |
tree | 4d3a1f9039269f0ff5d0e00cd1c3e8a0df1f1427 /src/script | |
parent | 848c3fe51a842950b14547491c74aaf580dc83ec (diff) | |
download | minetest-067888d54943d301c45843858c763d4f81db215d.tar.gz minetest-067888d54943d301c45843858c763d4f81db215d.tar.bz2 minetest-067888d54943d301c45843858c763d4f81db215d.zip |
LuaVoxelManip: Fix minor bug with set_lighting, remove coordinate params for light and liquid updates
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/lua_api/l_env.cpp | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 48 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.h | 4 |
3 files changed, 30 insertions, 24 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 89ba9798a..1cbf34ab9 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -591,7 +591,7 @@ int ModApiEnvMod::l_get_mapgen_object(lua_State *L) ManualMapVoxelManipulator *vm = mg->vm; // VoxelManip object - LuaVoxelManip *o = new LuaVoxelManip(vm, false); + LuaVoxelManip *o = new LuaVoxelManip(vm, true); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, "VoxelManip"); lua_setmetatable(L, -2); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 8bf65a555..50a48e89b 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., int LuaVoxelManip::gc_object(lua_State *L) { LuaVoxelManip *o = *(LuaVoxelManip **)(lua_touserdata(L, 1)); - if (o->do_gc) + if (!o->is_mapgen_vm) delete o; return 0; @@ -111,10 +111,12 @@ int LuaVoxelManip::l_write_to_map(lua_State *L) int LuaVoxelManip::l_update_liquids(lua_State *L) { LuaVoxelManip *o = checkobject(L, 1); + if (!o->is_mapgen_vm) + return 0; - ManualMapVoxelManipulator *vm = o->vm; INodeDefManager *ndef = STACK_TO_SERVER(L)->getNodeDefManager(); Map *map = &(get_scriptapi(L)->getEnv()->getMap()); + ManualMapVoxelManipulator *vm = o->vm; Mapgen mg; mg.vm = vm; @@ -131,20 +133,20 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L) NO_MAP_LOCK_REQUIRED; LuaVoxelManip *o = checkobject(L, 1); - v3s16 p1 = read_v3s16(L, 2); - v3s16 p2 = read_v3s16(L, 3); - sortBoxVerticies(p1, p2); - - ManualMapVoxelManipulator *vm = o->vm; + if (!o->is_mapgen_vm) + return 0; + INodeDefManager *ndef = STACK_TO_SERVER(L)->getNodeDefManager(); EmergeManager *emerge = STACK_TO_SERVER(L)->getEmergeManager(); - + ManualMapVoxelManipulator *vm = o->vm; + Mapgen mg; mg.vm = vm; mg.ndef = ndef; 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; } @@ -154,23 +156,24 @@ int LuaVoxelManip::l_set_lighting(lua_State *L) NO_MAP_LOCK_REQUIRED; LuaVoxelManip *o = checkobject(L, 1); - v3s16 p1 = read_v3s16(L, 2); - v3s16 p2 = read_v3s16(L, 3); - sortBoxVerticies(p1, p2); + if (!o->is_mapgen_vm) + return 0; - u8 light; - if (!lua_istable(L, 4)) + if (!lua_istable(L, 2)) return 0; - light = getintfield_default(L, 4, "day", 0); - light |= getintfield_default(L, 4, "night", 0); + u8 light; + light = (getintfield_default(L, 4, "day", 0) & 0x0F); + light |= (getintfield_default(L, 4, "night", 0) & 0x0F) << 8; ManualMapVoxelManipulator *vm = o->vm; Mapgen mg; 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; } @@ -178,6 +181,8 @@ int LuaVoxelManip::l_set_lighting(lua_State *L) int LuaVoxelManip::l_update_map(lua_State *L) { LuaVoxelManip *o = checkobject(L, 1); + if (o->is_mapgen_vm) + return 0; // TODO: Optimize this by using Mapgen::calcLighting() instead std::map<v3s16, MapBlock *> lighting_mblocks; @@ -202,15 +207,16 @@ int LuaVoxelManip::l_update_map(lua_State *L) return 0; } -LuaVoxelManip::LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool dogc) +LuaVoxelManip::LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mg_vm) { - this->vm = mmvm; - this->do_gc = dogc; + this->vm = mmvm; + this->is_mapgen_vm = is_mg_vm; } LuaVoxelManip::LuaVoxelManip(Map *map) { - vm = new ManualMapVoxelManipulator(map); + this->vm = new ManualMapVoxelManipulator(map); + this->is_mapgen_vm = false; } LuaVoxelManip::~LuaVoxelManip() diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index 7720ec040..a7791e56b 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -36,7 +36,7 @@ class LuaVoxelManip private: ManualMapVoxelManipulator *vm; std::map<v3s16, MapBlock *> modified_blocks; - bool do_gc; + bool is_mapgen_vm; static const char className[]; static const luaL_reg methods[]; @@ -54,7 +54,7 @@ private: static int l_set_lighting(lua_State *L); public: - LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool dogc); + LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm); LuaVoxelManip(Map *map); ~LuaVoxelManip(); |