[csharp] Cleanup VertexAttachment id threadsafety

This commit is contained in:
John 2017-06-14 04:11:38 +08:00 committed by GitHub
parent 61a5058a5c
commit 5e0ff3694d

View File

@ -34,17 +34,9 @@ namespace Spine {
/// <summary>>An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices.</summary> /// <summary>>An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices.</summary>
public class VertexAttachment : Attachment { public class VertexAttachment : Attachment {
static int nextID = 0; static int nextID = 0;
static Object nextIdLock = new Object(); static readonly Object nextIdLock = new Object();
static int GetNextID () {
int returnValue;
lock (nextIdLock) {
returnValue = nextID;
nextID++;
}
return returnValue;
}
internal readonly int id = (VertexAttachment.GetNextID() & 65535) << 11; internal readonly int id;
internal int[] bones; internal int[] bones;
internal float[] vertices; internal float[] vertices;
internal int worldVerticesLength; internal int worldVerticesLength;
@ -55,8 +47,12 @@ namespace Spine {
public float[] Vertices { get { return vertices; } set { vertices = value; } } public float[] Vertices { get { return vertices; } set { vertices = value; } }
public int WorldVerticesLength { get { return worldVerticesLength; } set { worldVerticesLength = value; } } public int WorldVerticesLength { get { return worldVerticesLength; } set { worldVerticesLength = value; } }
public VertexAttachment (String name) public VertexAttachment (string name)
: base(name) { : base(name) {
lock (VertexAttachment.nextIdLock) {
id = (VertexAttachment.nextID++ & 65535) << 11;
}
} }
public void ComputeWorldVertices (Slot slot, float[] worldVertices) { public void ComputeWorldVertices (Slot slot, float[] worldVertices) {