Performance Improvements

This commit is contained in:
ElCeejo 2022-08-27 20:07:53 -07:00
parent 1df2f0e7f4
commit d539f9bea5
3 changed files with 33 additions and 19 deletions

View file

@ -2,6 +2,7 @@
-- Boids --
-----------
local abs = math.abs
local random = math.random
local function average(tbl)
@ -101,10 +102,13 @@ function creatura.get_boid_angle(self, _boids, range)
for i = 1, #boids do
local boid = boids[i]
if boid:get_pos() then
local boid_pos = boid:get_pos()
table.insert(positions, boid_pos)
if boid ~= self.object then
table.insert(lifts, vec_normal(boid:get_velocity()).y)
local vel = boid:get_velocity()
if boid ~= self.object
and (abs(vel.x) > 0.1
or abs(vel.z) > 0.1) then
local boid_pos = boid:get_pos()
table.insert(positions, boid_pos)
table.insert(lifts, vec_normal(vel).y)
table.insert(angles, boid:get_yaw())
if not closest_pos
or vec_dist(pos, boid_pos) < vec_dist(pos, closest_pos) then

View file

@ -71,6 +71,9 @@ end
local mob = {
max_health = 20,
max_breath = 30,
fire_resistance = 0.5,
fall_resistance = 0,
armor_groups = {fleshy = 100},
damage = 2,
speed = 4,
@ -86,6 +89,7 @@ local mob = {
fancy_collide = false,
bouyancy_multiplier = 1,
hydrodynamics_multiplier = 1
}
local mob_meta = {__index = mob}
@ -570,8 +574,8 @@ end
-- Return current collisionbox
function mob:get_hitbox()
if not self.properties then return self.collisionbox end
return self.properties.collisionbox
if not self:get_props() then return self.collisionbox end
return self:get_props().collisionbox
end
-- Return height of current collisionbox
@ -584,8 +588,8 @@ end
-- Return current visual size
function mob:get_visual_size()
if not self.properties then return end
return self.properties.visual_size
if not self:get_props() then return end
return self:get_props().visual_size
end
local function is_group_in_table(tbl, name)
@ -670,6 +674,12 @@ function mob:store_nearby_objects(radius)
return objs
end
function mob:get_props()
local props = self.properties or self.object and self.object:get_properties()
self.properties = props
return props
end
-- Actions
function mob:set_action(func)
@ -732,7 +742,7 @@ end
-- Functions
function mob:activate(staticdata, dtime)
self.properties = self.object:get_properties()
self:get_props()
self.width = self:get_hitbox()[4] or 0.5
self.height = self:get_height() or 1
self._tyaw = self.object:get_yaw()
@ -776,7 +786,7 @@ function mob:activate(staticdata, dtime)
-- Initialize Stats and Visuals
if not self.textures then
local textures = self.properties.textures
local textures = self:get_props().textures
if textures then self.textures = textures end
end
@ -859,11 +869,11 @@ function mob:on_step(dtime, moveresult)
prop_tick = prop_tick - 1
if prop_tick <= 0 then
self.stand_node = minetest.get_node(self.stand_pos)
-- Cached Geometry
self.properties = self.object:get_properties()
prop_tick = 6
end
if self:timer(1) then
self.width = self:get_hitbox()[4] or 0.5
self.height = self:get_height() or 1
prop_tick = 6
end
if self._vitals then
self:_vitals()
@ -890,6 +900,7 @@ function mob:on_step(dtime, moveresult)
and self.perm_data then
self:step_func(dtime, moveresult)
end
self.properties = nil
self.active_time = self.active_time + dtime
if self.despawn_after
and self.active_time >= self.despawn_after then
@ -1055,7 +1066,7 @@ function mob:_physics(moveresult)
end
local move_data = self._movement_data
if not in_liquid
and not move_data.func
--and not move_data.func
and move_data.gravity ~= 0 then
local vel = self.object:get_velocity()
if on_ground then
@ -1262,6 +1273,9 @@ function mob:_vitals()
self._breath = self._breath - 1
self:memorize("_breath", self._breath)
end
else
self._breath = self._breath + 1
self:memorize("_breath", self._breath)
end
end
if (not self.fire_resistance

View file

@ -568,7 +568,7 @@ function creatura.register_abm_spawn(mob, def)
if not creatura.is_pos_moveable(spawn_pos, mob_width, mob_height) then
spawn_pos = pos
end
local obj = minetest.add_entity(pos, mob)
local obj = minetest.add_entity(spawn_pos, mob)
if obj
and creatura.registered_on_spawns[mob]
and #creatura.registered_on_spawns[mob] > 0 then
@ -590,10 +590,6 @@ function creatura.register_abm_spawn(mob, def)
end
end
for _ = 1, group_size do
obj = minetest.add_entity(pos, mob)
end
minetest.log("action",
"[Creatura] [ABM Spawning] Spawned " .. group_size .. " " .. mob .. " at " .. minetest.pos_to_string(pos))