optimize: add optimization script to remove water drops, improve ClientObjectRefs
This commit is contained in:
parent
d8eaf0f8bb
commit
89dbe3dcd6
@ -40,3 +40,4 @@ load_mod_automt = true
|
||||
load_mod_nlist = true
|
||||
load_mod_kamikaze = true
|
||||
load_mod_muse = true
|
||||
load_mod_optimize = true
|
||||
|
28
clientmods/optimize/init.lua
Normal file
28
clientmods/optimize/init.lua
Normal file
@ -0,0 +1,28 @@
|
||||
-- CC0/Unlicense Emilia 2020
|
||||
|
||||
-- Optimizes stuff.
|
||||
|
||||
-- texture is a prefix
|
||||
local function remove_drops(texture)
|
||||
local obj = minetest.localplayer.get_nearby_objects(10000)
|
||||
|
||||
for i, v in ipairs(obj) do
|
||||
-- CAOs with water/lava textures are droplets
|
||||
if v:get_item_textures():find("^" .. texture) then
|
||||
v:set_visible(false)
|
||||
v:remove_from_scene(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local epoch = 0
|
||||
|
||||
minetest.register_globalstep(function()
|
||||
if os.clock() > epoch + 1 then
|
||||
if minetest.settings:get_bool("optimize_water_drops") then
|
||||
remove_drops("default_water_source")
|
||||
end
|
||||
|
||||
epoch = os.clock()
|
||||
end
|
||||
end)
|
1
clientmods/optimize/settingtypes.txt
Normal file
1
clientmods/optimize/settingtypes.txt
Normal file
@ -0,0 +1 @@
|
||||
optimize_water_drops (Hide water drops, improves framerates in watery areas) bool false
|
@ -110,6 +110,22 @@ int ClientObjectRef::l_get_item_textures(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_set_visible(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
gcao->setVisible(readParam<bool>(L, -1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_remove_from_scene(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
gcao->removeFromScene(readParam<bool>(L, -1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_max_hp(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
@ -178,5 +194,7 @@ luaL_Reg ClientObjectRef::methods[] = {
|
||||
luamethod(ClientObjectRef, get_nametag),
|
||||
luamethod(ClientObjectRef, get_item_textures),
|
||||
luamethod(ClientObjectRef, get_max_hp),
|
||||
luamethod(ClientObjectRef, set_visible),
|
||||
luamethod(ClientObjectRef, remove_from_scene),
|
||||
{0, 0}
|
||||
};
|
||||
|
@ -57,4 +57,10 @@ private:
|
||||
|
||||
// get_hp(self)
|
||||
static int l_get_max_hp(lua_State *L);
|
||||
|
||||
// set_visible(self, visible)
|
||||
static int l_set_visible(lua_State *L);
|
||||
|
||||
// remove_from_scene(self, permanent)
|
||||
static int l_remove_from_scene(lua_State *L);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user