mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Better draw order key loading.
This commit is contained in:
parent
f174b1a3cb
commit
4b7a9633a7
@ -47,7 +47,6 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.DataInput;
|
import com.badlogic.gdx.utils.DataInput;
|
||||||
import com.badlogic.gdx.utils.IntArray;
|
|
||||||
import com.badlogic.gdx.utils.SerializationException;
|
import com.badlogic.gdx.utils.SerializationException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -169,8 +168,7 @@ public class SkeletonBinary {
|
|||||||
Skin skin = new Skin(skinName);
|
Skin skin = new Skin(skinName);
|
||||||
for (int i = 0; i < slotCount; i++) {
|
for (int i = 0; i < slotCount; i++) {
|
||||||
int slotIndex = input.readInt(true);
|
int slotIndex = input.readInt(true);
|
||||||
int attachmentCount = input.readInt(true);
|
for (int ii = 0, nn = input.readInt(true); ii < nn; ii++) {
|
||||||
for (int ii = 0; ii < attachmentCount; ii++) {
|
|
||||||
String name = input.readString();
|
String name = input.readString();
|
||||||
skin.addAttachment(slotIndex, name, readAttachment(input, skin, name));
|
skin.addAttachment(slotIndex, name, readAttachment(input, skin, name));
|
||||||
}
|
}
|
||||||
@ -211,8 +209,7 @@ public class SkeletonBinary {
|
|||||||
float duration = 0;
|
float duration = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int boneCount = input.readInt(true);
|
for (int i = 0, n = input.readInt(true); i < n; i++) {
|
||||||
for (int i = 0; i < boneCount; i++) {
|
|
||||||
int boneIndex = input.readInt(true);
|
int boneIndex = input.readInt(true);
|
||||||
int itemCount = input.readInt(true);
|
int itemCount = input.readInt(true);
|
||||||
for (int ii = 0; ii < itemCount; ii++) {
|
for (int ii = 0; ii < itemCount; ii++) {
|
||||||
@ -253,8 +250,7 @@ public class SkeletonBinary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int slotCount = input.readInt(true);
|
for (int i = 0, n = input.readInt(true); i < n; i++) {
|
||||||
for (int i = 0; i < slotCount; i++) {
|
|
||||||
int slotIndex = input.readInt(true);
|
int slotIndex = input.readInt(true);
|
||||||
int itemCount = input.readInt(true);
|
int itemCount = input.readInt(true);
|
||||||
for (int ii = 0; ii < itemCount; ii++) {
|
for (int ii = 0; ii < itemCount; ii++) {
|
||||||
@ -304,21 +300,30 @@ public class SkeletonBinary {
|
|||||||
|
|
||||||
int drawOrderCount = input.readInt(true);
|
int drawOrderCount = input.readInt(true);
|
||||||
if (drawOrderCount > 0) {
|
if (drawOrderCount > 0) {
|
||||||
Array<SlotData> slots = skeletonData.slots;
|
|
||||||
DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrderCount);
|
DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrderCount);
|
||||||
|
int slotCount = skeletonData.slots.size;
|
||||||
for (int i = 0; i < drawOrderCount; i++) {
|
for (int i = 0; i < drawOrderCount; i++) {
|
||||||
IntArray drawOrder = new IntArray(slots.size);
|
|
||||||
for (int ii = 0, n = slots.size; ii < n; ii++)
|
|
||||||
drawOrder.add(ii);
|
|
||||||
|
|
||||||
int offsetCount = input.readInt(true);
|
int offsetCount = input.readInt(true);
|
||||||
|
int[] drawOrder = new int[slotCount];
|
||||||
|
for (int ii = slotCount - 1; ii >= 0; ii--)
|
||||||
|
drawOrder[ii] = -1;
|
||||||
|
int[] unchanged = new int[slotCount - offsetCount];
|
||||||
|
int originalIndex = 0, unchangedIndex = 0;
|
||||||
for (int ii = 0; ii < offsetCount; ii++) {
|
for (int ii = 0; ii < offsetCount; ii++) {
|
||||||
int slotIndex = input.readInt(true);
|
int slotIndex = input.readInt(true);
|
||||||
int index = drawOrder.indexOf(slotIndex);
|
// Collect unchanged items.
|
||||||
drawOrder.removeIndex(index);
|
while (originalIndex != slotIndex)
|
||||||
drawOrder.insert(index + input.readInt(true), slotIndex);
|
unchanged[unchangedIndex++] = originalIndex++;
|
||||||
|
// Set changed items.
|
||||||
|
drawOrder[originalIndex + input.readInt(true)] = originalIndex++;
|
||||||
}
|
}
|
||||||
timeline.setFrame(i, input.readFloat(), drawOrder.toArray());
|
// Collect remaining unchanged items.
|
||||||
|
while (originalIndex < slotCount)
|
||||||
|
unchanged[unchangedIndex++] = originalIndex++;
|
||||||
|
// Fill in unchanged items.
|
||||||
|
for (int ii = slotCount - 1; ii >= 0; ii--)
|
||||||
|
if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex];
|
||||||
|
timeline.setFrame(i, input.readFloat(), drawOrder);
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[drawOrderCount - 1]);
|
duration = Math.max(duration, timeline.getFrames()[drawOrderCount - 1]);
|
||||||
|
|||||||
@ -46,7 +46,6 @@ import com.badlogic.gdx.files.FileHandle;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.IntArray;
|
|
||||||
import com.badlogic.gdx.utils.JsonReader;
|
import com.badlogic.gdx.utils.JsonReader;
|
||||||
import com.badlogic.gdx.utils.JsonValue;
|
import com.badlogic.gdx.utils.JsonValue;
|
||||||
import com.badlogic.gdx.utils.SerializationException;
|
import com.badlogic.gdx.utils.SerializationException;
|
||||||
@ -299,20 +298,30 @@ public class SkeletonJson {
|
|||||||
JsonValue drawOrdersMap = map.get("draworder");
|
JsonValue drawOrdersMap = map.get("draworder");
|
||||||
if (drawOrdersMap != null) {
|
if (drawOrdersMap != null) {
|
||||||
DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrdersMap.size);
|
DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrdersMap.size);
|
||||||
Array<SlotData> slots = skeletonData.slots;
|
int slotCount = skeletonData.slots.size;
|
||||||
int frameIndex = 0;
|
int frameIndex = 0;
|
||||||
for (JsonValue drawOrderMap = drawOrdersMap.child; drawOrderMap != null; drawOrderMap = drawOrderMap.next()) {
|
for (JsonValue drawOrderMap = drawOrdersMap.child; drawOrderMap != null; drawOrderMap = drawOrderMap.next()) {
|
||||||
IntArray drawOrder = new IntArray(slots.size);
|
int[] drawOrder = new int[slotCount];
|
||||||
for (int i = 0, n = slots.size; i < n; i++)
|
for (int i = slotCount - 1; i >= 0; i--)
|
||||||
drawOrder.add(i);
|
drawOrder[i] = -1;
|
||||||
|
int[] unchanged = new int[slotCount - drawOrderMap.get("offsets").size];
|
||||||
|
int originalIndex = 0, unchangedIndex = 0;
|
||||||
for (JsonValue offsetMap = drawOrderMap.getChild("offsets"); offsetMap != null; offsetMap = offsetMap.next()) {
|
for (JsonValue offsetMap = drawOrderMap.getChild("offsets"); offsetMap != null; offsetMap = offsetMap.next()) {
|
||||||
int slotIndex = skeletonData.findSlotIndex(offsetMap.getString("slot"));
|
int slotIndex = skeletonData.findSlotIndex(offsetMap.getString("slot"));
|
||||||
if (slotIndex == -1) throw new SerializationException("Slot not found: " + offsetMap.getString("slot"));
|
if (slotIndex == -1) throw new SerializationException("Slot not found: " + offsetMap.getString("slot"));
|
||||||
int index = drawOrder.indexOf(slotIndex);
|
// Collect unchanged items.
|
||||||
drawOrder.removeIndex(index);
|
while (originalIndex != slotIndex)
|
||||||
drawOrder.insert(index + offsetMap.getInt("offset"), slotIndex);
|
unchanged[unchangedIndex++] = originalIndex++;
|
||||||
|
// Set changed items.
|
||||||
|
drawOrder[originalIndex + offsetMap.getInt("offset")] = originalIndex++;
|
||||||
}
|
}
|
||||||
timeline.setFrame(frameIndex++, drawOrderMap.getFloat("time"), drawOrder.toArray());
|
// Collect remaining unchanged items.
|
||||||
|
while (originalIndex < slotCount)
|
||||||
|
unchanged[unchangedIndex++] = originalIndex++;
|
||||||
|
// Fill in unchanged items.
|
||||||
|
for (int i = slotCount - 1; i >= 0; i--)
|
||||||
|
if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex];
|
||||||
|
timeline.setFrame(frameIndex++, drawOrderMap.getFloat("time"), drawOrder);
|
||||||
}
|
}
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
|
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user