[lua] Fixed animation layering. Cause of the bug was a few places using pairs instead of manually iterating through all indices from 0 to len. Closes #1574.

This commit is contained in:
badlogic 2020-01-11 15:35:56 +01:00
parent 1855870d37
commit 9b801a993e
2 changed files with 78 additions and 51 deletions

View File

@ -227,7 +227,10 @@ function AnimationState:update (delta)
delta = delta * self.timeScale
local tracks = self.tracks
local queue = self.queue
for i,current in pairs(tracks) do
local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then
current.animationLast = current.nextAnimationLast
current.trackLast = current.nextTrackLast
@ -290,6 +293,7 @@ function AnimationState:update (delta)
end
end
end
i = i + 1
end
queue:drain()
@ -329,7 +333,11 @@ function AnimationState:apply (skeleton)
local queue = self.queue
local applied = false
for i,current in pairs(tracks) do
local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then
if not (current == nil or current.delay > 0) then
applied = true
@ -375,6 +383,8 @@ function AnimationState:apply (skeleton)
current.nextTrackLast = current.trackTime
end
end
i = i + 1
end
queue:drain()
return applied
@ -602,7 +612,9 @@ function AnimationState:clearTracks ()
local tracks = self.tracks
local oldDrainDisabled = queue.drainDisabled
queue.drainDisabled = true;
for i,track in pairs(tracks) do
local numTracks = #tracks
local i = 0
while i <= numTracks do
self:clearTrack(i)
end
tracks = {}
@ -751,8 +763,13 @@ function AnimationState:setEmptyAnimations (mixDuration)
local queue = self.queue
local oldDrainDisabled = queue.drainDisabled
queue.drainDisabled = true
for i,current in pairs(self.tracks) do
local tracks = self.tracks
local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then self:setEmptyAnimation(current.trackIndex, mixDuration) end
i = i + 1
end
queue.drainDisabled = oldDrainDisabled
queue:drain()
@ -814,7 +831,12 @@ function AnimationState:_animationsChanged ()
self.propertyIDs = {}
local highestIndex = -1
for i, entry in pairs(self.tracks) do
local tracks = self.tracks
local numTracks = #tracks
local i = 0
while i <= numTracks do
current = tracks[i]
if current then
if i > highestIndex then highestIndex = i end
if entry then
@ -830,6 +852,8 @@ function AnimationState:_animationsChanged ()
until (entry == nil)
end
end
i = i + 1
end
self.propertyIDs = {}
for i = highestIndex, 0, -1 do

View File

@ -174,10 +174,12 @@ function utils.randomTriangularWith(min, max, mode)
end
function utils.testBit(value, bit)
if (value == nil) then return 0 end
return value % (2 * bit) >= bit
end
function utils.setBit(value, bit)
if (value == nil) then return 0 end
if value % (2 * bit) >= bit then
return value
end
@ -185,6 +187,7 @@ function utils.setBit(value, bit)
end
function utils.clearBit(value, bit)
if (value == nil) then return 0 end
if value % (2 * bit) >= bit then
return value - bit
end