Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
bofeng-song committed Dec 12, 2023
1 parent f6f2f59 commit 79a6146
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 17 additions & 12 deletions cocos/spine/skeleton-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,28 @@ export class AnimationCache {
public totalTime = 0;
public frames: AnimationFrame[] = [];

constructor (data: spine.SkeletonData, animCache: AnimationCache | null) {
private constructor (data: spine.SkeletonData) {
this._privateMode = false;
this._inited = false;
this._invalid = true;
this._skeletonData = data;
}

if (!animCache || animCache._skeletonData !== data) {
this._instance = new spine.SkeletonInstance();
this._instance.isCache = true;
this._skeletonData = data;
this._skeleton = this._instance.initSkeleton(data);
this._instance.setUseTint(_useTint);
static createInstance (data: spine.SkeletonData, animCache: AnimationCache | null): AnimationCache {
const cache = new AnimationCache(data);
if (animCache && animCache._skeletonData === data) {
cache._instance = animCache._instance;
cache._skeleton = animCache._skeleton;
} else {
this._skeletonData = animCache._skeletonData;
this._instance = animCache._instance;
this._skeleton = animCache._skeleton;
const skeletonInstance = new spine.SkeletonInstance();
skeletonInstance.isCache = true;
cache._skeleton = skeletonInstance.initSkeleton(data);
skeletonInstance.setUseTint(_useTint);
cache._instance = skeletonInstance;
}
this._instance.addRef();
cache._instance.addRef();

return cache;
}

public init (skeletonInfo: SkeletonCacheItemInfo, animationName: string): void {
Expand Down Expand Up @@ -409,7 +414,7 @@ class SkeletonCache {
if (animationCache) {
delete this._animationPool[poolKey];
} else {
animationCache = new AnimationCache(spData, animCache);
animationCache = AnimationCache.createInstance(spData, animCache);
animationCache._privateMode = this._privateMode;
}
animationCache.init(skeletonInfo, animationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SpineSkeletonInstance::SpineSkeletonInstance() {
}

SpineSkeletonInstance::~SpineSkeletonInstance() {
SpineSkeletonSystem::removeSpineInstance(this);
_skeletonData = nullptr;
if (_clipper) delete _clipper;
if (_animState) delete _animState;
Expand Down Expand Up @@ -92,7 +93,6 @@ void SpineSkeletonInstance::updateAnimation(float dltTime) {
_skeleton->update(dltTime);
_animState->update(dltTime);
_animState->apply(*_skeleton);
_skeleton->updateWorldTransform();
}

SpineModel *SpineSkeletonInstance::updateRenderData() {
Expand Down Expand Up @@ -588,7 +588,6 @@ void SpineSkeletonInstance::release() {
--_referenceCount;

if (_referenceCount == 0) {
SpineSkeletonSystem::removeSpineInstance(this);
delete this;
}
}

0 comments on commit 79a6146

Please sign in to comment.