]> git.lizzy.rs Git - minetest.git/commitdiff
LuaVoxelManip: Add get_light_data() and set_light_data()
authorkwolekr <kwolekr@minetest.net>
Sat, 30 Nov 2013 02:16:08 +0000 (21:16 -0500)
committerkwolekr <kwolekr@minetest.net>
Sat, 30 Nov 2013 05:01:43 +0000 (00:01 -0500)
doc/lua_api.txt
src/script/lua_api/l_vmanip.cpp
src/script/lua_api/l_vmanip.h

index cd9e27b7a1e2112e5dacec037c5bc25707cb0f5a..b8ad99ce72556aef5ffca1c35937bff8add70e11 100644 (file)
@@ -1818,6 +1818,13 @@ methods:
 - set_lighting(light):  Set the lighting within the VoxelManip
   ^ light is a table, {day=<0...15>, night=<0...15>}
   ^ To be used only by a VoxelManip object from minetest.get_mapgen_object
+
+- get_light_data(): Gets the light data read into the VoxelManip object
+  ^ Returns an array (indicies 1 to volume) of integers ranging from 0 to 255
+  ^ Each value is the bitwise combination of day and night light values (0..15 each)
+  ^ light = day + (night * 16)
+- set_light_data(light_data):  Sets the param1 (light) contents of each node in the VoxelManip
+  ^ expects lighting data in the same format that get_light_data() returns
 - calc_lighting():  Calculate lighting within the VoxelManip
   ^ To be used only by a VoxelManip object from minetest.get_mapgen_object
 - update_liquids():  Update liquid flow
index db8884e10f290e4a91d2d257b1fa815def1f9e3a..5228b7c06319251993c5be22132e6af96c938443 100644 (file)
@@ -178,6 +178,48 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
        return 0;
 }
 
+int LuaVoxelManip::l_get_light_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_Integer light = vm->m_data[i].param1;
+               lua_pushinteger(L, light);
+               lua_rawseti(L, -2, i + 1);
+       }
+
+       return 1;
+}
+
+int LuaVoxelManip::l_set_light_data(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+
+       LuaVoxelManip *o = checkobject(L, 1);
+       ManualMapVoxelManipulator *vm = o->vm;
+
+       if (!lua_istable(L, 2))
+               return 0;
+
+       int volume = vm->m_area.getVolume();
+       for (int i = 0; i != volume; i++) {
+               lua_rawgeti(L, 2, i + 1);
+               u8 light = lua_tointeger(L, -1);
+
+               vm->m_data[i].param1 = light;
+
+               lua_pop(L, 1);
+       }
+
+       return 0;
+}
+
 int LuaVoxelManip::l_update_map(lua_State *L)
 {
        LuaVoxelManip *o = checkobject(L, 1);
@@ -299,5 +341,7 @@ const luaL_reg LuaVoxelManip::methods[] = {
        luamethod(LuaVoxelManip, update_liquids),
        luamethod(LuaVoxelManip, calc_lighting),
        luamethod(LuaVoxelManip, set_lighting),
+       luamethod(LuaVoxelManip, get_light_data),
+       luamethod(LuaVoxelManip, set_light_data),
        {0,0}
 };
index d2f035a3ee107e022feba391e5b3a309284d8130..b3393e09a30773158a079898bc2e20c92ba25eb9 100644 (file)
@@ -49,8 +49,11 @@ class LuaVoxelManip : public ModApiBase {
 
        static int l_update_map(lua_State *L);
        static int l_update_liquids(lua_State *L);
+
        static int l_calc_lighting(lua_State *L);
        static int l_set_lighting(lua_State *L);
+       static int l_get_light_data(lua_State *L);
+       static int l_set_light_data(lua_State *L);
 
 public:
        LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm);