Skip to content

Commit

Permalink
Merge commit '70b47cef5197dead34813347b9d4ddd1c30e4165' into v2.1.2
Browse files Browse the repository at this point in the history
* commit '70b47cef5197dead34813347b9d4ddd1c30e4165':
  refine uuid-loader error log code (cocos#4492)
  add baidu subcontext view help url for 2d-tasks/issues/1465 (cocos#4491)
  refine item error log (cocos#4487)
  Fix spine cache error when change skin (cocos#4488)
  fix instantiate prefab scale error (cocos#4454)
  fix spine and dragonbones update cache bug (cocos#4457)
  fix _histTest ignore scale bug (cocos#4456)
  merge xiaomi (cocos#4447)
  Optimize spine and dragonbones animation cache (cocos#4387)
  update test-deserialize code (cocos#4432)

# Conflicts:
#	cocos2d/core/CCNode.js
#	cocos2d/core/components/CCMask.js
#	extensions/dragonbones/ArmatureDisplay.js
  • Loading branch information
jareguo committed May 23, 2019
2 parents 296feb5 + 70b47ce commit 195914a
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 96 deletions.
12 changes: 5 additions & 7 deletions cocos2d/core/CCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ let NodeDefines = {
_contentSize: cc.Size,
_anchorPoint: cc.v2(0.5, 0.5),
_position: cc.Vec3,
_scale: cc.Vec3,
_scale: cc.Vec3.ONE,
_eulerAngles: cc.Vec3,
_skewX: 0.0,
_skewY: 0.0,
Expand Down Expand Up @@ -1162,11 +1162,6 @@ let NodeDefines = {
// Mouse event listener
this._mouseListener = null;

// default scale
this._scale.x = 1;
this._scale.y = 1;
this._scale.z = 1;

this._matrix = mathPools.mat4.get();
this._worldMatrix = mathPools.mat4.get();
this._localMatDirty = LocalDirtyFlag.ALL;
Expand Down Expand Up @@ -1857,7 +1852,10 @@ let NodeDefines = {
}

this._updateWorldMatrix();
mat4.invert(_mat4_temp, this._worldMatrix);
// If scale is 0, it can't be hit.
if (!mat4.invert(_mat4_temp, this._worldMatrix)) {
return false;
}
vec2.transformMat4(testPt, cameraPt, _mat4_temp);
testPt.x += this._anchorPoint.x * w;
testPt.y += this._anchorPoint.y * h;
Expand Down
5 changes: 4 additions & 1 deletion cocos2d/core/components/CCMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,10 @@ let Mask = cc.Class({
testPt = _vec2_temp;

node._updateWorldMatrix();
mat4.invert(_mat4_temp, node._worldMatrix);
// If scale is 0, it can't be hit.
if (!mat4.invert(_mat4_temp, node._worldMatrix)) {
return false;
}
vec2.transformMat4(testPt, cameraPt, _mat4_temp);
testPt.x += node._anchorPoint.x * w;
testPt.y += node._anchorPoint.y * h;
Expand Down
4 changes: 3 additions & 1 deletion cocos2d/core/load-pipeline/audio-downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ function loadDomAudio (item, callback) {
var dom = document.createElement('audio');
dom.src = item.url;

// TODO: move into adapter
const isXiaomiGame = (cc.sys.platform === cc.sys.XIAOMI_GAME);
const isBaiduGame = (cc.sys.platform === cc.sys.BAIDU_GAME);
if (CC_WECHATGAME || isBaiduGame) {
if (CC_WECHATGAME || isBaiduGame || isXiaomiGame) {
callback(null, dom);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/load-pipeline/uuid-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function loadDepends (pipeline, item, asset, depends, callback) {
missingAssetReporter.stashByOwner(dependObj, dependProp, Editor.serialize.asAsset(dependSrc));
}
else {
cc._throw(item.error);
cc._throw(item.error.message || item.error.errorMessage || item.error);
}
}
else {
Expand Down
37 changes: 36 additions & 1 deletion cocos2d/core/platform/CCSys.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const isBaiduGame = (settingPlatform === 'baidugame' || settingPlatform === 'bai
const isVivoGame = (settingPlatform === 'qgame');
const isOppoGame = (settingPlatform === 'quickgame');
const isHuaweiGame = (settingPlatform === 'huawei');

var _global = typeof window === 'undefined' ? global : window;

function initSys () {
/**
Expand Down Expand Up @@ -386,6 +388,12 @@ function initSys () {
* @default 110
*/
sys.HUAWEI_GAME = 110;
/**
* @property {Number} XIAOMI_GAME
* @readOnly
* @default 111
*/
sys.XIAOMI_GAME = 111;
/**
* BROWSER_TYPE_WECHAT
* @property {String} BROWSER_TYPE_WECHAT
Expand Down Expand Up @@ -421,6 +429,13 @@ function initSys () {
* @default "baidugamesub"
*/
sys.BROWSER_TYPE_BAIDU_GAME_SUB = "baidugamesub";
/**
* BROWSER_TYPE_XIAOMI_GAME
* @property {String} BROWSER_TYPE_XIAOMI_GAME
* @readOnly
* @default "xiaomigame"
*/
sys.BROWSER_TYPE_XIAOMI_GAME = "xiaomigame";
/**
* BROWSER_TYPE_QQ_PLAY
* @property {String} BROWSER_TYPE_QQ_PLAY
Expand Down Expand Up @@ -594,7 +609,27 @@ function initSys () {
return !!cc.renderer.device.ext(name);
}

if (CC_EDITOR && Editor.isMainProcess) {
if (_global.__platform && _global.__platform.getSystemInfo) {
let env = _global.__platform.getSystemInfo();
sys.isNative = env.isNative;
sys.isBrowser = env.isBrowser;
sys.platform = env.platform;
sys.browserType = env.browserType;
sys.isMobile = env.isMobile;
sys.language = env.language;
sys.languageCode = env.language.toLowerCase();
sys.os = env.os;
sys.osVersion = env.osVersion;
sys.osMainVersion = env.osMainVersion;
sys.browserVersion = env.browserVersion;
sys.windowPixelResolution = env.windowPixelResolution;
sys.localStorage = env.localStorage;
sys.capabilities = env.capabilities;
sys.__audioSupport = env.audioSupport;

_global.__platform = undefined;
}
else if (CC_EDITOR && Editor.isMainProcess) {
sys.isMobile = false;
sys.platform = sys.EDITOR_CORE;
sys.language = sys.LANGUAGE_UNKNOWN;
Expand Down
14 changes: 10 additions & 4 deletions cocos2d/core/platform/CCView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ const js = require('../platform/js');
const renderer = require('../renderer');
require('../platform/CCClass');

// TODO: move into adapter
const isXiaomiGame = (cc.sys.platform === cc.sys.XIAOMI_GAME);
const isBaiduGame = (cc.sys.platform === cc.sys.BAIDU_GAME);

var __BrowserGetter = {
init: function(){
if (!CC_WECHATGAME && !CC_QQPLAY && !isBaiduGame) {
if (!CC_WECHATGAME && !CC_QQPLAY && !isBaiduGame && !isXiaomiGame) {
this.html = document.getElementsByTagName("html")[0];
}
},
Expand Down Expand Up @@ -68,6 +70,10 @@ if (isBaiduGame) {
}
}

if (isXiaomiGame) {
__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_XIAOMI_GAME;
}

if (CC_WECHATGAME) {
if (cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT_GAME_SUB) {
__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_WECHAT_GAME_SUB;
Expand Down Expand Up @@ -414,7 +420,7 @@ cc.js.mixin(View.prototype, {
},

_adjustViewportMeta: function () {
if (this._isAdjustViewport && !CC_JSB && !CC_RUNTIME && !CC_WECHATGAME && !CC_QQPLAY && !isBaiduGame) {
if (this._isAdjustViewport && !CC_JSB && !CC_RUNTIME && !CC_WECHATGAME && !CC_QQPLAY && !isBaiduGame && !isXiaomiGame) {
this._setViewportMeta(__BrowserGetter.meta, false);
this._isAdjustViewport = false;
}
Expand Down Expand Up @@ -816,7 +822,7 @@ cc.js.mixin(View.prototype, {
* @param {ResolutionPolicy|Number} resolutionPolicy The resolution policy desired
*/
setRealPixelResolution: function (width, height, resolutionPolicy) {
if (!CC_JSB && !CC_RUNTIME && !CC_WECHATGAME && !CC_QQPLAY && !isBaiduGame) {
if (!CC_JSB && !CC_RUNTIME && !CC_WECHATGAME && !CC_QQPLAY && !isBaiduGame && !isXiaomiGame) {
// Set viewport's width
this._setViewportMeta({"width": width}, true);

Expand Down Expand Up @@ -1074,7 +1080,7 @@ cc.ContainerStrategy = cc.Class({
_setupContainer: function (view, w, h) {
var locCanvas = cc.game.canvas, locContainer = cc.game.container;

if (!CC_WECHATGAME && !isBaiduGame) {
if (!CC_WECHATGAME && !isBaiduGame && !isXiaomiGame) {
if (cc.sys.os === cc.sys.OS_ANDROID) {
document.body.style.width = (view._isRotated ? h : w) + 'px';
document.body.style.height = (view._isRotated ? w : h) + 'px';
Expand Down
4 changes: 3 additions & 1 deletion cocos2d/videoplayer/video-player-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,11 @@ VideoPlayerImpl._polyfill = {
* But native does not support this encode,
* so it is best to provide mp4 and webm or ogv file
*/
// TODO: move into adapter
const isXiaomiGame = (cc.sys.platform === cc.sys.XIAOMI_GAME);
const isBaiduGame = (cc.sys.platform === cc.sys.BAIDU_GAME);
let dom = document.createElement("video");
if (!CC_WECHATGAME && !isBaiduGame) {
if (!CC_WECHATGAME && !isBaiduGame && !isXiaomiGame) {
if (dom.canPlayType("video/ogg")) {
VideoPlayerImpl._polyfill.canPlayType.push(".ogg");
VideoPlayerImpl._polyfill.canPlayType.push(".ogv");
Expand Down
3 changes: 2 additions & 1 deletion editor/i18n/en/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = {
"toggleContainer": "https://docs.cocos.com/creator/manual/en/components/toggleContainer.html",
"slider": "https://docs.cocos.com/creator/manual/en/components/slider.html",
"block_input_events": "https://docs.cocos.com/creator/manual/en/components/block-input-events.html",
"wx_subcontext_view": "https://docs.cocos.com/creator/manual/en/publish/publish-wechatgame-sub-domain.html"
"wx_subcontext_view": "https://docs.cocos.com/creator/manual/en/publish/publish-wechatgame-sub-domain.html",
"swan_subcontext_view": "https://docs.cocos.com/creator/manual/en/publish/publish-baidugame-sub-domain.html"
},
"animation": {
"default_clip": "When checking, the deault animation clip is automatically played.",
Expand Down
3 changes: 2 additions & 1 deletion editor/i18n/zh/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = {
"toggleContainer": "https://docs.cocos.com/creator/manual/zh/components/toggleContainer.html",
"slider": "https://docs.cocos.com/creator/manual/zh/components/slider.html",
"block_input_events": "https://docs.cocos.com/creator/manual/zh/components/block-input-events.html",
"wx_subcontext_view": "https://docs.cocos.com/creator/manual/zh/publish/publish-wechatgame-sub-domain.html"
"wx_subcontext_view": "https://docs.cocos.com/creator/manual/zh/publish/publish-wechatgame-sub-domain.html",
"swan_subcontext_view": "https://docs.cocos.com/creator/manual/zh/publish/publish-baidugame-sub-domain.html"
},
'animation': {
'default_clip': '在勾选自动播放或调用 play() 时默认播放的动画 clip。',
Expand Down
82 changes: 65 additions & 17 deletions extensions/dragonbones/ArmatureCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
THE SOFTWARE.
****************************************************************************/
const MaxCacheTime = 30;
const FrameTime = 1 / 60;

let _vertices = [];
let _indices = [];
let _vertexOffset = 0;
let _indexOffset = 0;
let _vfOffset = 0;
let _frameTime = 1 / 60;
let _preTexUrl = null;
let _preBlendMode = null;
let _segVCount = 0;
Expand All @@ -44,13 +44,17 @@ let AnimationCache = cc.Class({
ctor () {
this.frames = [];
this.totalTime = 0;
this.isCompleted = false;
this._frameIdx = -1;

this._armatureInfo = null;
this._animationName = null;
this._tempSegments = null;
this._tempColors = null;
},

init (animationName) {
init (armatureInfo, animationName) {
this._armatureInfo = armatureInfo;
this._animationName = animationName;
},

Expand All @@ -62,24 +66,58 @@ let AnimationCache = cc.Class({
}
},

update (armature) {
if (!this._animationName) {
cc.error("AnimationCache:update animationName is empty");
return;
begin () {
let armatureInfo = this._armatureInfo;
if (armatureInfo.curAnimationCache) {
armatureInfo.curAnimationCache.updateToFrame();
}
let armature = armatureInfo.armature;
let animation = armature.animation;
animation.play(this._animationName, 1);
let frameIdx = 0;

armatureInfo.curAnimationCache = this;
this._frameIdx = -1;
this.totalTime = 0;
this.isCompleted = false;
},

end () {
if (!this._needToUpdate()) {
this._armatureInfo.curAnimationCache = null;
this.frames.length = this._frameIdx + 1;
this.isCompleted = true;
}
},

_needToUpdate (toFrameIdx) {
let armatureInfo = this._armatureInfo;
let armature = armatureInfo.armature;
let animation = armature.animation;
return !animation.isCompleted &&
this.totalTime < MaxCacheTime &&
(toFrameIdx == undefined || this._frameIdx < toFrameIdx);
},

updateToFrame (toFrameIdx) {
if (!this._needToUpdate(toFrameIdx)) return;

let armatureInfo = this._armatureInfo;
let armature = armatureInfo.armature;

do {
// Solid update frame rate 1/60.
armature.advanceTime(_frameTime);
this._updateFrame(armature, frameIdx);
frameIdx++;
this.totalTime += _frameTime;
} while (!animation.isCompleted && this.totalTime < MaxCacheTime);
// Update frame length.
this.frames.length = frameIdx;
armature.advanceTime(FrameTime);
this._frameIdx++;
this._updateFrame(armature, this._frameIdx);
this.totalTime += FrameTime;
} while (this._needToUpdate(toFrameIdx));

this.end();
},

updateAllFrame () {
this.begin();
this.updateToFrame();
},

_updateFrame (armature, index) {
Expand Down Expand Up @@ -315,6 +353,7 @@ let ArmatureCache = cc.Class({
// Cache all kinds of animation frame.
// When armature is dispose, clear all animation cache.
animationsCache : {},
curAnimationCache: null,
};
} else {
armature = armatureInfo.armature;
Expand All @@ -330,7 +369,9 @@ let ArmatureCache = cc.Class({
return animationsCache[animationName];
},

updateAnimationCache (armatureKey, animationName) {
initAnimationCache (armatureKey, animationName) {
if (!animationName) return null;

let armatureInfo = this._armatureCache[armatureKey];
let armature = armatureInfo && armatureInfo.armature;
if (!armature) return null;
Expand All @@ -348,18 +389,25 @@ let ArmatureCache = cc.Class({
delete this._animationPool[poolKey];
} else {
animationCache = new AnimationCache();
animationCache.init(animationName);
}
animationCache.init(armatureInfo, animationName);
animationsCache[animationName] = animationCache;
}
animationCache.update(armature);
return animationCache;
},

updateAnimationCache (armatureKey, animationName) {
let animationCache = this.initAnimationCache(armatureKey, animationName);
if (!animationCache) return;
animationCache.updateAllFrame();
if (animationCache.totalTime >= MaxCacheTime) {
cc.warn("Animation cache is overflow, maybe animation's frame is infinite, please change armature render mode to REALTIME, dragonbones uuid is [%s], animation name is [%s]", armatureKey, animationName);
}
return animationCache;
}
});

ArmatureCache.FrameTime = FrameTime;
ArmatureCache.sharedCache = new ArmatureCache();
ArmatureCache.canCache = function (armature) {
let slots = armature._slots;
Expand Down
Loading

0 comments on commit 195914a

Please sign in to comment.