Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust dependencies parsing in preloading mode #6941

Merged
merged 12 commits into from Jul 14, 2020

Conversation

holycanvas
Copy link
Contributor

@holycanvas holycanvas commented Jun 29, 2020

Re: cocos-creator/2d-tasks#

Changes:

cocos2d/core/platform/CCMacro.js Outdated Show resolved Hide resolved
cocos2d/core/assets/CCAsset.js Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
@jareguo
Copy link
Member

jareguo commented Jun 29, 2020

感觉这样的话开发者想扩展自己的类型难度会挺大的。

* loadAny(requests: string | string[] | Record<string, any> | Record<string, any>[], onProgress: (finished: number, total: number, item: cc.AssetManager.RequestItem) => void, onComplete: (err: Error, data: any) => void): void
* loadAny(requests: string | string[] | Record<string, any> | Record<string, any>[], options: Record<string, any>, onComplete: (err: Error, data: any) => void): void
Copy link
Contributor Author

@holycanvas holycanvas Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

声明的先后顺序,会影响 vscode 中的匹配,vscode中是从上往下匹配的。所以应该把越难匹配到的放在越上面,越容易匹配的放在越下面

* loadRemote<T extends cc.Asset>(url: string): void
*/
loadRemote (url, options, onComplete) {
var { options, onComplete } = parseParameters(options, undefined, onComplete);

if (this.assets.has(url)) {
Copy link
Contributor Author

@holycanvas holycanvas Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

远程资源也缓存好了

out.nativeDep && (out.nativeDep.uuid = uuid);

if (Array.isArray(json) && (!isDataValid(json) || isPrefabOrScene(json))) {
out = {
Copy link
Contributor Author

@holycanvas holycanvas Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判断有没有原生依赖,没有就走这个分支

};
}
else {
try {
Copy link
Contributor Author

@holycanvas holycanvas Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有原生资源依赖的统一进行反序列化

},

_parseDepsFromJson: CC_EDITOR || CC_PREVIEW ? function (json) {
if (isDataValid(json))
Copy link
Contributor Author

@holycanvas holycanvas Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所有资源都通过 json[1] 来找依赖,就不用在类里面定义了

cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
cocos2d/core/platform/deserialize-compiled.ts Outdated Show resolved Hide resolved
@@ -153,7 +153,7 @@ var utils = {

if (includeNative && !asyncLoadAssets && !info.preventPreloadNativeObject && info.nativeDep) {
config && (info.nativeDep.bundle = config.name);
depends.push(info.nativeDep);
depends.push(Object.assign({}, info.nativeDep));
Copy link
Contributor Author

@holycanvas holycanvas Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不能直接复用,数据会脏

@cocos-robot cocos-robot changed the base branch from v2.4.1 to v2.4.2-release Jul 6, 2020
Copy link
Contributor

@cocos-robot cocos-robot left a comment

We switched this PR to v2.4.2-release because v2.4.1 is about to be deleted.

localCanvas.parentNode.insertBefore(localContainer, localCanvas);
if (CC_EDITOR) {
//it is already a canvas, we wrap it around with a div
this.container = localContainer = document.createElement("DIV");
Copy link
Contributor Author

@holycanvas holycanvas Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

编辑器下的渲染走的这个分支,不太敢动

}
else {
// Can not move the existing canvas's position in iOS 14, so use canvas.parentNode as container
this.container = localContainer = localCanvas.parentNode;
Copy link
Contributor Author

@holycanvas holycanvas Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果提供的canvas,就把canvas的父节点作为container吧

@@ -62,7 +65,8 @@ var dependUtil = {
* getNativeDep(uuid: string): Record<string, any>
*/
getNativeDep (uuid) {
if (this._depends.has(uuid)) return this._depends.get(uuid).nativeDep;
let depend;
if (depend = this._depends.get(uuid)) return depend.nativeDep && Object.assign({}, depend.nativeDep);
Copy link
Member

@jareguo jareguo Jul 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个写法感觉在这里有点没必要,直接 let a = b; if (a) 不是更清晰吗

@holycanvas holycanvas merged commit cffd0d4 into cocos:v2.4.2-release Jul 14, 2020
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants