summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_vmanip.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-06-27 21:12:44 -0400
committerkwolekr <kwolekr@minetest.net>2013-06-27 22:35:35 -0400
commit6b3169e4d0ebd82661d7cca9e3a381124a897f1a (patch)
tree2990953547b3188aee6e5dfa7c68670e0046d31d /src/script/lua_api/l_vmanip.cpp
parent2e292b67a0a02b045969034c06aaf92b42a83a81 (diff)
downloadminetest-6b3169e4d0ebd82661d7cca9e3a381124a897f1a.tar.gz
minetest-6b3169e4d0ebd82661d7cca9e3a381124a897f1a.tar.bz2
minetest-6b3169e4d0ebd82661d7cca9e3a381124a897f1a.zip
LuaVoxelManip: Separate VoxelManip data get/set from emerging/blitting data back to map
Diffstat (limited to 'src/script/lua_api/l_vmanip.cpp')
-rw-r--r--src/script/lua_api/l_vmanip.cpp54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp
index 6743f40f9..f753f5f27 100644
--- a/src/script/lua_api/l_vmanip.cpp
+++ b/src/script/lua_api/l_vmanip.cpp
@@ -39,42 +39,52 @@ int LuaVoxelManip::gc_object(lua_State *L)
return 0;
}
-int LuaVoxelManip::l_read_chunk(lua_State *L)
+int LuaVoxelManip::l_read_from_map(lua_State *L)
{
LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
v3s16 bp1 = getNodeBlockPos(read_v3s16(L, 2));
v3s16 bp2 = getNodeBlockPos(read_v3s16(L, 3));
sortBoxVerticies(bp1, bp2);
- ManualMapVoxelManipulator *vm = o->vm;
+
vm->initialEmerge(bp1, bp2);
- v3s16 emerged_p1 = vm->m_area.MinEdge;
- v3s16 emerged_p2 = vm->m_area.MaxEdge;
+ push_v3s16(L, vm->m_area.MinEdge);
+ push_v3s16(L, vm->m_area.MaxEdge);
+
+ return 2;
+}
+
+int LuaVoxelManip::l_get_data(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
int volume = vm->m_area.getVolume();
lua_newtable(L);
for (int i = 0; i != volume; i++) {
- lua_Number cid = vm->m_data[i].getContent();
- lua_pushnumber(L, cid);
+ lua_Integer cid = vm->m_data[i].getContent();
+ lua_pushinteger(L, cid);
lua_rawseti(L, -2, i + 1);
}
- push_v3s16(L, emerged_p1);
- push_v3s16(L, emerged_p2);
-
- return 3;
+ return 1;
}
-int LuaVoxelManip::l_write_chunk(lua_State *L)
+int LuaVoxelManip::l_set_data(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
+
LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
+
if (!lua_istable(L, 2))
return 0;
- ManualMapVoxelManipulator *vm = o->vm;
-
int volume = vm->m_area.getVolume();
for (int i = 0; i != volume; i++) {
lua_rawgeti(L, 2, i + 1);
@@ -84,10 +94,18 @@ int LuaVoxelManip::l_write_chunk(lua_State *L)
lua_pop(L, 1);
}
+
+ return 0;
+}
+
+int LuaVoxelManip::l_write_to_map(lua_State *L)
+{
+ LuaVoxelManip *o = checkobject(L, 1);
+ ManualMapVoxelManipulator *vm = o->vm;
vm->blitBackAll(&o->modified_blocks);
-
- return 0;
+
+ return 0;
}
int LuaVoxelManip::l_update_liquids(lua_State *L)
@@ -258,8 +276,10 @@ void LuaVoxelManip::Register(lua_State *L)
const char LuaVoxelManip::className[] = "VoxelManip";
const luaL_reg LuaVoxelManip::methods[] = {
- luamethod(LuaVoxelManip, read_chunk),
- luamethod(LuaVoxelManip, write_chunk),
+ luamethod(LuaVoxelManip, read_from_map),
+ luamethod(LuaVoxelManip, get_data),
+ luamethod(LuaVoxelManip, set_data),
+ luamethod(LuaVoxelManip, write_to_map),
luamethod(LuaVoxelManip, update_map),
luamethod(LuaVoxelManip, update_liquids),
luamethod(LuaVoxelManip, calc_lighting),