mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add VoxelManip:close() for explicit free
This commit is contained in:
parent
79e0d834fd
commit
e03957ec0c
3 changed files with 23 additions and 0 deletions
|
@ -5249,6 +5249,13 @@ Methods
|
|||
where the engine will keep the map and the VM in sync automatically.
|
||||
* Note: this doesn't do what you think it does and is subject to removal. Don't use it!
|
||||
* `get_emerged_area()`: Returns actual emerged minimum and maximum positions.
|
||||
* `close()`: Frees the data buffers associated with the VoxelManip object.
|
||||
It will become empty.
|
||||
* Since Lua's garbage collector is not aware of the potentially significant
|
||||
memory behind a VoxelManip, frequent VoxelManip usage can cause the server to
|
||||
run out of RAM. Therefore it's recommend to call this method once you're done
|
||||
with the VoxelManip.
|
||||
* (introduced in 5.13.0)
|
||||
|
||||
`VoxelArea`
|
||||
-----------
|
||||
|
|
|
@ -344,6 +344,19 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L)
|
|||
return 2;
|
||||
}
|
||||
|
||||
int LuaVoxelManip::l_close(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
||||
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
|
||||
|
||||
if (o->is_mapgen_vm)
|
||||
throw LuaError("Cannot dispose of mapgen VoxelManip object");
|
||||
o->vm->clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) :
|
||||
is_mapgen_vm(is_mg_vm),
|
||||
vm(mmvm)
|
||||
|
@ -451,5 +464,6 @@ const luaL_Reg LuaVoxelManip::methods[] = {
|
|||
luamethod(LuaVoxelManip, set_param2_data),
|
||||
luamethod(LuaVoxelManip, was_modified),
|
||||
luamethod(LuaVoxelManip, get_emerged_area),
|
||||
luamethod(LuaVoxelManip, close),
|
||||
{0,0}
|
||||
};
|
||||
|
|
|
@ -45,6 +45,8 @@ private:
|
|||
static int l_was_modified(lua_State *L);
|
||||
static int l_get_emerged_area(lua_State *L);
|
||||
|
||||
static int l_close(lua_State *L);
|
||||
|
||||
public:
|
||||
MMVManip *vm = nullptr;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue