51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+#include <map>
#include "lua_api/l_vmanip.h"
#include "lua_api/l_internal.h"
#include "common/c_content.h"
#include "common/c_converter.h"
+#include "common/c_packer.h"
#include "emerge.h"
#include "environment.h"
#include "map.h"
LuaVoxelManip *o = checkobject(L, 1);
MMVManip *vm = o->vm;
+ if (vm->isOrphan())
+ return 0;
v3s16 bp1 = getNodeBlockPos(check_v3s16(L, 2));
v3s16 bp2 = getNodeBlockPos(check_v3s16(L, 3));
if (use_buffer)
lua_pushvalue(L, 2);
else
- lua_newtable(L);
+ lua_createtable(L, volume, 0);
for (u32 i = 0; i != volume; i++) {
lua_Integer cid = vm->m_data[i].getContent();
LuaVoxelManip *o = checkobject(L, 1);
bool update_light = !lua_isboolean(L, 2) || readParam<bool>(L, 2);
+
GET_ENV_PTR;
ServerMap *map = &(env->getServerMap());
+
+ std::map<v3s16, MapBlock*> modified_blocks;
if (o->is_mapgen_vm || !update_light) {
- o->vm->blitBackAll(&(o->modified_blocks));
+ o->vm->blitBackAll(&modified_blocks);
} else {
- voxalgo::blit_back_with_light(map, o->vm,
- &(o->modified_blocks));
+ voxalgo::blit_back_with_light(map, o->vm, &modified_blocks);
}
MapEditEvent event;
event.type = MEET_OTHER;
- for (const auto &modified_block : o->modified_blocks)
- event.modified_blocks.insert(modified_block.first);
-
- map->dispatchEvent(&event);
+ for (const auto &it : modified_blocks)
+ event.modified_blocks.insert(it.first);
+ map->dispatchEvent(event);
- o->modified_blocks.clear();
return 0;
}
LuaVoxelManip *o = checkobject(L, 1);
- Map *map = &(env->getMap());
+ ServerMap *map = &(env->getServerMap());
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
MMVManip *vm = o->vm;
u32 volume = vm->m_area.getVolume();
- lua_newtable(L);
+ lua_createtable(L, volume, 0);
for (u32 i = 0; i != volume; i++) {
lua_Integer light = vm->m_data[i].param1;
lua_pushinteger(L, light);
if (use_buffer)
lua_pushvalue(L, 2);
else
- lua_newtable(L);
+ lua_createtable(L, volume, 0);
for (u32 i = 0; i != volume; i++) {
lua_Integer param2 = vm->m_data[i].param2;
return *(LuaVoxelManip **)ud; // unbox pointer
}
+void *LuaVoxelManip::packIn(lua_State *L, int idx)
+{
+ LuaVoxelManip *o = checkobject(L, idx);
+
+ if (o->is_mapgen_vm)
+ throw LuaError("nope");
+ return o->vm->clone();
+}
+
+void LuaVoxelManip::packOut(lua_State *L, void *ptr)
+{
+ MMVManip *vm = reinterpret_cast<MMVManip*>(ptr);
+ if (!L) {
+ delete vm;
+ return;
+ }
+
+ // Associate vmanip with map if the Lua env has one
+ Environment *env = getEnv(L);
+ if (env)
+ vm->reparent(&(env->getMap()));
+
+ LuaVoxelManip *o = new LuaVoxelManip(vm, false);
+ *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
+ luaL_getmetatable(L, className);
+ lua_setmetatable(L, -2);
+}
+
void LuaVoxelManip::Register(lua_State *L)
{
lua_newtable(L);
lua_pop(L, 1); // drop metatable
- luaL_openlib(L, 0, methods, 0); // fill methodtable
+ luaL_register(L, nullptr, methods); // fill methodtable
lua_pop(L, 1); // drop methodtable
// Can be created from Lua (VoxelManip())
lua_register(L, className, create_object);
+
+ script_register_packer(L, className, packIn, packOut);
}
const char LuaVoxelManip::className[] = "VoxelManip";