LuaVoxelManip: Remove blank allocator

This commit is contained in:
kwolekr 2014-12-29 01:31:37 -05:00
parent 3c637b4baf
commit cc3ab5efa5
6 changed files with 22 additions and 46 deletions

@ -1613,7 +1613,7 @@ minetest.get_perlin(seeddiff, octaves, persistence, scale)
minetest.get_voxel_manip() minetest.get_voxel_manip()
^ Return voxel manipulator object ^ Return voxel manipulator object
minetest.get_voxel_manip(p1, p2) minetest.get_voxel_manip(p1, p2)
^ Return voxel manipulator object with blank data preallocated ^ Return voxel manipulator object with map pre-loaded
minetest.set_gen_notify(flags, {deco_ids}) minetest.set_gen_notify(flags, {deco_ids})
^ Set the types of on-generate notifications that should be collected ^ Set the types of on-generate notifications that should be collected
^ flags is a flag field with the available flags: ^ flags is a flag field with the available flags:
@ -2215,7 +2215,7 @@ methods:
VoxelManip: An interface to the MapVoxelManipulator for Lua VoxelManip: An interface to the MapVoxelManipulator for Lua
- Can be created via VoxelManip() - Can be created via VoxelManip()
- Also minetest.get_voxel_manip() - Also minetest.get_voxel_manip()
- Specify a pmin, pmax in either to allocate a blank chunk of data prefilled with cignore - Specify a pmin, pmax to create a VoxelManip with map already loaded
methods: methods:
- read_from_map(p1, p2): Reads a chunk of map from the map containing the region formed by p1 and p2. - read_from_map(p1, p2): Reads a chunk of map from the map containing the region formed by p1 and p2.
^ returns actual emerged pmin, actual emerged pmax ^ returns actual emerged pmin, actual emerged pmax

@ -3597,29 +3597,6 @@ ManualMapVoxelManipulator::~ManualMapVoxelManipulator()
{ {
} }
void ManualMapVoxelManipulator::initializeBlank(v3s16 blockpos_min,
v3s16 blockpos_max)
{
// Units of these are MapBlocks
v3s16 pmin = blockpos_min;
v3s16 pmax = blockpos_max;
VoxelArea block_area_nodes(pmin * MAP_BLOCKSIZE,
(pmax + 1) * MAP_BLOCKSIZE - v3s16(1,1,1));
addArea(block_area_nodes);
u32 extent = m_area.getVolume();
for (u32 i = 0; i != extent; i++)
m_data[i] = MapNode(CONTENT_IGNORE);
for (s32 z = pmin.Z; z <= pmax.Z; z++)
for (s32 y = pmin.Y; y <= pmax.Y; y++)
for (s32 x = pmin.X; x <= pmax.X; x++)
m_loaded_blocks[v3s16(x, y, z)] = 0;
m_is_dirty = false;
}
void ManualMapVoxelManipulator::initialEmerge(v3s16 blockpos_min, void ManualMapVoxelManipulator::initialEmerge(v3s16 blockpos_min,
v3s16 blockpos_max, bool load_if_inexistent) v3s16 blockpos_max, bool load_if_inexistent)
{ {

@ -189,7 +189,7 @@ public:
MapBlock * getBlockNoCreateNoEx(v3s16 p); MapBlock * getBlockNoCreateNoEx(v3s16 p);
/* Server overrides */ /* Server overrides */
virtual MapBlock * emergeBlock(v3s16 p, bool allow_generate=true) virtual MapBlock * emergeBlock(v3s16 p, bool create_blank=true)
{ return getBlockNoCreateNoEx(p); } { return getBlockNoCreateNoEx(p); }
// Returns InvalidPositionException if not found // Returns InvalidPositionException if not found
@ -550,8 +550,6 @@ public:
void setMap(Map *map) void setMap(Map *map)
{m_map = map;} {m_map = map;}
void initializeBlank(v3s16 pmin, v3s16 pmax);
void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max, void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
bool load_if_inexistent = true); bool load_if_inexistent = true);

@ -636,14 +636,9 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L)
GET_ENV_PTR; GET_ENV_PTR;
Map *map = &(env->getMap()); Map *map = &(env->getMap());
LuaVoxelManip *o = new LuaVoxelManip(map); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ?
new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) :
if (lua_istable(L, 1) && lua_istable(L, 2)) { new LuaVoxelManip(map);
v3s16 p1 = getNodeBlockPos(read_v3s16(L, 1));
v3s16 p2 = getNodeBlockPos(read_v3s16(L, 2));
sortBoxVerticies(p1, p2);
o->vm->initializeBlank(p1, p2);
}
*(void **)(lua_newuserdata(L, sizeof(void *))) = o; *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, "VoxelManip"); luaL_getmetatable(L, "VoxelManip");

@ -367,6 +367,17 @@ LuaVoxelManip::LuaVoxelManip(Map *map)
this->is_mapgen_vm = false; this->is_mapgen_vm = false;
} }
LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2)
{
this->vm = new ManualMapVoxelManipulator(map);
this->is_mapgen_vm = false;
v3s16 bp1 = getNodeBlockPos(p1);
v3s16 bp2 = getNodeBlockPos(p2);
sortBoxVerticies(bp1, bp2);
vm->initialEmerge(bp1, bp2);
}
LuaVoxelManip::~LuaVoxelManip() LuaVoxelManip::~LuaVoxelManip()
{ {
if (!is_mapgen_vm) if (!is_mapgen_vm)
@ -384,14 +395,9 @@ int LuaVoxelManip::create_object(lua_State *L)
return 0; return 0;
Map *map = &(env->getMap()); Map *map = &(env->getMap());
LuaVoxelManip *o = new LuaVoxelManip(map); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ?
new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) :
if (lua_istable(L, 1) && lua_istable(L, 2)) { new LuaVoxelManip(map);
v3s16 p1 = getNodeBlockPos(read_v3s16(L, 1));
v3s16 p2 = getNodeBlockPos(read_v3s16(L, 2));
sortBoxVerticies(p1, p2);
o->vm->initializeBlank(p1, p2);
}
*(void **)(lua_newuserdata(L, sizeof(void *))) = o; *(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className); luaL_getmetatable(L, className);

@ -33,6 +33,7 @@ class ManualMapVoxelManipulator;
*/ */
class LuaVoxelManip : public ModApiBase { class LuaVoxelManip : public ModApiBase {
private: private:
ManualMapVoxelManipulator *vm;
std::map<v3s16, MapBlock *> modified_blocks; std::map<v3s16, MapBlock *> modified_blocks;
bool is_mapgen_vm; bool is_mapgen_vm;
@ -64,9 +65,8 @@ private:
static int l_get_emerged_area(lua_State *L); static int l_get_emerged_area(lua_State *L);
public: public:
ManualMapVoxelManipulator *vm;
LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm); LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm);
LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2);
LuaVoxelManip(Map *map); LuaVoxelManip(Map *map);
~LuaVoxelManip(); ~LuaVoxelManip();