Selaa lähdekoodia

[lua] Store timeline ids inside set in Animation for O(1) lookup. See #1462.

badlogic 6 vuotta sitten
vanhempi
commit
2c0881da61
2 muutettua tiedostoa jossa 11 lisäystä ja 10 poistoa
  1. 9 0
      spine-lua/Animation.lua
  2. 2 10
      spine-lua/AnimationState.lua

+ 9 - 0
spine-lua/Animation.lua

@@ -50,8 +50,17 @@ function Animation.new (name, timelines, duration)
 	local self = {
 	local self = {
 		name = name,
 		name = name,
 		timelines = timelines,
 		timelines = timelines,
+		timelineIds = {},
 		duration = duration
 		duration = duration
 	}
 	}
+	
+	for i,timeline in ipairs(self.timelines) do
+		self.timelineIds[timeline:getPropertyId()] = true
+	end
+
+	function self:hasTimeline(id)
+		return self.timelineIds[id] == true
+	end
 
 
 	function self:apply (skeleton, lastTime, time, loop, events, alpha, blend, direction)
 	function self:apply (skeleton, lastTime, time, loop, events, alpha, blend, direction)
 		if not skeleton then error("skeleton cannot be nil.", 2) end
 		if not skeleton then error("skeleton cannot be nil.", 2) end

+ 2 - 10
spine-lua/AnimationState.lua

@@ -894,13 +894,13 @@ function AnimationState:computeHold(entry)
 			if to == nil or timeline.type == Animation.TimelineType.attachment
 			if to == nil or timeline.type == Animation.TimelineType.attachment
 				or timeline.type == Animation.TimelineType.drawOrder
 				or timeline.type == Animation.TimelineType.drawOrder
 				or timeline.type == Animation.TimelineType.event
 				or timeline.type == Animation.TimelineType.event
-				or not self:hasTimeline(to, id) then
+				or not to.animation:hasTimeline(id) then
 				timelineMode[i] = FIRST
 				timelineMode[i] = FIRST
 			else
 			else
 				local next = to.mixingTo
 				local next = to.mixingTo
 				skip = false
 				skip = false
 				while next do
 				while next do
-					if not self:hasTimeline(id) then
+					if not next.animation:hasTimeline(id) then
 						if entry.mixDuration > 0 then
 						if entry.mixDuration > 0 then
 							timelineMode[i] = HOLD_MIX
 							timelineMode[i] = HOLD_MIX
 							timelineHoldMix[i] = next
 							timelineHoldMix[i] = next
@@ -917,14 +917,6 @@ function AnimationState:computeHold(entry)
 	end
 	end
 end
 end
 
 
-function AnimationState:hasTimeline(entry, id)
-	local timelines = entry.animation.timelines
-	for i,timeline in ipairs(timelines) do
-		if timeline:getPropertyId() == id then return true end
-	end
-	return false
-end
-
 function AnimationState:getCurrent (trackIndex)
 function AnimationState:getCurrent (trackIndex)
 	return self.tracks[trackIndex]
 	return self.tracks[trackIndex]
 end
 end