Skip to content

Commit

Permalink
optimize computeWorldVertices to avoid every call to new SPVectorFloa…
Browse files Browse the repository at this point in the history
…t();.
  • Loading branch information
Canvasfull committed Oct 12, 2023
1 parent 9f827b0 commit 4f911f3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions cocos/spine/lib/spine-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,14 @@ function overrideProperty_VertexAttachment (): void {
overrideDefineArrayProp(prototype, prototype.getBones, 'bones');
overrideDefineArrayProp(prototype, prototype.getVertices, 'vertices');
const originComputeWorldVertices = prototype.computeWorldVertices;
const vectors = new spine.SPVectorFloat();
Object.defineProperty(prototype, 'computeWorldVertices', {
value (slot: spine.Slot, start: number, count: number, worldVertices: number[], offset: number, stride: number) {
const vectors = new spine.SPVectorFloat();
const length = worldVertices.length;
vectors.resize(length, 0);
for (let i = 0; i < length; i++) vectors.set(i, worldVertices[i]);
originComputeWorldVertices.call(this, slot, start, count, vectors, offset, stride);
for (let i = 0; i < length; i++) worldVertices[i] = vectors.get(i);
vectors.delete();
},
});
}
Expand Down Expand Up @@ -809,15 +808,14 @@ function overrideProperty_RegionAttachment (): void {
});

const originComputeWorldVertices = prototype.computeWorldVertices;
const vectors = new spine.SPVectorFloat();
Object.defineProperty(prototype, 'computeWorldVertices', {
value (bone: spine.Bone, worldVertices: number[], offset: number, stride: number) {
const vectors = new spine.SPVectorFloat();
const length = worldVertices.length;
vectors.resize(length, 0);
for (let i = 0; i < length; i++) vectors.set(i, worldVertices[i]);
originComputeWorldVertices.call(this, bone, vectors, offset, stride);
for (let i = 0; i < length; i++) worldVertices[i] = vectors.get(i);
vectors.delete();
},
});
}
Expand Down

0 comments on commit 4f911f3

Please sign in to comment.