mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Remove __instanceId from Node and Component (#2627)
* Add Scheduler.enableForTarget and change to use _id * Use _id instead of __instanceId in Texture2D * Fix ParticleSystem __instanceId usage * Use _id instead of __instanceId in ActionManager * Fix usage of Scheduler in InputManager * Use _id instead of __instanceId in EventManager * Totally remove ClassManager and __instanceId * Fix initialization process * Fix touch & mouse listener off check issue * Fix id not generated issue * Fix touch & mouse listener being removed by rejected persist node * Improve logic
This commit is contained in:
@@ -298,6 +298,10 @@ cc.Scheduler: pause state of the scheduled task doesn't match the element pause
|
||||
|
||||
cc.Scheduler: updateFunc parameter is deprecated in scheduleUpdate function, and will be removed in v2.0
|
||||
|
||||
### 1513
|
||||
|
||||
cc.Scheduler: scheduler stopped using `__instanceId` as id since v2.0, you should do scheduler.enableForTarget(target) before all scheduler API usage on target
|
||||
|
||||
### 1600
|
||||
|
||||
getZOrder is deprecated. Please use getLocalZOrder instead.
|
||||
|
||||
@@ -65,7 +65,7 @@ cc.ActionManager = function () {
|
||||
this._hashTargets = js.createMap(true);
|
||||
this._arrayTargets = [];
|
||||
this._currentTarget = null;
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
|
||||
};
|
||||
cc.ActionManager.prototype = {
|
||||
constructor: cc.ActionManager,
|
||||
@@ -123,11 +123,11 @@ cc.ActionManager.prototype = {
|
||||
throw new Error(cc._getError(1000));
|
||||
|
||||
//check if the action target already exists
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
//if doesn't exists, create a hashelement and push in mpTargets
|
||||
if (!element) {
|
||||
element = this._getElement(target, paused);
|
||||
this._hashTargets[target.__instanceId] = element;
|
||||
this._hashTargets[target._id] = element;
|
||||
this._arrayTargets.push(element);
|
||||
}
|
||||
else if (!element.actions) {
|
||||
@@ -166,7 +166,7 @@ cc.ActionManager.prototype = {
|
||||
// explicit null handling
|
||||
if (target == null)
|
||||
return;
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
if (element) {
|
||||
element.actions.length = 0;
|
||||
this._deleteHashElement(element);
|
||||
@@ -183,7 +183,7 @@ cc.ActionManager.prototype = {
|
||||
if (action == null)
|
||||
return;
|
||||
var target = action.getOriginalTarget();
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
|
||||
if (element) {
|
||||
for (var i = 0; i < element.actions.length; i++) {
|
||||
@@ -213,7 +213,7 @@ cc.ActionManager.prototype = {
|
||||
|
||||
cc.assertID(target, 1003);
|
||||
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
|
||||
if (element) {
|
||||
var limit = element.actions.length;
|
||||
@@ -239,7 +239,7 @@ cc.ActionManager.prototype = {
|
||||
if(tag === cc.Action.TAG_INVALID)
|
||||
cc.logID(1004);
|
||||
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
if (element) {
|
||||
if (element.actions != null) {
|
||||
for (var i = 0; i < element.actions.length; ++i) {
|
||||
@@ -273,7 +273,7 @@ cc.ActionManager.prototype = {
|
||||
* @return {Number}
|
||||
*/
|
||||
getNumberOfRunningActionsInTarget:function (target) {
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
if (element)
|
||||
return (element.actions) ? element.actions.length : 0;
|
||||
|
||||
@@ -286,7 +286,7 @@ cc.ActionManager.prototype = {
|
||||
* @param {Node} target
|
||||
*/
|
||||
pauseTarget:function (target) {
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
if (element)
|
||||
element.paused = true;
|
||||
},
|
||||
@@ -297,7 +297,7 @@ cc.ActionManager.prototype = {
|
||||
* @param {Node} target
|
||||
*/
|
||||
resumeTarget:function (target) {
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
if (element)
|
||||
element.paused = false;
|
||||
},
|
||||
@@ -384,8 +384,8 @@ cc.ActionManager.prototype = {
|
||||
_deleteHashElement:function (element) {
|
||||
var ret = false;
|
||||
if (element && !element.lock) {
|
||||
if (this._hashTargets[element.target.__instanceId]) {
|
||||
delete this._hashTargets[element.target.__instanceId];
|
||||
if (this._hashTargets[element.target._id]) {
|
||||
delete this._hashTargets[element.target._id];
|
||||
var targets = this._arrayTargets;
|
||||
for (var i = 0, l = targets.length; i < l; i++) {
|
||||
if (targets[i] === element) {
|
||||
@@ -444,7 +444,7 @@ cc.ActionManager.prototype = {
|
||||
|
||||
if (CC_TEST) {
|
||||
cc.ActionManager.prototype.isTargetPaused_TEST = function (target) {
|
||||
var element = this._hashTargets[target.__instanceId];
|
||||
var element = this._hashTargets[target._id];
|
||||
return element.paused;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,11 +27,10 @@ var js = cc.js;
|
||||
|
||||
var AnimationManager = cc.Class({
|
||||
ctor: function () {
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
|
||||
this._anims = new js.array.MutableForwardIterator([]);
|
||||
|
||||
this._delayEvents = [];
|
||||
|
||||
cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
|
||||
},
|
||||
|
||||
// for manager
|
||||
|
||||
@@ -337,7 +337,7 @@ cc.Director.prototype = {
|
||||
*/
|
||||
purgeDirector: function () {
|
||||
//cleanup scheduler
|
||||
this.getScheduler().unscheduleAll();
|
||||
this._scheduler.unscheduleAll();
|
||||
this._compScheduler.unscheduleAll();
|
||||
|
||||
this._nodeActivator.reset();
|
||||
@@ -1127,18 +1127,6 @@ cc.Director.EVENT_BEFORE_DRAW = "director_before_draw";
|
||||
*/
|
||||
cc.Director.EVENT_AFTER_DRAW = "director_after_draw";
|
||||
|
||||
cc.Director.sharedDirector = null;
|
||||
cc.Director.firstUseDirector = true;
|
||||
|
||||
cc.Director._getInstance = function () {
|
||||
if (cc.Director.firstUseDirector) {
|
||||
cc.Director.firstUseDirector = false;
|
||||
cc.Director.sharedDirector = new cc.Director();
|
||||
cc.Director.sharedDirector.init();
|
||||
}
|
||||
return cc.Director.sharedDirector;
|
||||
};
|
||||
|
||||
//Possible OpenGL projections used by director
|
||||
|
||||
/**
|
||||
|
||||
+12
-10
@@ -406,12 +406,20 @@ var game = {
|
||||
if (cc._engineLoaded) {
|
||||
this._prepareCalled = true;
|
||||
|
||||
this._initRenderer(config[CONFIG_KEY.width], config[CONFIG_KEY.height]);
|
||||
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en Director
|
||||
* !#zh 导演类。
|
||||
* @property director
|
||||
* @type {Director}
|
||||
*/
|
||||
cc.director = new cc.Director();
|
||||
|
||||
this._initRenderer(config[CONFIG_KEY.width], config[CONFIG_KEY.height]);
|
||||
|
||||
/**
|
||||
* !#en cc.view is the shared view object.
|
||||
* !#zh cc.view 是全局的视图对象。
|
||||
@@ -419,14 +427,8 @@ var game = {
|
||||
* @type {View}
|
||||
*/
|
||||
cc.view = View ? View._getInstance() : null;
|
||||
|
||||
/**
|
||||
* !#en Director
|
||||
* !#zh 导演类。
|
||||
* @property director
|
||||
* @type {Director}
|
||||
*/
|
||||
cc.director = cc.Director._getInstance();
|
||||
|
||||
cc.director.init();
|
||||
|
||||
/**
|
||||
* !#en cc.winSize is the alias object for the size of the current game window.
|
||||
|
||||
+37
-27
@@ -1148,15 +1148,19 @@ var Node = cc.Class({
|
||||
_currentHovered = null;
|
||||
}
|
||||
|
||||
if (this._touchListener) {
|
||||
this._touchListener.owner = null;
|
||||
this._touchListener.mask = null;
|
||||
this._touchListener = null;
|
||||
}
|
||||
if (this._mouseListener) {
|
||||
this._mouseListener.owner = null;
|
||||
this._mouseListener.mask = null;
|
||||
this._mouseListener = null;
|
||||
// Remove all event listeners if necessary
|
||||
if (this._touchListener || this._mouseListener) {
|
||||
eventManager.removeListeners(this);
|
||||
if (this._touchListener) {
|
||||
this._touchListener.owner = null;
|
||||
this._touchListener.mask = null;
|
||||
this._touchListener = null;
|
||||
}
|
||||
if (this._mouseListener) {
|
||||
this._mouseListener.owner = null;
|
||||
this._mouseListener.mask = null;
|
||||
this._mouseListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Recycle math objects
|
||||
@@ -1167,8 +1171,6 @@ var Node = cc.Class({
|
||||
cc.director.__fastOff(cc.Director.EVENT_AFTER_UPDATE, this.sortAllChildren, this);
|
||||
}
|
||||
|
||||
eventManager.removeListeners(this);
|
||||
|
||||
if (!destroyByParent) {
|
||||
// simulate some destruct logic to make undo system work correctly
|
||||
if (CC_EDITOR) {
|
||||
@@ -1260,6 +1262,10 @@ var Node = cc.Class({
|
||||
_onBatchCreated () {
|
||||
this._upgrade_1x_to_2x();
|
||||
|
||||
if (!this._id) {
|
||||
this._id = CC_EDITOR ? Editor.Utils.UuidUtils.uuid() : BaseNode.idGenerater.getNewId();
|
||||
}
|
||||
|
||||
this._updateOrderOfArrival();
|
||||
|
||||
let prefabInfo = this._prefab;
|
||||
@@ -1288,6 +1294,10 @@ var Node = cc.Class({
|
||||
// the same as _onBatchCreated but untouch prefab
|
||||
_onBatchRestored () {
|
||||
this._upgrade_1x_to_2x();
|
||||
|
||||
if (!this._id) {
|
||||
this._id = CC_EDITOR ? Editor.Utils.UuidUtils.uuid() : BaseNode.idGenerater.getNewId();
|
||||
}
|
||||
|
||||
if (!this._activeInHierarchy) {
|
||||
// deactivate ActionManager and EventManager by default
|
||||
@@ -1492,23 +1502,23 @@ var Node = cc.Class({
|
||||
* node.off(cc.Node.EventType.ANCHOR_CHANGED, callback, this);
|
||||
*/
|
||||
off (type, callback, target, useCapture) {
|
||||
let forDispatch = false;
|
||||
if (_touchEvents.indexOf(type) !== -1) {
|
||||
if (this._touchListener && !_checkListeners(this, _touchEvents)) {
|
||||
eventManager.removeListener(this._touchListener);
|
||||
this._touchListener = null;
|
||||
}
|
||||
forDispatch = true;
|
||||
}
|
||||
else if (_mouseEvents.indexOf(type) !== -1) {
|
||||
if (this._mouseListener && !_checkListeners(this, _mouseEvents)) {
|
||||
eventManager.removeListener(this._mouseListener);
|
||||
this._mouseListener = null;
|
||||
}
|
||||
forDispatch = true;
|
||||
}
|
||||
if (forDispatch) {
|
||||
let touchEvent = _touchEvents.indexOf(type) !== -1;
|
||||
let mouseEvent = !touchEvent && _mouseEvents.indexOf(type) !== -1;
|
||||
if (touchEvent || mouseEvent) {
|
||||
this._offDispatch(type, callback, target, useCapture);
|
||||
|
||||
if (touchEvent) {
|
||||
if (this._touchListener && !_checkListeners(this, _touchEvents)) {
|
||||
eventManager.removeListener(this._touchListener);
|
||||
this._touchListener = null;
|
||||
}
|
||||
}
|
||||
else if (mouseEvent) {
|
||||
if (this._mouseListener && !_checkListeners(this, _mouseEvents)) {
|
||||
eventManager.removeListener(this._mouseListener);
|
||||
this._mouseListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this._bubblingListeners) {
|
||||
this._bubblingListeners.off(type, callback, target);
|
||||
|
||||
+118
-30
@@ -27,8 +27,11 @@
|
||||
/**
|
||||
* @module cc
|
||||
*/
|
||||
var js = require('./platform/js');
|
||||
var MAX_POOL_SIZE = 20;
|
||||
const js = require('./platform/js');
|
||||
const IdGenerater = require('./platform/id-generater');
|
||||
const MAX_POOL_SIZE = 20;
|
||||
|
||||
var idGenerater = new IdGenerater('Scheduler');
|
||||
|
||||
//data structures
|
||||
/*
|
||||
@@ -256,10 +259,6 @@ CallbackTimer.put = function (timer) {
|
||||
}
|
||||
};
|
||||
|
||||
var getTargetId = function (target) {
|
||||
return target.__instanceId || target.uuid;
|
||||
};
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Scheduler is responsible of triggering the scheduled callbacks.<br/>
|
||||
@@ -301,7 +300,7 @@ cc.Scheduler.prototype = {
|
||||
//-----------------------private method----------------------
|
||||
|
||||
_removeHashElement: function (element) {
|
||||
delete this._hashForTimers[getTargetId(element.target)];
|
||||
delete this._hashForTimers[element.target._id];
|
||||
var arr = this._arrayForTimers;
|
||||
for (var i = 0, l = arr.length; i < l; i++) {
|
||||
if (arr[i] === element) {
|
||||
@@ -313,7 +312,7 @@ cc.Scheduler.prototype = {
|
||||
},
|
||||
|
||||
_removeUpdateFromHash: function (entry) {
|
||||
var targetId = getTargetId(entry.target);
|
||||
var targetId = entry.target._id;
|
||||
var self = this, element = self._hashForUpdates[targetId];
|
||||
if (element) {
|
||||
// Remove list entry from list
|
||||
@@ -346,6 +345,25 @@ cc.Scheduler.prototype = {
|
||||
},
|
||||
|
||||
//-----------------------public method-------------------------
|
||||
/**
|
||||
* !en This method should be called for any target which needs to schedule tasks, and this method should be called before any scheduler API usage.
|
||||
* This method will add a `_id` property if it doesn't exist.
|
||||
* !zh 任何需要用 Scheduler 管理任务的对象主体都应该调用这个方法,并且应该在调用任何 Scheduler API 之前调用这个方法。
|
||||
* 这个方法会给对象添加一个 `_id` 属性,如果这个属性不存在的话。
|
||||
* @method enableForTarget
|
||||
* @param {Object} target
|
||||
*/
|
||||
enableForTarget: function (target) {
|
||||
if (!target._id) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
}
|
||||
else {
|
||||
target._id = idGenerater.getNewId();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Modifies the time of all scheduled callbacks.<br/>
|
||||
@@ -494,14 +512,22 @@ cc.Scheduler.prototype = {
|
||||
|
||||
cc.assertID(target, 1502);
|
||||
|
||||
var instanceId = getTargetId(target);
|
||||
cc.assertID(instanceId, 1510);
|
||||
var element = this._hashForTimers[instanceId];
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
var element = this._hashForTimers[targetId];
|
||||
if (!element) {
|
||||
// Is this the 1st element ? Then set the pause level to all the callback_fns of this target
|
||||
element = HashTimerEntry.get(null, target, 0, null, null, paused);
|
||||
this._arrayForTimers.push(element);
|
||||
this._hashForTimers[instanceId] = element;
|
||||
this._hashForTimers[targetId] = element;
|
||||
} else if (element.paused !== paused) {
|
||||
cc.warnID(1511);
|
||||
}
|
||||
@@ -544,8 +570,16 @@ cc.Scheduler.prototype = {
|
||||
* @param {Boolean} paused
|
||||
*/
|
||||
scheduleUpdate: function(target, priority, paused) {
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
var hashElement = this._hashForUpdates[targetId];
|
||||
if (hashElement && hashElement.entry){
|
||||
// check if priority has changed
|
||||
@@ -601,8 +635,16 @@ cc.Scheduler.prototype = {
|
||||
// explicity handle nil arguments when removing an object
|
||||
if (!target || !callback)
|
||||
return;
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
|
||||
var self = this, element = self._hashForTimers[targetId];
|
||||
if (element) {
|
||||
@@ -642,8 +684,16 @@ cc.Scheduler.prototype = {
|
||||
unscheduleUpdate: function (target) {
|
||||
if (!target)
|
||||
return;
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
|
||||
var element = this._hashForUpdates[targetId];
|
||||
if (element) {
|
||||
@@ -668,8 +718,16 @@ cc.Scheduler.prototype = {
|
||||
if (!target){
|
||||
return;
|
||||
}
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom Selectors
|
||||
var element = this._hashForTimers[targetId];
|
||||
@@ -775,8 +833,16 @@ cc.Scheduler.prototype = {
|
||||
//selector, target
|
||||
cc.assertID(callback, 1508);
|
||||
cc.assertID(target, 1509);
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
|
||||
var element = this._hashForTimers[targetId];
|
||||
|
||||
@@ -906,8 +972,16 @@ cc.Scheduler.prototype = {
|
||||
*/
|
||||
pauseTarget: function (target) {
|
||||
cc.assertID(target, 1503);
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
|
||||
//customer selectors
|
||||
var self = this,
|
||||
@@ -937,20 +1011,26 @@ cc.Scheduler.prototype = {
|
||||
*/
|
||||
resumeTarget: function (target) {
|
||||
cc.assertID(target, 1504);
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
|
||||
// custom selectors
|
||||
var self = this,
|
||||
element = self._hashForTimers[targetId];
|
||||
|
||||
if (element) {
|
||||
element.paused = false;
|
||||
}
|
||||
|
||||
//update callback
|
||||
var elementUpdate = self._hashForUpdates[targetId];
|
||||
|
||||
if (elementUpdate) {
|
||||
elementUpdate.entry.paused = false;
|
||||
}
|
||||
@@ -965,8 +1045,16 @@ cc.Scheduler.prototype = {
|
||||
*/
|
||||
isTargetPaused: function (target) {
|
||||
cc.assertID(target, 1505);
|
||||
var targetId = getTargetId(target);
|
||||
cc.assertID(targetId, 1510);
|
||||
var targetId = target._id;
|
||||
if (!targetId) {
|
||||
if (target.__instanceId) {
|
||||
cc.warnID(1513);
|
||||
targetId = target._id = target.__instanceId;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1510);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom selectors
|
||||
var element = this._hashForTimers[targetId];
|
||||
|
||||
@@ -42,6 +42,8 @@ const GL_REPEAT = 10497; // gl.REPEAT
|
||||
const GL_CLAMP_TO_EDGE = 33071; // gl.CLAMP_TO_EDGE
|
||||
const GL_MIRRORED_REPEAT = 33648; // gl.MIRRORED_REPEAT
|
||||
|
||||
var idGenerater = new (require('../platform/id-generater'))('Tex');
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data. <br/>
|
||||
@@ -244,7 +246,7 @@ var Texture2D = cc.Class({
|
||||
|
||||
ctor () {
|
||||
// Id for generate hash in material
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
this._id = idGenerater.getNewId();
|
||||
|
||||
/**
|
||||
* !#en
|
||||
@@ -301,7 +303,7 @@ var Texture2D = cc.Class({
|
||||
},
|
||||
|
||||
getId () {
|
||||
return this.__instanceId;
|
||||
return this._id;
|
||||
},
|
||||
|
||||
toString () {
|
||||
|
||||
@@ -133,13 +133,12 @@ let CollisionManager = cc.Class({
|
||||
},
|
||||
|
||||
ctor: function () {
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
|
||||
this._contacts = [];
|
||||
this._colliders = [];
|
||||
|
||||
this._debugDrawer = null;
|
||||
this._enabledDebugDraw = false;
|
||||
|
||||
cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
|
||||
},
|
||||
|
||||
update: function (dt) {
|
||||
|
||||
@@ -52,7 +52,7 @@ var callLateUpdate = CC_SUPPORT_JIT ? 'c.lateUpdate(dt)' : function (c, dt) {
|
||||
|
||||
function sortedIndex (array, comp) {
|
||||
var order = comp.constructor._executionOrder;
|
||||
var id = comp.__instanceId;
|
||||
var id = comp._id;
|
||||
for (var l = 0, h = array.length - 1, m = h >>> 1;
|
||||
l <= h;
|
||||
m = (l + h) >>> 1
|
||||
@@ -66,7 +66,7 @@ function sortedIndex (array, comp) {
|
||||
l = m + 1;
|
||||
}
|
||||
else {
|
||||
var testId = test.__instanceId;
|
||||
var testId = test._id;
|
||||
if (testId > id) {
|
||||
h = m - 1;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ var Component = cc.Class({
|
||||
if (window._Scene && _Scene.AssetsWatcher) {
|
||||
_Scene.AssetsWatcher.initComponent(this);
|
||||
}
|
||||
// Support for Scheduler
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
this._id = idGenerater.getNewId();
|
||||
cc.engine.attachedObjsForEditor[this._id] = this;
|
||||
|
||||
/**
|
||||
* Register all related EventTargets,
|
||||
@@ -64,8 +64,10 @@ var Component = cc.Class({
|
||||
*/
|
||||
this.__eventTargets = [];
|
||||
} : function () {
|
||||
// Support for Scheduler
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
this._id = idGenerater.getNewId();
|
||||
if (CC_TEST) {
|
||||
cc.engine.attachedObjsForEditor[this._id] = this;
|
||||
}
|
||||
this.__eventTargets = [];
|
||||
},
|
||||
|
||||
@@ -117,14 +119,7 @@ var Component = cc.Class({
|
||||
*/
|
||||
uuid: {
|
||||
get () {
|
||||
var id = this._id;
|
||||
if ( !id ) {
|
||||
id = this._id = idGenerater.getNewId();
|
||||
if (CC_EDITOR || CC_TEST) {
|
||||
cc.engine.attachedObjsForEditor[id] = this;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
return this._id;
|
||||
},
|
||||
visible: false
|
||||
},
|
||||
|
||||
@@ -128,7 +128,7 @@ var eventManager = {
|
||||
|
||||
_setDirtyForNode: function (node) {
|
||||
// Mark the node dirty only when there is an event listener associated with it.
|
||||
if (this._nodeListenersMap[node.__instanceId] !== undefined) {
|
||||
if (this._nodeListenersMap[node._id] !== undefined) {
|
||||
this._dirtyNodes.push(node);
|
||||
}
|
||||
if (node.getChildren) {
|
||||
@@ -150,7 +150,7 @@ var eventManager = {
|
||||
cc.warnID(3506);
|
||||
return;
|
||||
}
|
||||
var listeners = this._nodeListenersMap[node.__instanceId], i, len;
|
||||
var listeners = this._nodeListenersMap[node._id], i, len;
|
||||
if (listeners) {
|
||||
for (i = 0, len = listeners.length; i < len; i++)
|
||||
listeners[i]._setPaused(true);
|
||||
@@ -174,7 +174,7 @@ var eventManager = {
|
||||
cc.warnID(3506);
|
||||
return;
|
||||
}
|
||||
var listeners = this._nodeListenersMap[node.__instanceId], i, len;
|
||||
var listeners = this._nodeListenersMap[node._id], i, len;
|
||||
if (listeners){
|
||||
for ( i = 0, len = listeners.length; i < len; i++)
|
||||
listeners[i]._setPaused(false);
|
||||
@@ -227,7 +227,7 @@ var eventManager = {
|
||||
|
||||
var locDirtyNodes = this._dirtyNodes, selListeners, selListener, locNodeListenersMap = this._nodeListenersMap;
|
||||
for (var i = 0, len = locDirtyNodes.length; i < len; i++) {
|
||||
selListeners = locNodeListenersMap[locDirtyNodes[i].__instanceId];
|
||||
selListeners = locNodeListenersMap[locDirtyNodes[i]._id];
|
||||
if (selListeners) {
|
||||
for (var j = 0, listenersLen = selListeners.length; j < listenersLen; j++) {
|
||||
selListener = selListeners[j];
|
||||
@@ -330,11 +330,11 @@ var eventManager = {
|
||||
var locNodePriorityMap = eventManager._nodePriorityMap,
|
||||
node1 = l1._getSceneGraphPriority(),
|
||||
node2 = l2._getSceneGraphPriority();
|
||||
if (!l2 || !node2 || !locNodePriorityMap[node2.__instanceId])
|
||||
if (!l2 || !node2 || !locNodePriorityMap[node2._id])
|
||||
return -1;
|
||||
else if (!l1 || !node1 || !locNodePriorityMap[node1.__instanceId])
|
||||
else if (!l1 || !node1 || !locNodePriorityMap[node1._id])
|
||||
return 1;
|
||||
return locNodePriorityMap[node2.__instanceId] - locNodePriorityMap[node1.__instanceId];
|
||||
return locNodePriorityMap[node2._id] - locNodePriorityMap[node1._id];
|
||||
},
|
||||
|
||||
_sortListenersOfFixedPriority: function (listenerID) {
|
||||
@@ -591,20 +591,20 @@ var eventManager = {
|
||||
},
|
||||
|
||||
_associateNodeAndEventListener: function (node, listener) {
|
||||
var listeners = this._nodeListenersMap[node.__instanceId];
|
||||
var listeners = this._nodeListenersMap[node._id];
|
||||
if (!listeners) {
|
||||
listeners = [];
|
||||
this._nodeListenersMap[node.__instanceId] = listeners;
|
||||
this._nodeListenersMap[node._id] = listeners;
|
||||
}
|
||||
listeners.push(listener);
|
||||
},
|
||||
|
||||
_dissociateNodeAndEventListener: function (node, listener) {
|
||||
var listeners = this._nodeListenersMap[node.__instanceId];
|
||||
var listeners = this._nodeListenersMap[node._id];
|
||||
if (listeners) {
|
||||
cc.js.array.remove(listeners, listener);
|
||||
if (listeners.length === 0)
|
||||
delete this._nodeListenersMap[node.__instanceId];
|
||||
delete this._nodeListenersMap[node._id];
|
||||
}
|
||||
},
|
||||
|
||||
@@ -664,10 +664,10 @@ var eventManager = {
|
||||
var childrenCount = children.length, locGlobalZOrderNodeMap = this._globalZOrderNodeMap, locNodeListenersMap = this._nodeListenersMap;
|
||||
|
||||
if (childrenCount > 0) {
|
||||
if (locNodeListenersMap[node.__instanceId] !== undefined) {
|
||||
if (locNodeListenersMap[node._id] !== undefined) {
|
||||
if (!locGlobalZOrderNodeMap)
|
||||
locGlobalZOrderNodeMap = [];
|
||||
locGlobalZOrderNodeMap.push(node.__instanceId);
|
||||
locGlobalZOrderNodeMap.push(node._id);
|
||||
}
|
||||
|
||||
var child;
|
||||
@@ -677,10 +677,10 @@ var eventManager = {
|
||||
this._visitTarget(child, false);
|
||||
}
|
||||
} else {
|
||||
if (locNodeListenersMap[node.__instanceId] !== undefined) {
|
||||
if (locNodeListenersMap[node._id] !== undefined) {
|
||||
if (!locGlobalZOrderNodeMap)
|
||||
locGlobalZOrderNodeMap = [];
|
||||
locGlobalZOrderNodeMap.push(node.__instanceId);
|
||||
locGlobalZOrderNodeMap.push(node._id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -906,17 +906,17 @@ var eventManager = {
|
||||
cc.warnID(3506);
|
||||
return;
|
||||
}
|
||||
if (listenerType.__instanceId !== undefined) {
|
||||
if (listenerType._id !== undefined) {
|
||||
// Ensure the node is removed from these immediately also.
|
||||
// Don't want any dangling pointers or the possibility of dealing with deleted objects..
|
||||
delete _t._nodePriorityMap[listenerType.__instanceId];
|
||||
delete _t._nodePriorityMap[listenerType._id];
|
||||
cc.js.array.remove(_t._dirtyNodes, listenerType);
|
||||
var listeners = _t._nodeListenersMap[listenerType.__instanceId], i;
|
||||
var listeners = _t._nodeListenersMap[listenerType._id], i;
|
||||
if (listeners) {
|
||||
var listenersCopy = cc.js.array.copy(listeners);
|
||||
for (i = 0; i < listenersCopy.length; i++)
|
||||
_t.removeListener(listenersCopy[i]);
|
||||
delete _t._nodeListenersMap[listenerType.__instanceId];
|
||||
delete _t._nodeListenersMap[listenerType._id];
|
||||
}
|
||||
|
||||
// Bug fix: ensure there are no references to the node in the list of listeners to be added.
|
||||
|
||||
@@ -137,8 +137,6 @@ var PhysicsManager = cc.Class({
|
||||
},
|
||||
|
||||
ctor: function () {
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
|
||||
this._debugDrawFlags = 0;
|
||||
this._debugDrawer = null;
|
||||
|
||||
@@ -154,6 +152,8 @@ var PhysicsManager = cc.Class({
|
||||
|
||||
this._accumulator = 0;
|
||||
|
||||
cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* If enabled accumulator, then will call step function with the fixed time step FIXED_TIME_STEP.
|
||||
|
||||
@@ -1239,18 +1239,6 @@ function parseAttributes (cls, attrs, className, propName, usedInGetter) {
|
||||
|
||||
cc.Class = CCClass;
|
||||
|
||||
// Merged from old _CCClass
|
||||
|
||||
/**
|
||||
* ClassManager
|
||||
*/
|
||||
cc.ClassManager = {
|
||||
instanceId: (0 | (Math.random() * 998)),
|
||||
getNewInstanceId: function () {
|
||||
return this.instanceId++;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isArray: function (defaultVal) {
|
||||
defaultVal = getDefault(defaultVal);
|
||||
|
||||
@@ -24,10 +24,6 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
if (!cc.ClassManager) {
|
||||
require("./CCClass");
|
||||
}
|
||||
|
||||
var eventManager = require('../event-manager');
|
||||
var inputManager = require("./CCInputManager");
|
||||
|
||||
@@ -53,8 +49,6 @@ cc.Acceleration = function (x, y, z, timestamp) {
|
||||
this.timestamp = timestamp || 0;
|
||||
};
|
||||
|
||||
inputManager.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
|
||||
/**
|
||||
* whether enable accelerometer event
|
||||
* @method setAccelerometerEnabled
|
||||
@@ -67,6 +61,7 @@ inputManager.setAccelerometerEnabled = function(isEnable){
|
||||
|
||||
_t._accelEnabled = isEnable;
|
||||
var scheduler = cc.director.getScheduler();
|
||||
scheduler.enableForTarget(_t);
|
||||
if(_t._accelEnabled){
|
||||
_t._accelCurTime = 0;
|
||||
scheduler.scheduleUpdate(_t);
|
||||
|
||||
@@ -22,7 +22,7 @@ class Atlas {
|
||||
insertSpriteFrame (spriteFrame) {
|
||||
let rect = spriteFrame._rect,
|
||||
texture = spriteFrame._texture,
|
||||
info = this._innerTextureInfos[texture.__instanceId];
|
||||
info = this._innerTextureInfos[texture._id];
|
||||
|
||||
let sx = rect.x, sy = rect.y;
|
||||
|
||||
@@ -48,7 +48,7 @@ class Atlas {
|
||||
|
||||
this._texture.drawTextureAt(texture, this._x, this._y);
|
||||
|
||||
this._innerTextureInfos[texture.__instanceId] = {
|
||||
this._innerTextureInfos[texture._id] = {
|
||||
x: this._x,
|
||||
y: this._y,
|
||||
texture: texture
|
||||
|
||||
@@ -138,7 +138,6 @@ var BaseNode = cc.Class({
|
||||
extends: cc.Object,
|
||||
|
||||
properties: {
|
||||
|
||||
// SERIALIZABLE
|
||||
|
||||
_parent: null,
|
||||
@@ -233,11 +232,7 @@ var BaseNode = cc.Class({
|
||||
*/
|
||||
uuid: {
|
||||
get () {
|
||||
var id = this._id;
|
||||
if (!id) {
|
||||
id = this._id = CC_EDITOR ? Editor.Utils.UuidUtils.uuid() : idGenerater.getNewId();
|
||||
}
|
||||
return id;
|
||||
return this._id;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -330,10 +325,10 @@ var BaseNode = cc.Class({
|
||||
*/
|
||||
ctor (name) {
|
||||
this._name = name !== undefined ? name : 'New Node';
|
||||
|
||||
this._activeInHierarchy = false;
|
||||
// Support for ActionManager and EventManager
|
||||
this.__instanceId = this._id || cc.ClassManager.getNewInstanceId();
|
||||
this._id = CC_EDITOR ? Editor.Utils.UuidUtils.uuid() : idGenerater.getNewId();
|
||||
|
||||
cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
|
||||
|
||||
/**
|
||||
* Register all related EventTargets,
|
||||
@@ -1294,6 +1289,8 @@ var BaseNode = cc.Class({
|
||||
},
|
||||
});
|
||||
|
||||
BaseNode.idGenerater = idGenerater;
|
||||
|
||||
// For walk
|
||||
BaseNode._stacks = [[]];
|
||||
BaseNode._stackId = 0;
|
||||
|
||||
@@ -1331,7 +1331,7 @@ var ParticleSystem = cc.Class({
|
||||
if (!this._material) {
|
||||
this._material = new ParticleMaterial();
|
||||
// Particle System cannot be batched, so every one use a unique hash id
|
||||
this._material.updateHash(this.__instanceId);
|
||||
this._material.updateHash(this._id);
|
||||
}
|
||||
|
||||
let vfx = this._vfx;
|
||||
|
||||
@@ -40,10 +40,10 @@ var CCFactory = dragonBones.CCFactory = cc.Class({
|
||||
},
|
||||
|
||||
ctor () {
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
this._dragonBones = new dragonBones.DragonBones();
|
||||
|
||||
if (!CC_EDITOR) {
|
||||
if (!CC_EDITOR && cc.director._scheduler) {
|
||||
cc.director._scheduler.enableForTarget(this);
|
||||
cc.director._scheduler.scheduleUpdate(this, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user