mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
remove findslotindex from skeletondata and make it into a table, for faster lookups
This commit is contained in:
parent
d69f514681
commit
c5016f0da0
@ -99,7 +99,7 @@ function Skeleton.new (skeletonData)
|
|||||||
function self:getAttachment (slotName, attachmentName)
|
function self:getAttachment (slotName, attachmentName)
|
||||||
if not slotName then error("slotName cannot be nil.", 2) end
|
if not slotName then error("slotName cannot be nil.", 2) end
|
||||||
if not attachmentName then error("attachmentName cannot be nil.", 2) end
|
if not attachmentName then error("attachmentName cannot be nil.", 2) end
|
||||||
local slotIndex = self.data:findSlotIndex(slotName)
|
local slotIndex = skeletonData.nameIndices[slotName]
|
||||||
if slotIndex == -1 then error("Slot not found: " .. slotName, 2) end
|
if slotIndex == -1 then error("Slot not found: " .. slotName, 2) end
|
||||||
if self.skin then
|
if self.skin then
|
||||||
local attachment = self.skin:getAttachment(slotIndex, attachmentName)
|
local attachment = self.skin:getAttachment(slotIndex, attachmentName)
|
||||||
|
|||||||
@ -28,6 +28,7 @@ function SkeletonData.new ()
|
|||||||
local self = {
|
local self = {
|
||||||
bones = {},
|
bones = {},
|
||||||
slots = {},
|
slots = {},
|
||||||
|
nameIndices = {},
|
||||||
skins = {},
|
skins = {},
|
||||||
animations = {}
|
animations = {}
|
||||||
}
|
}
|
||||||
@ -56,14 +57,6 @@ function SkeletonData.new ()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function self:findSlotIndex (slotName)
|
|
||||||
if not slotName then error("slotName cannot be nil.", 2) end
|
|
||||||
for i,slot in ipairs(self.slots) do
|
|
||||||
if slot.name == slotName then return i end
|
|
||||||
end
|
|
||||||
return -1
|
|
||||||
end
|
|
||||||
|
|
||||||
function self:findSkin (skinName)
|
function self:findSkin (skinName)
|
||||||
if not skinName then error("skinName cannot be nil.", 2) end
|
if not skinName then error("skinName cannot be nil.", 2) end
|
||||||
for i,skin in ipairs(self.skins) do
|
for i,skin in ipairs(self.skins) do
|
||||||
|
|||||||
@ -102,8 +102,8 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
end
|
end
|
||||||
|
|
||||||
slotData.attachmentName = slotMap["attachment"]
|
slotData.attachmentName = slotMap["attachment"]
|
||||||
|
|
||||||
table.insert(skeletonData.slots, slotData)
|
table.insert(skeletonData.slots, slotData)
|
||||||
|
skeletonData.nameIndices[slotData.name] = #skeletonData.slots
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
for skinName,skinMap in pairs(map) do
|
for skinName,skinMap in pairs(map) do
|
||||||
local skin = Skin.new(skinName)
|
local skin = Skin.new(skinName)
|
||||||
for slotName,slotMap in pairs(skinMap) do
|
for slotName,slotMap in pairs(skinMap) do
|
||||||
local slotIndex = skeletonData:findSlotIndex(slotName)
|
local slotIndex = skeletonData.nameIndices[slotName]
|
||||||
for attachmentName,attachmentMap in pairs(slotMap) do
|
for attachmentName,attachmentMap in pairs(slotMap) do
|
||||||
local attachment = readAttachment(attachmentName, attachmentMap, self.scale)
|
local attachment = readAttachment(attachmentName, attachmentMap, self.scale)
|
||||||
if attachment then
|
if attachment then
|
||||||
@ -213,7 +213,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
local slotsMap = map["slots"]
|
local slotsMap = map["slots"]
|
||||||
if slotsMap then
|
if slotsMap then
|
||||||
for slotName,timelineMap in pairs(slotsMap) do
|
for slotName,timelineMap in pairs(slotsMap) do
|
||||||
local slotIndex = skeletonData:findSlotIndex(slotName)
|
local slotIndex = skeletonData.nameIndices[slotName]
|
||||||
|
|
||||||
for timelineName,values in pairs(timelineMap) do
|
for timelineName,values in pairs(timelineMap) do
|
||||||
if timelineName == TIMELINE_COLOR then
|
if timelineName == TIMELINE_COLOR then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user