]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
LuaVoxelManip: Add option to allocate blank data
authorkwolekr <kwolekr@minetest.net>
Sun, 28 Dec 2014 04:09:36 +0000 (23:09 -0500)
committerkwolekr <kwolekr@minetest.net>
Sun, 28 Dec 2014 04:09:36 +0000 (23:09 -0500)
doc/lua_api.txt
src/map.cpp
src/map.h
src/script/lua_api/l_env.cpp
src/script/lua_api/l_vmanip.cpp
src/script/lua_api/l_vmanip.h

index be17bb288ce029cdd8c277ccaa4bd670c7533bf1..0ceac1fca352451fea89984f49fc5618c5dd5b00 100644 (file)
@@ -1594,6 +1594,8 @@ minetest.get_perlin(seeddiff, octaves, persistence, scale)
 ^ Return world-specific perlin noise (int(worldseed)+seeddiff)
 minetest.get_voxel_manip()
 ^ Return voxel manipulator object
+minetest.get_voxel_manip(p1, p2)
+^ Return voxel manipulator object with blank data preallocated
 minetest.set_gen_notify(flags, {deco_ids})
 ^ Set the types of on-generate notifications that should be collected
 ^ flags is a flag field with the available flags:
@@ -2192,6 +2194,7 @@ methods:
 VoxelManip: An interface to the MapVoxelManipulator for Lua
 - Can be created via VoxelManip()
 - Also minetest.get_voxel_manip()
+- Specify a pmin, pmax in either to allocate a blank chunk of data prefilled with cignore
 methods:
 - 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
@@ -2223,6 +2226,7 @@ methods:
 - update_liquids():  Update liquid flow
 - was_modified(): Returns true or false if the data in the voxel manipulator had been modified since
   the last read from map, due to a call to minetest.set_data() on the loaded area elsewhere
+- get_emerged_area(): Returns actual emerged pmin, actual emerged pmax
 
 VoxelArea: A helper class for voxel areas
 - Can be created via VoxelArea:new{MinEdge=pmin, MaxEdge=pmax}
index fde5b585d72459c918a9f27276b6b1ee4ef5cbb6..05e07212db3d631ac286626f2b3a57f1d9ae7750 100644 (file)
@@ -3597,8 +3597,31 @@ 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,
-                                               v3s16 blockpos_max, bool load_if_inexistent)
+       v3s16 blockpos_max, bool load_if_inexistent)
 {
        TimeTaker timer1("initialEmerge", &emerge_time);
 
index 70082d664518955858b23bde116bee9901c3f472..57edd77088293ad5c7b49c76834704230144baf1 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -550,12 +550,14 @@ class ManualMapVoxelManipulator : public VoxelManipulator
        void setMap(Map *map)
        {m_map = map;}
 
+       void initializeBlank(v3s16 pmin, v3s16 pmax);
+
        void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
-                       bool load_if_inexistent = true);
+               bool load_if_inexistent = true);
 
        // This is much faster with big chunks of generated data
        void blitBackAll(std::map<v3s16, MapBlock*> * modified_blocks,
-                       bool overwrite_generated = true);
+               bool overwrite_generated = true);
 
        bool m_is_dirty;
 
index 3d2e204246c9adae5606211236a01f2ad7e6dc35..9e713b9b8977da159974111abcab044e6954c067 100644 (file)
@@ -638,6 +638,13 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L)
        Map *map = &(env->getMap());
        LuaVoxelManip *o = new LuaVoxelManip(map);
 
+       if (lua_istable(L, 1) && lua_istable(L, 2)) {
+               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;
        luaL_getmetatable(L, "VoxelManip");
        lua_setmetatable(L, -2);
index 554a573430827d37a593f2670d5332587c8ac7b8..fb52aa21a7508dff9734d7f1ba13bccdd70ef352 100644 (file)
@@ -345,6 +345,16 @@ int LuaVoxelManip::l_was_modified(lua_State *L)
        return 1;
 }
 
+int LuaVoxelManip::l_get_emerged_area(lua_State *L)
+{
+       LuaVoxelManip *o = checkobject(L, 1);
+
+       push_v3s16(L, o->vm->m_area.MinEdge);
+       push_v3s16(L, o->vm->m_area.MaxEdge);
+
+       return 2;
+}
+
 LuaVoxelManip::LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mg_vm)
 {
        this->vm           = mmvm;
@@ -376,6 +386,13 @@ int LuaVoxelManip::create_object(lua_State *L)
        Map *map = &(env->getMap());
        LuaVoxelManip *o = new LuaVoxelManip(map);
 
+       if (lua_istable(L, 1) && lua_istable(L, 2)) {
+               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;
        luaL_getmetatable(L, className);
        lua_setmetatable(L, -2);
@@ -440,5 +457,6 @@ const luaL_reg LuaVoxelManip::methods[] = {
        luamethod(LuaVoxelManip, get_param2_data),
        luamethod(LuaVoxelManip, set_param2_data),
        luamethod(LuaVoxelManip, was_modified),
+       luamethod(LuaVoxelManip, get_emerged_area),
        {0,0}
 };
index 608b555561036fc8eb043df0efb45c01ffbc5d05..ead6efbc495c1701fde0dcd6eba48c9587a115a7 100644 (file)
@@ -33,7 +33,6 @@ class ManualMapVoxelManipulator;
  */
 class LuaVoxelManip : public ModApiBase {
 private:
-       ManualMapVoxelManipulator *vm;
        std::map<v3s16, MapBlock *> modified_blocks;
        bool is_mapgen_vm;
 
@@ -62,8 +61,11 @@ class LuaVoxelManip : public ModApiBase {
        static int l_set_param2_data(lua_State *L);
 
        static int l_was_modified(lua_State *L);
+       static int l_get_emerged_area(lua_State *L);
 
 public:
+       ManualMapVoxelManipulator *vm;
+
        LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm);
        LuaVoxelManip(Map *map);
        ~LuaVoxelManip();