]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/lua_api/l_vmanip.cpp
Light update for map blocks
[dragonfireclient.git] / src / script / lua_api / l_vmanip.cpp
index 0d8123acd437eaea75b8e8c08398df5a5667fcef..254a7e5a64fbfaf92455576d3aefeeb11a3d445a 100644 (file)
@@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "server.h"
 #include "mapgen.h"
+#include "voxelalgorithms.h"
 
 // garbage collector
 int LuaVoxelManip::gc_object(lua_State *L)
@@ -109,10 +110,25 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
        MAP_LOCK_REQUIRED;
 
        LuaVoxelManip *o = checkobject(L, 1);
-       MMVManip *vm = o->vm;
+       bool update_light = lua_isboolean(L, 2) ? lua_toboolean(L, 2) : true;
+       GET_ENV_PTR;
+       ServerMap *map = &(env->getServerMap());
+       if (o->is_mapgen_vm || !update_light) {
+               o->vm->blitBackAll(&(o->modified_blocks));
+       } else {
+               voxalgo::blit_back_with_light(map, o->vm,
+                       &(o->modified_blocks));
+       }
 
-       vm->blitBackAll(&o->modified_blocks);
+       MapEditEvent event;
+       event.type = MEET_OTHER;
+       for (std::map<v3s16, MapBlock *>::iterator it = o->modified_blocks.begin();
+                       it != o->modified_blocks.end(); ++it)
+               event.modified_blocks.insert(it->first);
+
+       map->dispatchEvent(&event);
 
+       o->modified_blocks.clear();
        return 0;
 }
 
@@ -277,11 +293,17 @@ int LuaVoxelManip::l_get_param2_data(lua_State *L)
        NO_MAP_LOCK_REQUIRED;
 
        LuaVoxelManip *o = checkobject(L, 1);
+       bool use_buffer  = lua_istable(L, 2);
+
        MMVManip *vm = o->vm;
 
        u32 volume = vm->m_area.getVolume();
 
-       lua_newtable(L);
+       if (use_buffer)
+               lua_pushvalue(L, 2);
+       else
+               lua_newtable(L);
+
        for (u32 i = 0; i != volume; i++) {
                lua_Integer param2 = vm->m_data[i].param2;
                lua_pushinteger(L, param2);
@@ -316,33 +338,6 @@ int LuaVoxelManip::l_set_param2_data(lua_State *L)
 
 int LuaVoxelManip::l_update_map(lua_State *L)
 {
-       GET_ENV_PTR;
-
-       LuaVoxelManip *o = checkobject(L, 1);
-       if (o->is_mapgen_vm)
-               return 0;
-
-       Map *map = &(env->getMap());
-
-       // TODO: Optimize this by using Mapgen::calcLighting() instead
-       std::map<v3s16, MapBlock *> lighting_mblocks;
-       std::map<v3s16, MapBlock *> *mblocks = &o->modified_blocks;
-
-       lighting_mblocks.insert(mblocks->begin(), mblocks->end());
-
-       map->updateLighting(lighting_mblocks, *mblocks);
-
-       MapEditEvent event;
-       event.type = MEET_OTHER;
-       for (std::map<v3s16, MapBlock *>::iterator
-               it = mblocks->begin();
-               it != mblocks->end(); ++it)
-               event.modified_blocks.insert(it->first);
-
-       map->dispatchEvent(&event);
-
-       mblocks->clear();
-
        return 0;
 }
 
@@ -458,7 +453,7 @@ void LuaVoxelManip::Register(lua_State *L)
 }
 
 const char LuaVoxelManip::className[] = "VoxelManip";
-const luaL_reg LuaVoxelManip::methods[] = {
+const luaL_Reg LuaVoxelManip::methods[] = {
        luamethod(LuaVoxelManip, read_from_map),
        luamethod(LuaVoxelManip, get_data),
        luamethod(LuaVoxelManip, set_data),