Skip to content

Commit

Permalink
Merge pull request cocos#1921 from jareguo/v1.6
Browse files Browse the repository at this point in the history
Cherry pick from master
  • Loading branch information
nantas authored Aug 22, 2017
2 parents 287cb78 + e62aad5 commit 3ec11c0
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 161 deletions.
39 changes: 35 additions & 4 deletions DebugInfos.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ if (CC_DEBUG) {
"3621": "Unknown type of %s.%s, maybe you want is '%s'.", //CCClass
"3622": "Unknown type of %s.%s, property should be defined in 'properties' or 'ctor'", //CCClass_2
"3623": "Can not use 'editor' attribute, '%s' not inherits from Components.", //CCClass_3
"3624": "'%s' overrided '%s' but '%s' is defined as 'false' so the super method will not be called. You can set '%s' to null to disable this warning.", //CCClass_4
"3624": "'%s' overwrote '%s' but '%s' is defined as 'false' so the super method will not be called. You can set '%s' to null to disable this warning.", //CCClass_4
"3625": "[isChildClassOf] superclass should be function type, not", //isChildClassOf
"3626": "Can't remove '%s' because '%s' depends on it.", //destroy
"3627": "Should not add renderer component (%s) to a Canvas node.", //_registSizeProvider
Expand All @@ -290,7 +290,7 @@ if (CC_DEBUG) {
"3633": "Properties function of '%s' should return an object!", //init
"3634": "Disallow to use '.' in property name", //appendProp
"3635": "Default array must be empty, set default value of %s.%s to [], and initialize in 'onLoad' or 'ctor' please. (just like 'this.%s = [...];')", //defineProp
"3636": "Do not set default value to non-empty object, unless the object defines its own 'clone' function. Set default value of %s.%s to null or {}, and initialize in 'onLoad' or 'ctor' please. (just like 'this.%s = {foo: bar};')", //defineProp_2
"3636": "Can not set default value to non-empty object, unless the object derived from cc.ValueType and overwrite the 'clone' function. Set default value of %s.%s to null or {}, and initialize in 'onLoad' or 'ctor' please. (just like 'this.%s = {foo: bar};')", //defineProp_2
"3637": "Can not declare %s.%s, it is already defined in the prototype of %s", //defineProp_3
"3638": "'%s': the getter of '%s' is already defined!", //defineGetSet_2
"3640": "'%s': the setter of '%s' is already defined!", //defineGetSet_4
Expand All @@ -303,8 +303,39 @@ if (CC_DEBUG) {
"3647": "The length of range array must be equal or greater than 2", //parseAttributes_4
"3648": "Can not declare %s.%s method, it is already defined in the properties of %s.",
"3649": "CCClass %s have conflict between its ctor and __ctor__.",
"3650": "No need to specifiy '%s' attribute for '%s' in class \"%s\".",
"3650": "No need to specifiy \"%s\" attribute for \"%s\" property in \"%s\" class.", // 已废弃,提示信息仅用于生成 markdown 给旧版本用户查阅
"3651": "Can not call `_super` or `prototype.ctor` in ES6 Classes \"%s\", use `super` instead please.",
"3652": "Failed to construct a dummy instance of the \"%s\" class using `new` behind the scenes. This is for getting default values declared in TypeScript. Please ensure the class will be able to construct during script's initialization. %s",
"3653": "Please do not specifiy \"default\" attribute in decorator of \"%s\" property in \"%s\" class.\n" +
" Default value must be initialized at their declaration: \uD83D\uDE02\n" +
" // Before:\n" +
" @property({\n" +
" type: cc.Integer\n" +
" default: 0 // <--\n" +
" })\n" +
" value;\n\n" +
" // After:\n" +
" @property({\n" +
" type: cc.Integer\n" +
" })\n" +
" value = 0; // <--",
"3654": "Please specifiy a default value for \"%s\" property at its declaration: \uD83D\uDE02\n" +
" // Before:\n" +
" @property(...)\n" +
" value;\n\n" +
" // After:\n" +
" @property(...)\n" +
" value = 0;",
"3655": "Can not specifiy \"get\" or \"set\" attribute in decorator for \"%s\" property in \"%s\" class.\n" +
" Please use:\n" +
" @property(...)\n" +
" get %s () {\n" +
" ...\n" +
" }\n" +
" @property\n" +
" set %s (value) {\n" +
" ...\n" +
" }",
//Prefab: 3700
"3700": "internal error: _prefab is undefined", //_doInstantiate
"3701": "Failed to load prefab asset for node '%s'", //syncWithPrefab
Expand Down Expand Up @@ -433,7 +464,7 @@ if (CC_DEBUG) {
"5514": "The 'default' value of '%s.%s' should not be used with a 'set' function.", //default_2
"5515": "The 'default' value of '%s.%s' can not be an constructor. Set default to null please.", //default_3
"5516": "Property '%s.%s' must define at least one of 'default', 'get' or 'set'.", //default_4
"5517": "'%s.%s' hides inherited property '%s.%s'. To make the current property override that implementation, add the `override: true` attribute please.", //default_5
"5517": "'%s.%s' hides inherited property '%s.%s'. To make the current property overwrite that implementation, add the `override: true` attribute please.", //default_5
//Find: 5600
"5600": "Argument must be non-nil", //find
"5601": "Can not get current scene.", //find_2
Expand Down
16 changes: 9 additions & 7 deletions cocos2d/core/CCDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,11 @@ cc.Director = Class.extend(/** @lends cc.Director# */{

// detach persist nodes
var game = cc.game;
var persistNodes = game._persistRootNodes;
for (let id in persistNodes) {
let node = persistNodes[id];
var persistNodeList = Object.keys(game._persistRootNodes).map(function (x) {
return game._persistRootNodes[x];
});
for (let i = 0; i < persistNodeList.length; i++) {
let node = persistNodeList[i];
game._ignoreRemovePersistNode = node;
node.parent = null;
game._ignoreRemovePersistNode = null;
Expand All @@ -558,7 +560,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
// auto release assets
CC_DEBUG && console.time('AutoRelease');
var autoReleaseAssets = oldScene && oldScene.autoReleaseAssets && oldScene.dependAssets;
AutoReleaseUtils.autoRelease(cc.loader, autoReleaseAssets, scene.dependAssets);
AutoReleaseUtils.autoRelease(autoReleaseAssets, scene.dependAssets, persistNodeList);
CC_DEBUG && console.timeEnd('AutoRelease');
}

Expand Down Expand Up @@ -587,10 +589,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
sgScene = scene._sgNode;

// Re-attach or replace persist nodes
for (let id in persistNodes) {
let node = persistNodes[id];
for (let i = 0; i < persistNodeList.length; i++) {
let node = persistNodeList[i];
CC_DEBUG && console.time('AttachPersist');
var existNode = scene.getChildByUuid(id);
var existNode = scene.getChildByUuid(node.uuid);
if (existNode) {
// scene also contains the persist node, select the old one
var index = existNode.getSiblingIndex();
Expand Down
1 change: 1 addition & 0 deletions cocos2d/core/assets/CCRawAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
****************************************************************************/

var CCObject = require('../platform/CCObject');

/**
* !#en
* The base class for registering asset types.
Expand Down
108 changes: 93 additions & 15 deletions cocos2d/core/load-pipeline/auto-release-utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/****************************************************************************
Copyright (c) 2017 Chukong Technologies Inc.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Chukong Aipu reserves all rights not expressly granted to you.
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.
****************************************************************************/

var JS = require('../platform/js');

function parseDepends (key, parsed) {
var item = cc.loader.getItem(key);
Expand All @@ -15,35 +41,87 @@ function parseDepends (key, parsed) {
}
}

function release (loader, key, nextSceneAssets) {
if (!nextSceneAssets || nextSceneAssets.indexOf(key) === -1) {
loader.release(key);
function visitAsset (asset, excludeMap) {
var key = cc.loader._getReferenceKey(asset);
if ( !excludeMap[key] ) {
excludeMap[key] = true;
parseDepends(key, excludeMap);
}
}

function visitComponent (comp, excludeMap) {
var props = Object.getOwnPropertyNames(comp);
for (var i = 0; i < props.length; i++) {
var value = comp[props[i]];
if (typeof value === 'object' && value) {
if (Array.isArray(value)) {
for (let j = 0; j < value.length; j++) {
let val = value[j];
if (val instanceof cc.RawAsset) {
visitAsset(val, excludeMap);
}
}
}
else if (!value.constructor || value.constructor === Object) {
let keys = Object.getOwnPropertyNames(value);
for (let j = 0; j < keys.length; j++) {
let val = value[keys[j]];
if (val instanceof cc.RawAsset) {
visitAsset(val, excludeMap);
}
}
}
else if (value instanceof cc.RawAsset) {
visitAsset(value, excludeMap);
}
}
}
}

function visitNode (node, excludeMap) {
for (let i = 0; i < node._components.length; i++) {
visitComponent(node._components[i], excludeMap);
}
for (let i = 0; i < node._children.length; i++) {
visitNode(node._children[i], excludeMap);
}
}

module.exports = {
// do auto release
autoRelease: function (loader, oldSceneAssets, nextSceneAssets) {
var releaseSettings = loader._autoReleaseSetting;
var i, key;
autoRelease: function (oldSceneAssets, nextSceneAssets, persistNodes) {
var releaseSettings = cc.loader._autoReleaseSetting;
var excludeMap = JS.createMap();

// collect next scene assets
if (nextSceneAssets) {
for (let i = 0; i < nextSceneAssets.length; i++) {
excludeMap[nextSceneAssets[i]] = true;
}
}

// collect assets used by persist nodes
for (let i = 0; i < persistNodes.length; i++) {
visitNode(persistNodes[i], excludeMap)
}

// remove ununsed scene assets
if (oldSceneAssets) {
for (i = 0; i < oldSceneAssets.length; i++) {
key = oldSceneAssets[i];
if (releaseSettings[key] !== false) {
release(loader, key, nextSceneAssets);
for (let i = 0; i < oldSceneAssets.length; i++) {
let key = oldSceneAssets[i];
if (releaseSettings[key] !== false && !excludeMap[key]) {
cc.loader.release(key);
}
}
}

// remove auto release assets
// (releasing asset will change _autoReleaseSetting, so don't use for-in)
var keys = Object.keys(releaseSettings);
// releasing asset will change _autoReleaseSetting, so don't use enumerator
for (i = 0; i < keys.length; i++) {
key = keys[i];
if (releaseSettings[key] === true) {
release(loader, key, nextSceneAssets);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
if (releaseSettings[key] === true && !excludeMap[key]) {
cc.loader.release(key);
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/CCAssetLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ var AssetLibrary = {
// 不使用 url.format 的原因是 windows 不支持 file:// 和 /// 开头的协议,所以只能用 replace 操作直接把路径转成 URL。
var libraryPath = options.libraryPath;
libraryPath = libraryPath.replace(/\\/g, '/');
_libraryBase = cc.path._setEndWithSep(libraryPath, '/');
_libraryBase = cc.path.stripSep(libraryPath) + '/';

_rawAssetsBase = options.rawAssetsBase;

Expand Down
3 changes: 1 addition & 2 deletions cocos2d/core/platform/CCClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,7 @@ function CCClass (options) {
continue;
}
var func = options[funcName];
// TODO: call validateMethod on es6
if (!preprocess.validateMethod(func, funcName, name, cls, base)) {
if (!preprocess.validateMethodWithProps(func, funcName, name, cls, base)) {
continue;
}
// use value to redefine some super method defined as getter
Expand Down
Loading

0 comments on commit 3ec11c0

Please sign in to comment.