Skip to content

Commit

Permalink
Merge pull request cocos#36 from sunnylanwanjun/v2.3.0-optimize-memory
Browse files Browse the repository at this point in the history
v2.3.0 fix some bug
  • Loading branch information
2youyou2 committed Jul 17, 2019
2 parents f404f75 + d4fb29a commit 65a2998
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 32 deletions.
23 changes: 13 additions & 10 deletions extensions/dragonbones/ArmatureDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ let ArmatureDisplay = cc.Class({
}
},

_emitCacheCompleteEvent () {
// Animation loop complete, the event diffrent from dragonbones inner event,
// It has no event object.
this._eventTarget.emit(dragonBones.EventObject.LOOP_COMPLETE);

// Animation complete the event diffrent from dragonbones inner event,
// It has no event object.
this._eventTarget.emit(dragonBones.EventObject.COMPLETE);
},

update (dt) {
if (!this.isAnimationCached()) return;
if (!this._playing) return;
Expand All @@ -532,7 +542,7 @@ let ArmatureDisplay = cc.Class({
// Animation Start, the event diffrent from dragonbones inner event,
// It has no event object.
if (this._accTime == 0 && this._playCount == 0) {
this._eventTarget && this._eventTarget.emit(dragonBones.EventObject.START);
this._eventTarget.emit(dragonBones.EventObject.START);
}

let globalTimeScale = dragonBones.timeScale;
Expand All @@ -543,26 +553,19 @@ let ArmatureDisplay = cc.Class({
}

if (frameCache.isCompleted && frameIdx >= frames.length) {

// Animation loop complete, the event diffrent from dragonbones inner event,
// It has no event object.
this._eventTarget && this._eventTarget.emit(dragonBones.EventObject.LOOP_COMPLETE);

// Animation complete the event diffrent from dragonbones inner event,
// It has no event object.
this._eventTarget && this._eventTarget.emit(dragonBones.EventObject.COMPLETE);

this._playCount ++;
if ((this.playTimes > 0 && this._playCount >= this.playTimes)) {
// set frame to end frame.
this._curFrame = frames[frames.length - 1];
this._accTime = 0;
this._playing = false;
this._playCount = 0;
this._emitCacheCompleteEvent();
return;
}
this._accTime = 0;
frameIdx = 0;
this._emitCacheCompleteEvent();
}

this._curFrame = frames[frameIdx];
Expand Down
2 changes: 1 addition & 1 deletion extensions/dragonbones/webgl-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function _getSlotMaterial (tex, blendMode) {
let useModel = !_comp.enableBatch;
// Add useModel flag due to if pre same db useModel but next db no useModel,
// then next db will multiply model matrix more than once.
let key = tex.url + src + dst + useModel;
let key = tex.getId() + src + dst + useModel;
let baseMaterial = _comp.sharedMaterials[0];
if (!baseMaterial) {
return null;
Expand Down
28 changes: 16 additions & 12 deletions extensions/spine/Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ sp.Skeleton = cc.Class({
*/
setSlotsRange (startSlotIndex, endSlotIndex) {
if (this.isAnimationCached()) {
console.warn("Slots visible range can not be modified in cached mode.");
cc.warn("Slots visible range can not be modified in cached mode.");
} else {
this._startSlotIndex = startSlotIndex;
this._endSlotIndex = endSlotIndex;
Expand All @@ -535,7 +535,7 @@ sp.Skeleton = cc.Class({
*/
setAnimationStateData (stateData) {
if (this.isAnimationCached()) {
console.warn("'setAnimationStateData' interface can not be invoked in cached mode.");
cc.warn("'setAnimationStateData' interface can not be invoked in cached mode.");
} else {
var state = new spine.AnimationState(stateData);
if (this._listener) {
Expand Down Expand Up @@ -637,6 +637,15 @@ sp.Skeleton = cc.Class({
}
},

_emitCacheCompleteEvent () {
if (!this._listener) return;
// Animation complete, the event diffrent from dragonbones inner event,
// It has no event object.
this._endEntry.animation.name = this._animationName;
this._listener.complete && this._listener.complete(this._endEntry);
this._listener.end && this._listener.end(this._endEntry);
},

_updateCache (dt) {
let frameCache = this._frameCache;
let frames = frameCache.frames;
Expand All @@ -656,24 +665,19 @@ sp.Skeleton = cc.Class({
}

if (frameCache.isCompleted && frameIdx >= frames.length) {

// Animation complete, the event diffrent from dragonbones inner event,
// It has no event object.
this._endEntry.animation.name = this._animationName;
this._listener && this._listener.complete && this._listener.complete(this._endEntry);
this._listener && this._listener.end && this._listener.end(this._endEntry);

this._playCount ++;
if (this._playTimes > 0 && this._playCount >= this._playTimes) {
// set frame to end frame.
this._curFrame = frames[frames.length - 1];
this._accTime = 0;
this._playCount = 0;
this._isAniComplete = true;
this._emitCacheCompleteEvent();
return;
}
this._accTime = 0;
frameIdx = 0;
this._emitCacheCompleteEvent();
}
this._curFrame = frames[frameIdx];
},
Expand Down Expand Up @@ -1062,7 +1066,7 @@ sp.Skeleton = cc.Class({
*/
getCurrent (trackIndex) {
if (this.isAnimationCached()) {
console.warn("'getCurrent' interface can not be invoked in cached mode.");
cc.warn("'getCurrent' interface can not be invoked in cached mode.");
} else {
if (this._state) {
return this._state.getCurrent(trackIndex);
Expand All @@ -1078,7 +1082,7 @@ sp.Skeleton = cc.Class({
*/
clearTracks () {
if (this.isAnimationCached()) {
console.warn("'clearTracks' interface can not be invoked in cached mode.");
cc.warn("'clearTracks' interface can not be invoked in cached mode.");
} else {
if (this._state) {
this._state.clearTracks();
Expand All @@ -1094,7 +1098,7 @@ sp.Skeleton = cc.Class({
*/
clearTrack (trackIndex) {
if (this.isAnimationCached()) {
console.warn("'clearTrack' interface can not be invoked in cached mode.");
cc.warn("'clearTrack' interface can not be invoked in cached mode.");
} else {
if (this._state) {
this._state.clearTrack(trackIndex);
Expand Down
3 changes: 1 addition & 2 deletions extensions/spine/editor/spine-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class SpineMeta extends CustomAssetMeta {
//this.textures[0] = value;
}

static version () { return '1.2.1'; }
static version () { return '1.2.2'; }
static defaultType () {
return 'spine';
}
Expand Down Expand Up @@ -176,7 +176,6 @@ class SpineMeta extends CustomAssetMeta {
var asset = new sp.SkeletonData();
asset.name = Path.basenameNoExt(fspath);
asset.skeletonJson = json;
asset.skeletonJsonStr = data;
asset.scale = this.scale;

loadAtlasText(fspath, (err, res) => {
Expand Down
22 changes: 16 additions & 6 deletions extensions/spine/skeleton-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ var SkeletonData = cc.Class({
},

properties: {

// store skeleton json string for jsb
skeletonJsonStr: "",
_skeletonJson: null,

// use by jsb
skeletonJsonStr: {
get: function () {
if (this._skeletonJson) {
return JSON.stringify(this._skeletonJson);
} else {
return "";
}
}
},

/**
* !#en See http://en.esotericsoftware.com/spine-json-format
* !#zh 可查看 Spine 官方文档 http://zh.esotericsoftware.com/spine-json-format
Expand All @@ -58,9 +66,11 @@ var SkeletonData = cc.Class({
return this._skeletonJson;
},
set: function (value) {
this._skeletonJson = value;
// If dynamic set skeletonJson field, auto update skeletonJsonStr field.
this.skeletonJsonStr = JSON.stringify(value);
if (typeof(value) == "string") {
this._skeletonJson = JSON.parse(value);
} else {
this._skeletonJson = value;
}
// If create by manual, uuid is empty.
if (!this._uuid && value.skeleton) {
this._uuid = value.skeleton.hash;
Expand Down
2 changes: 1 addition & 1 deletion extensions/spine/spine-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function _getSlotMaterial (tex, blendMode) {
}

let useModel = !_comp.enableBatch;
let key = tex.url + src + dst + _useTint + useModel;
let key = tex.getId() + src + dst + _useTint + useModel;
let baseMaterial = _comp.sharedMaterials[0];
if (!baseMaterial) return null;

Expand Down

0 comments on commit 65a2998

Please sign in to comment.