summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-05-05 20:49:57 +0200
committersfan5 <sfan5@live.de>2022-05-08 19:12:10 +0200
commit7fff9da71d2de352e0afea7482fc2e26534a51a4 (patch)
treef076924c543a5eb5876bc52f78256a2a80000167 /builtin
parentf128f4cba14aad9c7bbf46b79bb6147a49a3595b (diff)
downloadminetest-7fff9da71d2de352e0afea7482fc2e26534a51a4.tar.gz
minetest-7fff9da71d2de352e0afea7482fc2e26534a51a4.tar.bz2
minetest-7fff9da71d2de352e0afea7482fc2e26534a51a4.zip
item_entity: Cache collisionbox for use in on_step
I don't have absolute numbers but if calls to get_properties() take up 30%+ of on_step() execution time that's bound to matter.
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/item_entity.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua
index 3c058c48d..53f98a7c7 100644
--- a/builtin/game/item_entity.lua
+++ b/builtin/game/item_entity.lua
@@ -59,17 +59,20 @@ core.register_entity(":__builtin:item", {
math.floor(def.light_source / 2 + 0.5)
local size_bias = 1e-3 * math.random() -- small random bias to counter Z-fighting
+ local c = {-size, -size, -size, size, size, size}
self.object:set_properties({
is_visible = true,
visual = "wielditem",
textures = {itemname},
visual_size = {x = size + size_bias, y = size + size_bias},
- collisionbox = {-size, -size, -size, size, size, size},
+ collisionbox = c,
automatic_rotate = math.pi * 0.5 * 0.2 / size,
wield_item = self.itemstring,
glow = glow,
})
+ -- cache for usage in on_step
+ self._collisionbox = c
end,
get_staticdata = function(self)
@@ -94,6 +97,7 @@ core.register_entity(":__builtin:item", {
self.object:set_armor_groups({immortal = 1})
self.object:set_velocity({x = 0, y = 2, z = 0})
self.object:set_acceleration({x = 0, y = -gravity, z = 0})
+ self._collisionbox = self.initial_properties.collisionbox
self:set_item()
end,
@@ -164,7 +168,7 @@ core.register_entity(":__builtin:item", {
local pos = self.object:get_pos()
local node = core.get_node_or_nil({
x = pos.x,
- y = pos.y + self.object:get_properties().collisionbox[2] - 0.05,
+ y = pos.y + self._collisionbox[2] - 0.05,
z = pos.z
})
-- Delete in 'ignore' nodes
@@ -177,7 +181,7 @@ core.register_entity(":__builtin:item", {
if self.force_out then
-- This code runs after the entity got a push from the is_stuck code.
-- It makes sure the entity is entirely outside the solid node
- local c = self.object:get_properties().collisionbox
+ local c = self._collisionbox
local s = self.force_out_start
local f = self.force_out
local ok = (f.x > 0 and pos.x + c[1] > s.x + 0.5) or