Skip to content

Commit

Permalink
1.34.1 bone control optimization, repeated init bug fix.
Browse files Browse the repository at this point in the history
Cache bone control for better bone control performance.
Insure only one skeletonData initialization is done per Spine object.
  • Loading branch information
MikalDev committed Feb 3, 2021
1 parent be2a11f commit 2ca1df9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
Binary file added dist/Spine-v1.34.1.c3addon
Binary file not shown.
2 changes: 1 addition & 1 deletion src/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "plugin",
"name": "Spine",
"id": "Gritsenko_Spine",
"version": "1.34.0",
"version": "1.34.1",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand Down
22 changes: 11 additions & 11 deletions src/c3runtime/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@
// this.assetManager = new spine.SharedAssetManager();
// this.bgColor = new spine.Color(0.0, 0.0, 0.0, 0.0);

if (this._sdkType._skeletonData.notInitialized)
if (!this._sdkType._skeletonDataInitialized)
{
this._sdkType._skeletonDataInitializing = true;
this._sdkType._assetManager = new spine.SharedAssetManager();
this._sdkType._assetTag = this.uid;
this.assetManager = this._sdkType._assetManager;
this._sdkType._skeletonData.initializing = true;
const assetTag = this._sdkType._assetTag;

if (this.debug) console.log(this.GetInstance().GetUID(),'[Spine] Loading skeleton, textures, json, atlas');
if (this.debug) console.info(this.GetInstance().GetUID(),'[Spine] Loading skeleton, textures, json, atlas');
// Only load textures once for creation of skeletonData, not for each instance
// Disable PMA when loading Spine textures
spine.webgl.GLTexture.DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL = true;
Expand All @@ -140,7 +140,6 @@
}

this.assetManager.loadText(assetTag, this.atlasURI);
this._sdkType._skeletonData.initializing = false;
}
this.isSpineInitialized = true;
}
Expand Down Expand Up @@ -187,11 +186,10 @@
const assetTag = this._sdkType._assetTag;
const self = this;

if (this.debug) console.log("[Spine] Reading skeleton data:", this.uid, name, animationName);
if (this.debug) console.info("[Spine] Reading skeleton data:", this.uid, name, animationName);
// If skeletonData not initialized, create it and stop other instances from creating it
if (this._sdkType._skeletonData.notInitialized)
if (!this._sdkType._skeletonDataInitialized)
{
this._sdkType._skeletonData.notInitialized = false;
const atlasURI = assetManager.get(assetTag, this.atlasURI);
this._sdkType._atlas = new spine.TextureAtlas(atlasURI, function(path) {
return assetManager.get(self._sdkType._assetTag, self._sdkType._assetPaths[path]);
Expand All @@ -209,6 +207,8 @@
{
this._sdkType._skeletonData = this._sdkType._skeletonJson.readSkeletonData(assetManager.get(assetTag, this.jsonURI) [name] );
}
this._sdkType._skeletonDataInitialized = true;
this._sdkType._skeletonDataInitializing = false;
}

var skeleton = new spine.Skeleton(this._sdkType._skeletonData);
Expand Down Expand Up @@ -240,7 +240,7 @@
}
};

// if (this.debug) console.log('[Spine] track:', state.tracks[0]);
// if (this.debug) console.info('[Spine] track:', state.tracks[0]);

state.apply(skeleton);
skeleton.updateWorldTransform();
Expand Down Expand Up @@ -417,7 +417,7 @@
}

if (!this.isSpineInitialized) {
if (!this.initSpineInProgress && !this._sdkType._skeletonData.initializing)
if (!this.initSpineInProgress && !this._sdkType._skeletonDataInitializing)
{
this.initSpine();
}
Expand Down Expand Up @@ -497,7 +497,7 @@
let layerRect = wi.GetLayer().GetViewport();
let instanceRect = wi.GetBoundingBox();
let onScreen = instanceRect.intersectsRect(layerRect);
// console.log('[Spine] onscreen, rects', onScreen, layerRect, instanceRect);
// console.info('[Spine] onscreen, rects', onScreen, layerRect, instanceRect);
spineBatcher.setInstanceOnScreen(onScreen, this.uid);


Expand Down Expand Up @@ -575,7 +575,7 @@
let options = { mipMap: false, sampling: sampling }
if (this.debug)
{
console.log('[Spine] CreateDynamicTexture x,y:', Math.round(this.textureWidth), Math.round(this.textureHeight), this.uid, this.runtime.GetTickCount());
console.info('[Spine] CreateDynamicTexture x,y:', Math.round(this.textureWidth), Math.round(this.textureHeight), this.uid, this.runtime.GetTickCount());
}
this._elementTexture = renderer.CreateDynamicTexture(this.textureWidth, this.textureHeight, options);

Expand Down
15 changes: 12 additions & 3 deletions src/c3runtime/spine-bone-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ class SpineBoneControl {
const bones = this.bones;
for(let boneName in bones)
{
let bone = skeleton.findBone(boneName);
if (!bone) {console.warn('[Spine] applyBoneControl bone not found', boneName);continue;}
if(!bones[boneName].hasOwnProperty('__boneControlReference'))
{
let boneControlReference = skeleton.findBone(boneName);
if (!boneControlReference) {console.warn('[Spine] applyBoneControl bone not found', boneName);continue;}
// Cache reference
bones[boneName].__boneControlReference = boneControlReference;
}

for(const property in bones[boneName])
{
bone[property] = bones[boneName][property];
// Ignore reference to bone
if (property == '__boneControlReference') continue;

bones[boneName].__boneControlReference[property] = bones[boneName][property];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/c3runtime/spine-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ class SpineBatch {

if (!globalThis.spineBatcher)
{
console.log('[Spine] SpineBatcher init, 1.34.0');
console.log('[Spine] SpineBatcher init, 1.34.1');
globalThis.spineBatcher = new SpineBatch();
}
3 changes: 2 additions & 1 deletion src/c3runtime/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
OnCreate()
{
this.GetImageInfo().LoadAsset(this._runtime);
this._skeletonData = {notInitialized : true, initializing : false}
this._skeletonDataInitialized = false;
this._skeletonDataInitializing = false;
this._skeletonJson = null;
// Tag for asset manager for skeletonData assets.
this._assetTag = null;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const C3 = self.C3;

const PLUGIN_ID = "Gritsenko_Spine";
const PLUGIN_VERSION = "1.34.0";
const PLUGIN_VERSION = "1.34.1";
const PLUGIN_CATEGORY = "general";

const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {
Expand Down

0 comments on commit 2ca1df9

Please sign in to comment.