Fix mob animation "memory leak"

This commit is contained in:
jordan4ibanez 2021-04-16 13:58:08 -04:00
parent 024cf46307
commit d0695e7929
3 changed files with 31 additions and 28 deletions

View File

@ -219,6 +219,7 @@ function mobs:register_mob(name, def)
breathes_in_water = def.breathes_in_water or false, breathes_in_water = def.breathes_in_water or false,
physical = true, physical = true,
collisionbox = collisionbox, collisionbox = collisionbox,
collide_with_objects = def.collide_with_objects or false,
selectionbox = def.selectionbox or def.collisionbox, selectionbox = def.selectionbox or def.collisionbox,
visual = def.visual, visual = def.visual,
visual_size = def.visual_size or {x = 1, y = 1}, visual_size = def.visual_size or {x = 1, y = 1},
@ -306,6 +307,8 @@ function mobs:register_mob(name, def)
walk_timer = 0, walk_timer = 0,
stand_timer = 0, stand_timer = 0,
wandering = true, wandering = true,
current_animation = "",
--set_animation = mobs.set_animation,
--end j4i stuff --end j4i stuff
-- MCL2 extensions -- MCL2 extensions
@ -331,27 +334,21 @@ function mobs:register_mob(name, def)
on_spawn = def.on_spawn, on_spawn = def.on_spawn,
on_blast = def.on_blast or do_tnt, --on_blast = def.on_blast or do_tnt,
on_step = mobs.mob_step, on_step = mobs.mob_step,
do_punch = def.do_punch, --do_punch = def.do_punch,
on_punch = mob_punch, --on_punch = mob_punch,
on_breed = def.on_breed, --on_breed = def.on_breed,
on_grown = def.on_grown, --on_grown = def.on_grown,
on_detach_child = mob_detach_child, --on_detach_child = mob_detach_child,
on_activate = function(self, staticdata, dtime) on_activate = function(self, staticdata, dtime)
--this is a temporary hack so mobs stop
--glitching and acting really weird with the
--default built in engine collision detection
self.object:set_properties({
collide_with_objects = false,
})
self.object:set_acceleration(vector_new(0,-9.81, 0)) self.object:set_acceleration(vector_new(0,-9.81, 0))
return mobs.mob_activate(self, staticdata, def, dtime) return mobs.mob_activate(self, staticdata, def, dtime)
end, end,
@ -360,8 +357,7 @@ function mobs:register_mob(name, def)
return mobs.mob_staticdata(self) return mobs.mob_staticdata(self)
end, end,
harmed_by_heal = def.harmed_by_heal, --harmed_by_heal = def.harmed_by_heal,
}) })
if minetest_get_modpath("doc_identifier") ~= nil then if minetest_get_modpath("doc_identifier") ~= nil then

View File

@ -50,7 +50,13 @@ local state_execution = function(self,dtime)
if self.state == "stand" then if self.state == "stand" then
print("stand") --do animation
mobs.set_mob_animation(self, "stand")
--set the velocity of the mob
mobs.set_velocity(self,0)
--print("stand")
elseif self.state == "walk" then elseif self.state == "walk" then
@ -67,7 +73,7 @@ local state_execution = function(self,dtime)
end end
--do animation --do animation
mobs.set_animation(self, "walk") mobs.set_mob_animation(self, "walk")
--enable rotation locking --enable rotation locking
mobs.movement_rotation_lock(self) mobs.movement_rotation_lock(self)

View File

@ -1,7 +1,7 @@
local math_pi = math.pi local math_pi = math.pi
-- set defined animation -- set defined animation
mobs.set_animation = function(self, anim, fixed_frame) mobs.set_mob_animation = function(self, anim, fixed_frame)
if not self.animation or not anim then if not self.animation or not anim then
return return
@ -11,23 +11,21 @@ mobs.set_animation = function(self, anim, fixed_frame)
return return
end end
self.animation.current = self.animation.current or ""
--animations break if they are constantly set
--so we put this return gate to check if it is
--already at the animation we are trying to implement
if self.animation.current == anim then
return
end
if (not self.animation[anim .. "_start"] or not self.animation[anim .. "_end"]) then if (not self.animation[anim .. "_start"] or not self.animation[anim .. "_end"]) then
return return
end end
self.animation.current = anim --animations break if they are constantly set
--so we put this return gate to check if it is
--already at the animation we are trying to implement
if self.current_animation == anim then
return
end
local a_start = self.animation[anim .. "_start"] local a_start = self.animation[anim .. "_start"]
local a_end local a_end
if fixed_frame then if fixed_frame then
a_end = a_start a_end = a_start
else else
@ -39,6 +37,9 @@ mobs.set_animation = function(self, anim, fixed_frame)
y = a_end}, y = a_end},
self.animation[anim .. "_speed"] or self.animation.speed_normal or 15, self.animation[anim .. "_speed"] or self.animation.speed_normal or 15,
0, self.animation[anim .. "_loop"] ~= false) 0, self.animation[anim .. "_loop"] ~= false)
self.current_animation = anim
end end