From 8407361ff4ee63e70e91432283b723ed36a6e4af Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 11:50:48 +0800 Subject: [PATCH 001/839] remove bind from UIWidget.onFocusChanged; --- extensions/ccui/base-classes/UIWidget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ccui/base-classes/UIWidget.js b/extensions/ccui/base-classes/UIWidget.js index b7e7a16f76..d3463eebaf 100644 --- a/extensions/ccui/base-classes/UIWidget.js +++ b/extensions/ccui/base-classes/UIWidget.js @@ -186,7 +186,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ this._initRenderer(); this.setBright(true); - this.onFocusChanged = this.onFocusChange.bind(this); + this.onFocusChanged = this.onFocusChange; this.onNextFocusedWidget = null; this.setAnchorPoint(cc.p(0.5, 0.5)); From 5d140daecf66b286144c6f136e6dc2bbb899ada2 Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 11:55:15 +0800 Subject: [PATCH 002/839] remove bind from UILayout.onPassFocusToChild; --- extensions/ccui/layouts/UILayout.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extensions/ccui/layouts/UILayout.js b/extensions/ccui/layouts/UILayout.js index 99b242c2ae..67b6d62db9 100644 --- a/extensions/ccui/layouts/UILayout.js +++ b/extensions/ccui/layouts/UILayout.js @@ -246,7 +246,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ this.ignoreContentAdaptWithSize(false); this.setContentSize(cc.size(0, 0)); this.setAnchorPoint(0, 0); - this.onPassFocusToChild = this._findNearestChildWidgetIndex.bind(this); + this.onPassFocusToChild = this._findNearestChildWidgetIndex; return true; } return false; @@ -1065,16 +1065,16 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ var widgetPosition = this._getWorldCenterPoint(this._findFirstNonLayoutWidget()); if (direction === ccui.Widget.LEFT) { this.onPassFocusToChild = (previousWidgetPosition.x > widgetPosition.x) ? this._findNearestChildWidgetIndex.bind(this) - : this._findFarthestChildWidgetIndex.bind(this); + : this._findFarthestChildWidgetIndex; } else if (direction === ccui.Widget.RIGHT) { - this.onPassFocusToChild = (previousWidgetPosition.x > widgetPosition.x) ? this._findFarthestChildWidgetIndex.bind(this) - : this._findNearestChildWidgetIndex.bind(this); + this.onPassFocusToChild = (previousWidgetPosition.x > widgetPosition.x) ? this._findFarthestChildWidgetIndex + : this._findNearestChildWidgetIndex; }else if(direction === ccui.Widget.DOWN) { - this.onPassFocusToChild = (previousWidgetPosition.y > widgetPosition.y) ? this._findNearestChildWidgetIndex.bind(this) - : this._findFarthestChildWidgetIndex.bind(this); + this.onPassFocusToChild = (previousWidgetPosition.y > widgetPosition.y) ? this._findNearestChildWidgetIndex + : this._findFarthestChildWidgetIndex; }else if(direction === ccui.Widget.UP) { - this.onPassFocusToChild = (previousWidgetPosition.y < widgetPosition.y) ? this._findNearestChildWidgetIndex.bind(this) - : this._findFarthestChildWidgetIndex.bind(this); + this.onPassFocusToChild = (previousWidgetPosition.y < widgetPosition.y) ? this._findNearestChildWidgetIndex + : this._findFarthestChildWidgetIndex; }else cc.log("invalid direction!"); }, From 8b5bdf0a0d100296ec67d14dc9001bf77cf5db0c Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 11:58:55 +0800 Subject: [PATCH 003/839] filter out non-Widget; --- extensions/ccui/layouts/UILayoutManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ccui/layouts/UILayoutManager.js b/extensions/ccui/layouts/UILayoutManager.js index e12cc31333..d69a36618c 100644 --- a/extensions/ccui/layouts/UILayoutManager.js +++ b/extensions/ccui/layouts/UILayoutManager.js @@ -176,7 +176,7 @@ ccui.relativeLayoutManager = /** @lends ccui.relativeLayoutManager# */{ locWidgetChildren.length = 0; for (var i = 0, len = container.length; i < len; i++){ var child = container[i]; - if (child) { + if (child && child instanceof ccui.Widget) { var layoutParameter = child.getLayoutParameter(); layoutParameter._put = false; this._unlayoutChildCount++; From 841b91bc5dbc732c044d0217d8b00306d1f78871 Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 12:34:48 +0800 Subject: [PATCH 004/839] specify a parmaeter for item.getLayoutParameter in UIListView._remedyLayoutParameter; --- extensions/ccui/uiwidgets/scroll-widget/UIListView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ccui/uiwidgets/scroll-widget/UIListView.js b/extensions/ccui/uiwidgets/scroll-widget/UIListView.js index 370dd411b3..d77bfbf215 100644 --- a/extensions/ccui/uiwidgets/scroll-widget/UIListView.js +++ b/extensions/ccui/uiwidgets/scroll-widget/UIListView.js @@ -118,7 +118,7 @@ ccui.ListView = ccui.ScrollView.extend(/** @lends ccui.ListView# */{ _remedyLayoutParameter: function (item) { cc.assert(null != item, "ListView Item can't be nil!"); - var linearLayoutParameter = item.getLayoutParameter(); + var linearLayoutParameter = item.getLayoutParameter(ccui.LayoutParameter.LINEAR); var isLayoutParameterExists = true; if (!linearLayoutParameter) { linearLayoutParameter = new ccui.LinearLayoutParameter(); From b403b4efac7eb484046ca7596f9b6a196d977ec1 Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 12:37:45 +0800 Subject: [PATCH 005/839] fix interceptTouchEvent; --- extensions/ccui/uiwidgets/scroll-widget/UIListView.js | 2 ++ extensions/ccui/uiwidgets/scroll-widget/UIPageView.js | 2 ++ extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/extensions/ccui/uiwidgets/scroll-widget/UIListView.js b/extensions/ccui/uiwidgets/scroll-widget/UIListView.js index d77bfbf215..e00458cf65 100644 --- a/extensions/ccui/uiwidgets/scroll-widget/UIListView.js +++ b/extensions/ccui/uiwidgets/scroll-widget/UIListView.js @@ -463,6 +463,8 @@ ccui.ListView = ccui.ScrollView.extend(/** @lends ccui.ListView# */{ * @param {cc.Touch} touch */ interceptTouchEvent: function (eventType, sender, touch) { + if (!this.isTouchEnabled()) return; + ccui.ScrollView.prototype.interceptTouchEvent.call(this, eventType, sender, touch); if (eventType !== ccui.Widget.TOUCH_MOVED) { var parent = sender; diff --git a/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js b/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js index 49210ef9b2..a2cafab90d 100644 --- a/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js +++ b/extensions/ccui/uiwidgets/scroll-widget/UIPageView.js @@ -495,6 +495,8 @@ ccui.PageView = ccui.Layout.extend(/** @lends ccui.PageView# */{ * @param {cc.Touch} touch */ interceptTouchEvent: function (eventType, sender, touch) { + if (!this.isTouchEnabled()) return; + var touchPoint = touch.getLocation(); switch (eventType) { case ccui.Widget.TOUCH_BEGAN: diff --git a/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js b/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js index db3227ffbc..d5961d464c 100644 --- a/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js +++ b/extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js @@ -1452,6 +1452,8 @@ ccui.ScrollView = ccui.Layout.extend(/** @lends ccui.ScrollView# */{ * @param {cc.Touch} touch */ interceptTouchEvent: function (event, sender, touch) { + if (!this.isTouchEnabled()) return; + var touchPoint = touch.getLocation(); switch (event) { case ccui.Widget.TOUCH_BEGAN: From 188ff29e4d485fe95acfad660a76804b330f5da5 Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 12:46:30 +0800 Subject: [PATCH 006/839] correct CCActionNode's postion; --- extensions/cocostudio/action/CCActionNode.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/extensions/cocostudio/action/CCActionNode.js b/extensions/cocostudio/action/CCActionNode.js index a4ae9a9332..c6c18f3c25 100644 --- a/extensions/cocostudio/action/CCActionNode.js +++ b/extensions/cocostudio/action/CCActionNode.js @@ -63,6 +63,7 @@ ccs.ActionNode = ccs.Class.extend(/** @lends ccs.ActionNode# */{ */ initWithDictionary: function (dic, root) { this.setActionTag(dic["ActionTag"]); + this._initActionNodeFromRoot(root); var actionFrameList = dic["actionframelist"]; for (var i = 0; i < actionFrameList.length; i++) { var actionFrameDic = actionFrameList[i]; @@ -86,7 +87,19 @@ ccs.ActionNode = ccs.Class.extend(/** @lends ccs.ActionNode# */{ actionFrame.frameIndex = frameIndex; actionFrame.setEasingType(frameTweenType); actionFrame.setEasingParameter(frameTweenParameter); - actionFrame.setPosition(positionX, positionY); + + var actionNode = this.getActionNode(); + if (actionNode && actionNode.getParent()) { + var actionNodeParentAnchorInPoints = actionNode.getParent().getAnchorPointInPoints(); + actionFrame.setPosition( + positionX + actionNodeParentAnchorInPoints.x, + positionY + actionNodeParentAnchorInPoints.y + ); + } + else { + actionFrame.setPosition(positionX, positionY); + } + actionArray = this._frameArray[ccs.FRAME_TYPE_MOVE]; actionArray.push(actionFrame); } @@ -140,7 +153,6 @@ ccs.ActionNode = ccs.Class.extend(/** @lends ccs.ActionNode# */{ } actionFrameDic = null; } - this._initActionNodeFromRoot(root); }, _initActionNodeFromRoot: function (root) { From 49c39cf438463bda3533ab24aea398762a5553e8 Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 12:55:52 +0800 Subject: [PATCH 007/839] Child armature shuld be playing with its parent. --- .../cocostudio/armature/animation/CCArmatureAnimation.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/cocostudio/armature/animation/CCArmatureAnimation.js b/extensions/cocostudio/armature/animation/CCArmatureAnimation.js index 870ba7ed0f..09ab2fe7b0 100644 --- a/extensions/cocostudio/armature/animation/CCArmatureAnimation.js +++ b/extensions/cocostudio/armature/animation/CCArmatureAnimation.js @@ -292,8 +292,11 @@ ccs.ArmatureAnimation = ccs.ProcessBase.extend(/** @lends ccs.ArmatureAnimation# tween.play(movementBoneData, durationTo, durationTween, loop, tweenEasing); tween.setProcessScale(this._processScale); - if (bone.getChildArmature()) + if (bone.getChildArmature()) { bone.getChildArmature().getAnimation().setSpeedScale(this._processScale); + if (!bone.getChildArmature().getAnimation().isPlaying()) + bone.getChildArmature().getAnimation().playWithIndex(0); + } } else { if(!bone.isIgnoreMovementBoneData()){ //! this bone is not include in this movement, so hide it From 5f2183d656bcc15baad1ac9a6525336dd6cbf7fe Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 12:57:49 +0800 Subject: [PATCH 008/839] more compatiblity for isTween parameter; --- extensions/cocostudio/armature/utils/CCDataReaderHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/cocostudio/armature/utils/CCDataReaderHelper.js b/extensions/cocostudio/armature/utils/CCDataReaderHelper.js index cc3ffb62a3..60816852cc 100644 --- a/extensions/cocostudio/armature/utils/CCDataReaderHelper.js +++ b/extensions/cocostudio/armature/utils/CCDataReaderHelper.js @@ -790,7 +790,7 @@ ccs.dataReaderHelper = /** @lends ccs.dataReaderHelper# */{ frameData.soundEffect = frameData.strSoundEffect; var isTween = frameXML.getAttribute(ccs.CONST_A_TWEEN_FRAME); - frameData.isTween = !(isTween != undefined && isTween === "false"); + frameData.isTween = !(isTween != undefined && (isTween === "false" || isTween == "0")); if (dataInfo.flashToolVersion >= ccs.CONST_VERSION_2_0) { x = frameXML.getAttribute(ccs.CONST_A_COCOS2DX_X); From c18f6862542527e5da1fbd199d10595f0b246141 Mon Sep 17 00:00:00 2001 From: mutoo Date: Mon, 13 Apr 2015 13:54:34 +0800 Subject: [PATCH 009/839] rename CCTMXLayer.getTileSet/setTileSet to keep the same API with jsb; --- cocos2d/tilemap/CCTMXLayer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/tilemap/CCTMXLayer.js b/cocos2d/tilemap/CCTMXLayer.js index 9491fb6b70..9147574a1d 100644 --- a/cocos2d/tilemap/CCTMXLayer.js +++ b/cocos2d/tilemap/CCTMXLayer.js @@ -205,7 +205,7 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ * Tile set information for the layer * @return {cc.TMXTilesetInfo} */ - getTileset:function () { + getTileSet:function () { return this.tileset; }, @@ -213,7 +213,7 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ * Tile set information for the layer * @param {cc.TMXTilesetInfo} Var */ - setTileset:function (Var) { + setTileSet:function (Var) { this.tileset = Var; }, From 02cb2409c225db2aa3071d8431e49f8882223545 Mon Sep 17 00:00:00 2001 From: wuzhiming Date: Wed, 22 Apr 2015 15:45:37 +0800 Subject: [PATCH 010/839] #2849:add cocosruntime loaderlayer support for v3 --- extensions/runtime/CCLoaderLayer.js | 952 ++++++++++++++++++++++++++++ moduleConfig.json | 4 + 2 files changed, 956 insertions(+) create mode 100644 extensions/runtime/CCLoaderLayer.js diff --git a/extensions/runtime/CCLoaderLayer.js b/extensions/runtime/CCLoaderLayer.js new file mode 100644 index 0000000000..d28dc9b52f --- /dev/null +++ b/extensions/runtime/CCLoaderLayer.js @@ -0,0 +1,952 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +cc.INT_MAX = Number.MAX_VALUE; +cc.LoaderLayer = cc.Layer.extend({ + _backgroundSprite: null, + _progressBackgroundSprite: null, + _progressBarSprite: null, + _logoSprite: null, + _titleSprite: null, + _groupname: null, + _callback: null, + _selector: null, + _preloadCount: 0, + _isPreloadFromFailed: false, + _progressOriginalWidth: 0, + _isDefaultProgress: true, + _isLandScape: false, + _scaleFactor: null, + + ctor: function (config) { + this._super(); + this._setConfig(config); + }, + _setConfig: function (config) { + if (config) { + cc.LoaderLayer._userConfig = config; + } + }, + onEnter: function () { + this._super(); + this.initData(); + this.initView(); + var config = this._finalConfig; + if (config.onEnter) { + config.onEnter(this); + } + }, + onExit: function () { + this._super(); + var config = this._finalConfig; + if (config.logo.action) { + config.logo.action.release(); + } + if(config.title.action){ + config.title.action.release(); + } + if (config.onExit) { + config.onExit(this); + } + }, + initData: function () { + this._finalConfig = cc.cloneObject(cc.LoaderLayer._config); + var config = this._finalConfig; + if (cc.LoaderLayer._userConfig != null) { + var uConfig = cc.LoaderLayer._userConfig; + if (uConfig.background && uConfig.background.res) { + config.background.res = uConfig.background.res; + } + if (uConfig.title) { + var uTitle = uConfig.title; + var title = config.title; + title.show = typeof uTitle.show != "undefined" ? uTitle.show : title.show; + title.res = uTitle.res ? uTitle.res : title.res; + title.position = uTitle.position ? uTitle.position : title.position; + title.action = uTitle.action ? uTitle.action : title.action; + if (title.action) { + title.action = uTitle.action; + title.action.retain(); + } + } + if (uConfig.logo) { + var uLogo = uConfig.logo; + var logo = config.logo; + logo.show = typeof uLogo.show != "undefined" ? uLogo.show : logo.show; + logo.res = uLogo.res ? uLogo.res : logo.res; + logo.position = uLogo.position ? uLogo.position : logo.position; + if (typeof uLogo.action != "undefined") { + logo.action = uLogo.action; + if (logo.action) { + logo.action.retain(); + } + } + } + if (uConfig.progressBar) { + var uProgress = uConfig.progressBar; + var progress = config.progressBar; + progress.show = typeof uProgress.show != "undefined" ? uProgress.show : progress.show; + if (uProgress.res) { + progress.res = uProgress.res; + this._isDefaultProgress = false; + } + progress.offset = uProgress.offset ? uProgress.offset : progress.offset; + progress.position = uProgress.position ? uProgress.position : progress.position; + progress.barBackgroundRes = uProgress.barBackgroundRes ? uProgress.barBackgroundRes : progress.barBackgroundRes; + } + if (uConfig.tips) { + var uTips = uConfig.tips; + var tips = config.tips; + tips.show = typeof uTips.show != "undefined" ? uTips.show : tips.show; + tips.res = uTips.res ? uTips.res : tips.res; + tips.offset = uTips.offset ? uTips.offset : tips.offset; + tips.fontSize = uTips.fontSize ? uTips.fontSize : tips.fontSize; + tips.position = uTips.position ? uTips.position : tips.position; + tips.color = uTips.color ? uTips.color : tips.color; + if (uConfig.tips.tipsProgress && typeof uConfig.tips.tipsProgress == "function") { + tips.tipsProgress = uConfig.tips.tipsProgress; + } + } + if (typeof uConfig.onEnter == "function") { + config.onEnter = uConfig.onEnter; + } + if (typeof uConfig.onExit == "function") { + config.onExit = uConfig.onExit; + } + } + + if (typeof config.logo.action == "undefined" && cc.LoaderLayer._useDefaultSource) { + config.logo.action = cc.sequence( + cc.spawn(cc.moveBy(0.4, cc.p(0, 40)).easing(cc.easeIn(0.5)), cc.scaleTo(0.4, 0.95, 1.05).easing(cc.easeIn(0.5))), + cc.delayTime(0.08), + cc.spawn(cc.moveBy(0.4, cc.p(0, -40)).easing(cc.easeOut(0.5)), cc.scaleTo(0.4, 1.05, 0.95).easing(cc.easeOut(0.5))) + ).repeatForever(); + config.logo.action.retain(); + } + if (!config.tips.color) { + config.tips.color = cc.color(255, 255, 255); + } + }, + initView: function () { + var config = this._finalConfig; + this._contentLayer = new cc.Layer(); + this._isLandScape = cc.winSize.width > cc.winSize.height; + this._scaleFactor = !cc.LoaderLayer._useDefaultSource ? 1 : cc.winSize.width > cc.winSize.height ? cc.winSize.width / 720 : cc.winSize.width / 480; + + //background + this.backgroundSprite = new cc.Sprite(config.background.res); + this.addChild(this.backgroundSprite); + this.backgroundSprite.x = 0, this.backgroundSprite.y = 0, this.backgroundSprite.anchorX = 0, this.backgroundSprite.anchorY = 0; + if (cc.LoaderLayer._useDefaultSource) { + this.backgroundSprite.scaleX = cc.winSize.width / this.backgroundSprite.width; + this.backgroundSprite.scaleY = cc.winSize.height / this.backgroundSprite.height; + } + + //title + if (config.title.show) { + this.titleSprite = new cc.Sprite(config.title.res); + var defaultTitlePosition = cc.pAdd(cc.visibleRect.center, cc.p(0, this._scaleFactor < 1 ? 0 : this._isLandScape ? -80 : 30)); + this.titleSprite.setPosition(config.title.position ? config.title.position : defaultTitlePosition); + this._contentLayer.addChild(this.titleSprite); + if (config.title.action) { + this.titleSprite.runAction(config.title.action); + } + } + + //logo + if (config.logo.show) { + this.logoSprite = new cc.Sprite(config.logo.res); + var defaultLogoPosition = cc.pAdd(cc.visibleRect.top, cc.p(0, this._scaleFactor < 1 ? 0 : -this.logoSprite.height / 2 - (this._isLandScape ? 56 : 76))); + this.logoSprite.setPosition(config.logo.position ? config.logo.position : defaultLogoPosition); + this._contentLayer.addChild(this.logoSprite); + if (config.logo.action) { + this.logoSprite.runAction(config.logo.action); + } + } + + //progressbar + if (config.progressBar.show) { + this.progressBarSprite = new cc.Sprite(config.progressBar.res); + this._progressOriginalWidth = this.progressBarSprite.width; + this.progressBackgroundSprite = new cc.Sprite(config.progressBar.barBackgroundRes); + this.progressBarSprite.anchorX = 0; + this.progressBarSprite.anchorY = 0; + if (this._isDefaultProgress) { + this._barPoint = new cc.Sprite(config.progressBar.barPoint); + this.progressBarSprite.addChild(this._barPoint); + } + if (config.progressBar.barBackgroundRes == null) { + this.progressBackgroundSprite.setTextureRect(cc.rect(0, 0, this.progressBarSprite.width, this.progressBarSprite.height)); + } + if (config.progressBar.offset == null) { + var deltaProgressWithX = (this.progressBackgroundSprite.width - this.progressBarSprite.width) / 2; + var deltaProgressWithY = (this.progressBackgroundSprite.height - this.progressBarSprite.height) / 2; + config.progressBar.offset = cc.p(deltaProgressWithX, deltaProgressWithY); + } + this.progressBarSprite.setPosition(config.progressBar.offset); + this.progressBackgroundSprite.addChild(this.progressBarSprite); + var defaultProgressPosition = cc.pAdd(cc.visibleRect.bottom, cc.p(0, this.progressBarSprite.height / 2 + this._isLandScape ? 60 : 80)); + this.progressBackgroundSprite.setPosition(config.progressBar.position ? config.progressBar.position : defaultProgressPosition); + this._contentLayer.addChild(this.progressBackgroundSprite); + this._setProgress(0); + } + + //tips + if (config.tips.show) { + this.tipsLabel = new cc.LabelTTF("100%", "Arial", config.tips.fontSize); + this.tipsLabel.setColor(config.tips.color); + this.tipsLabel.setPosition(config.tips.position ? config.tips.position : this.progressBackgroundSprite ? cc.p(this.progressBackgroundSprite.x, this.progressBackgroundSprite.y + this.progressBackgroundSprite.height / 2 + 20) : cc.pAdd(cc.visibleRect.bottom, cc.p(0, 100))); + this._contentLayer.addChild(this.tipsLabel); + } + this.addChild(this._contentLayer); + if (this._scaleFactor < 1) { + this._contentLayer.setScale(this._scaleFactor); + this._contentLayer.setPosition(cc.pAdd(this._contentLayer.getPosition(), cc.p(0, -50))); + } + + }, + _setProgress: function (percent) { + if (this.progressBarSprite) { + percent < 1 ? percent : 1; + var width = percent * this._progressOriginalWidth; + this.progressBarSprite.setTextureRect(cc.rect(0, 0, width, this.progressBarSprite.height)); + if (this._isDefaultProgress) { + this._barPoint.setPosition(cc.p(this.progressBarSprite.width, this.progressBarSprite.height / 2)); + } + } + }, + setTipsString: function (str) { + if (this.tipsLabel != null) { + this.tipsLabel.setString(str); + } + }, + getProgressBar: function () { + return this.progressBarSprite; + }, + getTipsLabel: function () { + return this.tipsLabel; + }, + getLogoSprite: function () { + return this.logoSprite; + }, + getTitleSprite: function () { + return this.titleSprite; + }, + updateGroup: function (groupname, callback, target) { + this._groupname = groupname; + this._callback = callback; + this._selector = target; + }, + _resetLoadingLabel: function () { + this.setTipsString(""); + this._setProgress(0); + }, + _preloadSource: function () { + cc.log("_preloadSource: " + this._groupname); + this._resetLoadingLabel(); + if (cc.sys.isNative) { + cc.Loader.preload(this._groupname, this._preload_native, this); + } else { + this._preload_html5(); + } + }, + _preload_html5: function () { + var res = ""; + var groupIndex = []; + var config = this._finalConfig; + if (cc.isString(this._groupname)) { + if (this._groupname.indexOf(".") != -1) { + res = [this._groupname]; + } else { + res = window[this._groupname]; + } + } else if (cc.isArray(this._groupname)) { + res = []; + for (var i = 0; i < this._groupname.length; i++) { + var group = window[this._groupname[i]]; + var preCount = i > 0 ? groupIndex[i - 1] : 0; + groupIndex.push(preCount + group.length); + res = res.concat(group); + } + } + var self = this; + //var progressFunction = self.config.progressCallback ? self.config.progressCallback : null; + cc.loader.load(res, function (result, count, loadedCount) { + var checkGroupName = function (loadedCount) { + for (var i = 0; i < groupIndex.length; i++) { + if (groupIndex[i] >= loadedCount) { + return self._groupname[i]; + } + } + }; + var groupName = checkGroupName(loadedCount); + var status = { + groupName: groupName, + isCompleted: false, + percent: (loadedCount / count * 100) | 0,//(float), + stage: 1, //(1 download,2 unzip) + isFailed: false + } + if (status.percent != 0) { + self._setProgress(status.percent / 100); + } + config.tips.tipsProgress(status, self); + }, function () { + self.removeFromParent(); + self._preloadCount--; + if (self._callback) { + if (self._selector) { + self._callback(self._selector, true); + } else { + self._callback(true); + } + } + self._callback.call(this._target, !status.isFailed); + }); + }, + _preload_native: function (status) { + cc.log(JSON.stringify(status)); + var config = this._finalConfig; + if (status.percent) { + this._setProgress(status.percent / 100); + } + if (config.tips.tipsProgress) { + config.tips.tipsProgress(status, this); + } + if (status.isCompleted || status.isFailed) { + this._preloadCount--; + + if (status.isCompleted) { + cc.log("preload finish!"); + this._isPreloadFromFailed = false; + } + if (status.isFailed) { + cc.log("preload failed!"); + this._isPreloadFromFailed = true; + } + + // Remove loading layer from scene after loading was done. + if (this._preloadCount == 0 && !this._isPreloadFromFailed) { + this.removeFromParent(); + if (cc.LoaderLayer._useDefaultSource) { + var _config = cc.runtime.config.design_resolution || {width: 480, height: 720, policy: "SHOW_ALL"}; + cc.view.setDesignResolutionSize(_config.width, _config.height, cc.ResolutionPolicy[_config.policy]); + } + } + + // Callback must be invoked after removeFromParent. + this._callback.call(this._target, status); + } + }, + _addToScene: function () { + if (this._preloadCount == 0 && !this._isPreloadFromFailed) { + if (cc.sys.isNative && cc.LoaderLayer._useDefaultSource) { + var config = cc.runtime.config.design_resolution; + var isLandscape = false; + var isLargeThanResource = false; + if (config) { + var orientation = cc.runtime.config.orientation; + cc.log("_addToScene orientation is " + orientation); + if (orientation == "landscape") { + isLandscape = true; + isLargeThanResource = config.width > 720 || config.height > 480; + } else { + isLargeThanResource = config.width > 480 || config.height > 720; + } + } + cc.log("isLargeThanResource is " + isLargeThanResource); + cc.view.setDesignResolutionSize(isLargeThanResource ? config.width : isLandscape ? 720 : 480, isLargeThanResource ? config.height : isLandscape ? 480 : 720, cc.ResolutionPolicy["FIXED_HEIGHT"]); + } + cc.director.getRunningScene().addChild(this, cc.INT_MAX - 1); + } + this._preloadCount++; + } +}); +cc.LoaderLayer._config = {//default setting for loaderlayer + background: { + res: "res_engine/preload_bg.jpg" + }, + title: { + show: true, + res: "res_engine/preload_title.png", + position: null, + action: null + }, + logo: { + res: "res_engine/preload_logo.png", + show: true, + position: null + }, + progressBar: { + show: true, + res: "res_engine/progress_bar.png", + offset: null, + position: null, + barBackgroundRes: "res_engine/progress_bg.png", + barPoint: "res_engine/progress_light.png", + barShadow: "res_engine/shadow.png" + }, + tips: { + show: true, + fontSize: 22, + position: null, + color: null, + tipsProgress: function (status, loaderlayer) { + if(loaderlayer.getTipsLabel()){ + var statusStr = "正在"; + if (status.stage == cc.network.preloadstatus.DOWNLOAD) { + statusStr += "下载"; + } else if (status.stage == cc.network.preloadstatus.UNZIP) { + statusStr += "解压"; + } + if (status.groupName) { + statusStr += status.groupName; + } + statusStr += "进度:" + status.percent.toFixed(2) + "%"; + loaderlayer.getTipsLabel().setString(statusStr); + } + } + }, + progressCallback: function (progress) { + + }, + onEnter: function (layer) { + cc.log("LoaderLayer onEnter"); + }, + onExit: function (layer) { + cc.log("LoaderLayer onExit"); + } +} +cc.LoaderLayer.preload = function (groupname, callback, target) { + var loaderLayer = new cc.LoaderLayer(); + var preloadCb = function (status) { + if (status.isFailed) { + var tips, conirmfunc, cancelfunc; + switch (status.errorCode) { + case "err_no_space": + { + tips = "空间不足,请清理磁盘空间"; + conirmfunc = function () { + callPreload(); + }; + cancelfunc = function () { + cc.director.end(); + }; + break; + } + case "err_verify": + { + tips = "校验失败,是否重新下载?"; + conirmfunc = function () { + callPreload(); + } + cancelfunc = function () { + cc.director.end(); + } + break; + } + case "err_network": + { + tips = "网络异常是否重新下载"; + conirmfunc = function () { + callPreload(); + } + cancelfunc = function () { + cc.director.end(); + } + break; + } + default : + { + conirmfunc = cancelfunc = function () { + + } + } + } + cc._NetworkErrorDialog._show(status.errorCode, tips, conirmfunc, cancelfunc); + } else { + if (callback) { + if (target) { + callback.call(target, !status.isFailed); + } else { + callback(!status.isFailed) + } + } + } + } + var callPreload = function () { + if (cc.director.getRunningScene()) { + loaderLayer.updateGroup(groupname, preloadCb, target); + loaderLayer._addToScene(); + loaderLayer._preloadSource(); + } else { + cc.log("Current scene is null we can't start preload"); + } + }; + callPreload(); +} +cc.LoaderLayer._useDefaultSource = true; +cc.LoaderLayer.setUseDefaultSource = function (status) { + cc.LoaderLayer._useDefaultSource = status; +} +cc.LoaderLayer._userConfig = null; +cc.LoaderLayer.setConfig = function (config) { + if(config.title && config.title.action){ + config.title.action.retain(); + } + if(config.logo && config.logo.action){ + config.logo.action.retain(); + } + cc.LoaderLayer._userConfig = config; +} + +cc.Dialog = cc.Layer.extend({ + _userConfig: null, + _finalConfig: null, + _defaultConfig: null, + backgroundSprite: null, + _menuItemConfirm: null, + _menuItemCancel: null, + _messageLabel: null, + _eventListener: null, + _scaleFactor: null, + + ctor: function (config) { + this._super(); + this.setConfig(config); + }, + setConfig: function (config) { + if (config) { + this._userConfig = config; + } + this.removeAllChildren(); + this.initData(); + }, + initData: function () { + this._finalConfig = cc.cloneObject(cc.Dialog._defaultConfig); + var config = this._finalConfig; + if (this._userConfig != null) { + var uConfig = this._userConfig; + if (uConfig.position) { + config.position = uConfig.position; + } + if (uConfig.action) { + config.action = uConfig.action; + } + if (uConfig.background && uConfig.background.res) { + config.background = uConfig.background; + } + if (uConfig.confirmBtn) { + var uConfirmBtn = uConfig.confirmBtn; + var confirmBtn = config.confirmBtn; + confirmBtn.normalRes = uConfirmBtn.normalRes ? uConfirmBtn.normalRes : confirmBtn.normalRes; + confirmBtn.pressRes = uConfirmBtn.pressRes ? uConfirmBtn.pressRes : confirmBtn.pressRes; + confirmBtn.text = typeof uConfirmBtn.text != "undefined" ? uConfirmBtn.text : confirmBtn.text; + confirmBtn.textColor = uConfirmBtn.textColor ? uConfirmBtn.textColor : confirmBtn.textColor; + confirmBtn.fontSize = uConfirmBtn.fontSize ? uConfirmBtn.fontSize : confirmBtn.fontSize; + confirmBtn.position = uConfirmBtn.position ? uConfirmBtn.position : confirmBtn.position; + confirmBtn.callback = uConfirmBtn.callback ? uConfirmBtn.callback : confirmBtn.callback; + } + if (uConfig.cancelBtn) { + var uCancelBtn = uConfig.cancelBtn; + var cancelBtn = config.cancelBtn; + cancelBtn.normalRes = uCancelBtn.normalRes ? uCancelBtn.normalRes : cancelBtn.normalRes; + cancelBtn.pressRes = uCancelBtn.pressRes ? uCancelBtn.pressRes : cancelBtn.pressRes; + cancelBtn.text = typeof uCancelBtn.text != "undefined" ? uCancelBtn.text : cancelBtn.text; + cancelBtn.textColor = uCancelBtn.textColor ? uCancelBtn.textColor : cancelBtn.textColor; + cancelBtn.fontSize = uCancelBtn.fontSize ? uCancelBtn.fontSize : cancelBtn.fontSize; + cancelBtn.position = uCancelBtn.position ? uCancelBtn.position : cancelBtn.position; + cancelBtn.callback = uCancelBtn.callback ? uCancelBtn.callback : cancelBtn.callback; + } + if (uConfig.messageLabel) { + var uMessageLabel = uConfig.messageLabel; + var messageLabel = config.messageLabel; + messageLabel.text = typeof uMessageLabel.text != "undefined" ? uMessageLabel.text : messageLabel.text; + messageLabel.color = uMessageLabel.color ? uMessageLabel.color : messageLabel.color; + messageLabel.fontSize = uMessageLabel.fontSize ? uMessageLabel.fontSize : messageLabel.fontSize; + messageLabel.position = uMessageLabel.position ? uMessageLabel.position : messageLabel.position; + messageLabel.dimensions = uMessageLabel.dimensions ? uMessageLabel.dimensions : messageLabel.dimensions; + } + if (uConfig.target) { + config.target = uConfig.target; + } + if (typeof uConfig.onEnter == "function") { + config.onEnter = uConfig.onEnter; + } + if (typeof uConfig.onExit == "function") { + config.onExit = uConfig.onExit; + } + } + + if (!config.cancelBtn.textColor) { + config.cancelBtn.textColor = cc.color(255, 255, 255); + } + if (!config.confirmBtn.textColor) { + config.confirmBtn.textColor = cc.color(255, 255, 255); + } + + }, + initView: function () { + var useDefaultSource = cc.Dialog._useDefaultSource; + var winSize = cc.director.getWinSize(); + this._scaleFactor = !useDefaultSource ? 1 : winSize.width > winSize.height ? winSize.width / 720 : winSize.width / 480; + var config = this._finalConfig; + + //bg + this.backgroundSprite = new cc.Scale9Sprite(config.background.res); + this._setScale(this.backgroundSprite); + if (this._scaleFactor < 1) { + this.backgroundSprite.setScale(this._scaleFactor); + } + this.backgroundSprite.setPosition(config.position ? config.position : cc.p(winSize.width / 2, winSize.height / 2)); + + //menu + this.menuItemConfirm = this._createMenuItemSprite(config.confirmBtn, this._confirmCallback); + this.menuItemCancel = this._createMenuItemSprite(config.cancelBtn, this._cancelCallback); + this.menuItemCancel.setPosition(config.cancelBtn.position ? config.cancelBtn.position : cc.p(this.backgroundSprite.width / 2 - this.menuItemCancel.width / 2 - 20, this.menuItemCancel.height + 20)); + this.menuItemConfirm.setPosition(config.confirmBtn.position ? config.confirmBtn.position : cc.p(this.backgroundSprite.width / 2 + this.menuItemConfirm.width / 2 + 20, this.menuItemConfirm.height + 20)); + var menu = new cc.Menu(this.menuItemConfirm, this.menuItemCancel); + menu.setPosition(cc.p(0, 0)); + this.backgroundSprite.addChild(menu); + + //message + var fontSize = config.messageLabel.fontSize ? config.messageLabel.fontSize : this._scaleFactor > 1 ? 16 * this._scaleFactor : 16; + this.messageLabel = new cc.LabelTTF(config.messageLabel.text, "Arial", fontSize); + this.messageLabel.setDimensions(config.messageLabel.dimensions ? config.messageLabel.dimensions : cc.size(this.backgroundSprite.width - 30, this.backgroundSprite.height - this.menuItemConfirm.y - 10)); + this.messageLabel.setColor(config.messageLabel.color ? config.messageLabel.color : cc.color(255, 255, 255)); + this.messageLabel.setPosition(config.messageLabel.position ? config.messageLabel.position : cc.p(this.backgroundSprite.width / 2, this.backgroundSprite.height - this.messageLabel.height / 2 - 20)); + this.backgroundSprite.addChild(this.messageLabel); + if (!config.action) { + var action = cc.sequence(cc.EaseIn.create(cc.scaleTo(0.1, this.backgroundSprite.scale + 0.02), 0.4), cc.EaseOut.create(cc.scaleTo(0.1, this.backgroundSprite.scale), 0.3)); + this.backgroundSprite.runAction(action); + } else { + this.backgroundSprite.runAction(config.action); + } + this.addChild(this.backgroundSprite); + + }, + _createMenuItemSprite: function (res, callback) { + var spriteNormal = new cc.Scale9Sprite(res.normalRes); + var spritePress = new cc.Scale9Sprite(res.pressRes); + this._setScale(spriteNormal); + this._setScale(spritePress); + var fontSize = res.fontSize ? res.fontSize : this._scaleFactor > 1 ? 16 * this._scaleFactor : 16; + var menuLabel = new cc.LabelTTF(res.text, "Arial", fontSize); + menuLabel.setColor(res.textColor); + var menuItem = new cc.MenuItemSprite(spriteNormal, spritePress, callback, this); + menuLabel.setPosition(cc.p(menuItem.width / 2, menuItem.height / 2)); + menuItem.addChild(menuLabel); + return menuItem; + }, + _setScale: function (s9Sprite) { + if (this._scaleFactor > 1) { + s9Sprite.setContentSize(cc.size(this._scaleFactor * s9Sprite.width, this._scaleFactor * s9Sprite.height)); + } + }, + _confirmCallback: function () { + var config = this._finalConfig; + if (config.confirmBtn.callback) { + if (config.target) { + config.confirmBtn.callback.call(config.target, this); + } else { + config.confirmBtn.callback(this); + } + } + this.removeFromParent(); + }, + _cancelCallback: function () { + var config = this._finalConfig; + if (config.cancelBtn.callback) { + if (config.target) { + config.cancelBtn.callback.call(config.target, this); + } else { + config.cancelBtn.callback(this); + } + } + this.removeFromParent(); + }, + onEnter: function () { + this._super(); + var config = this._finalConfig; + this.initView(); + config.onEnter(this); + var self = this; + self._eventListener = cc.EventListener.create({ + event: cc.EventListener.TOUCH_ONE_BY_ONE, + swallowTouches: true, + onTouchBegan: function (touch, event) { + return true; + } + }); + cc.eventManager.addListener(self._eventListener, self); + }, + onExit: function () { + this._super(); + var config = this._finalConfig; + config.onExit(this); + this.removeAllChildren(); + cc.Dialog._dialog = null; + cc.eventManager.removeListener(this._eventListener); + } +}); + +cc.Dialog._dialog = null; +cc.Dialog._clearDialog = function () { + if (cc.Dialog._dialog != null) { + cc.Dialog._dialog.removeFromParent(); + cc.Dialog._dialog = null; + } +} + +cc.Dialog.show = function (tips, confirmCb, cancelCb) { + if (cc.Dialog._dialog != null) { + cc.log("other dialog is on the screen,this dialog can't show now"); + return; + } + + var conf; + if (typeof tips == "string") { + conf = { + messageLabel: { + text: tips + }, + confirmBtn: { + callback: confirmCb + }, + cancelBtn: { + callback: cancelCb + } + } + } else if (typeof tips == "object") { + conf = tips; + } else { + cc.log("tips is invalid"); + return; + } + + cc.Dialog._dialog = new cc.Dialog(conf); + if (cc.director.getRunningScene()) { + cc.director.getRunningScene().addChild(cc.Dialog._dialog, cc.INT_MAX); + } else { + cc.log("Current scene is null we can't show dialog"); + } +}; +cc.Dialog._useDefaultSource = true; +cc.Dialog.setUseDefaultSource = function (status) { + cc.Dialog._useDefaultSource = status; +} +cc.Dialog._defaultConfig = { + position: null, + target: null, + action: null, + background: { + res: "res_engine/dialog_bg.png" + }, + confirmBtn: { + normalRes: "res_engine/dialog_confirm_normal.png", + pressRes: "res_engine/dialog_confirm_press.png", + text: "确定", + textColor: null, + fontSize: null, + position: null, + callback: function () { + cc.log("this is confirm callback"); + } + }, + cancelBtn: { + normalRes: "res_engine/dialog_cancel_normal.png", + pressRes: "res_engine/dialog_cancel_press.png", + text: "取消", + textColor: null, + position: null, + fontSize: null, + callback: function () { + cc.log("this is cancel callback"); + } + }, + messageLabel: { + text: "", + color: null, + dimensions: null, + fontSize: null, + position: null + }, + onEnter: function (dialog) { + cc.log("dialog call onEnter"); + }, + onExit: function (dialog) { + cc.log("dialog call onExit"); + } +}; +cc._NetworkErrorDialog = function () { + cc.Dialog._clearDialog(); + cc.Dialog._dialog = new cc.Dialog(cc._NetworkErrorDialog._config); + return cc.Dialog._dialog; +} +cc._NetworkErrorDialog._config = { + networkError: {}, + spaceError: {}, + verifyError: {} +}; +cc._NetworkErrorDialog._show = function (type, tips, confirmCb, cancelCb) { + var networkDialog = cc._NetworkErrorDialog(); + var config; + switch (type) { + case "err_network": + { + config = cc._NetworkErrorDialog._config.networkError; + break; + } + case "err_no_space": + { + config = cc._NetworkErrorDialog._config.spaceError; + break; + } + case "err_verify": + { + config = cc._NetworkErrorDialog._config.verifyError; + break; + } + default: + { + cc.log("type is not found"); + return; + } + } + if (!networkDialog.getParent()) { + + config.confirmBtn = config.confirmBtn || {}; + config.confirmBtn.callback = function () { + if (confirmCb) + confirmCb(); + } + + config.cancelBtn = config.cancelBtn || {}; + config.cancelBtn.callback = function () { + if (cancelCb) + cancelCb(); + } + + config.messageLabel = config.messageLabel || {}; + if (typeof config.messageLabel.text == "undefined") { + config.messageLabel.text = tips; + } + + networkDialog.setConfig(config); + if (cc.director.getRunningScene()) { + cc.director.getRunningScene().addChild(networkDialog, cc.INT_MAX); + } else { + cc.log("Current scene is null we can't show dialog"); + } + } +} + +cc._NetworkErrorDialog._setConfig = function (key, config) { + if (key && config) { + switch (key) { + case "err_network": + { + cc._NetworkErrorDialog._config.networkError = config; + break; + } + case "err_no_space": + { + cc._NetworkErrorDialog._config.spaceError = config; + break; + } + case "err_verify": + { + cc._NetworkErrorDialog._config.verifyError = config; + break; + } + } + } +} + +cc.runtime = cc.runtime || {}; + +cc.runtime.setOption = function (promptype, config) { + if (config) { + switch (promptype) { + case "network_error_dialog": + { + cc._NetworkErrorDialog._setConfig("err_network", config); + break; + } + case "no_space_error_dialog": + { + cc._NetworkErrorDialog._setConfig("err_no_space", config); + break; + } + case "verify_error_dialog": + { + cc._NetworkErrorDialog._setConfig("err_verify", config); + break; + } + default : + { + cc.log("promptype not found please check your promptype"); + } + } + } else { + cc.log("config is null please check your config"); + } +} + +cc.cloneObject = function (obj) { + var o, obj; + if (obj.constructor == Object) { + o = new obj.constructor(); + } else { + o = new obj.constructor(obj.valueOf()); + } + for (var key in obj) { + if (o[key] != obj[key]) { + if (typeof(obj[key]) == 'object') { + o[key] = cc.cloneObject(obj[key]); + } else { + o[key] = obj[key]; + } + } + } + o.toString = obj.toString; + o.valueOf = obj.valueOf; + return o; +} +/** + * only use in JSB get network type + * @type {{}|*|cc.network} + */ +cc.network = cc.network || {}; +cc.network.type = { + NO_NETWORK: -1, + MOBILE: 0, + WIFI: 1 +} +cc.network.preloadstatus = { + DOWNLOAD: 1, + UNZIP: 2 +} +cc.runtime.network = cc.network; \ No newline at end of file diff --git a/moduleConfig.json b/moduleConfig.json index 0419870439..60bfbf3eb6 100644 --- a/moduleConfig.json +++ b/moduleConfig.json @@ -444,6 +444,10 @@ "external/chipmunk/chipmunk.js" ], + "runtime":[ + "core", + "extensions/runtime/CCLoaderLayer.js" + ], "socketio" : [ "external/socketio/socket.io.min.js" ], From 4144cc57244477c0e657ab1fba23e9f225eb0ee1 Mon Sep 17 00:00:00 2001 From: ZippoLag Date: Sun, 3 May 2015 13:48:04 -0300 Subject: [PATCH 011/839] objectNamed missing a return objectNamed missing a return statement (hence always returning null) --- cocos2d/tilemap/CCTMXObjectGroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/tilemap/CCTMXObjectGroup.js b/cocos2d/tilemap/CCTMXObjectGroup.js index 560c690afe..b5d41dbc9a 100644 --- a/cocos2d/tilemap/CCTMXObjectGroup.js +++ b/cocos2d/tilemap/CCTMXObjectGroup.js @@ -117,7 +117,7 @@ cc.TMXObjectGroup = cc.Class.extend(/** @lends cc.TMXObjectGroup# */{ * @return {object|Null} */ objectNamed:function (objectName) { - this.getObject(objectName); + return this.getObject(objectName); }, /** From 59063bb66b1292babd4cff7fe4afeb2a231e25af Mon Sep 17 00:00:00 2001 From: giuseppelt Date: Mon, 4 May 2015 13:41:08 +0200 Subject: [PATCH 012/839] Fixed TransitionSlideX callback sequence It fixes the missing array brackets in the sequence call and moves the callback to the inScene because outScene can be optional (very first scene) so the engine will miss the callback, with bad consequences like disabled events. --- cocos2d/transitions/CCTransition.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/transitions/CCTransition.js b/cocos2d/transitions/CCTransition.js index f5ccb82cfe..7d8c65c228 100644 --- a/cocos2d/transitions/CCTransition.js +++ b/cocos2d/transitions/CCTransition.js @@ -652,8 +652,8 @@ cc.TransitionSlideInL = cc.TransitionScene.extend(/** @lends cc.TransitionSlideI var inA = this.action(); var outA = this.action(); - var inAction = this.easeActionWithAction(inA); - var outAction = cc.sequence(this.easeActionWithAction(outA), cc.callFunc(this.finish, this)); + var inAction = cc.sequence([this.easeActionWithAction(inA), cc.callFunc(this.finish, this)]); + var outAction = this.easeActionWithAction(outA); this._inScene.runAction(inAction); this._outScene.runAction(outAction); }, From b158fdcf49b3a080c84ee59512a6a420f3672af7 Mon Sep 17 00:00:00 2001 From: yshumov Date: Tue, 5 May 2015 12:29:04 +0300 Subject: [PATCH 013/839] Fixed music end event. By issue https://github.com/cocos2d/cocos2d-html5/issues/2841 --- cocos2d/audio/CCAudio.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index e3890afd59..8e7c5e0059 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -671,6 +671,14 @@ cc.Audio = cc.Class.extend({ } audio.play(0, loop); audio.setVolume(this._musicVolume); + function cbEnd(){ + if (!this._currMusic._pause) { + this.stopMusic(); + } + } + var cbEndWithContext = cbEnd.bind(this); + audio._currentSource.onended = cbEndWithContext; + this._currMusic = audio; }, From 66f0a2957b735c97a19e91e8e55a5f308c6fd52b Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 6 May 2015 10:00:22 +0800 Subject: [PATCH 014/839] Audio load didn't use the search path --- cocos2d/audio/CCAudio.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index e3890afd59..220273ae81 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -503,6 +503,9 @@ cc.Audio = cc.Class.extend({ var i; + if(cc.loader.audioPath) + realUrl = cc.path.join(cc.loader.audioPath, realUrl); + var extname = cc.path.extname(realUrl); var typeList = [extname]; From e308189256dd67e3e65017e7790fa61ed2d9c478 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 6 May 2015 15:35:43 +0800 Subject: [PATCH 015/839] LayerColor's color will disappear when update transform after open bake --- cocos2d/core/layers/CCLayerCanvasRenderCmd.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js index 2fb954e115..c80fc3f574 100644 --- a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js +++ b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js @@ -223,6 +223,7 @@ var bakeContext = locBakeSprite.getCacheContext(); var ctx = bakeContext.getContext(); locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height); + ctx.fillStyle = bakeContext._currentFillStyle; bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y ); locBakeSprite.setPosition(boundingBox.x, boundingBox.y); From 774484ca791cfff81c983b20692761c0294764a3 Mon Sep 17 00:00:00 2001 From: SPACELAN Date: Wed, 6 May 2015 16:23:38 +0800 Subject: [PATCH 016/839] Found a bug in cc.math.Matrix4().inverse() and fixed it The `cc.math.Matrix4._gaussj` function changes the global var `identityMatrix` and makes the following calculations wrong. --- cocos2d/kazmath/mat4.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cocos2d/kazmath/mat4.js b/cocos2d/kazmath/mat4.js index b1af75efc3..d211589531 100644 --- a/cocos2d/kazmath/mat4.js +++ b/cocos2d/kazmath/mat4.js @@ -181,7 +181,8 @@ */ cc.kmMat4Inverse = function (pOut, pM) { var inv = new cc.math.Matrix4(pM); - if (cc.math.Matrix4._gaussj(inv, identityMatrix) === false) + var tmp = new cc.math.Matrix4(identityMatrix); + if (cc.math.Matrix4._gaussj(inv, tmp) === false) return null; pOut.assignFrom(inv); return pOut; @@ -193,7 +194,8 @@ */ proto.inverse = function(){ //cc.kmMat4Inverse var inv = new cc.math.Matrix4(this); - if (cc.math.Matrix4._gaussj(inv, identityMatrix) === false) + var tmp = new cc.math.Matrix4(identityMatrix); + if (cc.math.Matrix4._gaussj(inv, tmp) === false) return null; return inv; }; From 7dab18778bec49232b731fc667d4192680c96d4a Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 6 May 2015 18:23:51 +0800 Subject: [PATCH 017/839] Delete the redundant variables defined and cc.log --- extensions/ccui/uiwidgets/UIRichText.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIRichText.js b/extensions/ccui/uiwidgets/UIRichText.js index a92b642063..61f72cc08e 100644 --- a/extensions/ccui/uiwidgets/UIRichText.js +++ b/extensions/ccui/uiwidgets/UIRichText.js @@ -471,6 +471,7 @@ ccui.RichText = ccui.Widget.extend(/** @lends ccui.RichText# */{ var newContentSizeHeight = 0, locRenderersContainer = this._elementRenderersContainer; var locElementRenders = this._elementRenders; var i, j, row, nextPosX, l; + var lineHeight, offsetX; if (this._ignoreSize) { var newContentSizeWidth = 0; row = locElementRenders[0]; @@ -482,7 +483,7 @@ ccui.RichText = ccui.Widget.extend(/** @lends ccui.RichText# */{ l.setPosition(nextPosX, 0); locRenderersContainer.addChild(l, 1, j); - var lineHeight = l.getLineHeight ? l.getLineHeight() : newContentSizeHeight; + lineHeight = l.getLineHeight ? l.getLineHeight() : newContentSizeHeight; var iSize = l.getContentSize(); newContentSizeWidth += iSize.width; @@ -492,7 +493,7 @@ ccui.RichText = ccui.Widget.extend(/** @lends ccui.RichText# */{ //Text flow horizontal alignment: if(this._textHorizontalAlignment !== cc.TEXT_ALIGNMENT_LEFT) { - var offsetX = 0; + offsetX = 0; if (this._textHorizontalAlignment === cc.TEXT_ALIGNMENT_RIGHT) offsetX = this._contentSize.width - nextPosX; else if (this._textHorizontalAlignment === cc.TEXT_ALIGNMENT_CENTER) @@ -510,8 +511,7 @@ ccui.RichText = ccui.Widget.extend(/** @lends ccui.RichText# */{ var maxHeight = 0; for (j = 0; j < row.length; j++) { l = row[j]; - var lineHeight = l.getLineHeight ? l.getLineHeight() : l.getContentSize().height; - cc.log(lineHeight); + lineHeight = l.getLineHeight ? l.getLineHeight() : l.getContentSize().height; maxHeight = Math.max(Math.min(l.getContentSize().height, lineHeight), maxHeight); } maxHeights[i] = maxHeight; @@ -534,7 +534,7 @@ ccui.RichText = ccui.Widget.extend(/** @lends ccui.RichText# */{ } //Text flow alignment(s) if( this._textHorizontalAlignment !== cc.TEXT_ALIGNMENT_LEFT || this._textVerticalAlignment !== cc.VERTICAL_TEXT_ALIGNMENT_TOP) { - var offsetX = 0; + offsetX = 0; if (this._textHorizontalAlignment === cc.TEXT_ALIGNMENT_RIGHT) offsetX = this._contentSize.width - nextPosX; else if (this._textHorizontalAlignment === cc.TEXT_ALIGNMENT_CENTER) From 8f89482d279b7c19eed92e9523f1358a400b6300 Mon Sep 17 00:00:00 2001 From: mutoo Date: Fri, 8 May 2015 17:44:10 +0800 Subject: [PATCH 018/839] fix a typo in uiParser; --- extensions/cocostudio/loader/parsers/uiParser-1.x.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/cocostudio/loader/parsers/uiParser-1.x.js b/extensions/cocostudio/loader/parsers/uiParser-1.x.js index c14763e875..ff0ee42066 100644 --- a/extensions/cocostudio/loader/parsers/uiParser-1.x.js +++ b/extensions/cocostudio/loader/parsers/uiParser-1.x.js @@ -613,7 +613,7 @@ if(ph) widget.setPlaceHolder(ph); widget.setString(options["text"]||""); - var fs = options["fontSize1"]; + var fs = options["fontSize"]; if(fs) widget.setFontSize(fs); var fn = options["fontName"]; @@ -695,4 +695,4 @@ load.registerParser("ccui", "*", parser); -})(ccs._load, ccs._parser); \ No newline at end of file +})(ccs._load, ccs._parser); From 2e3dab38452410aaa077da72acb43b5b90f8fb8c Mon Sep 17 00:00:00 2001 From: Patricio Date: Fri, 8 May 2015 12:17:03 +0200 Subject: [PATCH 019/839] Animations with only one frame are allowed now. --- extensions/cocostudio/action/CCActionNode.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions/cocostudio/action/CCActionNode.js b/extensions/cocostudio/action/CCActionNode.js index a4ae9a9332..238a49541c 100644 --- a/extensions/cocostudio/action/CCActionNode.js +++ b/extensions/cocostudio/action/CCActionNode.js @@ -266,13 +266,17 @@ ccs.ActionNode = ccs.Class.extend(/** @lends ccs.ActionNode# */{ var locSequenceArray = []; for (var j = 0; j < locArray.length; j++) { var locFrame = locArray[j]; + var locAction = null; if (j !== 0) { var locSrcFrame = locArray[j - 1]; var locDuration = (locFrame.frameIndex - locSrcFrame.frameIndex) * this.getUnitTime(); - var locAction = locFrame.getAction(locDuration); - if(locAction) - locSequenceArray.push(locAction); + locAction = locFrame.getAction(locDuration); } + else { + locAction = locFrame.getAction(0); + } + if(locAction) + locSequenceArray.push(locAction); } if(locSequenceArray){ var locSequence = cc.sequence(locSequenceArray); @@ -414,4 +418,4 @@ ccs.ActionNode = ccs.Class.extend(/** @lends ccs.ActionNode# */{ return true; return this._action.isDone(); } -}); \ No newline at end of file +}); From c1c36a7d0fe8be091354a87300e7223d24f47fee Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 12 May 2015 14:31:13 +0800 Subject: [PATCH 020/839] Add ccui.VideoPlayer --- cocos2d/core/platform/CCEGLView.js | 24 ++ extensions/ccui/uiwidgets/UIVideoPlayer.js | 426 +++++++++++++++++++++ moduleConfig.json | 1 + 3 files changed, 451 insertions(+) create mode 100644 extensions/ccui/uiwidgets/UIVideoPlayer.js diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 01c58088ed..064e0324a3 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -164,6 +164,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ __resizeWithBrowserSize: false, _isAdjustViewPort: true, _targetDensityDPI: null, + _resizeCallbackList: null, /** * Constructor of cc.EGLView @@ -199,6 +200,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ _t._hDC = cc._canvas; _t._hRC = cc._renderContext; _t._targetDensityDPI = cc.DENSITYDPI_HIGH; + _t._resizeCallbackList = []; }, // Resize helper functions @@ -224,6 +226,11 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ var height = view._originalDesignResolutionSize.height; if (width > 0) view.setDesignResolutionSize(width, height, view._resolutionPolicy); + + for(var i= 0, len= view._resizeCallbackList.length; i Date: Tue, 12 May 2015 17:44:27 +0800 Subject: [PATCH 021/839] To prevent the events are covered --- cocos2d/audio/CCAudio.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 8e7c5e0059..faab5b2215 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -315,7 +315,10 @@ cc.Audio = cc.Class.extend({ if(self._ignoreEnded){ self._ignoreEnded = false; }else{ - self._playing = false; + if(!self._pause) + self.stop(); + else + self._playing = false; } }; }, @@ -671,13 +674,6 @@ cc.Audio = cc.Class.extend({ } audio.play(0, loop); audio.setVolume(this._musicVolume); - function cbEnd(){ - if (!this._currMusic._pause) { - this.stopMusic(); - } - } - var cbEndWithContext = cbEnd.bind(this); - audio._currentSource.onended = cbEndWithContext; this._currMusic = audio; }, From 6c424c7182502488564437d69ea081277d5d432d Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 12 May 2015 17:57:25 +0800 Subject: [PATCH 022/839] Repair the webaudio loop attribute is invalid for chrome 42 --- cocos2d/audio/CCAudio.js | 82 ++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 220273ae81..9f61d718a1 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -33,6 +33,7 @@ * replay : The first music will fail, must be replay after touchstart * emptied : Whether to use the emptied event to replace load callback * delay : delay created the context object - only webAudio + * manualLoop : WebAudio loop attribute failure, need to manually perform loop * * May be modifications for a few browser version */ @@ -109,43 +110,48 @@ console.log(e); } + if(cc.sys.isMobile){ + if(cc.sys.os !== cc.sys.OS_IOS) + cc.__audioSupport = supportTable[sys.browserType] || supportTable["common"]; + else + cc.__audioSupport = supportTable[sys.BROWSER_TYPE_SAFARI]; + }else{ + switch(sys.browserType){ + case sys.BROWSER_TYPE_IE: + cc.__audioSupport = supportTable[sys.BROWSER_TYPE_IE]; + break; + case sys.BROWSER_TYPE_FIREFOX: + cc.__audioSupport = supportTable[sys.BROWSER_TYPE_FIREFOX]; + break; + default: + cc.__audioSupport = supportTable["common"]; + } + } + /////////////////////////// // Browser compatibility// /////////////////////////// if(version){ switch(sys.browserType){ case sys.BROWSER_TYPE_CHROME: - if(parseInt(version) < 30){ - supportTable[sys.BROWSER_TYPE_CHROME] = {multichannel: false , webAudio: true , auto: false}; + version = parseInt(version); + if(version < 30){ + cc.__audioSupport = {multichannel: false , webAudio: true , auto: false}; + }else if(version === 42){ + cc.__audioSupport.manualLoop = true; } break; case sys.BROWSER_TYPE_MIUI: - version = version.match(/\d+/g); - if(version[0] < 2 || (version[0] === 2 && version[1] === 0 && version[2] <= 1)){ - supportTable[sys.BROWSER_TYPE_MIUI].auto = false; + if(cc.sys.isMobile){ + version = version.match(/\d+/g); + if(version[0] < 2 || (version[0] === 2 && version[1] === 0 && version[2] <= 1)){ + cc.__audioSupport.auto = false; + } } break; } } - if(cc.sys.isMobile){ - if(cc.sys.os !== cc.sys.OS_IOS) - cc.__audioSupport = supportTable[sys.browserType] || supportTable["common"]; - else - cc.__audioSupport = supportTable[sys.BROWSER_TYPE_SAFARI]; - }else{ - switch(sys.browserType){ - case sys.BROWSER_TYPE_IE: - cc.__audioSupport = supportTable[sys.BROWSER_TYPE_IE]; - break; - case sys.BROWSER_TYPE_FIREFOX: - cc.__audioSupport = supportTable[sys.BROWSER_TYPE_FIREFOX]; - break; - default: - cc.__audioSupport = supportTable["common"]; - } - } - if(DEBUG){ setTimeout(function(){ cc.log("browse type: " + sys.browserType); @@ -181,6 +187,7 @@ cc.Audio = cc.Class.extend({ _volume: null, _ignoreEnded: false, + _manualLoop: false, //DOM Audio _element: null, @@ -278,7 +285,10 @@ cc.Audio = cc.Class.extend({ var audio = this._context["createBufferSource"](); audio.buffer = this._buffer; audio["connect"](this._volume); - audio.loop = this.loop; + if(this._manualLoop) + audio.loop = false; + else + audio.loop = this.loop; this._startTime = this._context.currentTime; this._currentTime = offset || 0; @@ -312,6 +322,11 @@ cc.Audio = cc.Class.extend({ this._currentSource = audio; var self = this; audio["onended"] = function(){ + if(self._manualLoop && self._playing && self.loop){ + self.stop(); + self.play(); + return; + } if(self._ignoreEnded){ self._ignoreEnded = false; }else{ @@ -526,6 +541,8 @@ cc.Audio = cc.Class.extend({ volume["gain"].value = 1; volume["connect"](context["destination"]); audio = new cc.Audio(context, volume, realUrl); + if(polyfill.manualLoop) + audio._manualLoop = true; }catch(err){ SWA = false; cc.log("browser don't support webAudio"); @@ -585,18 +602,18 @@ cc.Audio = cc.Class.extend({ emptied(); }else{ termination = true; - element.pause(); - document.body.removeChild(element); + element.pause(); + document.body.removeChild(element); cb("audio load timeout : " + realUrl, audio); } }, 10000); var success = function(){ if(!cbCheck){ - element.pause(); - try { element.currentTime = 0; - element.volume = 1; } catch (e) {} - document.body.removeChild(element); + element.pause(); + try { element.currentTime = 0; + element.volume = 1; } catch (e) {} + document.body.removeChild(element); audio.setElement(element); element.removeEventListener("canplaythrough", success, false); element.removeEventListener("error", failure, false); @@ -609,8 +626,8 @@ cc.Audio = cc.Class.extend({ var failure = function(){ if(!cbCheck) return; - element.pause(); - document.body.removeChild(element); + element.pause(); + document.body.removeChild(element); element.removeEventListener("canplaythrough", success, false); element.removeEventListener("error", failure, false); element.removeEventListener("emptied", emptied, false); @@ -674,6 +691,7 @@ cc.Audio = cc.Class.extend({ } audio.play(0, loop); audio.setVolume(this._musicVolume); + this._currMusic = audio; }, From 84299a7edadda661a81d1dcf263cf404ea1d6f92 Mon Sep 17 00:00:00 2001 From: Igor Shmulyan Date: Tue, 12 May 2015 14:59:30 +0300 Subject: [PATCH 023/839] fixed crash when character not found into BMP font --- cocos2d/labels/CCLabelBMFont.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cocos2d/labels/CCLabelBMFont.js b/cocos2d/labels/CCLabelBMFont.js index 83bdf818cf..1a4a018471 100644 --- a/cocos2d/labels/CCLabelBMFont.js +++ b/cocos2d/labels/CCLabelBMFont.js @@ -439,7 +439,12 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ return 0; } var curTextFirstSprite = this.getChildByTag(startIndex); - var curTextLastSprite = this.getChildByTag(startIndex + endIndex); + var curTextLastSpriteId = startIndex + endIndex; + var curTextLastSprite = this.getChildByTag(curTextLastSpriteId); + while (!curTextLastSprite && 0 < curTextLastSpriteId) { + curTextLastSpriteId--; + curTextLastSprite = this.getChildByTag(curTextLastSpriteId); + } return this._getLetterPosXLeft(curTextLastSprite) - this._getLetterPosXLeft(curTextFirstSprite); }, From a6e029f035293ee1e14f98d51341db75710ce4e2 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 13 May 2015 11:13:18 +0800 Subject: [PATCH 024/839] Repair the positioning error problem --- extensions/ccui/uiwidgets/UIVideoPlayer.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index b150bf7a2b..8106563f49 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -325,10 +325,8 @@ ccui.VideoPlayer = ccui.Widget.extend({ b = t.b, c = t.c, d = t.d * scaleY, - tx = t.tx - cw/2 + cw*node._scaleX/2, - ty = t.ty - ch/2 + ch*node._scaleY/2; - //tx = (t.tx + ax*node._scaleX)*scaleX - (1-scaleX)*clientWidth/2 - (clientWidth - ax)*scaleX, - //ty = (t.ty + ay*node._scaleX)*scaleY - (1-scaleY)*clientHeight/2 - (clientHeight - ay)*scaleY; + tx = t.tx*scaleX - cw/2 + cw*node._scaleX/2*scaleX, + ty = t.ty*scaleY - ch/2 + ch*node._scaleY/2*scaleY; var matrix = "matrix(" + a + "," + b + "," + c + "," + d + "," + tx + "," + -ty + ")"; this._video.style["transform"] = matrix; this._video.style["-webkit-transform"] = matrix; From 043312dc8d3af12e894cf2a7e6aeeda37c3b79da Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 13 May 2015 11:32:19 +0800 Subject: [PATCH 025/839] Fix spine js parser issue to avoid NaN duration --- extensions/spine/Spine.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extensions/spine/Spine.js b/extensions/spine/Spine.js index 7a25bab80e..047db2b5ac 100644 --- a/extensions/spine/Spine.js +++ b/extensions/spine/Spine.js @@ -1941,7 +1941,7 @@ spine.SkeletonJson.prototype = { frameIndex++; } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5] || 0); } else if (timelineName == "attachment") { var timeline = new spine.AttachmentTimeline(values.length); @@ -1953,7 +1953,7 @@ spine.SkeletonJson.prototype = { timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]); } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1] || 0); } else throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"; @@ -1982,7 +1982,7 @@ spine.SkeletonJson.prototype = { frameIndex++; } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2] || 0); } else if (timelineName == "translate" || timelineName == "scale") { var timeline; @@ -2005,7 +2005,7 @@ spine.SkeletonJson.prototype = { frameIndex++; } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3] || 0); } else if (timelineName == "flipX" || timelineName == "flipY") { var x = timelineName == "flipX"; @@ -2020,7 +2020,7 @@ spine.SkeletonJson.prototype = { frameIndex++; } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2] || 0); } else throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"; } @@ -2043,7 +2043,7 @@ spine.SkeletonJson.prototype = { frameIndex++; } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.frameCount * 3 - 3]); + duration = Math.max(duration, timeline.frames[timeline.frameCount * 3 - 3] || 0); } var ffd = map["ffd"]; @@ -2104,7 +2104,7 @@ spine.SkeletonJson.prototype = { frameIndex++; } timelines[timelines.length] = timeline; - duration = Math.max(duration, timeline.frames[timeline.frameCount - 1]); + duration = Math.max(duration, timeline.frames[timeline.frameCount - 1] || 0); } } } @@ -2147,7 +2147,7 @@ spine.SkeletonJson.prototype = { timeline.setFrame(frameIndex++, drawOrderMap["time"], drawOrder); } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1] || 0); } var events = map["events"]; @@ -2165,7 +2165,7 @@ spine.SkeletonJson.prototype = { timeline.setFrame(frameIndex++, eventMap["time"], event); } timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1] || 0); } skeletonData.animations.push(new spine.Animation(name, timelines, duration)); From 1b1ca189d228bd4059e8736a0ef6c9ae0c338e72 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 13 May 2015 13:35:54 +0800 Subject: [PATCH 026/839] Fix LabelTTF multiline detection --- cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js b/cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js index fa687f865a..ceab041b9e 100644 --- a/cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js +++ b/cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js @@ -153,7 +153,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/; } } - if (this._strings.length > 0) + if (this._strings.length > 1) this._isMultiLine = true; var locSize, locStrokeShadowOffsetX = 0, locStrokeShadowOffsetY = 0; From ea4f525ef58a2cb8a314e2beead6ce5a6858e38a Mon Sep 17 00:00:00 2001 From: giuseppelt Date: Wed, 13 May 2015 16:29:14 +0200 Subject: [PATCH 027/839] TransitionSlide removed brackets from sequence call --- cocos2d/transitions/CCTransition.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/transitions/CCTransition.js b/cocos2d/transitions/CCTransition.js index 7d8c65c228..f14fa41ad2 100644 --- a/cocos2d/transitions/CCTransition.js +++ b/cocos2d/transitions/CCTransition.js @@ -652,7 +652,7 @@ cc.TransitionSlideInL = cc.TransitionScene.extend(/** @lends cc.TransitionSlideI var inA = this.action(); var outA = this.action(); - var inAction = cc.sequence([this.easeActionWithAction(inA), cc.callFunc(this.finish, this)]); + var inAction = cc.sequence(this.easeActionWithAction(inA), cc.callFunc(this.finish, this)); var outAction = this.easeActionWithAction(outA); this._inScene.runAction(inAction); this._outScene.runAction(outAction); From cb57063d0262a3d4cfe88fcf4c8b22523dd58a3a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 13 May 2015 23:01:59 +0800 Subject: [PATCH 028/839] Fix issue in ccui.Widget#getScale --- extensions/ccui/base-classes/UIWidget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ccui/base-classes/UIWidget.js b/extensions/ccui/base-classes/UIWidget.js index b7e7a16f76..bf4af67728 100644 --- a/extensions/ccui/base-classes/UIWidget.js +++ b/extensions/ccui/base-classes/UIWidget.js @@ -1768,7 +1768,7 @@ ccui.Widget = ccui.ProtectedNode.extend(/** @lends ccui.Widget# */{ return originalScale; }, getScale: function(){ - if(this.getScaleX() === this.getScaleY()) + if(this.getScaleX() !== this.getScaleY()) cc.log("Widget#scale. ScaleX != ScaleY. Don't know which one to return"); return this.getScaleX(); }, From 736a00bf6c9fd0e959ec776bab2cc226e3c4aa68 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 14 May 2015 10:41:40 +0800 Subject: [PATCH 029/839] Improve property declaration of cc.Texture2D --- cocos2d/core/textures/CCTexture2D.js | 1 - cocos2d/core/textures/TexturesPropertyDefine.js | 11 +++++++++-- cocos2d/core/textures/TexturesWebGL.js | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index dca144d060..38c59d2434 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -110,7 +110,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { * @extends cc.Class * * @property {WebGLTexture} name - <@readonly> WebGLTexture Object - * @property {Number} defaultPixelFormat - The default pixel format * @property {Number} pixelFormat - <@readonly> Pixel format of the texture * @property {Number} pixelsWidth - <@readonly> Width in pixels * @property {Number} pixelsHeight - <@readonly> Height in pixels diff --git a/cocos2d/core/textures/TexturesPropertyDefine.js b/cocos2d/core/textures/TexturesPropertyDefine.js index fe1eef3801..518a5f5139 100644 --- a/cocos2d/core/textures/TexturesPropertyDefine.js +++ b/cocos2d/core/textures/TexturesPropertyDefine.js @@ -152,6 +152,15 @@ cc._tmp.PrototypeTexture2D = function () { */ _c.PIXEL_FORMAT_DEFAULT = _c.PIXEL_FORMAT_RGBA8888; + /** + * The default pixel format + * @memberOf cc.Texture2D + * @name PIXEL_FORMAT_PVRTC2 + * @static + * @type {Number} + */ + _c.defaultPixelFormat = _c.PIXEL_FORMAT_DEFAULT; + var _M = cc.Texture2D._M = {}; _M[_c.PIXEL_FORMAT_RGBA8888] = "RGBA8888"; _M[_c.PIXEL_FORMAT_RGB888] = "RGB888"; @@ -198,8 +207,6 @@ cc._tmp.PrototypeTexture2D = function () { /** @expose */ _p.height; cc.defineGetterSetter(_p, "height", _p._getHeight); - - _c.defaultPixelFormat = _c.PIXEL_FORMAT_DEFAULT; }; cc._tmp.PrototypeTextureAtlas = function () { diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index c08cd2c49d..c2dc3b3683 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -38,7 +38,6 @@ cc._tmp.WebGLTexture2D = function () { * @extends cc.Class * * @property {WebGLTexture} name - <@readonly> WebGLTexture Object - * @property {Number} defaultPixelFormat - The default pixel format * @property {Number} pixelFormat - <@readonly> Pixel format of the texture * @property {Number} pixelsWidth - <@readonly> Width in pixels * @property {Number} pixelsHeight - <@readonly> Height in pixels From aacb872b7c96f5b81b8b4a25f2756b5566709f06 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 14 May 2015 15:40:00 +0800 Subject: [PATCH 030/839] Unified management event trigger --- cocos2d/core/event-manager/CCEventManager.js | 21 ++++ extensions/ccui/uiwidgets/UIVideoPlayer.js | 119 ++++++++----------- tools/build.xml | 1 + 3 files changed, 72 insertions(+), 69 deletions(-) diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index 46ba136659..d01b3527aa 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -745,6 +745,27 @@ cc.eventManager = /** @lends cc.eventManager# */{ } }, + _removeListenerInCallback: function(listeners, callback){ + if (listeners == null) + return false; + + for (var i = 0, len = listeners.length; i < len; i++) { + var selListener = listeners[i]; + if (selListener._onCustomEvent === callback || selListener._onEvent === callback) { + selListener._setRegistered(false); + if (selListener._getSceneGraphPriority() != null){ + this._dissociateNodeAndEventListener(selListener._getSceneGraphPriority(), selListener); + selListener._setSceneGraphPriority(null); // NULL out the node pointer so we don't have any dangling pointers to destroyed nodes. + } + + if (this._inDispatch === 0) + cc.arrayRemoveObject(listeners, selListener); + return true; + } + } + return false; + }, + _removeListenerInVector : function(listeners, listener){ if (listeners == null) return false; diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index 8106563f49..18f68d4f00 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -24,14 +24,10 @@ ccui.VideoPlayer = ccui.Widget.extend({ - _EventList: null, - ctor: function(path){ ccui.Widget.prototype.ctor.call(this); if(path) this.setURL(path); - - this._EventList = {};//play | pause | stop | complete }, _createRenderCmd: function(){ @@ -63,24 +59,6 @@ ccui.VideoPlayer = ccui.Widget.extend({ return ""; }, - /** - * Set the video address - * Automatically replace extname - * All supported video formats will be added to the video - * @param {String} path - */ - setFileName: function(path){ - this.setURL(path); - }, - - /** - * Get the video path - * @returns {String} - */ - getFileName: function(){ - this.getURL(path); - }, - /** * Play the video */ @@ -120,10 +98,7 @@ ccui.VideoPlayer = ccui.Widget.extend({ } setTimeout(function(){ - var list = self._EventList["stop"]; - if(list) - for(var i=0; i + From 2f6cd3d7d084bc53ec28ec25969cb201c3bc3f46 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 14 May 2015 15:40:13 +0800 Subject: [PATCH 031/839] Unified management event trigger --- CCBoot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/CCBoot.js b/CCBoot.js index 1be2d4ff3b..6181745665 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -2049,6 +2049,7 @@ cc.game = /** @lends cc.game# */{ EVENT_HIDE: "game_on_hide", EVENT_SHOW: "game_on_show", + EVENT_RESIZE: "game_on_resize", _eventHide: null, _eventShow: null, _onBeforeStartArr: [], From 23b4e36988f53fbfd5eaf1d519e2b874766aaa1c Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 14 May 2015 15:43:04 +0800 Subject: [PATCH 032/839] Unified management event trigger --- cocos2d/core/platform/CCEGLView.js | 1 - extensions/ccui/uiwidgets/UIVideoPlayer.js | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 064e0324a3..1800830f75 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -200,7 +200,6 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ _t._hDC = cc._canvas; _t._hRC = cc._renderContext; _t._targetDensityDPI = cc.DENSITYDPI_HIGH; - _t._resizeCallbackList = []; }, // Resize helper functions diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index 18f68d4f00..3fdbcef822 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -38,10 +38,10 @@ ccui.VideoPlayer = ccui.Widget.extend({ * Set the video address * Automatically replace extname * All supported video formats will be added to the video - * @param {String} path + * @param {String} address */ - setURL: function(path){ - this._renderCmd.updateURL(path); + setURL: function(address){ + this._renderCmd.updateURL(address); }, /** From 9c0a6507492b48202abb96535bb6016cd9622fd5 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 14 May 2015 17:06:54 +0800 Subject: [PATCH 033/839] Add the WebView --- extensions/ccui/uiwidgets/UIWebView.js | 355 +++++++++++++++++++++++++ moduleConfig.json | 1 + tools/build.xml | 1 + 3 files changed, 357 insertions(+) create mode 100644 extensions/ccui/uiwidgets/UIWebView.js diff --git a/extensions/ccui/uiwidgets/UIWebView.js b/extensions/ccui/uiwidgets/UIWebView.js new file mode 100644 index 0000000000..f64e11908a --- /dev/null +++ b/extensions/ccui/uiwidgets/UIWebView.js @@ -0,0 +1,355 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +ccui.WebView = ccui.Widget.extend({ + + ctor: function(path){ + ccui.Widget.prototype.ctor.call(this); + if(path) + this.loadURL(path); + this._EventList = {}; + }, + + + setJavascriptInterfaceScheme: function(scheme){}, + loadData: function(data, MIMEType, encoding, baseURL){}, + loadHTMLString: function(string, baseURL){}, + + + /** + * Load an URL + * @param {String} url + */ + loadURL: function(url){ + this._renderCmd.updateURL(url); + cc.eventManager.dispatchCustomEvent(ccui.WebView.EventType.LOADING); + }, + + /** + * Stop loading + */ + stopLoading: function(){ + cc.log("Web does not support loading"); + }, + reload: function(){ + var iframe = this._renderCmd._iframe; + if(iframe){ + var win = iframe.contentWindow; + if(win && win.location) + win.location.reload(); + } + }, + + /** + * Determine whether to go back + */ + canGoBack: function(){ + cc.log("Web does not support query history"); + }, + + /** + * Determine whether to go forward + */ + canGoForward: function(){ + cc.log("Web does not support query history"); + }, + + /** + * go back + */ + goBack: function(){ + var iframe = this._renderCmd._iframe; + if(iframe){ + var win = iframe.contentWindow; + if(win && win.location) + win.history.back(); + } + }, + + /** + * go forward + */ + goForward: function(){ + var iframe = this._renderCmd._iframe; + if(iframe){ + var win = iframe.contentWindow; + if(win && win.location) + win.history.forward(); + } + }, + + /** + * In the webview execution within a period of js string + * @param str + */ + evaluateJS: function(str){ + var iframe = this._renderCmd._iframe; + if(iframe){ + var win = iframe.contentWindow; + try{ + win.eval(str); + }catch(err){ + console.error(err); + } + } + }, + + /** + * Limited scale + */ + setScalesPageToFit: function(){ + cc.log("Web does not support zoom"); + }, + + /** + * The binding event + * @param event string: load | loading | error Or: ccui.WebView.EventType + * @param callback + */ + addEventListener: function(event, callback){ + if(!/^ui_webview_/.test(event)) + event = "ui_webview_" + event; + return cc.eventManager.addCustomListener(event, callback); + }, + + /** + * Delete events + * @param event + * @param callbackOrListener + */ + removeEventListener: function(event, callbackOrListener){ + var map, list; + if(!/^ui_webview_/.test(event)) + event = "ui_webview_" + event; + if(typeof callbackOrListener === "function"){ + map = cc.eventManager._listenersMap[event]; + if(map){ + list = map.getFixedPriorityListeners(); + list && cc.eventManager._removeListenerInCallback(list, callbackOrListener); + } + }else{ + map = cc.eventManager._listenersMap[event]; + if(map){ + list = map.getFixedPriorityListeners(); + list && cc.eventManager._removeListenerInVector(list, callbackOrListener); + } + } + }, + + //setOnShouldStartLoading: function(callback){}, + //setOnDidFinishLoading: function(){}, + //setOnDidFailLoading: function(){}, + //setOnJSCallback: function(){}, + + //getOnShouldStartLoading: function(){}, + //getOnDidFinishLoading: function(){}, + //getOnDidFailLoading: function(){}, + //getOnJSCallback: function(){}, + + _createRenderCmd: function(){ + return new ccui.WebView.RenderCmd(this); + }, + + setContentSize: function(w, h){ + ccui.Widget.prototype.setContentSize.call(this, w, h); + if(h === undefined){ + h = w.height; + w = w.width; + } + this._renderCmd.changeSize(w, h); + }, + + cleanup: function(){ + this._renderCmd.removeDom(); + this.stopAllActions(); + this.unscheduleAllCallbacks(); + } +}); + +ccui.WebView.EventType = { + LOADING: "ui_webview_loading", + LOADED: "ui_webview_load", + ERROR: "ui_webview_error" +}; + +(function(){ + + ccui.WebView.polyfill = { + devicePixelRatio: false, + enableDiv: false + }; + + if(cc.sys.os === cc.sys.OS_IOS) + ccui.WebView.polyfill.enableDiv = true; + +})(); + +(function(polyfill){ + + ccui.WebView.RenderCmd = function(node){ + cc.Node.CanvasRenderCmd.call(this, node); + + this._div = null; + this._iframe = null; + + if(polyfill.enableDiv){ + this._div = document.createElement("div"); + this._div.style["-webkit-overflow"] = "auto"; + this._div.style["-webkit-overflow-scrolling"] = "touch"; + this._iframe = document.createElement("iframe"); + this._div.appendChild(this._iframe); + }else{ + this._div = this._iframe = document.createElement("iframe"); + } + this._iframe.addEventListener("load", function(){ + cc.eventManager.dispatchCustomEvent(ccui.WebView.EventType.LOADED); + }); + this._iframe.addEventListener("error", function(){ + cc.eventManager.dispatchCustomEvent(ccui.WebView.EventType.ERROR); + }); + this._div.style["background-color"] = "#FFF"; + this._div.style.height = "200px"; + this._div.style.width = "300px"; + this._div.style.overflow = "scroll"; + this._listener = null; + this.initStyle(); + }; + + var proto = ccui.WebView.RenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype); + proto.constructor = ccui.WebView.RenderCmd; + + proto.updateStatus = function(){ + polyfill.devicePixelRatio = cc.view.isRetinaEnabled(); + var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag; + if(locFlag & flags.transformDirty){ + //update the transform + this.transform(this.getParentRenderCmd(), true); + this.updateMatrix(this._worldTransform, cc.view._scaleX, cc.view._scaleY); + this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.transformDirty ^ this._dirtyFlag; + } + }; + + proto.visit = function(){ + var self = this, + container = cc.container, + eventManager = cc.eventManager; + if(this._node._visible){ + container.appendChild(this._div); + if(this._listener === null) + this._listener = eventManager.addCustomListener(cc.game.EVENT_RESIZE, function () { + self.resize(); + }); + }else{ + var hasChild = false; + if('contains' in container) { + hasChild = container.contains(this._div); + }else { + hasChild = container.compareDocumentPosition(this._div) % 16; + } + if(hasChild) + container.removeChild(this._div); + var list = eventManager._listenersMap[cc.game.EVENT_RESIZE].getFixedPriorityListeners(); + eventManager._removeListenerInVector(list, this._listener); + this._listener = null; + } + this.updateStatus(); + this.resize(cc.view); + }; + + proto.resize = function(view){ + view = view || cc.view; + var node = this._node, + eventManager = cc.eventManager; + if(node._parent && node._visible) + this.updateMatrix(this._worldTransform, view._scaleX, view._scaleY); + else{ + var list = eventManager._listenersMap[cc.game.EVENT_RESIZE].getFixedPriorityListeners(); + eventManager._removeListenerInVector(list, this._listener); + this._listener = null; + } + }; + + proto.updateMatrix = function(t, scaleX, scaleY){ + var node = this._node; + if(polyfill.devicePixelRatio && scaleX !== 1 && scaleX !== 1){ + var dpr = window.devicePixelRatio; + scaleX = scaleX / dpr; + scaleY = scaleY / dpr; + } + if(this._loaded === false) return; + var cw = node._contentSize.width, + ch = node._contentSize.height; + var a = t.a * scaleX, + b = t.b, + c = t.c, + d = t.d * scaleY, + tx = t.tx*scaleX - cw/2 + cw*node._scaleX/2*scaleX, + ty = t.ty*scaleY - ch/2 + ch*node._scaleY/2*scaleY; + var matrix = "matrix(" + a + "," + b + "," + c + "," + d + "," + tx + "," + -ty + ")"; + this._div.style["transform"] = matrix; + this._div.style["-webkit-transform"] = matrix; + }; + + proto.initStyle = function(){ + if(!this._div) return; + var div = this._div; + div.style.position = "absolute"; + div.style.bottom = "0px"; + div.style.left = "0px"; + }; + + proto.updateURL = function(url){ + var iframe = this._iframe; + iframe.src = url; + var self = this; + var cb = function(){ + self._loaded = true; + iframe.removeEventListener("load", cb); + }; + iframe.addEventListener("load", cb); + }; + + proto.changeSize = function(w, h){ + var div = this._div; + if(div){ + div.style["width"] = w+"px"; + div.style["height"] = h+"px"; + } + }; + + proto.removeDom = function(){ + var div = this._div; + if(div){ + var hasChild = false; + if('contains' in cc.container) { + hasChild = cc.container.contains(div); + }else { + hasChild = cc.container.compareDocumentPosition(div) % 16; + } + if(hasChild) + cc.container.removeChild(div); + } + }; + +})(ccui.WebView.polyfill); \ No newline at end of file diff --git a/moduleConfig.json b/moduleConfig.json index a089e198d8..d665e1842a 100644 --- a/moduleConfig.json +++ b/moduleConfig.json @@ -323,6 +323,7 @@ "extensions/ccui/uiwidgets/UITextBMFont.js", "extensions/ccui/uiwidgets/UITextField.js", "extensions/ccui/uiwidgets/UIRichText.js", + "extensions/ccui/uiwidgets/UIWebView.js", "extensions/ccui/uiwidgets/scroll-widget/UIScrollView.js", "extensions/ccui/uiwidgets/scroll-widget/UIListView.js", "extensions/ccui/uiwidgets/scroll-widget/UIPageView.js" diff --git a/tools/build.xml b/tools/build.xml index 326af567d2..4cb0fecae1 100644 --- a/tools/build.xml +++ b/tools/build.xml @@ -224,6 +224,7 @@ + From f58b64259f88f36666b71bc5b02dfbe58dc9d39b Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 14 May 2015 18:10:43 +0800 Subject: [PATCH 034/839] Unified management event trigger --- cocos2d/core/platform/CCEGLView.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index 1800830f75..1360857192 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -164,7 +164,6 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ __resizeWithBrowserSize: false, _isAdjustViewPort: true, _targetDensityDPI: null, - _resizeCallbackList: null, /** * Constructor of cc.EGLView @@ -226,10 +225,6 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ if (width > 0) view.setDesignResolutionSize(width, height, view._resolutionPolicy); - for(var i= 0, len= view._resizeCallbackList.length; i Date: Thu, 14 May 2015 14:19:47 +0200 Subject: [PATCH 035/839] Fixed TransitionShrinkGrow callback sequence --- cocos2d/transitions/CCTransition.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cocos2d/transitions/CCTransition.js b/cocos2d/transitions/CCTransition.js index f14fa41ad2..b2dd0a1f1e 100644 --- a/cocos2d/transitions/CCTransition.js +++ b/cocos2d/transitions/CCTransition.js @@ -879,10 +879,8 @@ cc.TransitionShrinkGrow = cc.TransitionScene.extend(/** @lends cc.TransitionShri var scaleOut = cc.scaleTo(this._duration, 0.01); var scaleIn = cc.scaleTo(this._duration, 1.0); - this._inScene.runAction(this.easeActionWithAction(scaleIn)); - this._outScene.runAction( - cc.sequence(this.easeActionWithAction(scaleOut), cc.callFunc(this.finish, this)) - ); + this._inScene.runAction(cc.sequence(this.easeActionWithAction(scaleIn), cc.callFunc(this.finish, this)); + this._outScene.runAction(this.easeActionWithAction(scaleOut)); }, /** From 89a721e110cb5c4f10d81eb32ea79362d4741aa8 Mon Sep 17 00:00:00 2001 From: Ningxin Hu Date: Fri, 15 May 2015 12:43:15 +0800 Subject: [PATCH 036/839] Add SIMD version of kazmath functions Contributors: pan.han@intel.com yuhang.lan@intel.com --- cocos2d/kazmath/mat4.js | 424 ++++++++++++++++++++++++++++++++++++++++ cocos2d/kazmath/vec3.js | 24 +++ 2 files changed, 448 insertions(+) diff --git a/cocos2d/kazmath/mat4.js b/cocos2d/kazmath/mat4.js index d211589531..41eb3677c4 100644 --- a/cocos2d/kazmath/mat4.js +++ b/cocos2d/kazmath/mat4.js @@ -188,6 +188,11 @@ return pOut; }; + cc.kmMat4InverseSIMD = function (pOut, pM) { + pOut = pM.inverseSIMD(); + return pOut; + }; + /** * Calculates the inverse of current matrix. * @returns {cc.math.Matrix4} Returns null if there is no inverse, else returns a new inverse matrix object @@ -199,6 +204,133 @@ return null; return inv; }; + + proto.inverseSIMD = function(){ + var inv = new cc.math.Matrix4(); + var src = this.mat; + var dest = inv.mat; + var src0, src1, src2, src3; + var row0, row1, row2, row3; + var tmp1; + var minor0, minor1, minor2, minor3; + var det; + + // Load the 4 rows + var src0 = SIMD.float32x4.load(src, 0); + var src1 = SIMD.float32x4.load(src, 4); + var src2 = SIMD.float32x4.load(src, 8); + var src3 = SIMD.float32x4.load(src, 12); + + // Transpose the source matrix. Sort of. Not a true transpose operation + + tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); + row1 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); + row0 = SIMD.float32x4.shuffle(tmp1, row1, 0, 2, 4, 6); + row1 = SIMD.float32x4.shuffle(row1, tmp1, 1, 3, 5, 7); + + tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); + row3 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); + row2 = SIMD.float32x4.shuffle(tmp1, row3, 0, 2, 4, 6); + row3 = SIMD.float32x4.shuffle(row3, tmp1, 1, 3, 5, 7); + + // This is a true transposition, but it will lead to an incorrect result + + //tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); + //tmp2 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); + //row0 = SIMD.float32x4.shuffle(tmp1, tmp2, 0, 2, 4, 6); + //row1 = SIMD.float32x4.shuffle(tmp1, tmp2, 1, 3, 5, 7); + + //tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); + //tmp2 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); + //row2 = SIMD.float32x4.shuffle(tmp1, tmp2, 0, 2, 4, 6); + //row3 = SIMD.float32x4.shuffle(tmp1, tmp2, 1, 3, 5, 7); + + // ---- + tmp1 = SIMD.float32x4.mul(row2, row3); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor0 = SIMD.float32x4.mul(row1, tmp1); + minor1 = SIMD.float32x4.mul(row0, tmp1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.sub(SIMD.float32x4.mul(row1, tmp1), minor0); + minor1 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor1); + minor1 = SIMD.float32x4.swizzle(minor1, 2, 3, 0, 1); // 0x4E = 01001110 + + // ---- + tmp1 = SIMD.float32x4.mul(row1, row2); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor0); + minor3 = SIMD.float32x4.mul(row0, tmp1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row3, tmp1)); + minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor3); + minor3 = SIMD.float32x4.swizzle(minor3, 2, 3, 0, 1); // 0x4E = 01001110 + + // ---- + tmp1 = SIMD.float32x4.mul(SIMD.float32x4.swizzle(row1, 2, 3, 0, 1), row3); // 0x4E = 01001110 + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + row2 = SIMD.float32x4.swizzle(row2, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor0); + minor2 = SIMD.float32x4.mul(row0, tmp1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row2, tmp1)); + minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor2); + minor2 = SIMD.float32x4.swizzle(minor2, 2, 3, 0, 1); // 0x4E = 01001110 + + // ---- + tmp1 = SIMD.float32x4.mul(row0, row1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row2, tmp1), minor3); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row2, tmp1)); + + // ---- + tmp1 = SIMD.float32x4.mul(row0, row3); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row2, tmp1)); + minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor2); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor1); + minor2 = SIMD.float32x4.sub(minor2, SIMD.float32x4.mul(row1, tmp1)); + + // ---- + tmp1 = SIMD.float32x4.mul(row0, row2); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor1); + minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row1, tmp1)); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row3, tmp1)); + minor3 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor3); + + // Compute determinant + det = SIMD.float32x4.mul(row0, minor0); + det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 2, 3, 0, 1), det); // 0x4E = 01001110 + det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 1, 0, 3, 2), det); // 0xB1 = 10110001 + tmp1 = SIMD.float32x4.reciprocalApproximation(det); + det = SIMD.float32x4.sub(SIMD.float32x4.add(tmp1, tmp1), SIMD.float32x4.mul(det, SIMD.float32x4.mul(tmp1, tmp1))); + det = SIMD.float32x4.swizzle(det, 0, 0, 0, 0); + + // These shuffles aren't necessary if the faulty transposition is done + // up at the top of this function. + //minor0 = SIMD.float32x4.swizzle(minor0, 2, 1, 0, 3); + //minor1 = SIMD.float32x4.swizzle(minor1, 2, 1, 0, 3); + //minor2 = SIMD.float32x4.swizzle(minor2, 2, 1, 0, 3); + //minor3 = SIMD.float32x4.swizzle(minor3, 2, 1, 0, 3); + + // Compute final values by multiplying with 1/det + minor0 = SIMD.float32x4.mul(det, minor0); + minor1 = SIMD.float32x4.mul(det, minor1); + minor2 = SIMD.float32x4.mul(det, minor2); + minor3 = SIMD.float32x4.mul(det, minor3); + + SIMD.float32x4.store(dest, 0, minor0); + SIMD.float32x4.store(dest, 4, minor1); + SIMD.float32x4.store(dest, 8, minor2); + SIMD.float32x4.store(dest, 12, minor3); + + return inv; + }; /** * Returns true if current matrix is an identity matrix, false otherwise @@ -211,6 +343,33 @@ && mat[12] === 0 && mat[13] === 0 && mat[14] === 0 && mat[15] === 1); }; + proto.isIdentitySIMD = function () { + var inx4 = SIMD.float32x4.load(this.mat, 0); + var identityx4 = SIMD.float32x4.load(identityMatrix.mat, 0); + var ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + + inx4 = SIMD.float32x4.load(this.mat, 4); + identityx4 = SIMD.float32x4.load(identityMatrix.mat, 4); + ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + + inx4 = SIMD.float32x4.load(this.mat, 8); + identityx4 = SIMD.float32x4.load(identityMatrix.mat, 8); + ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + + inx4 = SIMD.float32x4.load(this.mat, 12); + identityx4 = SIMD.float32x4.load(identityMatrix.mat, 12); + ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + return true; + }; + /** * transpose the current matrix */ @@ -238,6 +397,36 @@ return this; }; + proto.transposeSIMD = function () { + var outArr = this.mat, inArr = this.mat; + var src0 = SIMD.float32x4.load(inArr, 0); + var src1 = SIMD.float32x4.load(inArr, 4); + var src2 = SIMD.float32x4.load(inArr, 8); + var src3 = SIMD.float32x4.load(inArr, 12); + var dst0; + var dst1; + var dst2; + var dst3; + var tmp01; + var tmp23; + + tmp01 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); + tmp23 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); + dst0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + dst1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + + tmp01 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); + tmp23 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); + dst2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + dst3 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + + SIMD.float32x4.store(outArr, 0, dst0); + SIMD.float32x4.store(outArr, 4, dst1); + SIMD.float32x4.store(outArr, 8, dst2); + SIMD.float32x4.store(outArr, 12, dst3); + return this; + }; + /** * Multiplies pM1 with pM2, stores the result in pOut, returns pOut */ @@ -273,6 +462,11 @@ return pOut; }; + cc.kmMat4MultiplySIMD = function (pOut, pM1, pM2) { + pOut = new cc.math.Matrix4(pM1); + return pOut.multiplySIMD(pM2); + }; + /** * current matrix multiplies with other matrix mat4 * @param {cc.math.Matrix4} mat4 @@ -310,6 +504,55 @@ return this; }; + proto.multiplySIMD = function(mat4) { + var a = this.mat; + var b = mat4.mat; + var out = this.mat; + + var a0 = SIMD.float32x4.load(a,0); + var a1 = SIMD.float32x4.load(a,4); + var a2 = SIMD.float32x4.load(a,8); + var a3 = SIMD.float32x4.load(a,12); + var b0 = SIMD.float32x4.load(b, 0); + SIMD.float32x4.store(out, 0, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3))))); + var b1 = SIMD.float32x4.load(b, 4); + SIMD.float32x4.store(out, 4, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3))))); + var b2 = SIMD.float32x4.load(b, 8); + SIMD.float32x4.store(out, 8, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3))))); + var b3 = SIMD.float32x4.load(b, 12); + SIMD.float32x4.store(out, 12, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3))))); + + return this; + }; + cc.getMat4MultiplyValue = function (pM1, pM2) { var m1 = pM1.mat, m2 = pM2.mat; var mat = new Float32Array(16); @@ -337,6 +580,11 @@ return mat; }; + cc.getMat4MultiplyValueSIMD = function (pM1, pM2) { + var mat = new cc.math.Matrix4(pM1); + return mat.multiplySIMD(pM2); + }; + /** * Assigns the value of pIn to pOut */ @@ -371,6 +619,15 @@ return pOut; }; + cc.kmMat4AssignSIMD = function (pOut, pIn) { + if(pOut == pIn) { + cc.log("cc.kmMat4Assign(): pOut equals pIn");//TODO: ADD SIMD? + return pOut; + } + + return pOut.assignFromSIMD(pIn); + }; + /** * Assigns the value of current matrix from mat4 * @param {cc.math.Matrix4} mat4 @@ -405,6 +662,23 @@ return this; }; + proto.assignFromSIMD = function (mat4) { + if(this == mat4) { + cc.log("cc.mat.Matrix4.assignFrom(): mat4 equals current matrix");//TODO: ADD SIMD? + return this; + } + + var outArr = this.mat; + var inArr = mat4.mat; + + SIMD.float32x4.store(outArr, 0, SIMD.float32x4.load(inArr, 0)); + SIMD.float32x4.store(outArr, 4, SIMD.float32x4.load(inArr, 4)); + SIMD.float32x4.store(outArr, 8, SIMD.float32x4.load(inArr, 8)); + SIMD.float32x4.store(outArr, 12, SIMD.float32x4.load(inArr, 12)); + + return this; + }; + /** * Returns true if current matrix equal mat4 (approximately) * @param {cc.math.Matrix4} mat4 @@ -423,6 +697,40 @@ return true; }; + proto.equalsSIMD = function (mat4) { + if(this === mat4){ + cc.log("cc.kmMat4AreEqual(): pMat1 and pMat2 are same object."); + return true; + } + var m10 = SIMD.float32x4.load(this.mat, 0); + var m20 = SIMD.float32x4.load(mat4.mat, 0); + + var epsilon = SIMD.float32x4.splat(cc.math.EPSILON); + + var ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m10, m20)), epsilon); + if (ret.signMask === 0) + return false; + + var m11 = SIMD.float32x4.load(this.mat, 4); + var m21 = SIMD.float32x4.load(mat4.mat, 4); + ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m11, m21)), epsilon); + if (ret.signMask === 0) + return false; + + var m12 = SIMD.float32x4.load(this.mat, 8); + var m22 = SIMD.float32x4.load(mat4.mat, 8); + ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m12, m22)), epsilon); + if (ret.signMask === 0) + return false; + + var m13 = SIMD.float32x4.load(this.mat, 12); + var m23 = SIMD.float32x4.load(mat4.mat, 12); + ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m13, m23)), epsilon); + if (ret.signMask === 0) + return false; + return true; + }; + /** * Builds an X-axis rotation matrix and stores it in matrix, returns matrix, if matrix is null, create a new matrix * @param {Number} radians @@ -825,6 +1133,10 @@ return pOut; }; + cc.kmMat4LookAtSIMD = function (pOut, pEye, pCenter, pUp) { + return pOut.lookAtSIMD(pEye, pCenter, pUp); + }; + var tempMatrix = new cc.math.Matrix4(); // an internal matrix proto.lookAt = function(eyeVec, centerVec, upVec) { var f = new cc.math.Vec3(centerVec), up = new cc.math.Vec3(upVec), mat = this.mat; @@ -858,6 +1170,107 @@ return this; }; + proto.lookAtSIMD = function(eyeVec, centerVec, upVec) { + var out = this.mat; + + var center = SIMD.float32x4(centerVec.x, centerVec.y, centerVec.z, 0.0); + var eye = SIMD.float32x4(eyeVec.x, eyeVec.y, eyeVec.z, 0.0); + var up = SIMD.float32x4(upVec.x, upVec.y, upVec.z, 0.0); + + // cc.kmVec3Subtract(f, pCenter, pEye); + var f = SIMD.float32x4.sub(center, eye); + // cc.kmVec3Normalize(f, f); + var tmp = SIMD.float32x4.mul(f, f); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + f = SIMD.float32x4.mul(f, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + // cc.kmVec3Assign(up, pUp); + // cc.kmVec3Normalize(up, up); + tmp = SIMD.float32x4.mul(up, up); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + up = SIMD.float32x4.mul(up, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + // cc.kmVec3Cross(s, f, up); + var s = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 1, 2, 0, 3), SIMD.float32x4.swizzle(up, 2, 0, 1, 3)), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 2, 0, 1, 3), SIMD.float32x4.swizzle(up, 1, 2, 0, 3))); + // cc.kmVec3Normalize(s, s); + tmp = SIMD.float32x4.mul(s, s); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + // cc.kmVec3Cross(u, s, f); + var u = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 1, 2, 0, 3), SIMD.float32x4.swizzle(f, 2, 0, 1, 3)), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 2, 0, 1, 3), SIMD.float32x4.swizzle(f, 1, 2, 0, 3))); + // cc.kmVec3Normalize(s, s); + tmp = SIMD.float32x4.mul(s, s); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + //cc.kmMat4Identity(pOut); + //pOut.mat[0] = s.x; + //pOut.mat[4] = s.y; + //pOut.mat[8] = s.z; + //pOut.mat[1] = u.x; + //pOut.mat[5] = u.y; + //pOut.mat[9] = u.z; + //pOut.mat[2] = -f.x; + //pOut.mat[6] = -f.y; + //pOut.mat[10] = -f.z; + var zero = SIMD.float32x4.splat(0.0); + f = SIMD.float32x4.neg(f); + var tmp01 = SIMD.float32x4.shuffle(s, u, 0, 1, 4, 5); + var tmp23 = SIMD.float32x4.shuffle(f, zero, 0, 1, 4, 5); + var a0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + var a1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + + var tmp01 = SIMD.float32x4.shuffle(s, u, 2, 3, 6, 7); + var tmp23 = SIMD.float32x4.shuffle(f, zero, 2, 3, 6, 7); + var a2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + var a3 = SIMD.float32x4(0.0, 0.0, 0.0, 1.0); + + // cc.kmMat4Translation(translate, -pEye.x, -pEye.y, -pEye.z); + var b0 = SIMD.float32x4(1.0, 0.0, 0.0, 0.0); + var b1 = SIMD.float32x4(0.0, 1.0, 0.0, 0.0); + var b2 = SIMD.float32x4(0.0, 0.0, 1.0, 0.0); + var b3 = SIMD.float32x4.neg(eye); + b3 = SIMD.float32x4.withW(b3, 1.0); + + // cc.kmMat4Multiply(pOut, pOut, translate); + SIMD.float32x4.store(out, 0, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3))))); + SIMD.float32x4.store(out, 4, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3))))); + SIMD.float32x4.store(out, 8, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3))))); + SIMD.float32x4.store(out, 12, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3))))); + return this; + }; + /** * Build a rotation matrix from an axis and an angle. Result is stored in pOut. * pOut is returned. @@ -1007,6 +1420,17 @@ var temp = cc.math.Quaternion.rotationMatrix(rotation); return temp.toAxisAndAngle(); }; + + if(typeof(SIMD) !== 'undefined' && cc.doNotUseSIMD !== true) { + proto.inverse = proto.inverseSIMD; + proto.isIdentity = proto.isIdentitySIMD; + proto.transpose = proto.transposeSIMD; + proto.multiply = proto.multiplySIMD; + proto.getMat4MultiplyValue = proto.getMat4MultiplyValueSIMD; + proto.assignFrom = proto.assignFromSIMD; + proto.equals = proto.equalsSIMD; + proto.lookAt = proto.lookAtSIMD; + } })(cc); diff --git a/cocos2d/kazmath/vec3.js b/cocos2d/kazmath/vec3.js index 282b34aaae..46bb0abea2 100644 --- a/cocos2d/kazmath/vec3.js +++ b/cocos2d/kazmath/vec3.js @@ -136,6 +136,26 @@ return this; }; + proto.transformCoordSIMD = function(mat4){ + var vec = SIMD.float32x4(this.x, this.y, this.z, 0.0); + var mat0 = SIMD.float32x4.load(mat4.mat, 0); + var mat1 = SIMD.float32x4.load(mat4.mat, 4); + var mat2 = SIMD.float32x4.load(mat4.mat, 8); + var mat3 = SIMD.float32x4.load(mat4.mat, 12); + + //cc.kmVec4Transform(v, inV,pM); + var out = SIMD.float32x4.add( + SIMD.float32x4.add(SIMD.float32x4.mul(mat0, SIMD.float32x4.swizzle(vec, 0, 0, 0, 0)), + SIMD.float32x4.mul(mat1, SIMD.float32x4.swizzle(vec, 1, 1, 1, 1))), + SIMD.float32x4.add(SIMD.float32x4.mul(mat2, SIMD.float32x4.swizzle(vec, 2, 2, 2, 2)), + mat3)); + + out = SIMD.float32x4.div(out, SIMD.float32x4.swizzle(out, 3, 3, 3, 3)); + this.fill(out); + + return this; + }; + proto.scale = function(scale){ // = cc.kmVec3Scale this.x *= scale; this.y *= scale; @@ -188,6 +208,10 @@ tyArr[2] = this.z; return tyArr; }; + + if(typeof(SIMD) !== 'undefined' && cc.doNotUseSIMD !== true) { + proto.transformCoord = proto.transformCoordSIMD; + } })(cc); From 244322cc979d5abe6b357671b18fcec1e6d09dc7 Mon Sep 17 00:00:00 2001 From: SPACELAN Date: Tue, 12 May 2015 12:52:54 +0800 Subject: [PATCH 037/839] Add SIMD benchmarks for kazmath --- cocos2d/kazmath/simd_benchmark/base.js | 139 ++++++++++++++++++ cocos2d/kazmath/simd_benchmark/index.html | 43 ++++++ .../kazmath/simd_benchmark/kernel-template.js | 64 ++++++++ .../kazmath/simd_benchmark/kmMat4AreEqual.js | 77 ++++++++++ .../kazmath/simd_benchmark/kmMat4Assign.js | 68 +++++++++ .../kazmath/simd_benchmark/kmMat4Inverse.js | 116 +++++++++++++++ .../simd_benchmark/kmMat4IsIdentity.js | 65 ++++++++ .../kazmath/simd_benchmark/kmMat4LookAt.js | 94 ++++++++++++ .../kazmath/simd_benchmark/kmMat4Multiply.js | 74 ++++++++++ .../kazmath/simd_benchmark/kmMat4Transpose.js | 82 +++++++++++ .../simd_benchmark/kmVec3TransformCoord.js | 65 ++++++++ cocos2d/kazmath/simd_benchmark/run.js | 38 +++++ cocos2d/kazmath/simd_benchmark/run_browser.js | 80 ++++++++++ 13 files changed, 1005 insertions(+) create mode 100644 cocos2d/kazmath/simd_benchmark/base.js create mode 100644 cocos2d/kazmath/simd_benchmark/index.html create mode 100644 cocos2d/kazmath/simd_benchmark/kernel-template.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmMat4Assign.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js create mode 100644 cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js create mode 100644 cocos2d/kazmath/simd_benchmark/run.js create mode 100644 cocos2d/kazmath/simd_benchmark/run_browser.js diff --git a/cocos2d/kazmath/simd_benchmark/base.js b/cocos2d/kazmath/simd_benchmark/base.js new file mode 100644 index 0000000000..d01857c77e --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/base.js @@ -0,0 +1,139 @@ +// SIMD Kernel Benchmark Harness +// Author: Peter Jensen + +function Benchmark (config) { + this.config = config; + this.initOk = true; // Initialize all properties used on a Benchmark object + this.cleanupOk = true; + this.useAutoIterations = true; + this.autoIterations = 0; + this.actualIterations = 0; + this.simdTime = 0; + this.nonSimdTime = 0; +} + +function Benchmarks () { + this.benchmarks = []; +} + +Benchmarks.prototype.add = function (benchmark) { + this.benchmarks.push (benchmark); + return this.benchmarks.length - 1; +} + +Benchmarks.prototype.runOne = function (benchmark) { + + function timeKernel(kernel, iterations) { + var start, stop; + start = Date.now(); + kernel(iterations); + stop = Date.now(); + return stop - start; + } + + function computeIterations() { + var desiredRuntime = 1000; // milliseconds for longest running kernel + var testIterations = 10; // iterations used to determine time for desiredRuntime + + // Make the slowest kernel run for at least 500ms + var simdTime = timeKernel(benchmark.config.kernelSimd, testIterations); + var nonSimdTime = timeKernel(benchmark.config.kernelNonSimd, testIterations); + var maxTime = simdTime > nonSimdTime ? simdTime : nonSimdTime; + while (maxTime < 500) { + testIterations *= 2; + simdTime = timeKernel(benchmark.config.kernelSimd, testIterations); + nonSimdTime = timeKernel(benchmark.config.kernelNonSimd, testIterations); + maxTime = simdTime > nonSimdTime ? simdTime : nonSimdTime; + } + maxTime = simdTime > nonSimdTime ? simdTime : nonSimdTime; + + // Compute iteration count for 1 second run of slowest kernel + var iterations = Math.ceil(desiredRuntime * testIterations / maxTime); + return iterations; + } + + // Initialize the kernels and check the correctness status + if (!benchmark.config.kernelInit()) { + benchmark.initOk = false; + return false; + } + + // Determine how many iterations to use. + if (benchmark.useAutoIterations) { + benchmark.autoIterations = computeIterations(); + benchmark.actualIterations = benchmark.autoIterations; + } + else { + benchmark.actualIterations = benchmark.config.kernelIterations; + } + + // Run the SIMD kernel + benchmark.simdTime = timeKernel(benchmark.config.kernelSimd, benchmark.actualIterations); + + // Run the non-SIMD kernel + benchmark.nonSimdTime = timeKernel(benchmark.config.kernelNonSimd, benchmark.actualIterations); + + // Do the final sanity check + if (!benchmark.config.kernelCleanup()) { + benchmark.cleanupOk = false; + return false; + } + + return true; +} + +Benchmarks.prototype.report = function (benchmark, outputFunctions) { + + function fillRight(str, width) { + str += ""; // make sure it's a string + while (str.length < width) { + str += " "; + } + return str; + } + + function fillLeft(str, width) { + str += ""; // make sure it's a string + while (str.length < width) { + str = " " + str; + } + return str; + } + + if (!benchmark.initOk) { + outputFunctions.notifyError(fillRight(benchmark.config.kernelName + ": ", 23) + "FAILED INIT"); + return; + } + if (!benchmark.cleanupOk) { + outputFunctions.notifyError(fillRight(benchmark.config.kernelName + ": ", 23) + "FAILED CLEANUP"); + return; + } + + var ratio = benchmark.nonSimdTime / benchmark.simdTime; + ratio = ratio.toFixed(2); + outputFunctions.notifyResult( + fillRight(benchmark.config.kernelName + ": ", 23) + + "Iterations(" + fillLeft(benchmark.actualIterations, 10) + ")" + + ", SIMD(" + fillLeft(benchmark.simdTime + "ms)", 8) + + ", Non-SIMD(" + fillLeft(benchmark.nonSimdTime + "ms)", 8) + + ", Speedup(" + ratio + ")"); + outputFunctions.timeData.labels.push(benchmark.config.kernelName); + outputFunctions.timeData.datasets[0].data.push(benchmark.simdTime); + outputFunctions.timeData.datasets[1].data.push(benchmark.nonSimdTime); + outputFunctions.speedupData.labels.push(benchmark.config.kernelName); + outputFunctions.speedupData.datasets[0].data.push(ratio); +} + +Benchmarks.prototype.runAll = function (outputFunctions, useAutoIterations) { + if (typeof useAutoIterations === "undefined") { + useAutoIterations = false; + } + for (var i = 0, n = this.benchmarks.length; i < n; ++i) { + var benchmark = this.benchmarks[i]; + benchmark.useAutoIterations = useAutoIterations; + this.runOne(benchmark); + this.report(benchmark, outputFunctions); + } +} + +var benchmarks = new Benchmarks (); diff --git a/cocos2d/kazmath/simd_benchmark/index.html b/cocos2d/kazmath/simd_benchmark/index.html new file mode 100644 index 0000000000..50f077c661 --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/index.html @@ -0,0 +1,43 @@ + + + + + Kazmath SIMD benchmarks + + + +

Running benchmarks...

+
+
+

+ +
+
+

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cocos2d/kazmath/simd_benchmark/kernel-template.js b/cocos2d/kazmath/simd_benchmark/kernel-template.js new file mode 100644 index 0000000000..d7c377585d --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kernel-template.js @@ -0,0 +1,64 @@ +// Kernel template +// Author: Peter Jensen +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "Test", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 100000000 + }; + + // Hook up to the harness + benchmarks.add (new Benchmark (kernelConfig)); + + // Kernel Initializer + function init () { + // Do initial sanity check and initialize data for the kernels. + // The sanity check should verify that the simd and nonSimd results + // are the same. + // It is recommended to do minimal object creation in the kernels + // themselves. If global data needs to be initialized, here would + // be the place to do it. + // If the sanity checks fails the kernels will not be executed + // Returns: + // true: First run (unoptimized) of the kernels passed + // false: First run (unoptimized) of the kernels failed + return simd (1) === nonSimd (1); + } + + // Kernel Cleanup + function cleanup () { + // Do final sanity check and perform cleanup. + // This function is called when all the kernel iterations have been + // executed, so they should be in their final optimized version. The + // sanity check done during initialization will probably be of the + // initial unoptimized version. + // Returns: + // true: Last run (optimized) of the kernels passed + // false: last run (optimized) of the kernels failed + return simd (1) === nonSimd (1); + } + + // SIMD version of the kernel + function simd (n) { + var s = 0; + for (var i = 0; i < n; ++i) { + s += i; + } + return s; + } + + // Non SIMD version of the kernel + function nonSimd (n) { + var s = 0; + for (var i = 0; i < n; ++i) { + s += i; + } + return s; + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js b/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js new file mode 100644 index 0000000000..a3dee727ac --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js @@ -0,0 +1,77 @@ +// kmMat4AreEqual + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmMat4AreEqual", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var T1 = new cc.kmMat4(); + var T2 = new cc.kmMat4(); + var T1x4 = new cc.kmMat4(); + var T2x4 = new cc.kmMat4(); + var areEqual, areEqualSIMD; + + function equals(A, B) { + for (var i = 0; i < 16; ++i) { + if (A[i] != B[i]) + return false; + } + return true; + } + + function init() { + T1.mat[0] = 1.0; + T1.mat[5] = 1.0; + T1.mat[10] = 1.0; + T1.mat[15] = 1.0; + + T2.mat[0] = 1.0; + T2.mat[5] = 1.0; + T2.mat[10] = 1.0; + T2.mat[15] = 1.0; + + T1x4.mat[0] = 1.0; + T1x4.mat[5] = 1.0; + T1x4.mat[10] = 1.0; + T1x4.mat[15] = 1.0; + + T2x4.mat[0] = 1.0; + T2x4.mat[5] = 1.0; + T2x4.mat[10] = 1.0; + T2x4.mat[15] = 1.0; + + nonSimd(1); + simd(1); + + return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat) && (areEqual === areEqualSIMD); + + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + areEqual = T1.equals(T2); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + areEqualSIMD = T1x4.equalsSIMD(T2x4); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js b/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js new file mode 100644 index 0000000000..e8e386f781 --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js @@ -0,0 +1,68 @@ +// kmMat4Assign + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmMat4Assign", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var T1 = new cc.kmMat4(); + var T2 = new cc.kmMat4(); + var T1x4 = new cc.kmMat4(); + var T2x4 = new cc.kmMat4(); + + function equals(A, B) { + for (var i = 0; i < 16; ++i) { + if (A[i] != B[i]) + return false; + } + return true; + } + + function init() { + T1.mat[0] = 1.0; + T1.mat[5] = 1.0; + T1.mat[10] = 1.0; + T1.mat[15] = 1.0; + + T1x4.mat[0] = 1.0; + T1x4.mat[5] = 1.0; + T1x4.mat[10] = 1.0; + T1x4.mat[15] = 1.0; + + nonSimd(1); + simd(1); + + return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat); + + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + //cc.kmMat4Assign(T2, T1); + T2.assignFrom(T1); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + //cc.kmMat4AssignSIMD(T2x4, T1x4); + T2x4.assignFromSIMD(T1x4); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js b/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js new file mode 100644 index 0000000000..212dff1af1 --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js @@ -0,0 +1,116 @@ +// kmMat4Inverse + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmMat4Inverse", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var src = new cc.kmMat4(); + var dst = new cc.kmMat4(); + var srcx4 = new cc.kmMat4(); + var dstx4 = new cc.kmMat4(); + var ident = new Float32Array( + [1,0,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1]); + + function equals(A, B) { + for (var i = 0; i < 16; ++i) { + if (Math.abs (A[i] - B[i]) > 5) + return false; + } + return true; + } + + function initMatrix(matrix) { + // These values were chosen somewhat randomly, but they will at least yield a solution. + matrix [0] = 0; matrix[1] = 1; matrix[2] = 2; matrix[3] = 3; + matrix [4] = -1; matrix[5] = -2; matrix[6] = -3; matrix[7] = -4; + matrix [8] = 0; matrix[9] = 0; matrix[10] = 2; matrix[11] = 3; + matrix [12] = -1; matrix[13] = -2; matrix[14] = 0; matrix[15] = -4; + } + + function mulMatrix(dst, op1, op2) { + for (var r = 0; r < 4; ++r) { + for (var c = 0; c < 4; ++c) { + var ri = 4*r; + dst[ri + c] = op1[ri]*op2[c] + op1[ri+1]*op2[c+4] + op1[ri+2]*op2[c+8] + op1[ri+3]*op2[c+12]; + } + } + } + + function printMatrix(matrix, str) { + print('--------matrix ' + str + '----------'); + for (var r = 0; r < 4; ++r) { + var str = ""; + var ri = r*4; + for (var c = 0; c < 4; ++c) { + var value = matrix[ri + c]; + str += " " + value.toFixed(2); + } + print(str); + } + } + + function checkMatrix(src, dst) { + // when multiplied with the src matrix it should yield the identity matrix + var tmp = new Float32Array(16); + mulMatrix(tmp, src, dst); + for (var i = 0; i < 16; ++i) { + if (Math.abs (tmp[i] - ident[i]) > 0.00001) { + return false; + } + } + return true; + } + + function init() { + initMatrix(src.mat); + // printMatrix(src); + nonSimd(1); + // printMatrix(dst); + if (!checkMatrix(src.mat, dst.mat)) { + return false; + } + + initMatrix(srcx4.mat); + simd(1); + // printMatrix(dst); + if (!checkMatrix(srcx4.mat, dstx4.mat)) { + return false; + } + + return true; + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + //cc.kmMat4Inverse(dst, src); + dst = src.inverse(); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + //cc.kmMat4InverseSIMD(dstx4, srcx4); + dstx4 = srcx4.inverseSIMD(); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js b/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js new file mode 100644 index 0000000000..9ab17ac744 --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js @@ -0,0 +1,65 @@ +// kmMat4IsIdentity + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmMat4IsIdentity", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var T1 = new cc.kmMat4(); + var T1x4 = new cc.kmMat4(); + var isIdentity, isIdentitySIMD; + + function equals(A, B) { + for (var i = 0; i < 16; ++i) { + if (A[i] != B[i]) + return false; + } + return true; + } + + function init() { + T1.mat[0] = 1.0; + T1.mat[5] = 1.0; + T1.mat[10] = 1.0; + T1.mat[15] = 1.0; + + T1x4.mat[0] = 1.0; + T1x4.mat[5] = 1.0; + T1x4.mat[10] = 1.0; + T1x4.mat[15] = 1.0; + + nonSimd(1); + simd(1); + + return equals(T1.mat, T1x4.mat) && (isIdentity === isIdentitySIMD); + + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + isIdentity = T1.isIdentity(); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + isIdentitySIMD = T1x4.isIdentitySIMD(); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js b/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js new file mode 100644 index 0000000000..1015ad14eb --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js @@ -0,0 +1,94 @@ +// kmMat4LookAt + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmMat4LookAt", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var eye = new cc.kmVec3(), center = new cc.kmVec3(), up = new cc.kmVec3(); + var T1 = new cc.kmMat4(); + var eye1 = new cc.kmVec3(), center1 = new cc.kmVec3(), up1 = new cc.kmVec3(); + var T1x4 = new cc.kmMat4(); + + function printMatrix(matrix) { + print('--------matrix----------'); + for (var r = 0; r < 4; ++r) { + var str = ""; + var ri = r*4; + for (var c = 0; c < 4; ++c) { + var value = matrix[ri + c]; + str += " " + value.toFixed(2); + } + print(str); + } + } + + function equals(A, B) { + for (var i = 0; i < 16; ++i) { + if (Math.abs (A[i] - B[i]) > 0.001) { + return false; + } + } + return true; + } + + function init() { + + eye.fill(0, 1, 2); + center.fill(2, 1, 0); + up.fill(1, 1, 1); + + eye1.fill(0, 1, 2); + center1.fill(2, 1, 0); + up1.fill(1, 1, 1); + /* + eye1.data[0] = 0; + eye1.data[1] = 1; + eye1.data[2] = 2; + + center1.data[0] = 2; + center1.data[1] = 1; + center1.data[2] = 0; + + up1.data[0] = 1; + up1.data[1] = 1; + up1.data[2] = 1; + */ + nonSimd(1); + //printMatrix(T1.mat); + simd(1); + //printMatrix(T1x4.mat); + + return equals(T1.mat, T1x4.mat); + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + //cc.kmMat4LookAt(T1, eye, center, up); + T1.lookAt(eye, center, up); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + //cc.kmMat4LookAtSIMD(T1x4, eye1, center1, up1); + T1x4.lookAtSIMD(eye1, center1, up1); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js b/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js new file mode 100644 index 0000000000..325b6f95bf --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js @@ -0,0 +1,74 @@ +// kmMat4Multiply + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmMat4Multiply", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var T1 = new cc.kmMat4(); + var T2 = new cc.kmMat4(); + var T1x4 = new cc.kmMat4(); + var T2x4 = new cc.kmMat4(); + + function equals(A, B) { + for (var i = 0; i < 16; ++i) { + if (A[i] != B[i]) + return false; + } + return true; + } + + function init() { + T1.mat[0] = 1.0; + T1.mat[5] = 1.0; + T1.mat[10] = 1.0; + T1.mat[15] = 1.0; + + T2.mat[0] = 1.0; + T2.mat[5] = 1.0; + T2.mat[10] = 1.0; + T2.mat[15] = 1.0; + + T1x4.mat[0] = 1.0; + T1x4.mat[5] = 1.0; + T1x4.mat[10] = 1.0; + T1x4.mat[15] = 1.0; + + T2x4.mat[0] = 1.0; + T2x4.mat[5] = 1.0; + T2x4.mat[10] = 1.0; + T2x4.mat[15] = 1.0; + + nonSimd(1); + simd(1); + return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat); + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + T1.multiply(T2); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + T1x4.multiplySIMD(T2x4); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js b/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js new file mode 100644 index 0000000000..cd1b776bf0 --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js @@ -0,0 +1,82 @@ +// kmMat4Transpose + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmMat4Transpose", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var T1 = new cc.kmMat4(); + var T2 = new cc.kmMat4(); + var T1x4 = new cc.kmMat4(); + var T2x4 = new cc.kmMat4(); + + function equals(A, B) { + for (var i = 0; i < 16; ++i) { + if (A[i] != B[i]) + return false; + } + return true; + } + + function printMatrix(matrix) { + print('--------matrix----------'); + for (var r = 0; r < 4; ++r) { + var str = ""; + var ri = r*4; + for (var c = 0; c < 4; ++c) { + var value = matrix[ri + c]; + str += " " + value.toFixed(2); + } + print(str); + } + } + + function init() { + T1.mat [0] = 0; T1.mat[1] = 1; T1.mat[2] = 2; T1.mat[3] = 3; + T1.mat [4] = -1; T1.mat[5] = -2; T1.mat[6] = -3; T1.mat[7] = -4; + T1.mat [8] = 0; T1.mat[9] = 0; T1.mat[10] = 2; T1.mat[11] = 3; + T1.mat [12] = -1; T1.mat[13] = -2; T1.mat[14] = 0; T1.mat[15] = -4; + + T1x4.mat [0] = 0; T1x4.mat[1] = 1; T1x4.mat[2] = 2; T1x4.mat[3] = 3; + T1x4.mat [4] = -1; T1x4.mat[5] = -2; T1x4.mat[6] = -3; T1x4.mat[7] = -4; + T1x4.mat [8] = 0; T1x4.mat[9] = 0; T1x4.mat[10] = 2; T1x4.mat[11] = 3; + T1x4.mat [12] = -1; T1x4.mat[13] = -2; T1x4.mat[14] = 0; T1x4.mat[15] = -4; + + nonSimd(1); + //printMatrix(T2.mat); + simd(1); + //printMatrix(T2x4.mat); + return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat); + + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + T2 = T1.transpose(); + //T1.transpose(); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + T2x4 = T1x4.transposeSIMD(); + //T1x4.transposeSIMD(); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js b/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js new file mode 100644 index 0000000000..541a926c9d --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js @@ -0,0 +1,65 @@ +// kmVec3TransformCoord + +(function () { + + // Kernel configuration + var kernelConfig = { + kernelName: "kmVec3TransformCoord", + kernelInit: init, + kernelCleanup: cleanup, + kernelSimd: simd, + kernelNonSimd: nonSimd, + kernelIterations: 10000 + }; + + // Hook up to the harness + benchmarks.add(new Benchmark(kernelConfig)); + + // Benchmark data, initialization and kernel functions + var V = new cc.kmVec3(); + var T = new cc.kmMat4(); + var Out = new cc.kmVec3(); + var Vx4 = new cc.kmVec3(); + var Tx4 = new cc.kmMat4(); + var Outx4 = new cc.kmVec3(); + + function init() { + T.mat[0] = 1.0; + T.mat[5] = 1.0; + T.mat[10] = 1.0; + T.mat[15] = 1.0; + + V.fill(0.0, 1.0, 0.0); + + Tx4.mat[0] = 1.0; + Tx4.mat[5] = 1.0; + Tx4.mat[10] = 1.0; + Tx4.mat[15] = 1.0; + + Vx4.fill(0.0, 1.0, 0.0); + + nonSimd(1); + simd(1); + //console.log(V); + //console.log(Vx4); + return V.equals(Vx4); + + } + + function cleanup() { + return init(); // Sanity checking before and after are the same + } + + function nonSimd(n) { + for (var i = 0; i < n; i++) { + V.transformCoord(T); + } + } + + function simd(n) { + for (var i = 0; i < n; i++) { + Vx4.transformCoordSIMD(Tx4); + } + } + +} ()); diff --git a/cocos2d/kazmath/simd_benchmark/run.js b/cocos2d/kazmath/simd_benchmark/run.js new file mode 100644 index 0000000000..1a1b253bd4 --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/run.js @@ -0,0 +1,38 @@ +"use strict" + +var cc = {}; + +load ('base.js'); + +load ('../utility.js'); +load ('../vec3.js'); +load ('../vec4.js'); +load ('../mat4.js'); + +// load individual benchmarks +load ('kernel-template.js'); +load ('kmMat4Multiply.js'); +load ('kmMat4Assign.js'); +load ('kmMat4AreEqual.js'); +load ('kmMat4Inverse.js'); +load ('kmMat4IsIdentity.js'); +load ('kmMat4Transpose.js'); +load ('kmMat4LookAt.js'); +load ('kmVec3TransformCoord.js'); + +function printResult (str) { + print (str); +} + +function printError (str) { + print (str); +} + +function printScore (str) { + print (str); +} + +benchmarks.runAll ({notifyResult: printResult, + notifyError: printError, + notifyScore: printScore}, + true); diff --git a/cocos2d/kazmath/simd_benchmark/run_browser.js b/cocos2d/kazmath/simd_benchmark/run_browser.js new file mode 100644 index 0000000000..5d2d0cdd74 --- /dev/null +++ b/cocos2d/kazmath/simd_benchmark/run_browser.js @@ -0,0 +1,80 @@ +var echo = document.getElementById('echo'); + +function printResult(str) { + console.log(str); + echo.innerHTML += str + '
'; +} + +function printError(str) { + console.log(str); + echo.innerHTML += str + '
'; +} + +function printScore(str) { + console.log(str); + echo.innerHTML += str + '
'; +} + +var timeData = { + labels: [], + datasets: [ + { + labels: 'Non-SIMD', + fillColor: "rgba(220,220,220,0.5)", + strokeColor: "rgba(220,220,220,0.8)", + highlightFill: "rgba(220,220,220,0.75)", + highlightStroke: "rgba(220,220,220,1)", + data: [] + }, + { + labels: 'SIMD', + fillColor: "rgba(151,187,205,0.5)", + strokeColor: "rgba(151,187,205,0.8)", + highlightFill: "rgba(151,187,205,0.75)", + highlightStroke: "rgba(151,187,205,1)", + data: [] + } + ] +}; + +var speedupData ={ + labels: [], + datasets: [ + { + labels: 'SIMD', + fillColor: "rgba(151,187,205,0.5)", + strokeColor: "rgba(151,187,205,0.8)", + highlightFill: "rgba(151,187,205,0.75)", + highlightStroke: "rgba(151,187,205,1)", + data: [] + } + ] +}; + +window.onload = function() { + if (typeof(SIMD) === 'undefined') { + var head = document.getElementById('head'); + head.innerHTML = 'SIMD is not implemented in your browser, stops.'; + return; + } + console.log('Running benchmarks.'); + benchmarks.runAll({notifyResult: printResult, + notifyError: printError, + notifyScore: printScore, + timeData: timeData, + speedupData: speedupData}, true); + document.getElementById('head').innerHTML = 'Results'; + document.getElementById('time').innerHTML = 'Time'; + document.getElementById('speedup').innerHTML = 'Speedup'; + var ctx1 = document.getElementById("canvasTime").getContext("2d"); + window.Bar1 = new Chart(ctx1).Bar(timeData, { + scaleLabel: "<%=value%>ms", + responsive: true + }); + var ctx2 = document.getElementById("canvasSpeedup").getContext("2d"); + window.Bar2 = new Chart(ctx2).Bar(speedupData, { + scaleLabel: " <%=value%>", + responsive: true + }); + console.log('Benchmarks completed.'); +}; From 5f14f68e7067884b1621db303d36f59a0658d13e Mon Sep 17 00:00:00 2001 From: Ningxin Hu Date: Fri, 15 May 2015 12:51:39 +0800 Subject: [PATCH 038/839] Add cc.sys.doNotUseSIMD It is used to control using SIMD.js optimziation or not. --- CCBoot.js | 5 +++++ cocos2d/kazmath/mat4.js | 2 +- cocos2d/kazmath/simd_benchmark/index.html | 5 +++-- cocos2d/kazmath/vec3.js | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index 1be2d4ff3b..b4a63d66c2 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -1822,6 +1822,11 @@ cc._initSys = function (config, CONFIG_KEY) { sys.openURL = function(url){ window.open(url); } + + /** + * Don't use SIMD.js optimization + */ + sys.doNotUseSIMD = false; }; //+++++++++++++++++++++++++something about sys end+++++++++++++++++++++++++++++ diff --git a/cocos2d/kazmath/mat4.js b/cocos2d/kazmath/mat4.js index 41eb3677c4..a090fb9bc2 100644 --- a/cocos2d/kazmath/mat4.js +++ b/cocos2d/kazmath/mat4.js @@ -1421,7 +1421,7 @@ return temp.toAxisAndAngle(); }; - if(typeof(SIMD) !== 'undefined' && cc.doNotUseSIMD !== true) { + if(typeof(SIMD) !== 'undefined' && cc.sys.doNotUseSIMD !== true) { proto.inverse = proto.inverseSIMD; proto.isIdentity = proto.isIdentitySIMD; proto.transpose = proto.transposeSIMD; diff --git a/cocos2d/kazmath/simd_benchmark/index.html b/cocos2d/kazmath/simd_benchmark/index.html index 50f077c661..19135bb2d6 100644 --- a/cocos2d/kazmath/simd_benchmark/index.html +++ b/cocos2d/kazmath/simd_benchmark/index.html @@ -19,8 +19,9 @@

diff --git a/cocos2d/kazmath/vec3.js b/cocos2d/kazmath/vec3.js index 46bb0abea2..eb6264a6f6 100644 --- a/cocos2d/kazmath/vec3.js +++ b/cocos2d/kazmath/vec3.js @@ -209,7 +209,7 @@ return tyArr; }; - if(typeof(SIMD) !== 'undefined' && cc.doNotUseSIMD !== true) { + if(typeof(SIMD) !== 'undefined' && cc.sys.doNotUseSIMD !== true) { proto.transformCoord = proto.transformCoordSIMD; } })(cc); From ff3d162c4d803fcc04b2ac1b9f7629d14bf80c40 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 15 May 2015 15:11:44 +0800 Subject: [PATCH 039/839] Adaptation model and fix mistakes in grammar --- cocos2d/transitions/CCTransition.js | 2 +- extensions/ccui/uiwidgets/UIWebView.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cocos2d/transitions/CCTransition.js b/cocos2d/transitions/CCTransition.js index b2dd0a1f1e..204f3897a7 100644 --- a/cocos2d/transitions/CCTransition.js +++ b/cocos2d/transitions/CCTransition.js @@ -879,7 +879,7 @@ cc.TransitionShrinkGrow = cc.TransitionScene.extend(/** @lends cc.TransitionShri var scaleOut = cc.scaleTo(this._duration, 0.01); var scaleIn = cc.scaleTo(this._duration, 1.0); - this._inScene.runAction(cc.sequence(this.easeActionWithAction(scaleIn), cc.callFunc(this.finish, this)); + this._inScene.runAction(cc.sequence(this.easeActionWithAction(scaleIn), cc.callFunc(this.finish, this))); this._outScene.runAction(this.easeActionWithAction(scaleOut)); }, diff --git a/extensions/ccui/uiwidgets/UIWebView.js b/extensions/ccui/uiwidgets/UIWebView.js index f64e11908a..e6ea298a44 100644 --- a/extensions/ccui/uiwidgets/UIWebView.js +++ b/extensions/ccui/uiwidgets/UIWebView.js @@ -79,6 +79,8 @@ ccui.WebView = ccui.Widget.extend({ * go back */ goBack: function(){ + if(ccui.WebView.polyfill.closeHistory) + return cc.log("The current browser does not support the GoBack"); var iframe = this._renderCmd._iframe; if(iframe){ var win = iframe.contentWindow; @@ -91,6 +93,8 @@ ccui.WebView = ccui.Widget.extend({ * go forward */ goForward: function(){ + if(ccui.WebView.polyfill.closeHistory) + return cc.log("The current browser does not support the GoForward"); var iframe = this._renderCmd._iframe; if(iframe){ var win = iframe.contentWindow; @@ -195,7 +199,7 @@ ccui.WebView.EventType = { (function(){ - ccui.WebView.polyfill = { + var polyfill = ccui.WebView.polyfill = { devicePixelRatio: false, enableDiv: false }; @@ -203,6 +207,17 @@ ccui.WebView.EventType = { if(cc.sys.os === cc.sys.OS_IOS) ccui.WebView.polyfill.enableDiv = true; + if(cc.sys.isMobile){ + if(cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX){ + polyfill.enableBG = true; + } + }else{ + if(cc.sys.browserType === cc.sys.BROWSER_TYPE_IE){ + polyfill.closeHistory = true; + } + } + + })(); (function(polyfill){ @@ -222,6 +237,10 @@ ccui.WebView.EventType = { }else{ this._div = this._iframe = document.createElement("iframe"); } + + if(polyfill.enableBG) + this._div.style["background"] = "#FFF"; + this._iframe.addEventListener("load", function(){ cc.eventManager.dispatchCustomEvent(ccui.WebView.EventType.LOADED); }); From 1fe8e9314cbf8d0653340f75646eb5a001a294c0 Mon Sep 17 00:00:00 2001 From: Ningxin Hu Date: Fri, 15 May 2015 15:39:56 +0800 Subject: [PATCH 040/839] Add vec3SIMD.js, mat4SIMD.js and SIMDPolyfill.js --- CCBoot.js | 5 - cocos2d/kazmath/SIMDPolyfill.js | 78 ++++++ cocos2d/kazmath/mat4.js | 424 ------------------------------- cocos2d/kazmath/mat4SIMD.js | 428 ++++++++++++++++++++++++++++++++ cocos2d/kazmath/vec3.js | 24 -- cocos2d/kazmath/vec3SIMD.js | 51 ++++ moduleConfig.json | 3 + 7 files changed, 560 insertions(+), 453 deletions(-) create mode 100644 cocos2d/kazmath/SIMDPolyfill.js create mode 100644 cocos2d/kazmath/mat4SIMD.js create mode 100644 cocos2d/kazmath/vec3SIMD.js diff --git a/CCBoot.js b/CCBoot.js index b4a63d66c2..1be2d4ff3b 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -1822,11 +1822,6 @@ cc._initSys = function (config, CONFIG_KEY) { sys.openURL = function(url){ window.open(url); } - - /** - * Don't use SIMD.js optimization - */ - sys.doNotUseSIMD = false; }; //+++++++++++++++++++++++++something about sys end+++++++++++++++++++++++++++++ diff --git a/cocos2d/kazmath/SIMDPolyfill.js b/cocos2d/kazmath/SIMDPolyfill.js new file mode 100644 index 0000000000..7c65b0a214 --- /dev/null +++ b/cocos2d/kazmath/SIMDPolyfill.js @@ -0,0 +1,78 @@ +/** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + Copyright (c) 2008, Luke Benstead. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +(function(cc) { + var _useSIMD = false; + + var mat4Proto = cc.math.Matrix4.prototype; + var mat4Inverse = mat4Proto.inverse; + var mat4IsIdentity = mat4Proto.isIdentity; + var mat4Transpose = mat4Proto.transpose; + var mat4Multiply = mat4Proto.multiply; + var mat4GetMat4MultiplyValue = mat4Proto.getMat4MultiplyValue; + var mat4AssignFrom = mat4Proto.assignFrom; + var mat4Equals = mat4Proto.equals; + var mat4LookAt = mat4Proto.lookAt; + + var vec3Proto = cc.math.Vec3.prototype; + var vec3TransformCoord = vec3Proto.transformCoord; + + function _isEnabledSIMD () { + return _useSIMD; + } + + function _enableSIMD (enable) { + if(typeof(SIMD) === 'undefined') + return; + + if (enable) { + mat4Proto.inverse = mat4Proto.inverseSIMD; + mat4Proto.isIdentity = mat4Proto.isIdentitySIMD; + mat4Proto.transpose = mat4Proto.transposeSIMD; + mat4Proto.multiply = mat4Proto.multiplySIMD; + mat4Proto.getMat4MultiplyValue = mat4Proto.getMat4MultiplyValueSIMD; + mat4Proto.assignFrom = mat4Proto.assignFromSIMD; + mat4Proto.equals = mat4Proto.equalsSIMD; + mat4Proto.lookAt = mat4Proto.lookAtSIMD; + vec3Proto.transformCoord = vec3Proto.transformCoordSIMD; + } else { + mat4Proto.inverse = mat4Inverse; + mat4Proto.isIdentity = mat4IsIdentity; + mat4Proto.transpose = mat4Transpose; + mat4Proto.multiply = mat4Multiply; + mat4Proto.getMat4MultiplyValue = mat4GetMat4MultiplyValue; + mat4Proto.assignFrom = mat4AssignFrom; + mat4Proto.equals = mat4Equals; + mat4Proto.lookAt = mat4LookAt; + vec3Proto.transformCoord = vec3TransformCoord; + } + _useSIMD = enable; + } + + cc.defineGetterSetter(cc.sys, "useSIMD", _isEnabledSIMD, _enableSIMD); +})(cc); \ No newline at end of file diff --git a/cocos2d/kazmath/mat4.js b/cocos2d/kazmath/mat4.js index a090fb9bc2..d211589531 100644 --- a/cocos2d/kazmath/mat4.js +++ b/cocos2d/kazmath/mat4.js @@ -188,11 +188,6 @@ return pOut; }; - cc.kmMat4InverseSIMD = function (pOut, pM) { - pOut = pM.inverseSIMD(); - return pOut; - }; - /** * Calculates the inverse of current matrix. * @returns {cc.math.Matrix4} Returns null if there is no inverse, else returns a new inverse matrix object @@ -204,133 +199,6 @@ return null; return inv; }; - - proto.inverseSIMD = function(){ - var inv = new cc.math.Matrix4(); - var src = this.mat; - var dest = inv.mat; - var src0, src1, src2, src3; - var row0, row1, row2, row3; - var tmp1; - var minor0, minor1, minor2, minor3; - var det; - - // Load the 4 rows - var src0 = SIMD.float32x4.load(src, 0); - var src1 = SIMD.float32x4.load(src, 4); - var src2 = SIMD.float32x4.load(src, 8); - var src3 = SIMD.float32x4.load(src, 12); - - // Transpose the source matrix. Sort of. Not a true transpose operation - - tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); - row1 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); - row0 = SIMD.float32x4.shuffle(tmp1, row1, 0, 2, 4, 6); - row1 = SIMD.float32x4.shuffle(row1, tmp1, 1, 3, 5, 7); - - tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); - row3 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); - row2 = SIMD.float32x4.shuffle(tmp1, row3, 0, 2, 4, 6); - row3 = SIMD.float32x4.shuffle(row3, tmp1, 1, 3, 5, 7); - - // This is a true transposition, but it will lead to an incorrect result - - //tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); - //tmp2 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); - //row0 = SIMD.float32x4.shuffle(tmp1, tmp2, 0, 2, 4, 6); - //row1 = SIMD.float32x4.shuffle(tmp1, tmp2, 1, 3, 5, 7); - - //tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); - //tmp2 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); - //row2 = SIMD.float32x4.shuffle(tmp1, tmp2, 0, 2, 4, 6); - //row3 = SIMD.float32x4.shuffle(tmp1, tmp2, 1, 3, 5, 7); - - // ---- - tmp1 = SIMD.float32x4.mul(row2, row3); - tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 - minor0 = SIMD.float32x4.mul(row1, tmp1); - minor1 = SIMD.float32x4.mul(row0, tmp1); - tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 - minor0 = SIMD.float32x4.sub(SIMD.float32x4.mul(row1, tmp1), minor0); - minor1 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor1); - minor1 = SIMD.float32x4.swizzle(minor1, 2, 3, 0, 1); // 0x4E = 01001110 - - // ---- - tmp1 = SIMD.float32x4.mul(row1, row2); - tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 - minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor0); - minor3 = SIMD.float32x4.mul(row0, tmp1); - tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 - minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row3, tmp1)); - minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor3); - minor3 = SIMD.float32x4.swizzle(minor3, 2, 3, 0, 1); // 0x4E = 01001110 - - // ---- - tmp1 = SIMD.float32x4.mul(SIMD.float32x4.swizzle(row1, 2, 3, 0, 1), row3); // 0x4E = 01001110 - tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 - row2 = SIMD.float32x4.swizzle(row2, 2, 3, 0, 1); // 0x4E = 01001110 - minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor0); - minor2 = SIMD.float32x4.mul(row0, tmp1); - tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 - minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row2, tmp1)); - minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor2); - minor2 = SIMD.float32x4.swizzle(minor2, 2, 3, 0, 1); // 0x4E = 01001110 - - // ---- - tmp1 = SIMD.float32x4.mul(row0, row1); - tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 - minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor2); - minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row2, tmp1), minor3); - tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 - minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row3, tmp1), minor2); - minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row2, tmp1)); - - // ---- - tmp1 = SIMD.float32x4.mul(row0, row3); - tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 - minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row2, tmp1)); - minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor2); - tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 - minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor1); - minor2 = SIMD.float32x4.sub(minor2, SIMD.float32x4.mul(row1, tmp1)); - - // ---- - tmp1 = SIMD.float32x4.mul(row0, row2); - tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 - minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor1); - minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row1, tmp1)); - tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 - minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row3, tmp1)); - minor3 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor3); - - // Compute determinant - det = SIMD.float32x4.mul(row0, minor0); - det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 2, 3, 0, 1), det); // 0x4E = 01001110 - det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 1, 0, 3, 2), det); // 0xB1 = 10110001 - tmp1 = SIMD.float32x4.reciprocalApproximation(det); - det = SIMD.float32x4.sub(SIMD.float32x4.add(tmp1, tmp1), SIMD.float32x4.mul(det, SIMD.float32x4.mul(tmp1, tmp1))); - det = SIMD.float32x4.swizzle(det, 0, 0, 0, 0); - - // These shuffles aren't necessary if the faulty transposition is done - // up at the top of this function. - //minor0 = SIMD.float32x4.swizzle(minor0, 2, 1, 0, 3); - //minor1 = SIMD.float32x4.swizzle(minor1, 2, 1, 0, 3); - //minor2 = SIMD.float32x4.swizzle(minor2, 2, 1, 0, 3); - //minor3 = SIMD.float32x4.swizzle(minor3, 2, 1, 0, 3); - - // Compute final values by multiplying with 1/det - minor0 = SIMD.float32x4.mul(det, minor0); - minor1 = SIMD.float32x4.mul(det, minor1); - minor2 = SIMD.float32x4.mul(det, minor2); - minor3 = SIMD.float32x4.mul(det, minor3); - - SIMD.float32x4.store(dest, 0, minor0); - SIMD.float32x4.store(dest, 4, minor1); - SIMD.float32x4.store(dest, 8, minor2); - SIMD.float32x4.store(dest, 12, minor3); - - return inv; - }; /** * Returns true if current matrix is an identity matrix, false otherwise @@ -343,33 +211,6 @@ && mat[12] === 0 && mat[13] === 0 && mat[14] === 0 && mat[15] === 1); }; - proto.isIdentitySIMD = function () { - var inx4 = SIMD.float32x4.load(this.mat, 0); - var identityx4 = SIMD.float32x4.load(identityMatrix.mat, 0); - var ret = SIMD.float32x4.equal(inx4, identityx4); - if(ret.signMask === 0x00) - return false; - - inx4 = SIMD.float32x4.load(this.mat, 4); - identityx4 = SIMD.float32x4.load(identityMatrix.mat, 4); - ret = SIMD.float32x4.equal(inx4, identityx4); - if(ret.signMask === 0x00) - return false; - - inx4 = SIMD.float32x4.load(this.mat, 8); - identityx4 = SIMD.float32x4.load(identityMatrix.mat, 8); - ret = SIMD.float32x4.equal(inx4, identityx4); - if(ret.signMask === 0x00) - return false; - - inx4 = SIMD.float32x4.load(this.mat, 12); - identityx4 = SIMD.float32x4.load(identityMatrix.mat, 12); - ret = SIMD.float32x4.equal(inx4, identityx4); - if(ret.signMask === 0x00) - return false; - return true; - }; - /** * transpose the current matrix */ @@ -397,36 +238,6 @@ return this; }; - proto.transposeSIMD = function () { - var outArr = this.mat, inArr = this.mat; - var src0 = SIMD.float32x4.load(inArr, 0); - var src1 = SIMD.float32x4.load(inArr, 4); - var src2 = SIMD.float32x4.load(inArr, 8); - var src3 = SIMD.float32x4.load(inArr, 12); - var dst0; - var dst1; - var dst2; - var dst3; - var tmp01; - var tmp23; - - tmp01 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); - tmp23 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); - dst0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); - dst1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); - - tmp01 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); - tmp23 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); - dst2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); - dst3 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); - - SIMD.float32x4.store(outArr, 0, dst0); - SIMD.float32x4.store(outArr, 4, dst1); - SIMD.float32x4.store(outArr, 8, dst2); - SIMD.float32x4.store(outArr, 12, dst3); - return this; - }; - /** * Multiplies pM1 with pM2, stores the result in pOut, returns pOut */ @@ -462,11 +273,6 @@ return pOut; }; - cc.kmMat4MultiplySIMD = function (pOut, pM1, pM2) { - pOut = new cc.math.Matrix4(pM1); - return pOut.multiplySIMD(pM2); - }; - /** * current matrix multiplies with other matrix mat4 * @param {cc.math.Matrix4} mat4 @@ -504,55 +310,6 @@ return this; }; - proto.multiplySIMD = function(mat4) { - var a = this.mat; - var b = mat4.mat; - var out = this.mat; - - var a0 = SIMD.float32x4.load(a,0); - var a1 = SIMD.float32x4.load(a,4); - var a2 = SIMD.float32x4.load(a,8); - var a3 = SIMD.float32x4.load(a,12); - var b0 = SIMD.float32x4.load(b, 0); - SIMD.float32x4.store(out, 0, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3))))); - var b1 = SIMD.float32x4.load(b, 4); - SIMD.float32x4.store(out, 4, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3))))); - var b2 = SIMD.float32x4.load(b, 8); - SIMD.float32x4.store(out, 8, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3))))); - var b3 = SIMD.float32x4.load(b, 12); - SIMD.float32x4.store(out, 12, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3))))); - - return this; - }; - cc.getMat4MultiplyValue = function (pM1, pM2) { var m1 = pM1.mat, m2 = pM2.mat; var mat = new Float32Array(16); @@ -580,11 +337,6 @@ return mat; }; - cc.getMat4MultiplyValueSIMD = function (pM1, pM2) { - var mat = new cc.math.Matrix4(pM1); - return mat.multiplySIMD(pM2); - }; - /** * Assigns the value of pIn to pOut */ @@ -619,15 +371,6 @@ return pOut; }; - cc.kmMat4AssignSIMD = function (pOut, pIn) { - if(pOut == pIn) { - cc.log("cc.kmMat4Assign(): pOut equals pIn");//TODO: ADD SIMD? - return pOut; - } - - return pOut.assignFromSIMD(pIn); - }; - /** * Assigns the value of current matrix from mat4 * @param {cc.math.Matrix4} mat4 @@ -662,23 +405,6 @@ return this; }; - proto.assignFromSIMD = function (mat4) { - if(this == mat4) { - cc.log("cc.mat.Matrix4.assignFrom(): mat4 equals current matrix");//TODO: ADD SIMD? - return this; - } - - var outArr = this.mat; - var inArr = mat4.mat; - - SIMD.float32x4.store(outArr, 0, SIMD.float32x4.load(inArr, 0)); - SIMD.float32x4.store(outArr, 4, SIMD.float32x4.load(inArr, 4)); - SIMD.float32x4.store(outArr, 8, SIMD.float32x4.load(inArr, 8)); - SIMD.float32x4.store(outArr, 12, SIMD.float32x4.load(inArr, 12)); - - return this; - }; - /** * Returns true if current matrix equal mat4 (approximately) * @param {cc.math.Matrix4} mat4 @@ -697,40 +423,6 @@ return true; }; - proto.equalsSIMD = function (mat4) { - if(this === mat4){ - cc.log("cc.kmMat4AreEqual(): pMat1 and pMat2 are same object."); - return true; - } - var m10 = SIMD.float32x4.load(this.mat, 0); - var m20 = SIMD.float32x4.load(mat4.mat, 0); - - var epsilon = SIMD.float32x4.splat(cc.math.EPSILON); - - var ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m10, m20)), epsilon); - if (ret.signMask === 0) - return false; - - var m11 = SIMD.float32x4.load(this.mat, 4); - var m21 = SIMD.float32x4.load(mat4.mat, 4); - ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m11, m21)), epsilon); - if (ret.signMask === 0) - return false; - - var m12 = SIMD.float32x4.load(this.mat, 8); - var m22 = SIMD.float32x4.load(mat4.mat, 8); - ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m12, m22)), epsilon); - if (ret.signMask === 0) - return false; - - var m13 = SIMD.float32x4.load(this.mat, 12); - var m23 = SIMD.float32x4.load(mat4.mat, 12); - ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m13, m23)), epsilon); - if (ret.signMask === 0) - return false; - return true; - }; - /** * Builds an X-axis rotation matrix and stores it in matrix, returns matrix, if matrix is null, create a new matrix * @param {Number} radians @@ -1133,10 +825,6 @@ return pOut; }; - cc.kmMat4LookAtSIMD = function (pOut, pEye, pCenter, pUp) { - return pOut.lookAtSIMD(pEye, pCenter, pUp); - }; - var tempMatrix = new cc.math.Matrix4(); // an internal matrix proto.lookAt = function(eyeVec, centerVec, upVec) { var f = new cc.math.Vec3(centerVec), up = new cc.math.Vec3(upVec), mat = this.mat; @@ -1170,107 +858,6 @@ return this; }; - proto.lookAtSIMD = function(eyeVec, centerVec, upVec) { - var out = this.mat; - - var center = SIMD.float32x4(centerVec.x, centerVec.y, centerVec.z, 0.0); - var eye = SIMD.float32x4(eyeVec.x, eyeVec.y, eyeVec.z, 0.0); - var up = SIMD.float32x4(upVec.x, upVec.y, upVec.z, 0.0); - - // cc.kmVec3Subtract(f, pCenter, pEye); - var f = SIMD.float32x4.sub(center, eye); - // cc.kmVec3Normalize(f, f); - var tmp = SIMD.float32x4.mul(f, f); - tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); - f = SIMD.float32x4.mul(f, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); - - // cc.kmVec3Assign(up, pUp); - // cc.kmVec3Normalize(up, up); - tmp = SIMD.float32x4.mul(up, up); - tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); - up = SIMD.float32x4.mul(up, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); - - // cc.kmVec3Cross(s, f, up); - var s = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 1, 2, 0, 3), SIMD.float32x4.swizzle(up, 2, 0, 1, 3)), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 2, 0, 1, 3), SIMD.float32x4.swizzle(up, 1, 2, 0, 3))); - // cc.kmVec3Normalize(s, s); - tmp = SIMD.float32x4.mul(s, s); - tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); - s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); - - // cc.kmVec3Cross(u, s, f); - var u = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 1, 2, 0, 3), SIMD.float32x4.swizzle(f, 2, 0, 1, 3)), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 2, 0, 1, 3), SIMD.float32x4.swizzle(f, 1, 2, 0, 3))); - // cc.kmVec3Normalize(s, s); - tmp = SIMD.float32x4.mul(s, s); - tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); - s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); - - //cc.kmMat4Identity(pOut); - //pOut.mat[0] = s.x; - //pOut.mat[4] = s.y; - //pOut.mat[8] = s.z; - //pOut.mat[1] = u.x; - //pOut.mat[5] = u.y; - //pOut.mat[9] = u.z; - //pOut.mat[2] = -f.x; - //pOut.mat[6] = -f.y; - //pOut.mat[10] = -f.z; - var zero = SIMD.float32x4.splat(0.0); - f = SIMD.float32x4.neg(f); - var tmp01 = SIMD.float32x4.shuffle(s, u, 0, 1, 4, 5); - var tmp23 = SIMD.float32x4.shuffle(f, zero, 0, 1, 4, 5); - var a0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); - var a1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); - - var tmp01 = SIMD.float32x4.shuffle(s, u, 2, 3, 6, 7); - var tmp23 = SIMD.float32x4.shuffle(f, zero, 2, 3, 6, 7); - var a2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); - var a3 = SIMD.float32x4(0.0, 0.0, 0.0, 1.0); - - // cc.kmMat4Translation(translate, -pEye.x, -pEye.y, -pEye.z); - var b0 = SIMD.float32x4(1.0, 0.0, 0.0, 0.0); - var b1 = SIMD.float32x4(0.0, 1.0, 0.0, 0.0); - var b2 = SIMD.float32x4(0.0, 0.0, 1.0, 0.0); - var b3 = SIMD.float32x4.neg(eye); - b3 = SIMD.float32x4.withW(b3, 1.0); - - // cc.kmMat4Multiply(pOut, pOut, translate); - SIMD.float32x4.store(out, 0, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3))))); - SIMD.float32x4.store(out, 4, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3))))); - SIMD.float32x4.store(out, 8, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3))))); - SIMD.float32x4.store(out, 12, SIMD.float32x4.add( - SIMD.float32x4.mul( - SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1), - SIMD.float32x4.add( - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2), - SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3))))); - return this; - }; - /** * Build a rotation matrix from an axis and an angle. Result is stored in pOut. * pOut is returned. @@ -1420,17 +1007,6 @@ var temp = cc.math.Quaternion.rotationMatrix(rotation); return temp.toAxisAndAngle(); }; - - if(typeof(SIMD) !== 'undefined' && cc.sys.doNotUseSIMD !== true) { - proto.inverse = proto.inverseSIMD; - proto.isIdentity = proto.isIdentitySIMD; - proto.transpose = proto.transposeSIMD; - proto.multiply = proto.multiplySIMD; - proto.getMat4MultiplyValue = proto.getMat4MultiplyValueSIMD; - proto.assignFrom = proto.assignFromSIMD; - proto.equals = proto.equalsSIMD; - proto.lookAt = proto.lookAtSIMD; - } })(cc); diff --git a/cocos2d/kazmath/mat4SIMD.js b/cocos2d/kazmath/mat4SIMD.js new file mode 100644 index 0000000000..f716de796b --- /dev/null +++ b/cocos2d/kazmath/mat4SIMD.js @@ -0,0 +1,428 @@ +/** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + Copyright (c) 2008, Luke Benstead. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +(function(cc) { + var proto = cc.math.Matrix4.prototype; + + cc.kmMat4InverseSIMD = function (pOut, pM) { + pOut = pM.inverseSIMD(); + return pOut; + }; + + proto.inverseSIMD = function(){ + var inv = new cc.math.Matrix4(); + var src = this.mat; + var dest = inv.mat; + var src0, src1, src2, src3; + var row0, row1, row2, row3; + var tmp1; + var minor0, minor1, minor2, minor3; + var det; + + // Load the 4 rows + var src0 = SIMD.float32x4.load(src, 0); + var src1 = SIMD.float32x4.load(src, 4); + var src2 = SIMD.float32x4.load(src, 8); + var src3 = SIMD.float32x4.load(src, 12); + + // Transpose the source matrix. Sort of. Not a true transpose operation + + tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); + row1 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); + row0 = SIMD.float32x4.shuffle(tmp1, row1, 0, 2, 4, 6); + row1 = SIMD.float32x4.shuffle(row1, tmp1, 1, 3, 5, 7); + + tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); + row3 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); + row2 = SIMD.float32x4.shuffle(tmp1, row3, 0, 2, 4, 6); + row3 = SIMD.float32x4.shuffle(row3, tmp1, 1, 3, 5, 7); + + // ---- + tmp1 = SIMD.float32x4.mul(row2, row3); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor0 = SIMD.float32x4.mul(row1, tmp1); + minor1 = SIMD.float32x4.mul(row0, tmp1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.sub(SIMD.float32x4.mul(row1, tmp1), minor0); + minor1 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor1); + minor1 = SIMD.float32x4.swizzle(minor1, 2, 3, 0, 1); // 0x4E = 01001110 + + // ---- + tmp1 = SIMD.float32x4.mul(row1, row2); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor0); + minor3 = SIMD.float32x4.mul(row0, tmp1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row3, tmp1)); + minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor3); + minor3 = SIMD.float32x4.swizzle(minor3, 2, 3, 0, 1); // 0x4E = 01001110 + + // ---- + tmp1 = SIMD.float32x4.mul(SIMD.float32x4.swizzle(row1, 2, 3, 0, 1), row3); // 0x4E = 01001110 + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + row2 = SIMD.float32x4.swizzle(row2, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor0); + minor2 = SIMD.float32x4.mul(row0, tmp1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row2, tmp1)); + minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor2); + minor2 = SIMD.float32x4.swizzle(minor2, 2, 3, 0, 1); // 0x4E = 01001110 + + // ---- + tmp1 = SIMD.float32x4.mul(row0, row1); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row2, tmp1), minor3); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row3, tmp1), minor2); + minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row2, tmp1)); + + // ---- + tmp1 = SIMD.float32x4.mul(row0, row3); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row2, tmp1)); + minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor2); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor1); + minor2 = SIMD.float32x4.sub(minor2, SIMD.float32x4.mul(row1, tmp1)); + + // ---- + tmp1 = SIMD.float32x4.mul(row0, row2); + tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001 + minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor1); + minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row1, tmp1)); + tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110 + minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row3, tmp1)); + minor3 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor3); + + // Compute determinant + det = SIMD.float32x4.mul(row0, minor0); + det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 2, 3, 0, 1), det); // 0x4E = 01001110 + det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 1, 0, 3, 2), det); // 0xB1 = 10110001 + tmp1 = SIMD.float32x4.reciprocalApproximation(det); + det = SIMD.float32x4.sub(SIMD.float32x4.add(tmp1, tmp1), SIMD.float32x4.mul(det, SIMD.float32x4.mul(tmp1, tmp1))); + det = SIMD.float32x4.swizzle(det, 0, 0, 0, 0); + + // Compute final values by multiplying with 1/det + minor0 = SIMD.float32x4.mul(det, minor0); + minor1 = SIMD.float32x4.mul(det, minor1); + minor2 = SIMD.float32x4.mul(det, minor2); + minor3 = SIMD.float32x4.mul(det, minor3); + + SIMD.float32x4.store(dest, 0, minor0); + SIMD.float32x4.store(dest, 4, minor1); + SIMD.float32x4.store(dest, 8, minor2); + SIMD.float32x4.store(dest, 12, minor3); + + return inv; + }; + + var identityMatrix = new cc.math.Matrix4().identity(); + proto.isIdentitySIMD = function () { + var inx4 = SIMD.float32x4.load(this.mat, 0); + var identityx4 = SIMD.float32x4.load(identityMatrix.mat, 0); + var ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + + inx4 = SIMD.float32x4.load(this.mat, 4); + identityx4 = SIMD.float32x4.load(identityMatrix.mat, 4); + ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + + inx4 = SIMD.float32x4.load(this.mat, 8); + identityx4 = SIMD.float32x4.load(identityMatrix.mat, 8); + ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + + inx4 = SIMD.float32x4.load(this.mat, 12); + identityx4 = SIMD.float32x4.load(identityMatrix.mat, 12); + ret = SIMD.float32x4.equal(inx4, identityx4); + if(ret.signMask === 0x00) + return false; + return true; + }; + + proto.transposeSIMD = function () { + var outArr = this.mat, inArr = this.mat; + var src0 = SIMD.float32x4.load(inArr, 0); + var src1 = SIMD.float32x4.load(inArr, 4); + var src2 = SIMD.float32x4.load(inArr, 8); + var src3 = SIMD.float32x4.load(inArr, 12); + var dst0; + var dst1; + var dst2; + var dst3; + var tmp01; + var tmp23; + + tmp01 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5); + tmp23 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5); + dst0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + dst1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + + tmp01 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7); + tmp23 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7); + dst2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + dst3 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + + SIMD.float32x4.store(outArr, 0, dst0); + SIMD.float32x4.store(outArr, 4, dst1); + SIMD.float32x4.store(outArr, 8, dst2); + SIMD.float32x4.store(outArr, 12, dst3); + return this; + }; + + cc.kmMat4MultiplySIMD = function (pOut, pM1, pM2) { + pOut = new cc.math.Matrix4(pM1); + return pOut.multiplySIMD(pM2); + }; + + proto.multiplySIMD = function(mat4) { + var a = this.mat; + var b = mat4.mat; + var out = this.mat; + + var a0 = SIMD.float32x4.load(a,0); + var a1 = SIMD.float32x4.load(a,4); + var a2 = SIMD.float32x4.load(a,8); + var a3 = SIMD.float32x4.load(a,12); + var b0 = SIMD.float32x4.load(b, 0); + SIMD.float32x4.store(out, 0, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3))))); + var b1 = SIMD.float32x4.load(b, 4); + SIMD.float32x4.store(out, 4, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3))))); + var b2 = SIMD.float32x4.load(b, 8); + SIMD.float32x4.store(out, 8, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3))))); + var b3 = SIMD.float32x4.load(b, 12); + SIMD.float32x4.store(out, 12, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3))))); + + return this; + }; + + cc.getMat4MultiplyValueSIMD = function (pM1, pM2) { + var mat = new cc.math.Matrix4(pM1); + return mat.multiplySIMD(pM2); + }; + + cc.kmMat4AssignSIMD = function (pOut, pIn) { + if(pOut == pIn) { + cc.log("cc.kmMat4Assign(): pOut equals pIn");//TODO: ADD SIMD? + return pOut; + } + + return pOut.assignFromSIMD(pIn); + }; + + proto.assignFromSIMD = function (mat4) { + if(this == mat4) { + cc.log("cc.mat.Matrix4.assignFrom(): mat4 equals current matrix");//TODO: ADD SIMD? + return this; + } + + var outArr = this.mat; + var inArr = mat4.mat; + + SIMD.float32x4.store(outArr, 0, SIMD.float32x4.load(inArr, 0)); + SIMD.float32x4.store(outArr, 4, SIMD.float32x4.load(inArr, 4)); + SIMD.float32x4.store(outArr, 8, SIMD.float32x4.load(inArr, 8)); + SIMD.float32x4.store(outArr, 12, SIMD.float32x4.load(inArr, 12)); + + return this; + }; + + proto.equalsSIMD = function (mat4) { + if(this === mat4){ + cc.log("cc.kmMat4AreEqual(): pMat1 and pMat2 are same object."); + return true; + } + var m10 = SIMD.float32x4.load(this.mat, 0); + var m20 = SIMD.float32x4.load(mat4.mat, 0); + + var epsilon = SIMD.float32x4.splat(cc.math.EPSILON); + + var ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m10, m20)), epsilon); + if (ret.signMask === 0) + return false; + + var m11 = SIMD.float32x4.load(this.mat, 4); + var m21 = SIMD.float32x4.load(mat4.mat, 4); + ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m11, m21)), epsilon); + if (ret.signMask === 0) + return false; + + var m12 = SIMD.float32x4.load(this.mat, 8); + var m22 = SIMD.float32x4.load(mat4.mat, 8); + ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m12, m22)), epsilon); + if (ret.signMask === 0) + return false; + + var m13 = SIMD.float32x4.load(this.mat, 12); + var m23 = SIMD.float32x4.load(mat4.mat, 12); + ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m13, m23)), epsilon); + if (ret.signMask === 0) + return false; + return true; + }; + + cc.kmMat4LookAtSIMD = function (pOut, pEye, pCenter, pUp) { + return pOut.lookAtSIMD(pEye, pCenter, pUp); + }; + + proto.lookAtSIMD = function(eyeVec, centerVec, upVec) { + var out = this.mat; + + var center = SIMD.float32x4(centerVec.x, centerVec.y, centerVec.z, 0.0); + var eye = SIMD.float32x4(eyeVec.x, eyeVec.y, eyeVec.z, 0.0); + var up = SIMD.float32x4(upVec.x, upVec.y, upVec.z, 0.0); + + // cc.kmVec3Subtract(f, pCenter, pEye); + var f = SIMD.float32x4.sub(center, eye); + // cc.kmVec3Normalize(f, f); + var tmp = SIMD.float32x4.mul(f, f); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + f = SIMD.float32x4.mul(f, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + // cc.kmVec3Assign(up, pUp); + // cc.kmVec3Normalize(up, up); + tmp = SIMD.float32x4.mul(up, up); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + up = SIMD.float32x4.mul(up, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + // cc.kmVec3Cross(s, f, up); + var s = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 1, 2, 0, 3), SIMD.float32x4.swizzle(up, 2, 0, 1, 3)), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 2, 0, 1, 3), SIMD.float32x4.swizzle(up, 1, 2, 0, 3))); + // cc.kmVec3Normalize(s, s); + tmp = SIMD.float32x4.mul(s, s); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + // cc.kmVec3Cross(u, s, f); + var u = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 1, 2, 0, 3), SIMD.float32x4.swizzle(f, 2, 0, 1, 3)), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 2, 0, 1, 3), SIMD.float32x4.swizzle(f, 1, 2, 0, 3))); + // cc.kmVec3Normalize(s, s); + tmp = SIMD.float32x4.mul(s, s); + tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3))); + s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp)); + + //cc.kmMat4Identity(pOut); + //pOut.mat[0] = s.x; + //pOut.mat[4] = s.y; + //pOut.mat[8] = s.z; + //pOut.mat[1] = u.x; + //pOut.mat[5] = u.y; + //pOut.mat[9] = u.z; + //pOut.mat[2] = -f.x; + //pOut.mat[6] = -f.y; + //pOut.mat[10] = -f.z; + var zero = SIMD.float32x4.splat(0.0); + f = SIMD.float32x4.neg(f); + var tmp01 = SIMD.float32x4.shuffle(s, u, 0, 1, 4, 5); + var tmp23 = SIMD.float32x4.shuffle(f, zero, 0, 1, 4, 5); + var a0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + var a1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7); + + var tmp01 = SIMD.float32x4.shuffle(s, u, 2, 3, 6, 7); + var tmp23 = SIMD.float32x4.shuffle(f, zero, 2, 3, 6, 7); + var a2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6); + var a3 = SIMD.float32x4(0.0, 0.0, 0.0, 1.0); + + // cc.kmMat4Translation(translate, -pEye.x, -pEye.y, -pEye.z); + var b0 = SIMD.float32x4(1.0, 0.0, 0.0, 0.0); + var b1 = SIMD.float32x4(0.0, 1.0, 0.0, 0.0); + var b2 = SIMD.float32x4(0.0, 0.0, 1.0, 0.0); + var b3 = SIMD.float32x4.neg(eye); + b3 = SIMD.float32x4.withW(b3, 1.0); + + // cc.kmMat4Multiply(pOut, pOut, translate); + SIMD.float32x4.store(out, 0, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3))))); + SIMD.float32x4.store(out, 4, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3))))); + SIMD.float32x4.store(out, 8, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3))))); + SIMD.float32x4.store(out, 12, SIMD.float32x4.add( + SIMD.float32x4.mul( + SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1), + SIMD.float32x4.add( + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2), + SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3))))); + return this; + }; + + +})(cc); diff --git a/cocos2d/kazmath/vec3.js b/cocos2d/kazmath/vec3.js index eb6264a6f6..282b34aaae 100644 --- a/cocos2d/kazmath/vec3.js +++ b/cocos2d/kazmath/vec3.js @@ -136,26 +136,6 @@ return this; }; - proto.transformCoordSIMD = function(mat4){ - var vec = SIMD.float32x4(this.x, this.y, this.z, 0.0); - var mat0 = SIMD.float32x4.load(mat4.mat, 0); - var mat1 = SIMD.float32x4.load(mat4.mat, 4); - var mat2 = SIMD.float32x4.load(mat4.mat, 8); - var mat3 = SIMD.float32x4.load(mat4.mat, 12); - - //cc.kmVec4Transform(v, inV,pM); - var out = SIMD.float32x4.add( - SIMD.float32x4.add(SIMD.float32x4.mul(mat0, SIMD.float32x4.swizzle(vec, 0, 0, 0, 0)), - SIMD.float32x4.mul(mat1, SIMD.float32x4.swizzle(vec, 1, 1, 1, 1))), - SIMD.float32x4.add(SIMD.float32x4.mul(mat2, SIMD.float32x4.swizzle(vec, 2, 2, 2, 2)), - mat3)); - - out = SIMD.float32x4.div(out, SIMD.float32x4.swizzle(out, 3, 3, 3, 3)); - this.fill(out); - - return this; - }; - proto.scale = function(scale){ // = cc.kmVec3Scale this.x *= scale; this.y *= scale; @@ -208,10 +188,6 @@ tyArr[2] = this.z; return tyArr; }; - - if(typeof(SIMD) !== 'undefined' && cc.sys.doNotUseSIMD !== true) { - proto.transformCoord = proto.transformCoordSIMD; - } })(cc); diff --git a/cocos2d/kazmath/vec3SIMD.js b/cocos2d/kazmath/vec3SIMD.js new file mode 100644 index 0000000000..0bf4ff4b87 --- /dev/null +++ b/cocos2d/kazmath/vec3SIMD.js @@ -0,0 +1,51 @@ +/** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011-2012 cocos2d-x.org + Copyright (c) 2013-2014 Chukong Technologies Inc. + Copyright (c) 2008, Luke Benstead. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + (function(cc) { + var proto = cc.math.Vec3.prototype; + + proto.transformCoordSIMD = function(mat4){ + var vec = SIMD.float32x4(this.x, this.y, this.z, 0.0); + var mat0 = SIMD.float32x4.load(mat4.mat, 0); + var mat1 = SIMD.float32x4.load(mat4.mat, 4); + var mat2 = SIMD.float32x4.load(mat4.mat, 8); + var mat3 = SIMD.float32x4.load(mat4.mat, 12); + + //cc.kmVec4Transform(v, inV,pM); + var out = SIMD.float32x4.add( + SIMD.float32x4.add(SIMD.float32x4.mul(mat0, SIMD.float32x4.swizzle(vec, 0, 0, 0, 0)), + SIMD.float32x4.mul(mat1, SIMD.float32x4.swizzle(vec, 1, 1, 1, 1))), + SIMD.float32x4.add(SIMD.float32x4.mul(mat2, SIMD.float32x4.swizzle(vec, 2, 2, 2, 2)), + mat3)); + + out = SIMD.float32x4.div(out, SIMD.float32x4.swizzle(out, 3, 3, 3, 3)); + this.fill(out); + + return this; + }; +})(cc); diff --git a/moduleConfig.json b/moduleConfig.json index a089e198d8..726b9105d8 100644 --- a/moduleConfig.json +++ b/moduleConfig.json @@ -144,6 +144,9 @@ "cocos2d/kazmath/plane.js", "cocos2d/kazmath/quaternion.js", "cocos2d/kazmath/aabb.js", + "cocos2d/kazmath/vec3SIMD.js", + "cocos2d/kazmath/mat4SIMD.js", + "cocos2d/kazmath/SIMDPolyfill.js", "cocos2d/kazmath/gl/mat4stack.js", "cocos2d/kazmath/gl/matrix.js" ], From 32ea37829ff3aa403628be539d350992cd5a318a Mon Sep 17 00:00:00 2001 From: Ningxin Hu Date: Fri, 15 May 2015 15:55:45 +0800 Subject: [PATCH 041/839] Update kazmath simd_benchmark accordingly --- cocos2d/kazmath/simd_benchmark/index.html | 6 +++--- cocos2d/kazmath/simd_benchmark/run.js | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cocos2d/kazmath/simd_benchmark/index.html b/cocos2d/kazmath/simd_benchmark/index.html index 19135bb2d6..5b115d91c9 100644 --- a/cocos2d/kazmath/simd_benchmark/index.html +++ b/cocos2d/kazmath/simd_benchmark/index.html @@ -19,14 +19,14 @@

+ + diff --git a/cocos2d/kazmath/simd_benchmark/run.js b/cocos2d/kazmath/simd_benchmark/run.js index 1a1b253bd4..8441ae1eda 100644 --- a/cocos2d/kazmath/simd_benchmark/run.js +++ b/cocos2d/kazmath/simd_benchmark/run.js @@ -8,6 +8,8 @@ load ('../utility.js'); load ('../vec3.js'); load ('../vec4.js'); load ('../mat4.js'); +load ('../vec3SIMD.js'); +load ('../mat4SIMD.js'); // load individual benchmarks load ('kernel-template.js'); From b9e38ad88f99b8aa2a2e72e850a88391d18c2ead Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 15 May 2015 16:02:39 +0800 Subject: [PATCH 042/839] Add notes --- extensions/ccui/uiwidgets/UIWebView.js | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIWebView.js b/extensions/ccui/uiwidgets/UIWebView.js index e6ea298a44..684c7f5fe1 100644 --- a/extensions/ccui/uiwidgets/UIWebView.js +++ b/extensions/ccui/uiwidgets/UIWebView.js @@ -52,6 +52,10 @@ ccui.WebView = ccui.Widget.extend({ stopLoading: function(){ cc.log("Web does not support loading"); }, + + /** + * Reload the WebView + */ reload: function(){ var iframe = this._renderCmd._iframe; if(iframe){ @@ -105,7 +109,7 @@ ccui.WebView = ccui.Widget.extend({ /** * In the webview execution within a period of js string - * @param str + * @param {String} str */ evaluateJS: function(str){ var iframe = this._renderCmd._iframe; @@ -128,24 +132,20 @@ ccui.WebView = ccui.Widget.extend({ /** * The binding event - * @param event string: load | loading | error Or: ccui.WebView.EventType - * @param callback + * @param {ccui.WebView.EventType} ccui.WebView.EventType + * @param {Function} callback */ addEventListener: function(event, callback){ - if(!/^ui_webview_/.test(event)) - event = "ui_webview_" + event; return cc.eventManager.addCustomListener(event, callback); }, /** * Delete events - * @param event - * @param callbackOrListener + * @param {ccui.WebView.EventType} event + * @param {Function|Listener} callbackOrListener */ removeEventListener: function(event, callbackOrListener){ var map, list; - if(!/^ui_webview_/.test(event)) - event = "ui_webview_" + event; if(typeof callbackOrListener === "function"){ map = cc.eventManager._listenersMap[event]; if(map){ @@ -175,6 +175,11 @@ ccui.WebView = ccui.Widget.extend({ return new ccui.WebView.RenderCmd(this); }, + /** + * Set the contentSize + * @param {Number} w + * @param {Number} h + */ setContentSize: function(w, h){ ccui.Widget.prototype.setContentSize.call(this, w, h); if(h === undefined){ @@ -184,6 +189,9 @@ ccui.WebView = ccui.Widget.extend({ this._renderCmd.changeSize(w, h); }, + /** + * remove node + */ cleanup: function(){ this._renderCmd.removeDom(); this.stopAllActions(); @@ -191,6 +199,10 @@ ccui.WebView = ccui.Widget.extend({ } }); +/** + * The WebView support list of events + * @type {{LOADING: string, LOADED: string, ERROR: string}} + */ ccui.WebView.EventType = { LOADING: "ui_webview_loading", LOADED: "ui_webview_load", From e3afcc11a35af5feed51418976076a92a5b35f6d Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 15 May 2015 16:12:09 +0800 Subject: [PATCH 043/839] Add notes and fix some small problems --- extensions/ccui/uiwidgets/UIVideoPlayer.js | 16 +++++++++------ extensions/ccui/uiwidgets/UIWebView.js | 24 ++++++++-------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index 3fdbcef822..f3e6cca5f3 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -202,6 +202,10 @@ ccui.VideoPlayer = ccui.Widget.extend({ }); +/** + * The VideoPlayer support list of events + * @type {{PLAYING: string, PAUSED: string, STOPPED: string, COMPLETED: string}} + */ ccui.VideoPlayer.EventType = { PLAYING: "ui_video_play", PAUSED: "ui_video_pause", @@ -215,7 +219,7 @@ ccui.VideoPlayer.EventType = { * @devicePixelRatio Whether you need to consider devicePixelRatio calculated position * @event To get the data using events */ - video.polyfill = { + video._polyfill = { devicePixelRatio: false, event: "canplay", canPlayType: [] @@ -224,14 +228,14 @@ ccui.VideoPlayer.EventType = { (function(){ var dom = document.createElement("video"); if(dom.canPlayType("video/ogg")) - video.polyfill.canPlayType.push(".ogg"); + video._polyfill.canPlayType.push(".ogg"); if(dom.canPlayType("video/mp4")) - video.polyfill.canPlayType.push(".mp4"); + video._polyfill.canPlayType.push(".mp4"); })(); if(cc.sys.OS_IOS === cc.sys.os){ - video.polyfill.devicePixelRatio = true; - video.polyfill.event = "progress"; + video._polyfill.devicePixelRatio = true; + video._polyfill.event = "progress"; } })(ccui.VideoPlayer); @@ -402,4 +406,4 @@ ccui.VideoPlayer.EventType = { } }; -})(ccui.VideoPlayer.polyfill); \ No newline at end of file +})(ccui.VideoPlayer._polyfill); \ No newline at end of file diff --git a/extensions/ccui/uiwidgets/UIWebView.js b/extensions/ccui/uiwidgets/UIWebView.js index 684c7f5fe1..83dd763efe 100644 --- a/extensions/ccui/uiwidgets/UIWebView.js +++ b/extensions/ccui/uiwidgets/UIWebView.js @@ -83,7 +83,7 @@ ccui.WebView = ccui.Widget.extend({ * go back */ goBack: function(){ - if(ccui.WebView.polyfill.closeHistory) + if(ccui.WebView._polyfill.closeHistory) return cc.log("The current browser does not support the GoBack"); var iframe = this._renderCmd._iframe; if(iframe){ @@ -97,7 +97,7 @@ ccui.WebView = ccui.Widget.extend({ * go forward */ goForward: function(){ - if(ccui.WebView.polyfill.closeHistory) + if(ccui.WebView._polyfill.closeHistory) return cc.log("The current browser does not support the GoForward"); var iframe = this._renderCmd._iframe; if(iframe){ @@ -116,6 +116,7 @@ ccui.WebView = ccui.Widget.extend({ if(iframe){ var win = iframe.contentWindow; try{ + cc.eventManager.dispatchCustomEvent(ccui.WebView.EventType.JS_EVALUATED); win.eval(str); }catch(err){ console.error(err); @@ -161,16 +162,6 @@ ccui.WebView = ccui.Widget.extend({ } }, - //setOnShouldStartLoading: function(callback){}, - //setOnDidFinishLoading: function(){}, - //setOnDidFailLoading: function(){}, - //setOnJSCallback: function(){}, - - //getOnShouldStartLoading: function(){}, - //getOnDidFinishLoading: function(){}, - //getOnDidFailLoading: function(){}, - //getOnJSCallback: function(){}, - _createRenderCmd: function(){ return new ccui.WebView.RenderCmd(this); }, @@ -206,18 +197,19 @@ ccui.WebView = ccui.Widget.extend({ ccui.WebView.EventType = { LOADING: "ui_webview_loading", LOADED: "ui_webview_load", - ERROR: "ui_webview_error" + ERROR: "ui_webview_error", + JS_EVALUATED: "ui_webview_js" }; (function(){ - var polyfill = ccui.WebView.polyfill = { + var polyfill = ccui.WebView._polyfill = { devicePixelRatio: false, enableDiv: false }; if(cc.sys.os === cc.sys.OS_IOS) - ccui.WebView.polyfill.enableDiv = true; + polyfill.enableDiv = true; if(cc.sys.isMobile){ if(cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX){ @@ -383,4 +375,4 @@ ccui.WebView.EventType = { } }; -})(ccui.WebView.polyfill); \ No newline at end of file +})(ccui.WebView._polyfill); \ No newline at end of file From 00583391556044562fb058af50382e5a964b5acb Mon Sep 17 00:00:00 2001 From: Ningxin Hu Date: Fri, 15 May 2015 16:11:17 +0800 Subject: [PATCH 044/839] Add kazmathSIMD module --- moduleConfig.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/moduleConfig.json b/moduleConfig.json index 726b9105d8..bcc74e1973 100644 --- a/moduleConfig.json +++ b/moduleConfig.json @@ -144,12 +144,16 @@ "cocos2d/kazmath/plane.js", "cocos2d/kazmath/quaternion.js", "cocos2d/kazmath/aabb.js", - "cocos2d/kazmath/vec3SIMD.js", - "cocos2d/kazmath/mat4SIMD.js", - "cocos2d/kazmath/SIMDPolyfill.js", "cocos2d/kazmath/gl/mat4stack.js", "cocos2d/kazmath/gl/matrix.js" ], + "kazmathSIMD" : [ + "kazmath", + + "cocos2d/kazmath/vec3SIMD.js", + "cocos2d/kazmath/mat4SIMD.js", + "cocos2d/kazmath/SIMDPolyfill.js" + ], "labels" : [ "core", From 1e5a35a93c28a640e79bb342758a0b97d116281c Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 15 May 2015 16:14:43 +0800 Subject: [PATCH 045/839] Modify event trigger order --- extensions/ccui/uiwidgets/UIWebView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ccui/uiwidgets/UIWebView.js b/extensions/ccui/uiwidgets/UIWebView.js index 83dd763efe..3c912b48e8 100644 --- a/extensions/ccui/uiwidgets/UIWebView.js +++ b/extensions/ccui/uiwidgets/UIWebView.js @@ -116,8 +116,8 @@ ccui.WebView = ccui.Widget.extend({ if(iframe){ var win = iframe.contentWindow; try{ - cc.eventManager.dispatchCustomEvent(ccui.WebView.EventType.JS_EVALUATED); win.eval(str); + cc.eventManager.dispatchCustomEvent(ccui.WebView.EventType.JS_EVALUATED); }catch(err){ console.error(err); } From 1bcbf0618d2a43fcbe7ad167f1b554025c4ff858 Mon Sep 17 00:00:00 2001 From: John Jardine Date: Fri, 15 May 2015 09:41:07 -0400 Subject: [PATCH 046/839] Polygon Points property change for consistency between frameworks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes consistency issue by changing “polygonPoints” property to “points” for storage of polygon points in CCTMXXMLParser.js. This allows CCTMXXMLParser.js to behave the same as CCTMXXMLParser.cpp in the other framework. --- cocos2d/tilemap/CCTMXXMLParser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/tilemap/CCTMXXMLParser.js b/cocos2d/tilemap/CCTMXXMLParser.js index 63b295d0e7..7ba659e735 100644 --- a/cocos2d/tilemap/CCTMXXMLParser.js +++ b/cocos2d/tilemap/CCTMXXMLParser.js @@ -783,7 +783,7 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{ if(polygonProps && polygonProps.length > 0) { var selPgPointStr = polygonProps[0].getAttribute('points'); if(selPgPointStr) - objectProp["polygonPoints"] = this._parsePointsString(selPgPointStr); + objectProp["points"] = this._parsePointsString(selPgPointStr); } //polyline From 8f435454dacd616deb92c6e9eb1f837457e85dc5 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Mon, 18 May 2015 14:21:18 +0800 Subject: [PATCH 047/839] Too early to remove dirtyFlag --- extensions/ccui/layouts/UILayoutCanvasRenderCmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ccui/layouts/UILayoutCanvasRenderCmd.js b/extensions/ccui/layouts/UILayoutCanvasRenderCmd.js index d3861d2573..ed7f9950f9 100644 --- a/extensions/ccui/layouts/UILayoutCanvasRenderCmd.js +++ b/extensions/ccui/layouts/UILayoutCanvasRenderCmd.js @@ -133,7 +133,6 @@ this._clipElemType = node._stencil instanceof cc.Sprite; this._syncStatus(parentCmd); - this._dirtyFlag = 0; cc.renderer.pushRenderCommand(this._rendererSaveCmd); if (this._clipElemType) { @@ -171,6 +170,7 @@ locProtectChildren[j].visit(this); cc.renderer.pushRenderCommand(this._rendererRestoreCmd); } + this._dirtyFlag = 0; }; ccui.Layout.CanvasRenderCmd._getSharedCache = function () { From 8c72e4565963a89631f682b71206b38e6c0967c1 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Mon, 18 May 2015 18:35:03 +0800 Subject: [PATCH 048/839] Texture should inherit property --- cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js index dd08d36c00..37fc069f29 100644 --- a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js +++ b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js @@ -203,7 +203,10 @@ if (displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255) { if (this._colorized) { this._colorized = false; + var rect = cc.rect(node._rect.x, node._rect.y, node._rect.width, node._rect.height); + var isRotation = node._rectRotated; node.texture = this._originalTexture; + node.setTextureRect(rect, isRotation); } return; } From d8331b5a1e61b61682a451235296ee3165726bd5 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 19 May 2015 09:51:45 +0800 Subject: [PATCH 049/839] Texture should inherit property --- cocos2d/core/sprites/CCSprite.js | 2 ++ cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/sprites/CCSprite.js b/cocos2d/core/sprites/CCSprite.js index b6662b3455..65a240e65b 100644 --- a/cocos2d/core/sprites/CCSprite.js +++ b/cocos2d/core/sprites/CCSprite.js @@ -966,6 +966,8 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ _clearRect: function(){ var texture = this._texture; if(texture){ + if(texture._htmlElementObj instanceof HTMLCanvasElement) + return; var textureRect = texture._contentSize; var spriteRect = this._rect; if( diff --git a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js index 37fc069f29..dd08d36c00 100644 --- a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js +++ b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js @@ -203,10 +203,7 @@ if (displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255) { if (this._colorized) { this._colorized = false; - var rect = cc.rect(node._rect.x, node._rect.y, node._rect.width, node._rect.height); - var isRotation = node._rectRotated; node.texture = this._originalTexture; - node.setTextureRect(rect, isRotation); } return; } From 7c1dcd3301d5b332346ba00dd0f6eba9fa90b38c Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 19 May 2015 10:12:02 +0800 Subject: [PATCH 050/839] Revert "Texture should inherit property" This reverts commit d8331b5a1e61b61682a451235296ee3165726bd5. --- cocos2d/core/sprites/CCSprite.js | 2 -- cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/sprites/CCSprite.js b/cocos2d/core/sprites/CCSprite.js index 65a240e65b..b6662b3455 100644 --- a/cocos2d/core/sprites/CCSprite.js +++ b/cocos2d/core/sprites/CCSprite.js @@ -966,8 +966,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ _clearRect: function(){ var texture = this._texture; if(texture){ - if(texture._htmlElementObj instanceof HTMLCanvasElement) - return; var textureRect = texture._contentSize; var spriteRect = this._rect; if( diff --git a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js index dd08d36c00..37fc069f29 100644 --- a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js +++ b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js @@ -203,7 +203,10 @@ if (displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255) { if (this._colorized) { this._colorized = false; + var rect = cc.rect(node._rect.x, node._rect.y, node._rect.width, node._rect.height); + var isRotation = node._rectRotated; node.texture = this._originalTexture; + node.setTextureRect(rect, isRotation); } return; } From f4648d29c64adc77cf6d482c13c80b8212cb1fd1 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 19 May 2015 10:17:06 +0800 Subject: [PATCH 051/839] Optimize performance --- cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js index 37fc069f29..35b1fa82c9 100644 --- a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js +++ b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js @@ -203,9 +203,9 @@ if (displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255) { if (this._colorized) { this._colorized = false; - var rect = cc.rect(node._rect.x, node._rect.y, node._rect.width, node._rect.height); + var rect = cc.rect(node._rect); var isRotation = node._rectRotated; - node.texture = this._originalTexture; + node.setTexture(this._originalTexture); node.setTextureRect(rect, isRotation); } return; From 3c50924b035cbe5f71363b4da9efb15688de5deb Mon Sep 17 00:00:00 2001 From: Zachary Lester Date: Tue, 19 May 2015 01:30:57 -0700 Subject: [PATCH 052/839] Fix typo in AUTHORS.txt Altered sentence explaining how authors were ordered so as to fix its grammar and more clearly convey its meaning. --- AUTHORS.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index e61d18e5cb..f3ba252624 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -1,6 +1,6 @@ Cocos2d-html5 authors -(ordered by the join in time) +(Ordered by join time) Core Developers: From c1cf4c5230d2a4383763f10701867bdef385baa2 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 19 May 2015 17:11:39 +0800 Subject: [PATCH 053/839] PlayMusic should not increase the search path(timeline 2.x) --- extensions/cocostudio/loader/parsers/timelineParser-2.x.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js index e5644ccada..86496e99e1 100644 --- a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js +++ b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js @@ -1131,13 +1131,10 @@ var volume = json["Volume"] || 0; cc.audioEngine.setMusicVolume(volume); //var name = json["Name"]; - var resPath = ""; - if(cc.loader.resPath) - resPath = (cc.loader.resPath + "/").replace(/\/\/$/, "/"); loadTexture(json["FileData"], resourcePath, function(path, type){ cc.loader.load(path, function(){ - cc.audioEngine.playMusic(resPath + path, loop); + cc.audioEngine.playMusic(path, loop); }); }); From 127cb997341fd426c1b3c1abc38d44bac1f147f1 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 19 May 2015 17:46:50 +0800 Subject: [PATCH 054/839] Resource path error --- extensions/cocostudio/loader/parsers/compatible.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/cocostudio/loader/parsers/compatible.js b/extensions/cocostudio/loader/parsers/compatible.js index caa681d4fc..3f34b13956 100644 --- a/extensions/cocostudio/loader/parsers/compatible.js +++ b/extensions/cocostudio/loader/parsers/compatible.js @@ -41,7 +41,7 @@ * @returns {*} */ widgetFromJsonFile: function(file){ - var json = cc.loader.getRes(file); + var json = cc.loader.getRes(cc.path.join(cc.loader.resPath, file)); if(json) this._fileDesignSizes[file] = cc.size(json["designWidth"]||0, json["designHeight"]||0); From 240679b074ac421c68ecddde2bfbc89e4c6a0134 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 20 May 2015 15:36:53 +0800 Subject: [PATCH 055/839] Premultiply texture's alpha for png by default to fix Cocos Studio render issues --- cocos2d/core/platform/CCLoaders.js | 2 +- cocos2d/core/textures/TexturesWebGL.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/platform/CCLoaders.js b/cocos2d/core/platform/CCLoaders.js index 541e3b91c5..e27536d7c3 100644 --- a/cocos2d/core/platform/CCLoaders.js +++ b/cocos2d/core/platform/CCLoaders.js @@ -54,7 +54,7 @@ cc._imgLoader = { }); } }; -cc.loader.register(["png", "jpg", "bmp","jpeg","gif", "ico"], cc._imgLoader); +cc.loader.register(["png", "jpg", "bmp","jpeg","gif", "ico", "tiff"], cc._imgLoader); cc._serverImgLoader = { load : function(realUrl, url, res, cb){ cc.loader.cache[url] = cc.loader.loadImg(res.src, function(err, img){ diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index c2dc3b3683..2b4f0260e4 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -845,17 +845,23 @@ cc._tmp.WebGLTextureCache = function () { var _p = cc.textureCache; _p.handleLoadedTexture = function (url) { - var locTexs = this._textures; + var locTexs = this._textures, tex, ext; //remove judge(webgl) if (!cc._rendererInitialized) { locTexs = this._loadedTexturesBefore; } - var tex = locTexs[url]; + tex = locTexs[url]; if (!tex) { tex = locTexs[url] = new cc.Texture2D(); tex.url = url; } - tex.handleLoadedTexture(); + ext = cc.path.extname(url); + if (ext === ".png") { + tex.handleLoadedTexture(true); + } + else { + tex.handleLoadedTexture(); + } }; /** From 42ba88358cb80e44b32fa4e264d3fc7e1bef4cd8 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 20 May 2015 15:37:00 +0800 Subject: [PATCH 056/839] Fix typo --- cocos2d/core/textures/TexturesWebGL.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index 2b4f0260e4..9d9224179c 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -441,10 +441,10 @@ cc._tmp.WebGLTexture2D = function () { /** * handler of texture loaded event - * @param {Boolean} [premultipled=false] + * @param {Boolean} [premultiplied=false] */ - handleLoadedTexture: function (premultipled) { - premultipled = (premultipled === undefined)?false: premultipled; + handleLoadedTexture: function (premultiplied) { + premultiplied = (premultiplied === undefined)?false: premultiplied; var self = this; // Not sure about this ! Some texture need to be updated even after loaded if (!cc._rendererInitialized) @@ -463,7 +463,7 @@ cc._tmp.WebGLTexture2D = function () { cc.glBindTexture2D(self); gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4); - if(premultipled) + if(premultiplied) gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); // Specify OpenGL texture image @@ -476,7 +476,7 @@ cc._tmp.WebGLTexture2D = function () { self.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURE); cc.glBindTexture2D(null); - if(premultipled) + if(premultiplied) gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0); var pixelsWide = self._htmlElementObj.width; @@ -488,7 +488,7 @@ cc._tmp.WebGLTexture2D = function () { self.maxS = 1; self.maxT = 1; - self._hasPremultipliedAlpha = premultipled; + self._hasPremultipliedAlpha = premultiplied; self._hasMipmaps = false; //dispatch load event to listener. From 68f6224b6c984787b99a802f6c30068b5b1a0260 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 21 May 2015 15:24:41 +0800 Subject: [PATCH 057/839] Error loading path of resources --- extensions/cocostudio/loader/load.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/cocostudio/loader/load.js b/extensions/cocostudio/loader/load.js index 751ee53918..b30a27e675 100644 --- a/extensions/cocostudio/loader/load.js +++ b/extensions/cocostudio/loader/load.js @@ -33,6 +33,8 @@ ccs._load = (function(){ */ var load = function(file, type, path){ + file = cc.path.join(cc.loader.resPath, file); + var json = cc.loader.getRes(file); if(!json) From 6f7a2330428c5037e894f7c0a9f96e369b1820f4 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 21 May 2015 15:26:12 +0800 Subject: [PATCH 058/839] Error loading path of resources --- CCBoot.js | 1 - 1 file changed, 1 deletion(-) diff --git a/CCBoot.js b/CCBoot.js index 6181745665..b2335d2d38 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -784,7 +784,6 @@ cc.loader = /** @lends cc.loader# */{ this.removeEventListener('load', loadCallback, false); this.removeEventListener('error', errorCallback, false); - cc.loader.cache[url] = img; if (callback) callback(null, img); }; From 7fa429c1b0aba70d22c500546760dbbe2d93284d Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 21 May 2015 16:08:29 +0800 Subject: [PATCH 059/839] Repair after bake texture may wrong question and synchronous ccui.Scale9Sprite --- cocos2d/core/layers/CCLayerCanvasRenderCmd.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js index c80fc3f574..c22a6f7179 100644 --- a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js +++ b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js @@ -122,6 +122,7 @@ this._syncStatus(parentCmd); cc.renderer.pushRenderCommand(this); + this._cacheDirty = true; //the bakeSprite is drawing this._bakeSprite.visit(this); From 133dafbe482f45b4747389e613e5d27a31659068 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 21 May 2015 16:08:39 +0800 Subject: [PATCH 060/839] Repair after bake texture may wrong question and synchronous ccui.Scale9Sprite --- .../gui/control-extension/CCScale9Sprite.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extensions/gui/control-extension/CCScale9Sprite.js b/extensions/gui/control-extension/CCScale9Sprite.js index 9e1fefa38a..676059269f 100644 --- a/extensions/gui/control-extension/CCScale9Sprite.js +++ b/extensions/gui/control-extension/CCScale9Sprite.js @@ -462,11 +462,11 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ if(!locLoaded){ texture.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. - var preferredSize = this._preferredSize, restorePreferredSize = (preferredSize.width !== 0 || preferredSize.height !== 0); - if(restorePreferredSize)preferredSize = cc.size(preferredSize.width, preferredSize.height); + var preferredSize = this._preferredSize, restorePreferredSize = preferredSize.width !== 0 && preferredSize.height !== 0; + if (restorePreferredSize) preferredSize = cc.size(preferredSize.width, preferredSize.height); var size = sender.getContentSize(); this.updateWithBatchNode(this._scale9Image, cc.rect(0,0,size.width,size.height), false, this._capInsets); - if(restorePreferredSize)this.setPreferredSize(preferredSize); + if (restorePreferredSize)this.setPreferredSize(preferredSize); this._positionsAreDirty = true; this.dispatchEvent("load"); }, this); @@ -495,10 +495,10 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ if(!locLoaded){ spriteFrame.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. - var preferredSize = this._preferredSize, restorePreferredSize = (preferredSize.width !== 0 || preferredSize.height !== 0); - if(restorePreferredSize)preferredSize = cc.size(preferredSize.width, preferredSize.height); + var preferredSize = this._preferredSize, restorePreferredSize = preferredSize.width !== 0 && preferredSize.height !== 0; + if (restorePreferredSize) preferredSize = cc.size(preferredSize.width, preferredSize.height); this.updateWithBatchNode(this._scale9Image, sender.getRect(), cc._renderType === cc._RENDER_TYPE_WEBGL && sender.isRotated(), this._capInsets); - if(restorePreferredSize)this.setPreferredSize(preferredSize); + if (restorePreferredSize)this.setPreferredSize(preferredSize); this._positionsAreDirty = true; this.dispatchEvent("load"); },this); @@ -897,10 +897,10 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{ if(!locLoaded){ spriteFrame.addEventListener("load", function(sender){ // the texture is rotated on Canvas render mode, so isRotated always is false. - var preferredSize = this._preferredSize, restorePreferredSize = (preferredSize.width !== 0 || preferredSize.height !== 0); - if(restorePreferredSize)preferredSize = cc.size(preferredSize.width, preferredSize.height); + var preferredSize = this._preferredSize, restorePreferredSize = preferredSize.width !== 0 && preferredSize.height !== 0; + if (restorePreferredSize) preferredSize = cc.size(preferredSize.width, preferredSize.height); this.updateWithBatchNode(this._scale9Image, sender.getRect(), cc._renderType === cc._RENDER_TYPE_WEBGL && sender.isRotated(), this._capInsets); - if(restorePreferredSize)this.setPreferredSize(preferredSize); + if (restorePreferredSize)this.setPreferredSize(preferredSize); this._positionsAreDirty = true; this.dispatchEvent("load"); },this); From b3e336904751022c499822f849a65f4a31b51b29 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 21 May 2015 16:26:34 +0800 Subject: [PATCH 061/839] Repair after bake texture may wrong question and synchronous ccui.Scale9Sprite --- cocos2d/core/layers/CCLayerCanvasRenderCmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js index c22a6f7179..4d422028d7 100644 --- a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js +++ b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js @@ -47,7 +47,7 @@ this._needDraw = true; cc.renderer.childrenOrderDirty = true; //limit: 1. its children's blendfunc are invalid. - this._isBaked = this._cacheDirty = true; + this._isBaked = true; var children = this._node._children; for(var i = 0, len = children.length; i < len; i++) From bf0803f87b93c2deb65fd317778512e40e2e2156 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 21 May 2015 18:02:50 +0800 Subject: [PATCH 062/839] Repair after bake texture may wrong question and synchronous ccui.Scale9Sprite --- cocos2d/core/layers/CCLayerCanvasRenderCmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js index 4d422028d7..c22a6f7179 100644 --- a/cocos2d/core/layers/CCLayerCanvasRenderCmd.js +++ b/cocos2d/core/layers/CCLayerCanvasRenderCmd.js @@ -47,7 +47,7 @@ this._needDraw = true; cc.renderer.childrenOrderDirty = true; //limit: 1. its children's blendfunc are invalid. - this._isBaked = true; + this._isBaked = this._cacheDirty = true; var children = this._node._children; for(var i = 0, len = children.length; i < len; i++) From bcd1cfa3a2fc18af099d5d580074fd712119b00a Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Mon, 25 May 2015 17:50:48 +0800 Subject: [PATCH 063/839] Issue #2910: CCScheduler.js unscheduleAllWithMinPriority has a problem --- cocos2d/core/CCScheduler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/CCScheduler.js b/cocos2d/core/CCScheduler.js index 688726099e..19fdde336b 100644 --- a/cocos2d/core/CCScheduler.js +++ b/cocos2d/core/CCScheduler.js @@ -727,7 +727,7 @@ cc.Scheduler = cc.Class.extend(/** @lends cc.Scheduler# */{ unscheduleAllWithMinPriority: function(minPriority){ // Custom Selectors var i, element, arr = this._arrayForTimers; - for(i=0; i=0; i--){ element = arr[i]; this.unscheduleAllForTarget(element.target); } From 5b0dcf8a3008fb1a7749d79cf9d18ef35e8b0cf7 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 26 May 2015 15:51:41 +0800 Subject: [PATCH 064/839] Repair isBaked return the undefined --- cocos2d/core/layers/CCLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/layers/CCLayer.js b/cocos2d/core/layers/CCLayer.js index f80af56a0c..4e414c6397 100644 --- a/cocos2d/core/layers/CCLayer.js +++ b/cocos2d/core/layers/CCLayer.js @@ -83,7 +83,7 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{ * @see cc.Layer#bake and cc.Layer#unbake */ isBaked: function(){ - return this._isBaked; + return this._renderCmd._isBaked; }, addChild: function(child, localZOrder, tag){ From 50f9533e6fe4cedaadabc2d1e46a45d18106b34e Mon Sep 17 00:00:00 2001 From: Mykyta Usikov Date: Tue, 26 May 2015 13:40:08 +0300 Subject: [PATCH 065/839] fixed CCProgressTimerCanvasRenderCmd to properly show colorized sprites; --- .../CCProgressTimerCanvasRenderCmd.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cocos2d/progress-timer/CCProgressTimerCanvasRenderCmd.js b/cocos2d/progress-timer/CCProgressTimerCanvasRenderCmd.js index fbb87b8ced..551481334f 100644 --- a/cocos2d/progress-timer/CCProgressTimerCanvasRenderCmd.js +++ b/cocos2d/progress-timer/CCProgressTimerCanvasRenderCmd.js @@ -90,7 +90,7 @@ //draw sprite var image = locSprite._texture.getHtmlElementObj(); - if (locSprite._colorized) { + if (locSprite._renderCmd._colorized) { context.drawImage(image, 0, 0, locTextureCoord.width, locTextureCoord.height, locX * scaleX, locY * scaleY, locWidth * scaleX, locHeight * scaleY); @@ -226,10 +226,10 @@ spriteCmd._syncDisplayOpacity(); } -/* if(colorDirty || opacityDirty){ + if(colorDirty || opacityDirty){ spriteCmd._updateColor(); - this._updateColor(); - }*/ + //this._updateColor(); + } if (locFlag & flags.transformDirty) { //update the transform @@ -256,10 +256,10 @@ spriteCmd._updateDisplayOpacity(); } -/* if(colorDirty || opacityDirty){ + if(colorDirty || opacityDirty){ spriteCmd._updateColor(); - this._updateColor(); - }*/ + //this._updateColor(); + } if(locFlag & flags.transformDirty){ //update the transform From d6081a9fb69e3a562684b50571fc30402c74d21c Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 27 May 2015 16:48:55 +0800 Subject: [PATCH 066/839] Modify event trigger mechanism --- extensions/ccui/uiwidgets/UIVideoPlayer.js | 93 +++++++++++++--------- extensions/ccui/uiwidgets/UIWebView.js | 63 ++++++++------- 2 files changed, 92 insertions(+), 64 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index f3e6cca5f3..8a1d660738 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -26,6 +26,7 @@ ccui.VideoPlayer = ccui.Widget.extend({ ctor: function(path){ ccui.Widget.prototype.ctor.call(this); + this._EventList = {}; if(path) this.setURL(path); }, @@ -98,7 +99,7 @@ ccui.VideoPlayer = ccui.Widget.extend({ } setTimeout(function(){ - cc.eventManager.dispatchCustomEvent(ccui.VideoPlayer.EventType.STOPPED); + self._dispatchEvent(ccui.VideoPlayer.EventType.STOPPED); }, 0); }, /** @@ -128,58 +129,78 @@ ccui.VideoPlayer = ccui.Widget.extend({ cc.log("On the web is always keep the aspect ratio"); }, isKeepAspectRatioEnabled: function(){ - return true; + return false; }, + /** + * Set whether the full screen + * May appear inconsistent in different browsers + * @param {boolean} enable + */ setFullScreenEnabled: function(enable){ var video = this._renderCmd._video; - if(video) - cc.screen.requestFullScreen(video); + if(video){ + if(enable) + cc.screen.requestFullScreen(video); + else + cc.screen.exitFullScreen(video); + } }, + + /** + * Determine whether already full screen + */ isFullScreenEnabled: function(){ cc.log("Can't know status"); }, /** - * + * The binding event * @param {String} event play | pause | stop | complete * @param {Function} callback */ - addEventListener: function(event, callback){ - if(!/^ui_video_/.test(event)) - event = "ui_video_" + event; - return cc.eventManager.addCustomListener(event, callback); + setEventListener: function(event, callback){ + var list = this._EventList[event]; + if(!list) + list = this._EventList[event] = []; + list[0] = callback; }, /** - * + * Delete events * @param {String} event play | pause | stop | complete - * @param {Function|Object} callbackOrListener + * @param {Function|Object} callback */ - removeEventListener: function(event, callbackOrListener){ - var map, list; - if(!/^ui_video_/.test(event)) - event = "ui_video_" + event; - if(typeof callbackOrListener === "function"){ - map = cc.eventManager._listenersMap[event]; - if(map){ - list = map.getFixedPriorityListeners(); - list && cc.eventManager._removeListenerInCallback(list, callbackOrListener); - } - }else{ - map = cc.eventManager._listenersMap[event]; - if(map){ - list = map.getFixedPriorityListeners(); - list && cc.eventManager._removeListenerInVector(list, callbackOrListener); - } + removeEventListener: function(event, callback){ + var list = this._EventList[event]; + if(list){ + if(callback) + for(var i=0; i Date: Wed, 27 May 2015 17:15:17 +0800 Subject: [PATCH 067/839] Modify event trigger mechanism --- extensions/ccui/uiwidgets/UIVideoPlayer.js | 30 +++++----------------- extensions/ccui/uiwidgets/UIWebView.js | 28 +++++--------------- 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index 8a1d660738..463635d36d 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -160,37 +160,21 @@ ccui.VideoPlayer = ccui.Widget.extend({ * @param {Function} callback */ setEventListener: function(event, callback){ - var list = this._EventList[event]; - if(!list) - list = this._EventList[event] = []; - list[0] = callback; + this._EventList[event] = callback; }, /** * Delete events - * @param {String} event play | pause | stop | complete - * @param {Function|Object} callback + * @param {ccui.VideoPlayer.EventType} event */ - removeEventListener: function(event, callback){ - var list = this._EventList[event]; - if(list){ - if(callback) - for(var i=0; i Date: Wed, 27 May 2015 17:19:29 +0800 Subject: [PATCH 068/839] Consolidate the grammar --- extensions/ccui/uiwidgets/UIVideoPlayer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index 463635d36d..ff842577d7 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -156,7 +156,7 @@ ccui.VideoPlayer = ccui.Widget.extend({ /** * The binding event - * @param {String} event play | pause | stop | complete + * @param {ccui.VideoPlayer.EventType} event * @param {Function} callback */ setEventListener: function(event, callback){ @@ -372,10 +372,10 @@ ccui.VideoPlayer.EventType = { node._dispatchEvent(ccui.VideoPlayer.EventType.COMPLETED); }); video.addEventListener("play", function(){ - node._dispatchEvent(ccui.VideoPlayer.EventType.PLAYING) + node._dispatchEvent(ccui.VideoPlayer.EventType.PLAYING); }); video.addEventListener("pause", function(){ - node._dispatchEvent(ccui.VideoPlayer.EventType.PAUSED) + node._dispatchEvent(ccui.VideoPlayer.EventType.PAUSED); }); }; From 766b3a6cacade93e347c20e6f8a2defc104f2c20 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 28 May 2015 10:23:25 +0800 Subject: [PATCH 069/839] The interface should return true --- extensions/ccui/uiwidgets/UIWebView.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/ccui/uiwidgets/UIWebView.js b/extensions/ccui/uiwidgets/UIWebView.js index 52512ad480..e9ac910b60 100644 --- a/extensions/ccui/uiwidgets/UIWebView.js +++ b/extensions/ccui/uiwidgets/UIWebView.js @@ -69,6 +69,7 @@ ccui.WebView = ccui.Widget.extend({ */ canGoBack: function(){ cc.log("Web does not support query history"); + return true; }, /** @@ -76,6 +77,7 @@ ccui.WebView = ccui.Widget.extend({ */ canGoForward: function(){ cc.log("Web does not support query history"); + return true; }, /** From 52055f8776ec7990a0158feeff7c1c0dbbfe3209 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 28 May 2015 14:17:17 +0800 Subject: [PATCH 070/839] Studio automatically loaded rely on resources --- extensions/cocostudio/loader/load.js | 22 +++++++++++++++++++ .../cocostudio/loader/parsers/action-2.x.js | 12 ++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/extensions/cocostudio/loader/load.js b/extensions/cocostudio/loader/load.js index 751ee53918..60b02f2fe6 100644 --- a/extensions/cocostudio/loader/load.js +++ b/extensions/cocostudio/loader/load.js @@ -221,3 +221,25 @@ ccs.csLoader = { return ccs._load(file); } }; + + +cc._jsonLoader = { + load : function(realUrl, url, res, cb){ + cc.loader.loadJson(realUrl, function(error, data){ + if(data && data["Content"] && data["Content"]["Content"]["UsedResources"]){ + var list = data["Content"]["Content"]["UsedResources"], + dirname = cc.path.dirname(realUrl); + for(var i=0; i Date: Fri, 29 May 2015 10:57:34 +0800 Subject: [PATCH 071/839] Update wide will to empty all of the attributes --- cocos2d/core/sprites/CCBakeSprite.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos2d/core/sprites/CCBakeSprite.js b/cocos2d/core/sprites/CCBakeSprite.js index 305e84a467..85822cb4f8 100644 --- a/cocos2d/core/sprites/CCBakeSprite.js +++ b/cocos2d/core/sprites/CCBakeSprite.js @@ -63,8 +63,14 @@ cc.BakeSprite = cc.Sprite.extend(/** @lends cc.BakeSprite# */{ sizeOrWidth = sizeOrWidth.width; } var locCanvas = this._cacheCanvas; + var strokeStyle = this._cacheContext._context.strokeStyle; + var fillStyle = this._cacheContext._context.fillStyle; locCanvas.width = sizeOrWidth; locCanvas.height = height; //TODO note baidu browser reset the context after set width or height + if(strokeStyle !== this._cacheContext._context.strokeStyle) + this._cacheContext._context.strokeStyle = strokeStyle; + if(fillStyle !== this._cacheContext._context.fillStyle) + this._cacheContext._context.fillStyle = fillStyle; this.getTexture().handleLoadedTexture(); this.setTextureRect(cc.rect(0,0, sizeOrWidth, height), false); } From 738da11b7a44d949127f9c17fe61a26a6007d892 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 29 May 2015 11:33:22 +0800 Subject: [PATCH 072/839] Update wide will to empty all of the attributes --- cocos2d/core/sprites/CCBakeSprite.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/sprites/CCBakeSprite.js b/cocos2d/core/sprites/CCBakeSprite.js index 85822cb4f8..b586ea6f8f 100644 --- a/cocos2d/core/sprites/CCBakeSprite.js +++ b/cocos2d/core/sprites/CCBakeSprite.js @@ -58,13 +58,14 @@ cc.BakeSprite = cc.Sprite.extend(/** @lends cc.BakeSprite# */{ * @param {Number} [height] */ resetCanvasSize: function(sizeOrWidth, height){ + var locCanvas = this._cacheCanvas, + locContext = this._cacheContext, + strokeStyle = locContext._context.strokeStyle, + fillStyle = locContext._context.fillStyle; if(height === undefined){ height = sizeOrWidth.height; sizeOrWidth = sizeOrWidth.width; } - var locCanvas = this._cacheCanvas; - var strokeStyle = this._cacheContext._context.strokeStyle; - var fillStyle = this._cacheContext._context.fillStyle; locCanvas.width = sizeOrWidth; locCanvas.height = height; //TODO note baidu browser reset the context after set width or height if(strokeStyle !== this._cacheContext._context.strokeStyle) From e3c580a9f7e9ef71da71c426ee10813ab7405ac8 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 29 May 2015 13:33:42 +0800 Subject: [PATCH 073/839] Update wide will to empty all of the attributes --- cocos2d/core/sprites/CCBakeSprite.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/sprites/CCBakeSprite.js b/cocos2d/core/sprites/CCBakeSprite.js index b586ea6f8f..bcde14c2d0 100644 --- a/cocos2d/core/sprites/CCBakeSprite.js +++ b/cocos2d/core/sprites/CCBakeSprite.js @@ -68,10 +68,10 @@ cc.BakeSprite = cc.Sprite.extend(/** @lends cc.BakeSprite# */{ } locCanvas.width = sizeOrWidth; locCanvas.height = height; //TODO note baidu browser reset the context after set width or height - if(strokeStyle !== this._cacheContext._context.strokeStyle) - this._cacheContext._context.strokeStyle = strokeStyle; - if(fillStyle !== this._cacheContext._context.fillStyle) - this._cacheContext._context.fillStyle = fillStyle; + if(strokeStyle !== locContext._context.strokeStyle) + locContext._context.strokeStyle = strokeStyle; + if(fillStyle !== locContext._context.fillStyle) + locContext._context.fillStyle = fillStyle; this.getTexture().handleLoadedTexture(); this.setTextureRect(cc.rect(0,0, sizeOrWidth, height), false); } From 46da3b7da60d9daa7ef874b53b575cdc9a285270 Mon Sep 17 00:00:00 2001 From: IShm Date: Mon, 1 Jun 2015 12:26:07 +0300 Subject: [PATCH 074/839] added empty sprite for not found character into font --- cocos2d/labels/CCLabelBMFont.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cocos2d/labels/CCLabelBMFont.js b/cocos2d/labels/CCLabelBMFont.js index 1a4a018471..e79df5a28a 100644 --- a/cocos2d/labels/CCLabelBMFont.js +++ b/cocos2d/labels/CCLabelBMFont.js @@ -327,7 +327,18 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ var fontDef = locFontDict[key]; if (!fontDef) { cc.log("cocos2d: LabelBMFont: character not found " + locStr[i]); - continue; + + fontDef = { + rect: { + x: 0, + y: 0, + width: 0, + height: 0 + }, + xOffset: 0, + yOffset: 0, + xAdvance: 0 + }; } var rect = cc.rect(fontDef.rect.x, fontDef.rect.y, fontDef.rect.width, fontDef.rect.height); @@ -439,12 +450,7 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{ return 0; } var curTextFirstSprite = this.getChildByTag(startIndex); - var curTextLastSpriteId = startIndex + endIndex; - var curTextLastSprite = this.getChildByTag(curTextLastSpriteId); - while (!curTextLastSprite && 0 < curTextLastSpriteId) { - curTextLastSpriteId--; - curTextLastSprite = this.getChildByTag(curTextLastSpriteId); - } + var curTextLastSprite = this.getChildByTag(startIndex + endIndex); return this._getLetterPosXLeft(curTextLastSprite) - this._getLetterPosXLeft(curTextFirstSprite); }, From 795c066a19e300a5490c5f2ed58b5a26fcbb01d8 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 3 Jun 2015 12:16:32 +0800 Subject: [PATCH 075/839] Fixed texture does not rotate bug --- extensions/ccui/uiwidgets/UILoadingBar.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/extensions/ccui/uiwidgets/UILoadingBar.js b/extensions/ccui/uiwidgets/UILoadingBar.js index 0b9b90eaed..1f1d76b020 100644 --- a/extensions/ccui/uiwidgets/UILoadingBar.js +++ b/extensions/ccui/uiwidgets/UILoadingBar.js @@ -240,7 +240,9 @@ ccui.LoadingBar = ccui.Widget.extend(/** @lends ccui.LoadingBar# */{ this._setPercent(percent); }, - _setPercent: function(percent){ + _setPercent: function(){ + var rect, spriteRenderer, spriteTextureRect; + if (this._totalLength <= 0) return; var res = this._percent / 100.0; @@ -248,16 +250,18 @@ ccui.LoadingBar = ccui.Widget.extend(/** @lends ccui.LoadingBar# */{ if (this._scale9Enabled) this._setScale9Scale(); else { - var spriteRenderer = this._barRenderer; - var rect = spriteRenderer.getTextureRect(); - rect.width = this._barRendererTextureSize.width * res; - this._barRenderer.setTextureRect( + spriteRenderer = this._barRenderer; + spriteTextureRect = this._barRendererTextureSize; + rect = spriteRenderer.getTextureRect(); + rect.width = spriteTextureRect.width * res; + spriteRenderer.setTextureRect( cc.rect( rect.x, rect.y, - this._barRendererTextureSize.width * res, - this._barRendererTextureSize.height - ) + spriteTextureRect.width * res, + spriteTextureRect.height + ), + spriteRenderer._rectRotated ); } }, From b5b28bfe99b97b3ff2a900c2aa6d53c458b72e3a Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 3 Jun 2015 14:13:22 +0800 Subject: [PATCH 076/839] Fixed audioEngine.playEffect loop failures in chrome 42 --- cocos2d/audio/CCAudio.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index e4c2f2cce3..2cf33adfd3 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -469,6 +469,7 @@ cc.Audio = cc.Class.extend({ self._setBufferCallback = null; }; } + audio._manualLoop = this._manualLoop; } audio._AUDIO_TYPE = this._AUDIO_TYPE; return audio; From 3b5995a47b61fc7d55b379aeb2da86cdebb75364 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 3 Jun 2015 15:27:05 +0800 Subject: [PATCH 077/839] Armature set color --- extensions/cocostudio/loader/parsers/timelineParser-2.x.js | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js index 86496e99e1..3d220101f9 100644 --- a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js +++ b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js @@ -1232,6 +1232,7 @@ node.getAnimation().play(currentAnimationName, -1, isLoop); }); + node.setColor(getColor(json["CColor"])); return node; }; From cc321f0c6a02d8aeff47ba3a347799c7cdcff7d7 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 3 Jun 2015 17:56:30 +0800 Subject: [PATCH 078/839] The definition of variables move to the head --- extensions/ccui/uiwidgets/UILoadingBar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/ccui/uiwidgets/UILoadingBar.js b/extensions/ccui/uiwidgets/UILoadingBar.js index 1f1d76b020..6646aa0599 100644 --- a/extensions/ccui/uiwidgets/UILoadingBar.js +++ b/extensions/ccui/uiwidgets/UILoadingBar.js @@ -241,11 +241,11 @@ ccui.LoadingBar = ccui.Widget.extend(/** @lends ccui.LoadingBar# */{ }, _setPercent: function(){ - var rect, spriteRenderer, spriteTextureRect; + var res, rect, spriteRenderer, spriteTextureRect; if (this._totalLength <= 0) return; - var res = this._percent / 100.0; + res = this._percent / 100.0; if (this._scale9Enabled) this._setScale9Scale(); From 7201bc97679083bac5da206a07de7d12476e488b Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 4 Jun 2015 16:16:19 +0800 Subject: [PATCH 079/839] Fixed custom easing animation bug --- extensions/cocostudio/loader/parsers/action-2.x.js | 8 +++++--- extensions/cocostudio/timeline/Frame.js | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/extensions/cocostudio/loader/parsers/action-2.x.js b/extensions/cocostudio/loader/parsers/action-2.x.js index b0b44e3e43..900a1fe001 100644 --- a/extensions/cocostudio/loader/parsers/action-2.x.js +++ b/extensions/cocostudio/loader/parsers/action-2.x.js @@ -257,11 +257,13 @@ var type = options["Type"]; frame.setTweenType(type); var points = options["Points"]; + var result = []; if(points){ - points = points.map(function(p){ - return cc.p(p["X"], p["Y"]); + points.forEach(function(p){ + result.push(p["X"]); + result.push(p["Y"]); }); - frame.setEasingParams(points); + frame.setEasingParams(result); } }; diff --git a/extensions/cocostudio/timeline/Frame.js b/extensions/cocostudio/timeline/Frame.js index 24d924ee52..89a147c24b 100644 --- a/extensions/cocostudio/timeline/Frame.js +++ b/extensions/cocostudio/timeline/Frame.js @@ -190,6 +190,14 @@ ccs.Frame = ccs.Class.extend({ }); ccs.Frame.tweenToMap = { + "-1": function(time, easingParam){ + if (easingParam) + { + var tt = 1 - time; + return easingParam[1]*tt*tt*tt + 3*easingParam[3]*time*tt*tt + 3*easingParam[5]*time*time*tt + easingParam[7]*time*time*time; + } + return time; + }, 1: cc._easeSineInObj.easing,//Sine_EaseIn 2: cc._easeSineOutObj.easing,//Sine_EaseOut 3: cc._easeSineInOutObj.easing,//Sine_EaseInOut From 7430cab1712635259d95903161b199673ffd1df4 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 4 Jun 2015 16:58:35 +0800 Subject: [PATCH 080/839] fixed: resPath (ccs.load) --- extensions/cocostudio/loader/load.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/extensions/cocostudio/loader/load.js b/extensions/cocostudio/loader/load.js index 5aa8571670..60b02f2fe6 100644 --- a/extensions/cocostudio/loader/load.js +++ b/extensions/cocostudio/loader/load.js @@ -33,8 +33,6 @@ ccs._load = (function(){ */ var load = function(file, type, path){ - file = cc.path.join(cc.loader.resPath, file); - var json = cc.loader.getRes(file); if(!json) From db5b57ffd451590aa1565349c9c68298de798df7 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 5 Jun 2015 12:27:10 +0800 Subject: [PATCH 081/839] Activate premultiplied alpha --- cocos2d/core/platform/CCConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/platform/CCConfig.js b/cocos2d/core/platform/CCConfig.js index d22450daad..951f822f4b 100644 --- a/cocos2d/core/platform/CCConfig.js +++ b/cocos2d/core/platform/CCConfig.js @@ -117,7 +117,7 @@ cc.SPRITEBATCHNODE_RENDER_SUBPIXEL = 1; * @constant * @type {Number} */ -cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA = 0; +cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA = 1; /** *

From f74232d94083b13ef61cd2d664d964a3f7af5339 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Mon, 8 Jun 2015 11:58:11 +0800 Subject: [PATCH 082/839] Fixed UIText color settings bug --- extensions/cocostudio/loader/parsers/timelineParser-2.x.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js index 3d220101f9..b7f7bf0a4e 100644 --- a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js +++ b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js @@ -562,8 +562,11 @@ widget.setUnifySizeEnabled(false); + var color = json["CColor"]; + json["CColor"] = null; + widget.setTextColor(getColor(color)); this.widgetAttributes(widget, json, widget.isIgnoreContentAdaptWithSize()); - + json["CColor"] = color; return widget; }; From 2d87e02b62ddcb30cf9a6dfc1e2c148f0b5ae5c0 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Mon, 8 Jun 2015 15:39:38 +0800 Subject: [PATCH 083/839] Fixed control LayoutComponent positioning bug --- extensions/cocostudio/loader/parsers/timelineParser-2.x.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js index b7f7bf0a4e..8305f09c4f 100644 --- a/extensions/cocostudio/loader/parsers/timelineParser-2.x.js +++ b/extensions/cocostudio/loader/parsers/timelineParser-2.x.js @@ -121,6 +121,8 @@ node.setCascadeColorEnabled(true); node.setCascadeOpacityEnabled(true); + + setLayoutComponent(node, json); }; parser.parseChild = function(node, children, resourcePath){ @@ -327,6 +329,11 @@ if (color != null) widget.setColor(getColor(color)); + setLayoutComponent(widget, json); + }; + + var setLayoutComponent = function(widget, json){ + var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget); if(!layoutComponent) return; From d06f0e2bc2639fd59bbcfc0881100b835f7ab04f Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Mon, 8 Jun 2015 18:01:05 +0800 Subject: [PATCH 084/839] fix return empty texture2d when add image with same url multiple times,relate issue #2928 --- cocos2d/core/textures/CCTextureCache.js | 13 +++++++++++-- cocos2d/core/textures/TexturesWebGL.js | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/textures/CCTextureCache.js b/cocos2d/core/textures/CCTextureCache.js index 8068eb485b..b1f402ff67 100644 --- a/cocos2d/core/textures/CCTextureCache.js +++ b/cocos2d/core/textures/CCTextureCache.js @@ -342,8 +342,17 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) { //remove judge var tex = locTexs[url] || locTexs[cc.loader._aliases[url]]; if (tex) { - cb && cb.call(target, tex); - return tex; + if(tex.isLoaded()) { + cb && cb.call(target, tex); + return tex; + } + else + { + tex.addEventListener("load", function(){ + cb && cb.call(target, tex); + }, target); + return tex; + } } tex = locTexs[url] = new cc.Texture2D(); diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index 9d9224179c..b289008755 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -888,8 +888,20 @@ cc._tmp.WebGLTextureCache = function () { } var tex = locTexs[url] || locTexs[cc.loader._aliases[url]]; if (tex) { - cb && cb.call(target, tex); - return tex; + if(tex.isLoaded()) { + cb && cb.call(target, tex); + return tex; + } + else + { + tex.addEventListener("load", function(){ + cb && cb.call(target, tex); + }, target); + return tex; + } + } else { + tex = locTexs[url] = new cc.Texture2D(); + tex.url = url; } tex = locTexs[url] = new cc.Texture2D(); From c411435047ff48733b38b98590722557555a1add Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Mon, 8 Jun 2015 18:14:48 +0800 Subject: [PATCH 085/839] fix the error code --- cocos2d/core/textures/TexturesWebGL.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index b289008755..5826bfef7b 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -899,9 +899,6 @@ cc._tmp.WebGLTextureCache = function () { }, target); return tex; } - } else { - tex = locTexs[url] = new cc.Texture2D(); - tex.url = url; } tex = locTexs[url] = new cc.Texture2D(); From 8d5bcee5851de833ed507cfcdd7c23c3be47ec42 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 9 Jun 2015 14:03:11 +0800 Subject: [PATCH 086/839] Set the background image should disable background color --- extensions/ccui/layouts/UILayout.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extensions/ccui/layouts/UILayout.js b/extensions/ccui/layouts/UILayout.js index 99b242c2ae..db18220930 100644 --- a/extensions/ccui/layouts/UILayout.js +++ b/extensions/ccui/layouts/UILayout.js @@ -41,6 +41,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ _backGroundImageFileName: null, _backGroundImageCapInsets: null, _colorType: null, + _colorTypeBackup: null, _bgImageTexType: ccui.Widget.LOCAL_TEXTURE, _colorRender: null, _gradientRender: null, @@ -531,6 +532,8 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ this._backGroundImageTextureSize = locBackgroundImage.getContentSize(); locBackgroundImage.setPosition(this._contentSize.width * 0.5, this._contentSize.height * 0.5); this._updateBackGroundImageColor(); + this._colorTypeBackup = this._colorType; + this.setBackGroundColorType(0); }, /** @@ -602,6 +605,11 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ this._backGroundImageFileName = ""; this._backGroundImageTextureSize.width = 0; this._backGroundImageTextureSize.height = 0; + if(this._colorTypeBackup !== null){ + var type = this._colorTypeBackup; + this._colorTypeBackup = null; + this.setBackGroundColorType(type); + } }, /** @@ -609,6 +617,10 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{ * @param {ccui.Layout.BG_COLOR_NONE|ccui.Layout.BG_COLOR_SOLID|ccui.Layout.BG_COLOR_GRADIENT} type */ setBackGroundColorType: function (type) { + if(this._colorTypeBackup !== null){ + this._colorTypeBackup = type; + return; + } if (this._colorType === type) return; switch (this._colorType) { From 55a84ec5234ef59c49d0499444b5b553949eb777 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 10 Jun 2015 11:43:25 +0800 Subject: [PATCH 087/839] Fixed #2931: Fix draw node, Layer's blend function issue --- cocos2d/core/layers/CCLayer.js | 2 +- cocos2d/core/platform/CCMacro.js | 2 +- cocos2d/core/sprites/CCSprite.js | 2 +- cocos2d/core/textures/TexturesWebGL.js | 2 +- cocos2d/shape-nodes/CCDrawNode.js | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/layers/CCLayer.js b/cocos2d/core/layers/CCLayer.js index 4e414c6397..42a6cf70e1 100644 --- a/cocos2d/core/layers/CCLayer.js +++ b/cocos2d/core/layers/CCLayer.js @@ -191,7 +191,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{ */ ctor: function(color, width, height){ cc.Layer.prototype.ctor.call(this); - this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + this._blendFunc = new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); cc.LayerColor.prototype.init.call(this, color, width, height); }, diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js index cabb8f2c30..e1c852497a 100644 --- a/cocos2d/core/platform/CCMacro.js +++ b/cocos2d/core/platform/CCMacro.js @@ -171,7 +171,7 @@ cc.REPEAT_FOREVER = Number.MAX_VALUE - 1; * @constant * @type Number */ -cc.BLEND_SRC = cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA ? 1 : 0x0302; +cc.BLEND_SRC = (cc._renderType === cc._RENDER_TYPE_WEBGL && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) ? cc.ONE : cc.SRC_ALPHA; /** * default gl blend dst function. Compatible with premultiplied alpha images. diff --git a/cocos2d/core/sprites/CCSprite.js b/cocos2d/core/sprites/CCSprite.js index b6662b3455..9d7acb18ff 100644 --- a/cocos2d/core/sprites/CCSprite.js +++ b/cocos2d/core/sprites/CCSprite.js @@ -738,7 +738,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{ this._renderCmd._checkTextureBoundary(texture, rect, rotated); - _t.texture = texture; + _t.setTexture(texture); _t.setTextureRect(rect, rotated); // by default use "Self Render". diff --git a/cocos2d/core/textures/TexturesWebGL.js b/cocos2d/core/textures/TexturesWebGL.js index 9d9224179c..663a83966f 100644 --- a/cocos2d/core/textures/TexturesWebGL.js +++ b/cocos2d/core/textures/TexturesWebGL.js @@ -444,7 +444,7 @@ cc._tmp.WebGLTexture2D = function () { * @param {Boolean} [premultiplied=false] */ handleLoadedTexture: function (premultiplied) { - premultiplied = (premultiplied === undefined)?false: premultiplied; + premultiplied = (premultiplied === undefined) ? false : premultiplied; var self = this; // Not sure about this ! Some texture need to be updated even after loaded if (!cc._rendererInitialized) diff --git a/cocos2d/shape-nodes/CCDrawNode.js b/cocos2d/shape-nodes/CCDrawNode.js index 1d222cb9e7..1b63d3426d 100644 --- a/cocos2d/shape-nodes/CCDrawNode.js +++ b/cocos2d/shape-nodes/CCDrawNode.js @@ -105,7 +105,7 @@ cc.DrawNodeCanvas = cc.Node.extend(/** @lends cc.DrawNode# */{ var locCmd = this._renderCmd; locCmd._buffer = this._buffer = []; locCmd._drawColor = this._drawColor = cc.color(255, 255, 255, 255); - locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); this.init(); }, @@ -516,7 +516,7 @@ cc.DrawNodeWebGL = cc.Node.extend({ ctor:function () { cc.Node.prototype.ctor.call(this); this._buffer = []; - this._blendFunc = new cc.BlendFunc(cc.BLEND_SRC, cc.BLEND_DST); + this._blendFunc = new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA); this._drawColor = cc.color(255,255,255,255); this.init(); From 3b16bd8303a9c18ded8aba76effe1ac98e5bbdca Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 10 Jun 2015 12:01:18 +0800 Subject: [PATCH 088/839] Fix constant undefined issue --- cocos2d/core/platform/CCMacro.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js index e1c852497a..ae2d815e20 100644 --- a/cocos2d/core/platform/CCMacro.js +++ b/cocos2d/core/platform/CCMacro.js @@ -166,20 +166,6 @@ cc.radiansToDegress = function (angle) { */ cc.REPEAT_FOREVER = Number.MAX_VALUE - 1; -/** - * default gl blend src function. Compatible with premultiplied alpha images. - * @constant - * @type Number - */ -cc.BLEND_SRC = (cc._renderType === cc._RENDER_TYPE_WEBGL && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) ? cc.ONE : cc.SRC_ALPHA; - -/** - * default gl blend dst function. Compatible with premultiplied alpha images. - * @constant - * @type Number - */ -cc.BLEND_DST = 0x0303; - /** * Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix * @param {cc.Node} node setup node @@ -455,6 +441,20 @@ cc.CLAMP_TO_EDGE = 0x812f; */ cc.MIRRORED_REPEAT = 0x8370; +/** + * default gl blend src function. Compatible with premultiplied alpha images. + * @constant + * @type Number + */ +cc.BLEND_SRC = (cc._renderType === cc._RENDER_TYPE_WEBGL && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) ? cc.ONE : cc.SRC_ALPHA; + +/** + * default gl blend dst function. Compatible with premultiplied alpha images. + * @constant + * @type Number + */ +cc.BLEND_DST = 0x0303; + /** * Check webgl error.Error will be shown in console if exists. * @function From 412837f88815890731e7efd6cc7e726c4bd1cab7 Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Wed, 10 Jun 2015 15:43:46 +0800 Subject: [PATCH 089/839] don't need use full path, the cache is relative path --- extensions/cocostudio/loader/load.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/extensions/cocostudio/loader/load.js b/extensions/cocostudio/loader/load.js index 5aa8571670..60b02f2fe6 100644 --- a/extensions/cocostudio/loader/load.js +++ b/extensions/cocostudio/loader/load.js @@ -33,8 +33,6 @@ ccs._load = (function(){ */ var load = function(file, type, path){ - file = cc.path.join(cc.loader.resPath, file); - var json = cc.loader.getRes(file); if(!json) From 6871db4de3ba49da9d6109636cc2b2810e8a4e8c Mon Sep 17 00:00:00 2001 From: Kevin Kirsche Date: Wed, 10 Jun 2015 18:05:28 -0400 Subject: [PATCH 090/839] Remove moot `version` property from bower.json Per bower/bower.json-spec@a325da3 --- bower.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 5493b6e512..e97d56bb83 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,5 @@ { "name": "cocos2d-html5", - "version": "3.4", "homepage": "http://www.cocos2d-x.org", "authors": [ "AUTHORS.txt" @@ -34,4 +33,4 @@ "test", "tests" ] -} \ No newline at end of file +} From b29721a39a33efffcf0d2ee89ea7bedf783390ae Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 11 Jun 2015 11:02:12 +0800 Subject: [PATCH 091/839] Plist file parsing (action-2.x.js) --- .../cocostudio/loader/parsers/action-2.x.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/extensions/cocostudio/loader/parsers/action-2.x.js b/extensions/cocostudio/loader/parsers/action-2.x.js index 900a1fe001..2f19946113 100644 --- a/extensions/cocostudio/loader/parsers/action-2.x.js +++ b/extensions/cocostudio/loader/parsers/action-2.x.js @@ -194,11 +194,20 @@ { name: "FileData", handle: function(options, resourcePath){ - var frame = new ccs.TextureFrame(); - var texture = options["TextureFile"]; + var frame, texture, plist, path, spriteFrame; + frame = new ccs.TextureFrame(); + texture = options["TextureFile"]; if(texture != null) { - var path = texture["Path"]; - var spriteFrame = cc.spriteFrameCache.getSpriteFrame(path); + plist = texture["Plist"]; + path = texture["Path"]; + spriteFrame = cc.spriteFrameCache.getSpriteFrame(path); + if(!spriteFrame && plist){ + if(cc.loader.getRes(resourcePath + plist)){ + cc.spriteFrameCache.addSpriteFrames(resourcePath + plist); + }else{ + cc.log("%s need to be preloaded", resourcePath + plist); + } + } if(spriteFrame == null){ path = resourcePath + path; } From 19ebf245baddd6b99875205e1f664295785a3308 Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Thu, 11 Jun 2015 11:09:44 +0800 Subject: [PATCH 092/839] load remote url don't need add respath, add url match method --- CCBoot.js | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index b2335d2d38..f90ffc16da 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -837,8 +837,13 @@ cc.loader = /** @lends cc.loader# */{ cc.error("loader for [" + type + "] not exists!"); return cb(); } - var basePath = loader.getBasePath ? loader.getBasePath() : self.resPath; - var realUrl = self.getUrl(basePath, url); + var realUrl = url; + if (!url.match(cc.urlRegExp)) + { + var basePath = loader.getBasePath ? loader.getBasePath() : self.resPath; + realUrl = self.getUrl(basePath, url); + } + if(cc.game.config["noCache"] && typeof realUrl === "string"){ if(self._noCacheRex.test(realUrl)) realUrl += "&_t=" + (new Date() - 0); @@ -2351,3 +2356,33 @@ Function.prototype.bind = Function.prototype.bind || function (oThis) { return fBound; }; + +cc.urlRegExp = new RegExp( + "^" + + // protocol identifier + "(?:(?:https?|ftp)://)" + + // user:pass authentication + "(?:\\S+(?::\\S*)?@)?" + + "(?:" + + // IP address dotted notation octets + // excludes loopback network 0.0.0.0 + // excludes reserved space >= 224.0.0.0 + // excludes network & broacast addresses + // (first & last IP address of each class) + "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + + "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + + "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" + + "|" + + // host name + "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" + + // domain name + "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" + + // TLD identifier + "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" + + ")" + + // port number + "(?::\\d{2,5})?" + + // resource path + "(?:/\\S*)?" + + "$", "i" +); From cce2328e1b1d3c0c52cf32cedbbcbccf6cd9c6e3 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 11 Jun 2015 14:23:20 +0800 Subject: [PATCH 093/839] fix bug: fix actiontimeline can not step to last frame when loop play --- .../cocostudio/timeline/ActionTimeline.js | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/extensions/cocostudio/timeline/ActionTimeline.js b/extensions/cocostudio/timeline/ActionTimeline.js index d458bb958b..dedc489b48 100644 --- a/extensions/cocostudio/timeline/ActionTimeline.js +++ b/extensions/cocostudio/timeline/ActionTimeline.js @@ -121,6 +121,7 @@ ccs.ActionTimeline = cc.Action.extend({ _loop: null, _frameEventListener: null, _animationInfos: null, + _lastFrameListener: null, ctor: function(){ cc.Action.prototype.ctor.call(this); @@ -399,15 +400,24 @@ ccs.ActionTimeline = cc.Action.extend({ } this._time += delta * this._timeSpeed; - this._currentFrame = this._time / this._frameInternal | 0; + var endoffset = this._time - this._endFrame * this._frameInternal; - this._stepToFrame(this._currentFrame); - - if(this._time > this._endFrame * this._frameInternal){ + if(endoffset < this._frameInternal){ + this._currentFrame = this._time / this._frameInternal; + this._stepToFrame(this._currentFrame); + if(endoffset >= 0 && this._lastFrameListener) + this._lastFrameListener(); + }else{ this._playing = this._loop; - if(!this._playing) + if(!this._playing){ this._time = this._endFrame * this._frameInternal; - else + if (this._currentFrame != this._endFrame){ + this._currentFrame = this._endFrame; + this._stepToFrame(this._currentFrame); + if(this._lastFrameListener) + this._lastFrameListener(); + } + }else this.gotoFrameAndPlay(this._startFrame, this._endFrame, this._loop); } @@ -492,6 +502,14 @@ ccs.ActionTimeline = cc.Action.extend({ getAnimationInfo: function(name){ return this._animationInfos[name]; + }, + + setLastFrameCallFunc: function(listener){ + this._lastFrameListener = listener; + }, + + clearLastFrameCallFunc: function(){ + this._lastFrameListener = null; } }); From 9fb5cccc60dbceb97aec534db3fc31f103485ee7 Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Thu, 11 Jun 2015 17:35:14 +0800 Subject: [PATCH 094/839] rename jsb.urlRegExp to cc._urlRegExp --- CCBoot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CCBoot.js b/CCBoot.js index f90ffc16da..eaab8d21e9 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -838,7 +838,7 @@ cc.loader = /** @lends cc.loader# */{ return cb(); } var realUrl = url; - if (!url.match(cc.urlRegExp)) + if (!url.match(cc._urlRegExp)) { var basePath = loader.getBasePath ? loader.getBasePath() : self.resPath; realUrl = self.getUrl(basePath, url); @@ -2357,7 +2357,7 @@ Function.prototype.bind = Function.prototype.bind || function (oThis) { return fBound; }; -cc.urlRegExp = new RegExp( +cc._urlRegExp = new RegExp( "^" + // protocol identifier "(?:(?:https?|ftp)://)" + From 531d5aadf865b392dc00528ab2a35f076bd4db81 Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Fri, 12 Jun 2015 10:25:00 +0800 Subject: [PATCH 095/839] fix the prompt can not use in wechat --- cocos2d/text-input/CCIMEDispatcher.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos2d/text-input/CCIMEDispatcher.js b/cocos2d/text-input/CCIMEDispatcher.js index 4b713086e5..05b86215b7 100644 --- a/cocos2d/text-input/CCIMEDispatcher.js +++ b/cocos2d/text-input/CCIMEDispatcher.js @@ -389,7 +389,8 @@ cc.IMEDispatcher = cc.Class.extend(/** @lends cc.imeDispatcher# */{ this._currentInputString = delegate.string || ""; var tipMessage = delegate.getTipMessage ? delegate.getTipMessage() : "please enter your word:"; - var userInput = prompt(tipMessage, this._currentInputString); + // wechat cover the prompt funciton .So need use the Window.prototype.prompt + var userInput = Window.prototype.prompt.call(window, tipMessage, this._currentInputString); if(userInput != null) this._processDomInputString(userInput); this.dispatchInsertText("\n", 1); From 71c5db165e2fb84ac0203889b23286904296ef09 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 12 Jun 2015 11:51:38 +0800 Subject: [PATCH 096/839] Fix Uint8Array initialize issue --- cocos2d/core/utils/BinaryLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/utils/BinaryLoader.js b/cocos2d/core/utils/BinaryLoader.js index 013c3dee6e..f0e692dc3b 100644 --- a/cocos2d/core/utils/BinaryLoader.js +++ b/cocos2d/core/utils/BinaryLoader.js @@ -105,7 +105,7 @@ cc.loader.loadBinarySync = function (url) { }; //Compatibility with IE9 -var Uint8Array = Uint8Array || Array; +window.Uint8Array = window.Uint8Array || window.Array; if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) { var IEBinaryToArray_ByteStr_Script = From 77ba0a3c847a967531ebff68cb0bbe31678165e6 Mon Sep 17 00:00:00 2001 From: Igor Shmulyan Date: Fri, 12 Jun 2015 10:49:09 +0300 Subject: [PATCH 097/839] restoring of sprite's color was fixed for browsers that not supported canvas new blend modes --- .../core/sprites/CCSpriteCanvasRenderCmd.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js index 35b1fa82c9..2361afdfa3 100644 --- a/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js +++ b/cocos2d/core/sprites/CCSpriteCanvasRenderCmd.js @@ -168,10 +168,7 @@ var node = this._node, displayedColor = this._displayedColor; if (displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255){ - if(this._colorized){ - this._colorized = false; - node.texture = this._originalTexture; - } + this._setOriginalTexture(); return; } @@ -201,13 +198,7 @@ proto._updateColor = function () { var node = this._node, displayedColor = this._displayedColor; if (displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255) { - if (this._colorized) { - this._colorized = false; - var rect = cc.rect(node._rect); - var isRotation = node._rectRotated; - node.setTexture(this._originalTexture); - node.setTextureRect(rect, isRotation); - } + this._setOriginalTexture(); return; } @@ -231,6 +222,17 @@ } }; } + + proto._setOriginalTexture = function () { + if (this._colorized) { + this._colorized = false; + var node = this._node; + var rect = cc.rect(node._rect); + var isRotation = node._rectRotated; + node.setTexture(this._originalTexture); + node.setTextureRect(rect, isRotation); + } + }; proto.getQuad = function () { //throw an error. it doesn't support this function. From 011bf0dbd1747c85e2d79909ba816e767ae08e5a Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 12 Jun 2015 17:47:16 +0800 Subject: [PATCH 098/839] Issue #2835: Fixed cc.TextFieldTTF Delegate memory leaks due --- cocos2d/text-input/CCTextFieldTTF.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cocos2d/text-input/CCTextFieldTTF.js b/cocos2d/text-input/CCTextFieldTTF.js index b5c9fb1283..3f1a686deb 100644 --- a/cocos2d/text-input/CCTextFieldTTF.js +++ b/cocos2d/text-input/CCTextFieldTTF.js @@ -126,7 +126,6 @@ cc.TextFieldTTF = cc.LabelTTF.extend(/** @lends cc.TextFieldTTF# */{ ctor:function (placeholder, dimensions, alignment, fontName, fontSize) { this.colorSpaceHolder = cc.color(127, 127, 127); this._colorText = cc.color(255,255,255, 255); - cc.imeDispatcher.addDelegate(this); cc.LabelTTF.prototype.ctor.call(this); if(fontSize !== undefined){ @@ -140,6 +139,16 @@ cc.TextFieldTTF = cc.LabelTTF.extend(/** @lends cc.TextFieldTTF# */{ } }, + onEnter: function(){ + cc.LabelTTF.prototype.onEnter.call(this); + cc.imeDispatcher.addDelegate(this); + }, + + onExit: function(){ + cc.LabelTTF.prototype.onExit.call(this); + cc.imeDispatcher.removeDelegate(this); + }, + /** * Gets the delegate. * @return {cc.Node} From 3afb9e609f75fc2a171ec4e210e6d02927758914 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Sat, 13 Jun 2015 13:43:52 +0800 Subject: [PATCH 099/839] Merge -x #8853 --- extensions/cocostudio/timeline/Frame.js | 3 ++ extensions/cocostudio/timeline/Timeline.js | 38 ++++++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/extensions/cocostudio/timeline/Frame.js b/extensions/cocostudio/timeline/Frame.js index 89a147c24b..6ce6790ce1 100644 --- a/extensions/cocostudio/timeline/Frame.js +++ b/extensions/cocostudio/timeline/Frame.js @@ -35,12 +35,14 @@ ccs.Frame = ccs.Class.extend({ _node: null, _tweenType: null, _easingParam: null, + _enterWhenPassed: null, ctor: function(){ this._frameIndex = 0; this._tween = true; this._timeline = null; this._node = null; + this._enterWhenPassed = false; this._easingParam = []; }, @@ -1284,6 +1286,7 @@ ccs.EventFrame = ccs.Frame.extend({ ctor: function(){ ccs.Frame.prototype.ctor.call(this); this._event = ""; + this._enterWhenPassed = true; }, /** diff --git a/extensions/cocostudio/timeline/Timeline.js b/extensions/cocostudio/timeline/Timeline.js index 273ef72a11..7f4745a6c7 100644 --- a/extensions/cocostudio/timeline/Timeline.js +++ b/extensions/cocostudio/timeline/Timeline.js @@ -206,6 +206,13 @@ ccs.Timeline = ccs.Class.extend({ if(this._currentKeyFrameIndex >= this._frames[0].getFrameIndex()) needEnterFrame = true; + this._fromIndex = 0; + + if(length > 1) + this._toIndex = 1; + else + this._toIndex = 0; + from = to = this._frames[0]; this._currentKeyFrameIndex = 0; this._betweenDuration = this._frames[0].getFrameIndex(); @@ -213,6 +220,9 @@ ccs.Timeline = ccs.Class.extend({ } else if(frameIndex >= this._frames[length - 1].getFrameIndex()) { + this._fromIndex = length - 1; + this._toIndex = 0; + from = to = this._frames[length - 1]; this._currentKeyFrameIndex = this._frames[length - 1].getFrameIndex(); this._betweenDuration = 0; @@ -236,6 +246,16 @@ ccs.Timeline = ccs.Class.extend({ low = mid + 1; } + this._fromIndex = target; + + if(length > 1) + this._toIndex = (target + 1) | 0; + else + this._toIndex = (target) | 0; + + from = this._frames[this._fromIndex]; + to = this._frames[this._toIndex]; + from = this._frames[target]; to = this._frames[target+1]; @@ -254,6 +274,8 @@ ccs.Timeline = ccs.Class.extend({ }, _updateCurrentKeyFrame: function(frameIndex){ + if(frameIndex > 60) + var a = 0; //! If play to current frame's front or back, then find current frame again if (frameIndex < this._currentKeyFrameIndex || frameIndex >= this._currentKeyFrameIndex + this._betweenDuration) { @@ -273,10 +295,10 @@ ccs.Timeline = ccs.Class.extend({ } else if(frameIndex >= this._frames[length - 1].getFrameIndex()) { - from = to = this._frames[length - 1]; - this._currentKeyFrameIndex = this._frames[length - 1].getFrameIndex(); - this._betweenDuration = 0; - break; + var lastFrameIndex = this._frames[length - 1].getFrameIndex(); + if(this._currentKeyFrameIndex >= lastFrameIndex) + return; + frameIndex = lastFrameIndex; } do{ @@ -293,10 +315,12 @@ ccs.Timeline = ccs.Class.extend({ to = this._frames[this._toIndex]; if (frameIndex === from.getFrameIndex()) - { break; - } - }while (frameIndex < from.getFrameIndex() || frameIndex >= to.getFrameIndex()); + if(frameIndex > from.getFrameIndex() && frameIndex < to.getFrameIndex()) + break; + if(from.isEnterWhenPassed()) + from.onEnter(to); + }while (true); this._betweenDuration = to.getFrameIndex() - from.getFrameIndex(); From bb01ba81e9d0b648d30a2cabbd095c84e9f7a566 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Mon, 15 Jun 2015 15:22:29 +0800 Subject: [PATCH 100/839] Fixed sorted result is wrong(_sortEventListenersOfSceneGraphPriorityDes) --- cocos2d/core/event-manager/CCEventManager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index d01b3527aa..0d02a9a661 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -313,8 +313,10 @@ cc.eventManager = /** @lends cc.eventManager# */{ _sortEventListenersOfSceneGraphPriorityDes : function(l1, l2){ var locNodePriorityMap = cc.eventManager._nodePriorityMap, node1 = l1._getSceneGraphPriority(), node2 = l2._getSceneGraphPriority(); - if(!l1 || !l2 || !node1 || !node2 || !locNodePriorityMap[node1.__instanceId] || !locNodePriorityMap[node2.__instanceId]) + if( !l2 || !node2 || !locNodePriorityMap[node2.__instanceId] ) return -1; + else if( !l1 || !node1 || !locNodePriorityMap[node1.__instanceId] ) + return 1; return locNodePriorityMap[l2._getSceneGraphPriority().__instanceId] - locNodePriorityMap[l1._getSceneGraphPriority().__instanceId]; }, From 367ba065b9883ec73bec70aebea55e58685d9f7f Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 16 Jun 2015 16:46:40 +0800 Subject: [PATCH 101/839] Fixed a bug that Change the url failure(VideoPlayer) --- extensions/ccui/uiwidgets/UIVideoPlayer.js | 93 ++++++++++++++-------- 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index ff842577d7..597d9ca23b 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -50,14 +50,7 @@ ccui.VideoPlayer = ccui.Widget.extend({ * @returns {String} */ getURL: function() { - var video = this._renderCmd._video; - if (video) { - var source = video.getElementsByTagName("source"); - if (source && source[0]) - return source[0].src; - } - - return ""; + return this._renderCmd._url; }, /** @@ -65,8 +58,10 @@ ccui.VideoPlayer = ccui.Widget.extend({ */ play: function(){ var video = this._renderCmd._video; - if(video) + if(video){ + this._renderCmd._played = true; video.play(); + } }, /** @@ -248,12 +243,8 @@ ccui.VideoPlayer.EventType = { (function(polyfill){ ccui.VideoPlayer.RenderCmd = function(node){ cc.Node.CanvasRenderCmd.call(this, node); - this._video = document.createElement("video"); - //this._video.controls = "controls"; - this._video.preload = "metadata"; - this._video.style["visibility"] = "hidden"; - this._loaded = false; this._listener = null; + this._url = ""; this.initStyle(); }; @@ -332,36 +323,67 @@ ccui.VideoPlayer.EventType = { }; proto.updateURL = function(path){ - var video = this._video; - var source = document.createElement("source"); - source.src = path; - video.appendChild(source); - var extname = cc.path.extname(path); - for(var i=0; i Date: Tue, 16 Jun 2015 18:24:02 +0800 Subject: [PATCH 102/839] Change the path(UIVideoPlayerTest.js) --- extensions/ccui/uiwidgets/UIVideoPlayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/ccui/uiwidgets/UIVideoPlayer.js b/extensions/ccui/uiwidgets/UIVideoPlayer.js index 597d9ca23b..11bb68fce3 100644 --- a/extensions/ccui/uiwidgets/UIVideoPlayer.js +++ b/extensions/ccui/uiwidgets/UIVideoPlayer.js @@ -364,7 +364,7 @@ ccui.VideoPlayer.EventType = { }; video.addEventListener(polyfill.event, cb); - video.controls = "controls"; + //video.controls = "controls"; video.preload = "metadata"; video.style["visibility"] = "hidden"; this._loaded = false; From c0641b40e6981ffcd7deba28122e6ae0eb9596b6 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 17 Jun 2015 11:34:27 +0800 Subject: [PATCH 103/839] Preventing operation of the remote address error --- extensions/ccui/uiwidgets/UIWebView.js | 36 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/extensions/ccui/uiwidgets/UIWebView.js b/extensions/ccui/uiwidgets/UIWebView.js index e9ac910b60..b4afc7af4e 100644 --- a/extensions/ccui/uiwidgets/UIWebView.js +++ b/extensions/ccui/uiwidgets/UIWebView.js @@ -84,13 +84,17 @@ ccui.WebView = ccui.Widget.extend({ * go back */ goBack: function(){ - if(ccui.WebView._polyfill.closeHistory) - return cc.log("The current browser does not support the GoBack"); - var iframe = this._renderCmd._iframe; - if(iframe){ - var win = iframe.contentWindow; - if(win && win.location) - win.history.back(); + try{ + if(ccui.WebView._polyfill.closeHistory) + return cc.log("The current browser does not support the GoBack"); + var iframe = this._renderCmd._iframe; + if(iframe){ + var win = iframe.contentWindow; + if(win && win.location) + win.history.back(); + } + }catch(err){ + cc.log(err); } }, @@ -98,13 +102,17 @@ ccui.WebView = ccui.Widget.extend({ * go forward */ goForward: function(){ - if(ccui.WebView._polyfill.closeHistory) - return cc.log("The current browser does not support the GoForward"); - var iframe = this._renderCmd._iframe; - if(iframe){ - var win = iframe.contentWindow; - if(win && win.location) - win.history.forward(); + try{ + if(ccui.WebView._polyfill.closeHistory) + return cc.log("The current browser does not support the GoForward"); + var iframe = this._renderCmd._iframe; + if(iframe){ + var win = iframe.contentWindow; + if(win && win.location) + win.history.forward(); + } + }catch(err){ + cc.log(err); } }, From d8a7b863917772fbb3bb612cb37c36b074e7e6f4 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 17 Jun 2015 11:48:52 +0800 Subject: [PATCH 104/839] Fixed widgetFromJsonFile bug(#20035) --- extensions/cocostudio/loader/parsers/compatible.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/cocostudio/loader/parsers/compatible.js b/extensions/cocostudio/loader/parsers/compatible.js index 3f34b13956..caa681d4fc 100644 --- a/extensions/cocostudio/loader/parsers/compatible.js +++ b/extensions/cocostudio/loader/parsers/compatible.js @@ -41,7 +41,7 @@ * @returns {*} */ widgetFromJsonFile: function(file){ - var json = cc.loader.getRes(cc.path.join(cc.loader.resPath, file)); + var json = cc.loader.getRes(file); if(json) this._fileDesignSizes[file] = cc.size(json["designWidth"]||0, json["designHeight"]||0); From 900744fd49669196eb4ae3e6fa125d4b0855d636 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 17 Jun 2015 13:52:54 +0800 Subject: [PATCH 105/839] Prevent reference method does not exist --- cocos2d/core/utils/BinaryLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/utils/BinaryLoader.js b/cocos2d/core/utils/BinaryLoader.js index f0e692dc3b..e199733458 100644 --- a/cocos2d/core/utils/BinaryLoader.js +++ b/cocos2d/core/utils/BinaryLoader.js @@ -107,7 +107,7 @@ cc.loader.loadBinarySync = function (url) { //Compatibility with IE9 window.Uint8Array = window.Uint8Array || window.Array; -if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) { +if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) && window.IEBinaryToArray_ByteStr && window.IEBinaryToArray_ByteStr_Last) { var IEBinaryToArray_ByteStr_Script = "\r\n" + //"