Skip to content

Commit cc3ab5e

Browse files
committedDec 29, 2014
LuaVoxelManip: Remove blank allocator
1 parent 3c637b4 commit cc3ab5e

File tree

6 files changed

+22
-46
lines changed

6 files changed

+22
-46
lines changed
 

‎doc/lua_api.txt

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

‎src/map.cpp

-23
Original file line numberDiff line numberDiff line change
@@ -3597,29 +3597,6 @@ ManualMapVoxelManipulator::~ManualMapVoxelManipulator()
35973597
{
35983598
}
35993599

3600-
void ManualMapVoxelManipulator::initializeBlank(v3s16 blockpos_min,
3601-
v3s16 blockpos_max)
3602-
{
3603-
// Units of these are MapBlocks
3604-
v3s16 pmin = blockpos_min;
3605-
v3s16 pmax = blockpos_max;
3606-
3607-
VoxelArea block_area_nodes(pmin * MAP_BLOCKSIZE,
3608-
(pmax + 1) * MAP_BLOCKSIZE - v3s16(1,1,1));
3609-
3610-
addArea(block_area_nodes);
3611-
u32 extent = m_area.getVolume();
3612-
for (u32 i = 0; i != extent; i++)
3613-
m_data[i] = MapNode(CONTENT_IGNORE);
3614-
3615-
for (s32 z = pmin.Z; z <= pmax.Z; z++)
3616-
for (s32 y = pmin.Y; y <= pmax.Y; y++)
3617-
for (s32 x = pmin.X; x <= pmax.X; x++)
3618-
m_loaded_blocks[v3s16(x, y, z)] = 0;
3619-
3620-
m_is_dirty = false;
3621-
}
3622-
36233600
void ManualMapVoxelManipulator::initialEmerge(v3s16 blockpos_min,
36243601
v3s16 blockpos_max, bool load_if_inexistent)
36253602
{

‎src/map.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class Map /*: public NodeContainer*/
189189
MapBlock * getBlockNoCreateNoEx(v3s16 p);
190190

191191
/* Server overrides */
192-
virtual MapBlock * emergeBlock(v3s16 p, bool allow_generate=true)
192+
virtual MapBlock * emergeBlock(v3s16 p, bool create_blank=true)
193193
{ return getBlockNoCreateNoEx(p); }
194194

195195
// Returns InvalidPositionException if not found
@@ -550,8 +550,6 @@ class ManualMapVoxelManipulator : public VoxelManipulator
550550
void setMap(Map *map)
551551
{m_map = map;}
552552

553-
void initializeBlank(v3s16 pmin, v3s16 pmax);
554-
555553
void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
556554
bool load_if_inexistent = true);
557555

‎src/script/lua_api/l_env.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,9 @@ int ModApiEnvMod::l_get_voxel_manip(lua_State *L)
636636
GET_ENV_PTR;
637637

638638
Map *map = &(env->getMap());
639-
LuaVoxelManip *o = new LuaVoxelManip(map);
640-
641-
if (lua_istable(L, 1) && lua_istable(L, 2)) {
642-
v3s16 p1 = getNodeBlockPos(read_v3s16(L, 1));
643-
v3s16 p2 = getNodeBlockPos(read_v3s16(L, 2));
644-
sortBoxVerticies(p1, p2);
645-
o->vm->initializeBlank(p1, p2);
646-
}
639+
LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ?
640+
new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) :
641+
new LuaVoxelManip(map);
647642

648643
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
649644
luaL_getmetatable(L, "VoxelManip");

‎src/script/lua_api/l_vmanip.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,17 @@ LuaVoxelManip::LuaVoxelManip(Map *map)
367367
this->is_mapgen_vm = false;
368368
}
369369

370+
LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2)
371+
{
372+
this->vm = new ManualMapVoxelManipulator(map);
373+
this->is_mapgen_vm = false;
374+
375+
v3s16 bp1 = getNodeBlockPos(p1);
376+
v3s16 bp2 = getNodeBlockPos(p2);
377+
sortBoxVerticies(bp1, bp2);
378+
vm->initialEmerge(bp1, bp2);
379+
}
380+
370381
LuaVoxelManip::~LuaVoxelManip()
371382
{
372383
if (!is_mapgen_vm)
@@ -384,14 +395,9 @@ int LuaVoxelManip::create_object(lua_State *L)
384395
return 0;
385396

386397
Map *map = &(env->getMap());
387-
LuaVoxelManip *o = new LuaVoxelManip(map);
388-
389-
if (lua_istable(L, 1) && lua_istable(L, 2)) {
390-
v3s16 p1 = getNodeBlockPos(read_v3s16(L, 1));
391-
v3s16 p2 = getNodeBlockPos(read_v3s16(L, 2));
392-
sortBoxVerticies(p1, p2);
393-
o->vm->initializeBlank(p1, p2);
394-
}
398+
LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ?
399+
new LuaVoxelManip(map, read_v3s16(L, 1), read_v3s16(L, 2)) :
400+
new LuaVoxelManip(map);
395401

396402
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
397403
luaL_getmetatable(L, className);

‎src/script/lua_api/l_vmanip.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ManualMapVoxelManipulator;
3333
*/
3434
class LuaVoxelManip : public ModApiBase {
3535
private:
36+
ManualMapVoxelManipulator *vm;
3637
std::map<v3s16, MapBlock *> modified_blocks;
3738
bool is_mapgen_vm;
3839

@@ -64,9 +65,8 @@ class LuaVoxelManip : public ModApiBase {
6465
static int l_get_emerged_area(lua_State *L);
6566

6667
public:
67-
ManualMapVoxelManipulator *vm;
68-
6968
LuaVoxelManip(ManualMapVoxelManipulator *mmvm, bool is_mapgen_vm);
69+
LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2);
7070
LuaVoxelManip(Map *map);
7171
~LuaVoxelManip();
7272

0 commit comments

Comments
 (0)
Please sign in to comment.