#include "emerge.h"
#include "environment.h"
#include "map.h"
+#include "mapblock.h"
#include "server.h"
-#include "mapgen.h"
+#include "mapgen/mapgen.h"
+#include "voxelalgorithms.h"
// garbage collector
int LuaVoxelManip::gc_object(lua_State *L)
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();
MMVManip *vm = o->vm;
if (!lua_istable(L, 2))
- return 0;
+ throw LuaError("VoxelManip:set_data called with missing parameter");
u32 volume = vm->m_area.getVolume();
for (u32 i = 0; i != volume; i++) {
MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
- MMVManip *vm = o->vm;
+ bool update_light = !lua_isboolean(L, 2) || readParam<bool>(L, 2);
+ 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));
+ }
+
+ MapEditEvent event;
+ event.type = MEET_OTHER;
+ for (const auto &modified_block : o->modified_blocks)
+ event.modified_blocks.insert(modified_block.first);
- vm->blitBackAll(&o->modified_blocks);
+ map->dispatchEvent(event);
+ o->modified_blocks.clear();
return 0;
}
{
NO_MAP_LOCK_REQUIRED;
- INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+ const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
LuaVoxelManip *o = checkobject(L, 1);
v3s16 pos = check_v3s16(L, 2);
{
NO_MAP_LOCK_REQUIRED;
- INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+ const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
LuaVoxelManip *o = checkobject(L, 1);
v3s16 pos = check_v3s16(L, 2);
LuaVoxelManip *o = checkobject(L, 1);
Map *map = &(env->getMap());
- INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+ const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
MMVManip *vm = o->vm;
Mapgen mg;
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
- if (!o->is_mapgen_vm)
+ if (!o->is_mapgen_vm) {
+ warningstream << "VoxelManip:calc_lighting called for a non-mapgen "
+ "VoxelManip object" << std::endl;
return 0;
+ }
- INodeDefManager *ndef = getServer(L)->getNodeDefManager();
+ const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
EmergeManager *emerge = getServer(L)->getEmergeManager();
MMVManip *vm = o->vm;
v3s16 fpmax = vm->m_area.MaxEdge;
v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) : fpmin + yblock;
v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) : fpmax - yblock;
- bool propagate_shadow = lua_isboolean(L, 4) ? lua_toboolean(L, 4) : true;
+ bool propagate_shadow = !lua_isboolean(L, 4) || readParam<bool>(L, 4);
sortBoxVerticies(pmin, pmax);
if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
- if (!o->is_mapgen_vm)
+ if (!o->is_mapgen_vm) {
+ warningstream << "VoxelManip:set_lighting called for a non-mapgen "
+ "VoxelManip object" << std::endl;
return 0;
+ }
if (!lua_istable(L, 2))
- return 0;
+ throw LuaError("VoxelManip:set_lighting called with missing parameter");
u8 light;
light = (getintfield_default(L, 2, "day", 0) & 0x0F);
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);
MMVManip *vm = o->vm;
if (!lua_istable(L, 2))
- return 0;
+ throw LuaError("VoxelManip:set_light_data called with missing "
+ "parameter");
u32 volume = vm->m_area.getVolume();
for (u32 i = 0; i != volume; i++) {
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;
MMVManip *vm = o->vm;
if (!lua_istable(L, 2))
- return 0;
+ throw LuaError("VoxelManip:set_param2_data called with missing "
+ "parameter");
u32 volume = vm->m_area.getVolume();
for (u32 i = 0; i != volume; i++) {
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;
}
return 2;
}
-LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm)
+LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) :
+ is_mapgen_vm(is_mg_vm),
+ vm(mmvm)
{
- this->vm = mmvm;
- this->is_mapgen_vm = is_mg_vm;
}
-LuaVoxelManip::LuaVoxelManip(Map *map)
+LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map))
{
- this->vm = new MMVManip(map);
- this->is_mapgen_vm = false;
}
LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2)
{
- this->vm = new MMVManip(map);
- this->is_mapgen_vm = false;
+ vm = new MMVManip(map);
v3s16 bp1 = getNodeBlockPos(p1);
v3s16 bp2 = getNodeBlockPos(p2);
}
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),