From 92319bb2cee1c0cb93ca87cb38307afa13ca774d Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 22 Aug 2017 16:23:54 +0800 Subject: [PATCH 1/3] tweaks --- cocos2d/core/CCDirector.js | 2 +- cocos2d/core/component-scheduler.js | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index b61e7681ff..96e914cc79 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -589,9 +589,9 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ sgScene = scene._sgNode; // Re-attach or replace persist nodes + CC_BUILD && CC_DEBUG && console.time('AttachPersist'); for (let i = 0; i < persistNodeList.length; i++) { let node = persistNodeList[i]; - CC_BUILD && CC_DEBUG && console.time('AttachPersist'); var existNode = scene.getChildByUuid(node.uuid); if (existNode) { // scene also contains the persist node, select the old one diff --git a/cocos2d/core/component-scheduler.js b/cocos2d/core/component-scheduler.js index 676a3547b9..5f0bbfd910 100644 --- a/cocos2d/core/component-scheduler.js +++ b/cocos2d/core/component-scheduler.js @@ -203,14 +203,14 @@ function enableInEditor (comp) { } } -function createInvokeImpl (code, useDt) { +function createInvokeImpl (funcOrCode, useDt) { if (CC_EDITOR) { if (useDt) { return function (iterator, dt) { var array = iterator.array; for (iterator.i = 0; iterator.i < array.length; ++iterator.i) { var comp = array[iterator.i]; - code(comp, dt); + funcOrCode(comp, dt); } }; } @@ -219,7 +219,7 @@ function createInvokeImpl (code, useDt) { var array = iterator.array; for (iterator.i = 0; iterator.i < array.length; ++iterator.i) { var comp = array[iterator.i]; - code(comp); + funcOrCode(comp); } }; } @@ -235,7 +235,7 @@ function createInvokeImpl (code, useDt) { var body = 'var a=it.array;' + 'for(it.i=0;it.i Date: Mon, 14 Aug 2017 10:25:42 +0800 Subject: [PATCH 2/3] remove some old deprecated code --- cocos2d/deprecated.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 5117c57c35..2c7f620613 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -62,12 +62,6 @@ if (CC_DEV) { return typeof obj === 'function'; }; }); - js.get(cc.js, "isFunction", function () { - cc.warnID(1400, 'cc.js.isFunction', '"typeof obj === \'function\'"'); - return function(obj) { - return typeof obj === 'function'; - }; - }); /** * Check the obj whether is number or not @@ -101,12 +95,6 @@ if (CC_DEV) { return Array.isArray(obj); }; }); - js.get(cc.js, "isArray", function () { - cc.warnID(1400, 'cc.js.isArray', '"Array.isArray(obj)"'); - return function(obj) { - return Array.isArray(obj); - }; - }); js.get(cc, "isUndefined", function () { cc.warnID(1400, 'cc.isUndefined', '"typeof obj === \'undefined\'"'); @@ -114,12 +102,6 @@ if (CC_DEV) { return typeof obj === 'undefined'; }; }); - js.get(cc.js, "isUndefined", function () { - cc.warnID(1400, 'cc.js.isUndefined', '"typeof obj === \'undefined\'"'); - return function(obj) { - return typeof obj === 'undefined'; - }; - }); js.get(cc, "isObject", function () { cc.warnID(1400, 'cc.isObject', '"typeof obj === \'object\'"'); @@ -128,13 +110,6 @@ if (CC_DEV) { }; }); - js.get(cc.js, "isObject", function () { - cc.warnID(1400, 'cc.js.isObject', '"typeof obj === \'object\'"'); - return function(obj) { - return typeof obj === "object"; - }; - }); - /** * cc.Point is the class for point object, please do not use its constructor to create points, use cc.p() alias function instead. * @class cc.Point @@ -698,6 +673,3 @@ if (CC_DEV) { }); } - -// remove after 1.6 -js.obsolete(cc.loader, 'cc.loader.loadResAll', 'loadResDir'); From 785d43baf116650c7a18576988f138929fb6e612 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 14 Aug 2017 15:25:09 +0800 Subject: [PATCH 3/3] add misc.pushToMap --- cocos2d/core/load-pipeline/CCLoader.js | 4 +-- cocos2d/core/load-pipeline/asset-table.js | 27 +++---------------- cocos2d/core/load-pipeline/pack-downloader.js | 22 +++------------ cocos2d/core/utils/misc.js | 22 +++++++++++++++ 4 files changed, 31 insertions(+), 44 deletions(-) diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index 2451757eda..0c24f509fc 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -234,7 +234,7 @@ proto.load = function(resources, progressCallback, completeCallback) { callInNextTick(function () { if (completeCallback) { if (singleRes) { - var id = res.url; + let id = res.url; completeCallback.call(self, items.getError(id), items.getContent(id)); } else { @@ -244,7 +244,7 @@ proto.load = function(resources, progressCallback, completeCallback) { } if (CC_EDITOR) { - for (var id in self._cache) { + for (let id in self._cache) { if (self._cache[id].complete) { self.removeItem(id); } diff --git a/cocos2d/core/load-pipeline/asset-table.js b/cocos2d/core/load-pipeline/asset-table.js index 95b2ff2a67..20b734877b 100644 --- a/cocos2d/core/load-pipeline/asset-table.js +++ b/cocos2d/core/load-pipeline/asset-table.js @@ -23,6 +23,8 @@ THE SOFTWARE. ****************************************************************************/ +var pushToMap = require('../utils/misc').pushToMap; + function Entry (uuid, type) { this.uuid = uuid; this.type = type; @@ -133,30 +135,7 @@ proto.add = function (path, uuid, type, isMainAsset) { // (can not use path.slice because length of extname maybe 0) path = path.substring(0, path.length - cc.path.extname(path).length); var newEntry = new Entry(uuid, type); - var pathToUuid = this._pathToUuid; - var exists = pathToUuid[path]; - if (exists) { - if (Array.isArray(exists)) { - if (isMainAsset) { - // load main asset first - exists.unshift(newEntry); - } - else { - exists.push(newEntry); - } - } - else { - if (isMainAsset) { - pathToUuid[path] = [newEntry, exists]; - } - else { - pathToUuid[path] = [exists, newEntry]; - } - } - } - else { - pathToUuid[path] = newEntry; - } + pushToMap(this._pathToUuid, path, newEntry, isMainAsset); }; proto.reset = function () { diff --git a/cocos2d/core/load-pipeline/pack-downloader.js b/cocos2d/core/load-pipeline/pack-downloader.js index b60ba7df46..4fd1c52b8a 100644 --- a/cocos2d/core/load-pipeline/pack-downloader.js +++ b/cocos2d/core/load-pipeline/pack-downloader.js @@ -24,6 +24,7 @@ ****************************************************************************/ var JsonUnpacker = require('./json-unpacker'); +var pushToMap = require('../utils/misc').pushToMap; // {assetUuid: packUuid|[packUuid]} // If value is array of packUuid, then the first one will be prioritized for download, @@ -57,24 +58,9 @@ module.exports = { var uuids = packs[packUuid]; for (var i = 0; i < uuids.length; i++) { var uuid = uuids[i]; - var allIncludedPacks = uuidToPack[uuid]; - if (allIncludedPacks) { - if (Array.isArray(allIncludedPacks)) { - allIncludedPacks.push(packUuid); - } - else { - uuidToPack[uuid] = allIncludedPacks = [allIncludedPacks, packUuid]; - } - if (uuids.length === 1) { - // the smallest pack must be at the beginning of the array to download more first - var swapToLast = allIncludedPacks[0]; - allIncludedPacks[0] = allIncludedPacks[allIncludedPacks.length - 1]; - allIncludedPacks[allIncludedPacks.length - 1] = swapToLast; - } - } - else { - uuidToPack[uuid] = packUuid; - } + // the smallest pack must be at the beginning of the array to download more first + var pushFront = uuids.length === 1; + pushToMap(uuidToPack, uuid, packUuid, pushFront); } } }, diff --git a/cocos2d/core/utils/misc.js b/cocos2d/core/utils/misc.js index e576f74298..f2d26ba72d 100644 --- a/cocos2d/core/utils/misc.js +++ b/cocos2d/core/utils/misc.js @@ -139,3 +139,25 @@ for (let i = 0; i < 64; ++i) BASE64_VALUES[BASE64_KEYS.charCodeAt(i)] = i; // decoded value indexed by base64 char code misc.BASE64_VALUES = BASE64_VALUES; + +// set value to map, if key exists, push to array +misc.pushToMap = function (map, key, value, pushFront) { + var exists = map[key]; + if (exists) { + if (Array.isArray(exists)) { + if (pushFront) { + exists.push(exists[0]); + exists[0] = value; + } + else { + exists.push(value); + } + } + else { + map[key] = (pushFront ? [value, exists] : [exists, value]); + } + } + else { + map[key] = value; + } +};