mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[csharp] Port of commit ec5b721: Set array sizes up front rather than shrink afterward. Also changed IkConstraintData.Bones type from List<BoneData> to ExposedList<BoneData> for unification reasons.
This commit is contained in:
parent
625f9b076a
commit
5193613445
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
## C# ##
|
## C# ##
|
||||||
* **Breaking changes**
|
* **Breaking changes**
|
||||||
|
* **Changed `IkConstraintData.Bones` type from `List<BoneData>` to `ExposedList<BoneData>`** for unification reasons. *Note: this modification will most likely not affect user code.*
|
||||||
|
|
||||||
* **Additions**
|
* **Additions**
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ using System.Collections.Generic;
|
|||||||
namespace Spine {
|
namespace Spine {
|
||||||
/// <summary>Stores the setup pose for an IkConstraint.</summary>
|
/// <summary>Stores the setup pose for an IkConstraint.</summary>
|
||||||
public class IkConstraintData : ConstraintData {
|
public class IkConstraintData : ConstraintData {
|
||||||
internal List<BoneData> bones = new List<BoneData>();
|
internal ExposedList<BoneData> bones = new ExposedList<BoneData>();
|
||||||
internal BoneData target;
|
internal BoneData target;
|
||||||
internal int bendDirection = 1;
|
internal int bendDirection = 1;
|
||||||
internal bool compress, stretch, uniform;
|
internal bool compress, stretch, uniform;
|
||||||
@ -43,7 +43,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>The bones that are constrained by this IK Constraint.</summary>
|
/// <summary>The bones that are constrained by this IK Constraint.</summary>
|
||||||
public List<BoneData> Bones {
|
public ExposedList<BoneData> Bones {
|
||||||
get { return bones; }
|
get { return bones; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -160,8 +160,12 @@ namespace Spine {
|
|||||||
if (string.IsNullOrEmpty(skeletonData.audioPath)) skeletonData.audioPath = null;
|
if (string.IsNullOrEmpty(skeletonData.audioPath)) skeletonData.audioPath = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int n;
|
||||||
|
Object[] o;
|
||||||
|
|
||||||
// Bones.
|
// Bones.
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
o = skeletonData.bones.Resize(n = ReadVarint(input, true)).Items;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
String name = ReadString(input);
|
String name = ReadString(input);
|
||||||
BoneData parent = i == 0 ? null : skeletonData.bones.Items[ReadVarint(input, true)];
|
BoneData parent = i == 0 ? null : skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
BoneData data = new BoneData(i, name, parent);
|
BoneData data = new BoneData(i, name, parent);
|
||||||
@ -177,10 +181,12 @@ namespace Spine {
|
|||||||
data.skinRequired = ReadBoolean(input);
|
data.skinRequired = ReadBoolean(input);
|
||||||
if (nonessential) ReadInt(input); // Skip bone color.
|
if (nonessential) ReadInt(input); // Skip bone color.
|
||||||
skeletonData.bones.Add(data);
|
skeletonData.bones.Add(data);
|
||||||
|
o[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slots.
|
// Slots.
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
o = skeletonData.slots.Resize(n = ReadVarint(input, true)).Items;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
String slotName = ReadString(input);
|
String slotName = ReadString(input);
|
||||||
BoneData boneData = skeletonData.bones.Items[ReadVarint(input, true)];
|
BoneData boneData = skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
SlotData slotData = new SlotData(i, slotName, boneData);
|
SlotData slotData = new SlotData(i, slotName, boneData);
|
||||||
@ -200,32 +206,36 @@ namespace Spine {
|
|||||||
|
|
||||||
slotData.attachmentName = ReadString(input);
|
slotData.attachmentName = ReadString(input);
|
||||||
slotData.blendMode = (BlendMode)ReadVarint(input, true);
|
slotData.blendMode = (BlendMode)ReadVarint(input, true);
|
||||||
skeletonData.slots.Add(slotData);
|
o[i] = slotData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IK constraints.
|
// IK constraints.
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
o = skeletonData.ikConstraints.Resize(n = ReadVarint(input, true)).Items;
|
||||||
|
for (int i = 0, nn; i < n; i++) {
|
||||||
IkConstraintData data = new IkConstraintData(ReadString(input));
|
IkConstraintData data = new IkConstraintData(ReadString(input));
|
||||||
data.order = ReadVarint(input, true);
|
data.order = ReadVarint(input, true);
|
||||||
data.skinRequired = ReadBoolean(input);
|
data.skinRequired = ReadBoolean(input);
|
||||||
for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++)
|
Object[] bones = data.bones.Resize(nn = ReadVarint(input, true)).Items;
|
||||||
data.bones.Add(skeletonData.bones.Items[ReadVarint(input, true)]);
|
for (int ii = 0; ii < nn; ii++)
|
||||||
|
bones[ii] = skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
data.target = skeletonData.bones.Items[ReadVarint(input, true)];
|
data.target = skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
data.mix = ReadFloat(input);
|
data.mix = ReadFloat(input);
|
||||||
data.bendDirection = ReadSByte(input);
|
data.bendDirection = ReadSByte(input);
|
||||||
data.compress = ReadBoolean(input);
|
data.compress = ReadBoolean(input);
|
||||||
data.stretch = ReadBoolean(input);
|
data.stretch = ReadBoolean(input);
|
||||||
data.uniform = ReadBoolean(input);
|
data.uniform = ReadBoolean(input);
|
||||||
skeletonData.ikConstraints.Add(data);
|
o[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform constraints.
|
// Transform constraints.
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
o = skeletonData.transformConstraints.Resize(n = ReadVarint(input, true)).Items;
|
||||||
|
for (int i = 0, nn; i < n; i++) {
|
||||||
TransformConstraintData data = new TransformConstraintData(ReadString(input));
|
TransformConstraintData data = new TransformConstraintData(ReadString(input));
|
||||||
data.order = ReadVarint(input, true);
|
data.order = ReadVarint(input, true);
|
||||||
data.skinRequired = ReadBoolean(input);
|
data.skinRequired = ReadBoolean(input);
|
||||||
for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++)
|
Object[] bones = data.bones.Resize(nn = ReadVarint(input, true)).Items;
|
||||||
data.bones.Add(skeletonData.bones.Items[ReadVarint(input, true)]);
|
for (int ii = 0; ii < nn; ii++)
|
||||||
|
bones[ii] = skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
data.target = skeletonData.bones.Items[ReadVarint(input, true)];
|
data.target = skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
data.local = ReadBoolean(input);
|
data.local = ReadBoolean(input);
|
||||||
data.relative = ReadBoolean(input);
|
data.relative = ReadBoolean(input);
|
||||||
@ -239,16 +249,18 @@ namespace Spine {
|
|||||||
data.translateMix = ReadFloat(input);
|
data.translateMix = ReadFloat(input);
|
||||||
data.scaleMix = ReadFloat(input);
|
data.scaleMix = ReadFloat(input);
|
||||||
data.shearMix = ReadFloat(input);
|
data.shearMix = ReadFloat(input);
|
||||||
skeletonData.transformConstraints.Add(data);
|
o[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path constraints
|
// Path constraints
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
o = skeletonData.pathConstraints.Resize(n = ReadVarint(input, true)).Items;
|
||||||
|
for (int i = 0, nn; i < n; i++) {
|
||||||
PathConstraintData data = new PathConstraintData(ReadString(input));
|
PathConstraintData data = new PathConstraintData(ReadString(input));
|
||||||
data.order = ReadVarint(input, true);
|
data.order = ReadVarint(input, true);
|
||||||
data.skinRequired = ReadBoolean(input);
|
data.skinRequired = ReadBoolean(input);
|
||||||
for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++)
|
Object[] bones = data.bones.Resize(nn = ReadVarint(input, true)).Items;
|
||||||
data.bones.Add(skeletonData.bones.Items[ReadVarint(input, true)]);
|
for (int ii = 0; ii < nn; ii++)
|
||||||
|
bones[ii] = skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
data.target = skeletonData.slots.Items[ReadVarint(input, true)];
|
data.target = skeletonData.slots.Items[ReadVarint(input, true)];
|
||||||
data.positionMode = (PositionMode)Enum.GetValues(typeof(PositionMode)).GetValue(ReadVarint(input, true));
|
data.positionMode = (PositionMode)Enum.GetValues(typeof(PositionMode)).GetValue(ReadVarint(input, true));
|
||||||
data.spacingMode = (SpacingMode)Enum.GetValues(typeof(SpacingMode)).GetValue(ReadVarint(input, true));
|
data.spacingMode = (SpacingMode)Enum.GetValues(typeof(SpacingMode)).GetValue(ReadVarint(input, true));
|
||||||
@ -260,7 +272,7 @@ namespace Spine {
|
|||||||
if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale;
|
if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale;
|
||||||
data.rotateMix = ReadFloat(input);
|
data.rotateMix = ReadFloat(input);
|
||||||
data.translateMix = ReadFloat(input);
|
data.translateMix = ReadFloat(input);
|
||||||
skeletonData.pathConstraints.Add(data);
|
o[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default skin.
|
// Default skin.
|
||||||
@ -271,11 +283,16 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skins.
|
// Skins.
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
{
|
||||||
skeletonData.skins.Add(ReadSkin(input, skeletonData, false, nonessential));
|
int i = skeletonData.skins.Count;
|
||||||
|
o = skeletonData.skins.Resize(n = i + ReadVarint(input, true)).Items;
|
||||||
|
for (; i < n; i++)
|
||||||
|
o[i] = ReadSkin(input, skeletonData, false, nonessential);
|
||||||
|
}
|
||||||
|
|
||||||
// Linked meshes.
|
// Linked meshes.
|
||||||
for (int i = 0, n = linkedMeshes.Count; i < n; i++) {
|
n = linkedMeshes.Count;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
SkeletonJson.LinkedMesh linkedMesh = linkedMeshes[i];
|
SkeletonJson.LinkedMesh linkedMesh = linkedMeshes[i];
|
||||||
Skin skin = linkedMesh.skin == null ? skeletonData.DefaultSkin : skeletonData.FindSkin(linkedMesh.skin);
|
Skin skin = linkedMesh.skin == null ? skeletonData.DefaultSkin : skeletonData.FindSkin(linkedMesh.skin);
|
||||||
if (skin == null) throw new Exception("Skin not found: " + linkedMesh.skin);
|
if (skin == null) throw new Exception("Skin not found: " + linkedMesh.skin);
|
||||||
@ -288,7 +305,8 @@ namespace Spine {
|
|||||||
linkedMeshes.Clear();
|
linkedMeshes.Clear();
|
||||||
|
|
||||||
// Events.
|
// Events.
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
o = skeletonData.events.Resize(n = ReadVarint(input, true)).Items;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
EventData data = new EventData(ReadString(input));
|
EventData data = new EventData(ReadString(input));
|
||||||
data.Int = ReadVarint(input, false);
|
data.Int = ReadVarint(input, false);
|
||||||
data.Float = ReadFloat(input);
|
data.Float = ReadFloat(input);
|
||||||
@ -298,36 +316,34 @@ namespace Spine {
|
|||||||
data.Volume = ReadFloat(input);
|
data.Volume = ReadFloat(input);
|
||||||
data.Balance = ReadFloat(input);
|
data.Balance = ReadFloat(input);
|
||||||
}
|
}
|
||||||
skeletonData.events.Add(data);
|
o[i] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animations.
|
// Animations.
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
o = skeletonData.animations.Resize(n = ReadVarint(input, true)).Items;
|
||||||
ReadAnimation(ReadString(input), input, skeletonData);
|
for (int i = 0; i < n; i++)
|
||||||
|
o[i] = ReadAnimation(ReadString(input), input, skeletonData);
|
||||||
skeletonData.bones.TrimExcess();
|
|
||||||
skeletonData.slots.TrimExcess();
|
|
||||||
skeletonData.skins.TrimExcess();
|
|
||||||
skeletonData.events.TrimExcess();
|
|
||||||
skeletonData.animations.TrimExcess();
|
|
||||||
skeletonData.ikConstraints.TrimExcess();
|
|
||||||
skeletonData.pathConstraints.TrimExcess();
|
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <returns>May be null.</returns>
|
/// <returns>May be null.</returns>
|
||||||
private Skin ReadSkin (Stream input, SkeletonData skeletonData, bool defaultSkin, bool nonessential) {
|
private Skin ReadSkin (Stream input, SkeletonData skeletonData, bool defaultSkin, bool nonessential) {
|
||||||
|
|
||||||
Skin skin = new Skin(defaultSkin ? "default" : ReadString(input));
|
Skin skin = new Skin(defaultSkin ? "default" : ReadString(input));
|
||||||
|
|
||||||
if (!defaultSkin) {
|
if (!defaultSkin) {
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
Object[] bones = skeletonData.bones.Resize(ReadVarint(input, true)).Items;
|
||||||
skin.bones.Add(skeletonData.bones.Items[ReadVarint(input, true)]);
|
for (int i = 0, n = skeletonData.bones.Count; i < n; i++)
|
||||||
|
bones[i] = skeletonData.bones.Items[ReadVarint(input, true)];
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
||||||
skin.constraints.Add(skeletonData.ikConstraints.Items[ReadVarint(input, true)]);
|
skin.constraints.Add(skeletonData.ikConstraints.Items[ReadVarint(input, true)]);
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
||||||
skin.constraints.Add(skeletonData.transformConstraints.Items[ReadVarint(input, true)]);
|
skin.constraints.Add(skeletonData.transformConstraints.Items[ReadVarint(input, true)]);
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
for (int i = 0, n = ReadVarint(input, true); i < n; i++)
|
||||||
skin.constraints.Add(skeletonData.pathConstraints.Items[ReadVarint(input, true)]);
|
skin.constraints.Add(skeletonData.pathConstraints.Items[ReadVarint(input, true)]);
|
||||||
|
skin.constraints.TrimExcess();
|
||||||
}
|
}
|
||||||
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
|
||||||
int slotIndex = ReadVarint(input, true);
|
int slotIndex = ReadVarint(input, true);
|
||||||
@ -552,8 +568,8 @@ namespace Spine {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReadAnimation (String name, Stream input, SkeletonData skeletonData) {
|
private Animation ReadAnimation (String name, Stream input, SkeletonData skeletonData) {
|
||||||
var timelines = new ExposedList<Timeline>();
|
var timelines = new ExposedList<Timeline>(32);
|
||||||
float scale = Scale;
|
float scale = Scale;
|
||||||
float duration = 0;
|
float duration = 0;
|
||||||
|
|
||||||
@ -837,7 +853,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timelines.TrimExcess();
|
timelines.TrimExcess();
|
||||||
skeletonData.animations.Add(new Animation(name, timelines, duration));
|
return new Animation(name, timelines, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReadCurve (Stream input, int frameIndex, CurveTimeline timeline) {
|
private void ReadCurve (Stream input, int frameIndex, CurveTimeline timeline) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user