mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 16:52:43 +08:00
Merge pull request #2387 from umbrellaPP/next
2.0, 整理优化 literalMap 和 flatMap
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
require('../core/platform/CCClass');
|
||||
var JS = require('../core/platform/js');
|
||||
|
||||
/*
|
||||
* @class HashElement
|
||||
@@ -60,7 +61,7 @@ var HashElement = function () {
|
||||
* @example {@link utils/api/engine/docs/cocos2d/core/CCActionManager/ActionManager.js}
|
||||
*/
|
||||
cc.ActionManager = function () {
|
||||
this._hashTargets = {};
|
||||
this._hashTargets = JS.createMap(true);
|
||||
this._arrayTargets = [];
|
||||
this._currentTarget = null;
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
|
||||
@@ -24,11 +24,12 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var JS = require('../core/platform/js');
|
||||
var Audio = require('./CCAudio');
|
||||
|
||||
var instanceId = 0;
|
||||
var id2audio = {};
|
||||
var url2id = {};
|
||||
var id2audio = JS.createMap(true);
|
||||
var url2id = JS.createMap(true);
|
||||
|
||||
var getAudioFromPath = function (path) {
|
||||
var id = instanceId++;
|
||||
@@ -439,8 +440,8 @@ var audioEngine = {
|
||||
*/
|
||||
uncacheAll: function () {
|
||||
this.stopAll();
|
||||
id2audio = {};
|
||||
url2id = {};
|
||||
id2audio = JS.createMap(true);
|
||||
url2id = JS.createMap(true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
|
||||
var JS = require('./platform/js');
|
||||
var MAX_POOL_SIZE = 20;
|
||||
|
||||
//data structures
|
||||
@@ -285,8 +285,8 @@ cc.Scheduler = function () {
|
||||
this._updatesNegList = []; // list of priority < 0
|
||||
this._updates0List = []; // list of priority == 0
|
||||
this._updatesPosList = []; // list of priority > 0
|
||||
this._hashForUpdates = {}; // hash used to fetch quickly the list entries for pause, delete, etc
|
||||
this._hashForTimers = {}; // Used for "selectors with interval"
|
||||
this._hashForUpdates = JS.createMap(true); // hash used to fetch quickly the list entries for pause, delete, etc
|
||||
this._hashForTimers = JS.createMap(true); // Used for "selectors with interval"
|
||||
this._currentTarget = null;
|
||||
this._currentTargetSalvaged = false;
|
||||
this._updateHashLocked = false; // If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
var AnimationAnimator = require('../../animation/animation-animator');
|
||||
var AnimationClip = require('../../animation/animation-clip');
|
||||
var JS = require('../platform/js');
|
||||
|
||||
function equalClips (clip1, clip2) {
|
||||
if (clip1 === clip2) {
|
||||
@@ -76,7 +77,7 @@ var Animation = cc.Class({
|
||||
// The actual implement for Animation
|
||||
this._animator = null;
|
||||
|
||||
this._nameToState = {};
|
||||
this._nameToState = JS.createMap(true);
|
||||
this._didInit = false;
|
||||
|
||||
this._currentClip = null;
|
||||
@@ -591,7 +592,7 @@ var Animation = cc.Class({
|
||||
},
|
||||
|
||||
_createStates: function() {
|
||||
this._nameToState = {};
|
||||
this._nameToState = JS.createMap(true);
|
||||
|
||||
// create animation states
|
||||
var state = null;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
var js = require('../platform/js');
|
||||
var JS = require('../platform/js');
|
||||
require('./CCEventListener');
|
||||
var ListenerID = cc.EventListener.ListenerID;
|
||||
|
||||
@@ -113,7 +113,7 @@ var eventManager = {
|
||||
_listenersMap: {},
|
||||
_priorityDirtyFlagMap: {},
|
||||
_nodeListenersMap: {},
|
||||
_nodePriorityMap: {},
|
||||
_nodePriorityMap: JS.createMap(true),
|
||||
_globalZOrderNodeMap: [],
|
||||
_toAddedListeners: [],
|
||||
_toRemovedListeners: [],
|
||||
@@ -316,7 +316,7 @@ var eventManager = {
|
||||
|
||||
// Reset priority index
|
||||
this._nodePriorityIndex = 0;
|
||||
this._nodePriorityMap = {};
|
||||
this._nodePriorityMap = JS.createMap(true);
|
||||
|
||||
this._visitTarget(rootNode, true);
|
||||
|
||||
@@ -1088,7 +1088,7 @@ var eventManager = {
|
||||
};
|
||||
|
||||
|
||||
js.get(cc, 'eventManager', function () {
|
||||
JS.get(cc, 'eventManager', function () {
|
||||
cc.warnID(1405, 'cc.eventManager', 'cc.EventTarget or cc.systemEvent');
|
||||
return eventManager;
|
||||
});
|
||||
|
||||
@@ -122,7 +122,7 @@ function CCLoader () {
|
||||
this.onProgress = null;
|
||||
|
||||
// assets to release automatically
|
||||
this._autoReleaseSetting = {};
|
||||
this._autoReleaseSetting = JS.createMap(true);
|
||||
|
||||
if (CC_DEBUG) {
|
||||
this._releasedAssetChecker_DEBUG = new ReleasedAssetChecker();
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
var pushToMap = require('../utils/misc').pushToMap;
|
||||
var JS = require('../platform/js');
|
||||
|
||||
function Entry (uuid, type) {
|
||||
this.uuid = uuid;
|
||||
@@ -38,7 +39,7 @@ function Entry (uuid, type) {
|
||||
*/
|
||||
|
||||
function AssetTable () {
|
||||
this._pathToUuid = {};
|
||||
this._pathToUuid = JS.createMap(true);
|
||||
}
|
||||
|
||||
function isMatchByWord (path, test) {
|
||||
@@ -164,7 +165,7 @@ proto._getInfo_DEBUG = CC_DEBUG && function (uuid, out_info) {
|
||||
};
|
||||
|
||||
proto.reset = function () {
|
||||
this._pathToUuid = {};
|
||||
this._pathToUuid = JS.createMap(true);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ require('../utils/CCPath');
|
||||
var JS = require('../platform/js');
|
||||
|
||||
var _qid = (0|(Math.random()*998));
|
||||
var _queues = {};
|
||||
var _queues = JS.createMap(true);
|
||||
var _pool = [];
|
||||
var _POOL_MAX_LENGTH = 10;
|
||||
|
||||
@@ -38,7 +38,7 @@ var ItemState = {
|
||||
ERROR: 3
|
||||
};
|
||||
|
||||
var _queueDeps = {};
|
||||
var _queueDeps = JS.createMap(true);
|
||||
|
||||
function isIdValid (id) {
|
||||
var realId = id.url || id;
|
||||
@@ -211,7 +211,7 @@ var LoadingItems = function (pipeline, urlList, onProgress, onComplete) {
|
||||
* @property map
|
||||
* @type {Object}
|
||||
*/
|
||||
this.map = {};
|
||||
this.map = JS.createMap(true);
|
||||
|
||||
/**
|
||||
* !#en The map of completed items.
|
||||
@@ -730,7 +730,7 @@ proto.destroy = function () {
|
||||
this.onProgress = null;
|
||||
this.onComplete = null;
|
||||
|
||||
this.map = {};
|
||||
this.map = JS.createMap(true);
|
||||
this.completed = {};
|
||||
|
||||
this.totalCount = 0;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
var Unpackers = require('./unpackers');
|
||||
var pushToMap = require('../utils/misc').pushToMap;
|
||||
var JS = require('../platform/js');
|
||||
|
||||
// when more than one package contains the required asset,
|
||||
// choose to load from the package with the largest state value.
|
||||
@@ -43,14 +44,14 @@ function UnpackerData () {
|
||||
// {assetUuid: packUuid|[packUuid]}
|
||||
// If value is array of packUuid, then the first one will be prioritized for download,
|
||||
// so the smallest pack must be at the beginning of the array.
|
||||
var uuidToPack = {};
|
||||
var uuidToPack = JS.createMap(true);
|
||||
|
||||
// {packUuid: assetIndices}
|
||||
var packIndices = {};
|
||||
var packIndices = JS.createMap(true);
|
||||
|
||||
// {packUuid: UnpackerData}
|
||||
// We have to cache all packs in global because for now there's no operation context in loader.
|
||||
var globalUnpackers = {};
|
||||
var globalUnpackers = JS.createMap(true);
|
||||
|
||||
|
||||
function error (uuid, packUuid) {
|
||||
@@ -177,8 +178,8 @@ module.exports = {
|
||||
if (CC_TEST) {
|
||||
cc._Test.PackDownloader = module.exports;
|
||||
cc._Test.PackDownloader.reset = function () {
|
||||
uuidToPack = {};
|
||||
packIndices = {};
|
||||
globalUnpackers = {};
|
||||
uuidToPack = JS.createMap(true);
|
||||
packIndices = JS.createMap(true);
|
||||
globalUnpackers = JS.createMap(true);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ function flow (pipe, item) {
|
||||
*/
|
||||
var Pipeline = function (pipes) {
|
||||
this._pipes = pipes;
|
||||
this._cache = {};
|
||||
this._cache = JS.createMap(true);
|
||||
|
||||
for (var i = 0; i < pipes.length; ++i) {
|
||||
var pipe = pipes[i];
|
||||
|
||||
@@ -30,6 +30,7 @@ var PackDownloader = require('../load-pipeline/pack-downloader');
|
||||
var AutoReleaseUtils = require('../load-pipeline/auto-release-utils');
|
||||
var decodeUuid = require('../utils/decode-uuid');
|
||||
var MD5Pipe = require('../load-pipeline/md5-pipe');
|
||||
var JS = require('./js');
|
||||
|
||||
/**
|
||||
* The asset library which managing loading/unloading assets in project.
|
||||
@@ -42,7 +43,7 @@ var MD5Pipe = require('../load-pipeline/md5-pipe');
|
||||
|
||||
var _libraryBase = '';
|
||||
var _rawAssetsBase = ''; // The base dir for raw assets in runtime
|
||||
var _uuidToRawAsset = {};
|
||||
var _uuidToRawAsset = JS.createMap(true);
|
||||
|
||||
function isScene (asset) {
|
||||
return asset && (asset.constructor === cc.SceneAsset || asset instanceof cc.Scene);
|
||||
|
||||
@@ -33,7 +33,7 @@ const gfx = renderEngine.gfx;
|
||||
const SpriteMaterial = renderEngine.SpriteMaterial;
|
||||
const RenderData = renderEngine.RenderData;
|
||||
|
||||
let _sharedMaterials = {};
|
||||
let _sharedMaterials = js.createMap();
|
||||
|
||||
let _slotColor = cc.color(0, 0, 255, 255);
|
||||
let _boneColor = cc.color(255, 0, 0, 255);
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
var JS = cc.js;
|
||||
|
||||
module.exports = (function () {
|
||||
'use strict';
|
||||
|
||||
@@ -12736,7 +12738,7 @@ module.exports = (function () {
|
||||
this._precision = `precision highp float;\n`;
|
||||
|
||||
// register templates
|
||||
this._templates = {};
|
||||
this._templates = JS.createMap();
|
||||
for (let i = 0; i < templates.length; ++i) {
|
||||
let tmpl = templates[i];
|
||||
this.define(tmpl.name, tmpl.vert, tmpl.frag, tmpl.defines);
|
||||
@@ -12746,7 +12748,7 @@ module.exports = (function () {
|
||||
this._chunks = {};
|
||||
Object.assign(this._chunks, chunks);
|
||||
|
||||
this._cache = {};
|
||||
this._cache = JS.createMap(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -14224,7 +14226,7 @@ module.exports = (function () {
|
||||
|
||||
class MaterialUtil {
|
||||
constructor () {
|
||||
this._cache = {};
|
||||
this._cache = JS.createMap(true);
|
||||
}
|
||||
|
||||
get (key) {
|
||||
|
||||
@@ -29,6 +29,7 @@ require('../cocos2d/core/platform/CCClass');
|
||||
require('../cocos2d/core/assets/CCAsset');
|
||||
var WebTexture = require('../cocos2d/core/textures/CCTexture2D');
|
||||
var WebSpriteFrame = require('../cocos2d/core/sprites/CCSpriteFrame');
|
||||
var JS = cc.js;
|
||||
|
||||
cc.js.unregisterClass(WebTexture, WebSpriteFrame);
|
||||
|
||||
@@ -80,7 +81,7 @@ prototype.addImage = function (url, cb, target) {
|
||||
|
||||
// cc.textureCache
|
||||
|
||||
cc.textureCache._textures = {};
|
||||
cc.textureCache._textures = JS.createMap(true);
|
||||
cc.textureCache.cacheImage = function (key, texture) {
|
||||
if (texture instanceof cc.Texture2D) {
|
||||
this._textures[key] = texture;
|
||||
|
||||
Reference in New Issue
Block a user