diff --git a/spine-csharp/src/AnimationState.cs b/spine-csharp/src/AnimationState.cs index ab9ac7be0..99258d76a 100644 --- a/spine-csharp/src/AnimationState.cs +++ b/spine-csharp/src/AnimationState.cs @@ -274,7 +274,7 @@ namespace Spine { bool shortestRotation = current.shortestRotation; bool firstFrame = !shortestRotation && current.timelinesRotation.Count != timelineCount << 1; - if (firstFrame) current.timelinesRotation.Resize(timelineCount << 1); + if (firstFrame) current.timelinesRotation.EnsureSize(timelineCount << 1); float[] timelinesRotation = current.timelinesRotation.Items; for (int ii = 0; ii < timelineCount; ii++) { @@ -390,7 +390,7 @@ namespace Spine { bool shortestRotation = from.shortestRotation; bool firstFrame = !shortestRotation && from.timelinesRotation.Count != timelineCount << 1; - if (firstFrame) from.timelinesRotation.Resize(timelineCount << 1); + if (firstFrame) from.timelinesRotation.EnsureSize(timelineCount << 1); float[] timelinesRotation = from.timelinesRotation.Items; from.totalAlpha = 0; @@ -827,7 +827,7 @@ namespace Spine { private TrackEntry ExpandToIndex (int index) { if (index < tracks.Count) return tracks.Items[index]; - tracks.Resize(index + 1); + tracks.EnsureSize(index + 1); return null; } @@ -898,7 +898,7 @@ namespace Spine { TrackEntry to = entry.mixingTo; Timeline[] timelines = entry.animation.timelines.Items; int timelinesCount = entry.animation.timelines.Count; - int[] timelineMode = entry.timelineMode.Resize(timelinesCount).Items; + int[] timelineMode = entry.timelineMode.EnsureSize(timelinesCount).Items; entry.timelineHoldMix.Clear(); TrackEntry[] timelineHoldMix = entry.timelineHoldMix.Resize(timelinesCount).Items; HashSet propertyIds = this.propertyIds; diff --git a/spine-csharp/src/ExposedList.cs b/spine-csharp/src/ExposedList.cs index 092999a1a..36c705cdc 100644 --- a/spine-csharp/src/ExposedList.cs +++ b/spine-csharp/src/ExposedList.cs @@ -102,6 +102,15 @@ namespace Spine { return this; } + public ExposedList EnsureSize (int newSize) { + int itemsLength = Items.Length; + if (newSize > itemsLength) { + Array.Resize(ref Items, newSize); + } + Count = newSize; + return this; + } + public void EnsureCapacity (int min) { if (Items.Length < min) { int newCapacity = Items.Length == 0 ? DefaultCapacity : Items.Length * 2; diff --git a/spine-csharp/src/PathConstraint.cs b/spine-csharp/src/PathConstraint.cs index 908dbb423..777fc9542 100644 --- a/spine-csharp/src/PathConstraint.cs +++ b/spine-csharp/src/PathConstraint.cs @@ -83,7 +83,7 @@ namespace Spine { bool tangents = data.rotateMode == RotateMode.Tangent, scale = data.rotateMode == RotateMode.ChainScale; int boneCount = this.bones.Count, spacesCount = tangents ? boneCount : boneCount + 1; BonePose[] bonesItems = this.bones.Items; - float[] spaces = this.spaces.Resize(spacesCount).Items, lengths = scale ? this.lengths.Resize(boneCount).Items : null; + float[] spaces = this.spaces.EnsureSize(spacesCount).Items, lengths = scale ? this.lengths.EnsureSize(boneCount).Items : null; float spacing = p.spacing; switch (data.spacingMode) { case SpacingMode.Percent: @@ -200,7 +200,7 @@ namespace Spine { float[] ComputeWorldPositions (Skeleton skeleton, PathAttachment path, int spacesCount, bool tangents) { Slot slot = this.slot; float position = applied.position; - float[] spaces = this.spaces.Items, output = this.positions.Resize(spacesCount * 3 + 2).Items, world; + float[] spaces = this.spaces.Items, output = this.positions.EnsureSize(spacesCount * 3 + 2).Items, world; bool closed = path.Closed; int verticesLength = path.WorldVerticesLength, curveCount = verticesLength / 6, prevCurve = NONE; @@ -224,7 +224,7 @@ namespace Spine { break; } - world = this.world.Resize(8).Items; + world = this.world.EnsureSize(8).Items; for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) { float space = spaces[i] * multiplier; position += space; @@ -279,7 +279,7 @@ namespace Spine { // World vertices. if (closed) { verticesLength += 2; - world = this.world.Resize(verticesLength).Items; + world = this.world.EnsureSize(verticesLength).Items; path.ComputeWorldVertices(skeleton, slot, 2, verticesLength - 4, world, 0, 2); path.ComputeWorldVertices(skeleton, slot, 0, 2, world, verticesLength - 4, 2); world[verticesLength - 2] = world[0]; @@ -287,12 +287,12 @@ namespace Spine { } else { curveCount--; verticesLength -= 4; - world = this.world.Resize(verticesLength).Items; + world = this.world.EnsureSize(verticesLength).Items; path.ComputeWorldVertices(skeleton, slot, 2, verticesLength, world, 0, 2); } // Curve lengths. - float[] curves = this.curves.Resize(curveCount).Items; + float[] curves = this.curves.EnsureSize(curveCount).Items; pathLength = 0; float x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0; float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy; diff --git a/spine-csharp/src/SkeletonBinary.cs b/spine-csharp/src/SkeletonBinary.cs index 88b507843..7e248f892 100644 --- a/spine-csharp/src/SkeletonBinary.cs +++ b/spine-csharp/src/SkeletonBinary.cs @@ -192,7 +192,7 @@ namespace Spine { o[i] = input.ReadString(); // Bones. - BoneData[] bones = skeletonData.bones.Resize(n = input.ReadInt(true)).Items; + BoneData[] bones = skeletonData.bones.EnsureSize(n = input.ReadInt(true)).Items; for (int i = 0; i < n; i++) { string name = input.ReadString(); BoneData parent = i == 0 ? null : bones[input.ReadInt(true)]; @@ -217,7 +217,7 @@ namespace Spine { } // Slots. - SlotData[] slots = skeletonData.slots.Resize(n = input.ReadInt(true)).Items; + SlotData[] slots = skeletonData.slots.EnsureSize(n = input.ReadInt(true)).Items; for (int i = 0; i < n; i++) { string slotName = input.ReadString(); @@ -239,7 +239,7 @@ namespace Spine { // Constraints. int constraintCount = input.ReadInt(true); - IConstraintData[] constraints = skeletonData.constraints.Resize(constraintCount).Items; + IConstraintData[] constraints = skeletonData.constraints.EnsureSize(constraintCount).Items; for (int i = 0; i < constraintCount; i++) { string name = input.ReadString(); int nn; @@ -247,7 +247,7 @@ namespace Spine { switch (input.ReadUByte()) { case CONSTRAINT_IK: { var data = new IkConstraintData(name); - BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items; + BoneData[] constraintBones = data.bones.EnsureSize(nn = input.ReadInt(true)).Items; for (int ii = 0; ii < nn; ii++) constraintBones[ii] = bones[input.ReadInt(true)]; data.target = bones[input.ReadInt(true)]; @@ -265,7 +265,7 @@ namespace Spine { } case CONSTRAINT_TRANSFORM: { var data = new TransformConstraintData(name); - BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items; + BoneData[] constraintBones = data.bones.EnsureSize(nn = input.ReadInt(true)).Items; for (int ii = 0; ii < nn; ii++) constraintBones[ii] = bones[input.ReadInt(true)]; data.source = bones[input.ReadInt(true)]; @@ -275,7 +275,7 @@ namespace Spine { data.localTarget = (flags & 4) != 0; data.additive = (flags & 8) != 0; data.clamp = (flags & 16) != 0; - FromProperty[] froms = data.properties.Resize(nn = flags >> 5).Items; + FromProperty[] froms = data.properties.EnsureSize(nn = flags >> 5).Items; for (int ii = 0, tn; ii < nn; ii++) { float fromScale = 1; FromProperty from; @@ -297,7 +297,7 @@ namespace Spine { default: from = null; break; } from.offset = input.ReadFloat() * fromScale; - ToProperty[] tos = from.to.Resize(tn = input.ReadSByte()).Items; + ToProperty[] tos = from.to.EnsureSize(tn = input.ReadSByte()).Items; for (int t = 0; t < tn; t++) { float toScale = 1; ToProperty to; @@ -345,7 +345,7 @@ namespace Spine { } case CONSTRAINT_PATH: { var data = new PathConstraintData(name); - BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items; + BoneData[] constraintBones = data.bones.EnsureSize(nn = input.ReadInt(true)).Items; for (int ii = 0; ii < nn; ii++) constraintBones[ii] = bones[input.ReadInt(true)]; data.slot = slots[input.ReadInt(true)]; @@ -447,7 +447,7 @@ namespace Spine { // Skins. { int i = skeletonData.skins.Count; - o = skeletonData.skins.Resize(n = i + input.ReadInt(true)).Items; + o = skeletonData.skins.EnsureSize(n = i + input.ReadInt(true)).Items; for (; i < n; i++) o[i] = ReadSkin(input, skeletonData, false, nonessential); } @@ -466,7 +466,7 @@ namespace Spine { linkedMeshes.Clear(); // Events. - o = skeletonData.events.Resize(n = input.ReadInt(true)).Items; + o = skeletonData.events.EnsureSize(n = input.ReadInt(true)).Items; for (int i = 0; i < n; i++) { var data = new EventData(input.ReadString()); data.Int = input.ReadInt(false); @@ -481,7 +481,7 @@ namespace Spine { } // Animations. - Animation[] animations = skeletonData.animations.Resize(n = input.ReadInt(true)).Items; + Animation[] animations = skeletonData.animations.EnsureSize(n = input.ReadInt(true)).Items; for (int i = 0; i < n; i++) animations[i] = ReadAnimation(input, input.ReadString(), skeletonData); @@ -513,12 +513,12 @@ namespace Spine { if (nonessential) input.ReadInt(); // discard, Color.rgba8888ToColor(skin.color, input.readInt()); int n; - object[] from = skeletonData.bones.Items, to = skin.bones.Resize(n = input.ReadInt(true)).Items; + object[] from = skeletonData.bones.Items, to = skin.bones.EnsureSize(n = input.ReadInt(true)).Items; for (int i = 0; i < n; i++) to[i] = from[input.ReadInt(true)]; from = skeletonData.constraints.Items; - to = skin.constraints.Resize(n = input.ReadInt(true)).Items; + to = skin.constraints.EnsureSize(n = input.ReadInt(true)).Items; for (int i = 0; i < n; i++) to[i] = from[input.ReadInt(true)]; diff --git a/spine-csharp/src/SkeletonClipping.cs b/spine-csharp/src/SkeletonClipping.cs index 19fc3757b..4b9194e7a 100644 --- a/spine-csharp/src/SkeletonClipping.cs +++ b/spine-csharp/src/SkeletonClipping.cs @@ -53,7 +53,7 @@ namespace Spine { clipAttachment = clip; int n = clip.worldVerticesLength; - float[] vertices = clippingPolygon.Resize(n).Items; + float[] vertices = clippingPolygon.EnsureSize(n).Items; clip.ComputeWorldVertices(skeleton, slot, 0, n, vertices, 0, 2); MakeClockwise(clippingPolygon); clippingPolygons = triangulator.Decompose(clippingPolygon, triangulator.Triangulate(clippingPolygon)); @@ -106,7 +106,7 @@ namespace Spine { if (clipOutputLength == 0) continue; int clipOutputCount = clipOutputLength >> 1; - float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items; + float[] clippedVerticesItems = clippedVertices.EnsureSize(s + clipOutputCount * 2).Items; for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) { float x = clipOutputItems[ii], y = clipOutputItems[ii + 1]; clippedVerticesItems[s] = x; @@ -114,7 +114,7 @@ namespace Spine { } s = clippedTriangles.Count; - int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3 * (clipOutputCount - 2)).Items; + int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3 * (clipOutputCount - 2)).Items; clipOutputCount--; for (int ii = 1; ii < clipOutputCount; ii++, s += 3) { clippedTrianglesItems[s] = index; @@ -123,7 +123,7 @@ namespace Spine { } index += clipOutputCount + 1; } else { - float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * 2).Items; + float[] clippedVerticesItems = clippedVertices.EnsureSize(s + 3 * 2).Items; clippedVerticesItems[s] = x1; clippedVerticesItems[s + 1] = y1; clippedVerticesItems[s + 2] = x2; @@ -132,7 +132,7 @@ namespace Spine { clippedVerticesItems[s + 5] = y3; s = clippedTriangles.Count; - int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3).Items; + int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3).Items; clippedTrianglesItems[s] = index; clippedTrianglesItems[s + 1] = index + 1; clippedTrianglesItems[s + 2] = index + 2; @@ -178,8 +178,8 @@ namespace Spine { float d = 1 / (d0 * d2 + d1 * (y1 - y3)); int clipOutputCount = clipOutputLength >> 1; - float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items; - float[] clippedUVsItems = clippedUVs.Resize(s + clipOutputCount * 2).Items; + float[] clippedVerticesItems = clippedVertices.EnsureSize(s + clipOutputCount * 2).Items; + float[] clippedUVsItems = clippedUVs.EnsureSize(s + clipOutputCount * 2).Items; for (int ii = 0; ii < clipOutputLength; ii += 2, s += 2) { float x = clipOutputItems[ii], y = clipOutputItems[ii + 1]; clippedVerticesItems[s] = x; @@ -193,7 +193,7 @@ namespace Spine { } s = clippedTriangles.Count; - int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3 * (clipOutputCount - 2)).Items; + int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3 * (clipOutputCount - 2)).Items; clipOutputCount--; for (int ii = 1; ii < clipOutputCount; ii++, s += 3) { clippedTrianglesItems[s] = index; @@ -202,8 +202,8 @@ namespace Spine { } index += clipOutputCount + 1; } else { - float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * 2).Items; - float[] clippedUVsItems = clippedUVs.Resize(s + 3 * 2).Items; + float[] clippedVerticesItems = clippedVertices.EnsureSize(s + 3 * 2).Items; + float[] clippedUVsItems = clippedUVs.EnsureSize(s + 3 * 2).Items; clippedVerticesItems[s] = x1; clippedVerticesItems[s + 1] = y1; clippedVerticesItems[s + 2] = x2; @@ -219,7 +219,7 @@ namespace Spine { clippedUVsItems[s + 5] = v3; s = clippedTriangles.Count; - int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3).Items; + int[] clippedTrianglesItems = clippedTriangles.EnsureSize(s + 3).Items; clippedTrianglesItems[s] = index; clippedTrianglesItems[s + 1] = index + 1; clippedTrianglesItems[s + 2] = index + 2; @@ -324,7 +324,7 @@ namespace Spine { for (int i = 0, n = output.Count - 2; i < n; i++) originalOutput.Add(output.Items[i]); } else - originalOutput.Resize(originalOutput.Count - 2); + originalOutput.EnsureSize(originalOutput.Count - 2); return clipped; } diff --git a/spine-csharp/src/Triangulator.cs b/spine-csharp/src/Triangulator.cs index 68550a11e..fa76a9d21 100644 --- a/spine-csharp/src/Triangulator.cs +++ b/spine-csharp/src/Triangulator.cs @@ -47,12 +47,12 @@ namespace Spine { ExposedList indicesArray = this.indicesArray; indicesArray.Clear(); - int[] indices = indicesArray.Resize(vertexCount).Items; + int[] indices = indicesArray.EnsureSize(vertexCount).Items; for (int i = 0; i < vertexCount; i++) indices[i] = i; ExposedList isConcaveArray = this.isConcaveArray; - bool[] isConcave = isConcaveArray.Resize(vertexCount).Items; + bool[] isConcave = isConcaveArray.EnsureSize(vertexCount).Items; for (int i = 0, n = vertexCount; i < n; ++i) isConcave[i] = IsConcave(i, vertexCount, vertices, indices); diff --git a/spine-csharp/src/package.json b/spine-csharp/src/package.json index 46375587f..8043c6b24 100644 --- a/spine-csharp/src/package.json +++ b/spine-csharp/src/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-csharp", "displayName": "spine-csharp Runtime", "description": "This plugin provides the spine-csharp core runtime.", - "version": "4.3.10", + "version": "4.3.11", "unity": "2018.3", "author": { "name": "Esoteric Software", diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs index 96a5e8809..0a30759c9 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs @@ -558,9 +558,7 @@ namespace Spine.Unity { Settings settings = this.settings; int newSubmeshCount = submeshIndex + 1; - if (submeshes.Items.Length < newSubmeshCount) - submeshes.Resize(newSubmeshCount); - submeshes.Count = newSubmeshCount; + submeshes.EnsureSize(newSubmeshCount); ExposedList submesh = submeshes.Items[submeshIndex]; if (submesh == null) submeshes.Items[submeshIndex] = submesh = new ExposedList(); @@ -1078,7 +1076,7 @@ namespace Spine.Unity { if (updateTriangles) { // Match submesh buffers count with submeshInstruction count. if (this.submeshes.Items.Length < submeshInstructionCount) { - this.submeshes.Resize(submeshInstructionCount); + this.submeshes.EnsureSize(submeshInstructionCount); for (int i = 0, n = submeshInstructionCount; i < n; i++) { ExposedList submeshBuffer = this.submeshes.Items[i]; if (submeshBuffer == null) @@ -1329,8 +1327,8 @@ namespace Spine.Unity { uv2 = new ExposedList(minimumVertexCount); uv3 = new ExposedList(minimumVertexCount); } - uv2.Resize(minimumVertexCount); - uv3.Resize(minimumVertexCount); + uv2.EnsureSize(minimumVertexCount); + uv3.EnsureSize(minimumVertexCount); } if (includeNormals) { diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index b598690e4..7dd1322e7 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/spine-unity/Assets/Spine/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-unity", "displayName": "spine-unity Runtime", "description": "This plugin provides the spine-unity runtime core and examples. Spine Examples can be installed via the Samples tab.", - "version": "4.3.28", + "version": "4.3.29", "unity": "2018.3", "author": { "name": "Esoteric Software",