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
fix small issues #6688
fix small issues #6688
Changes from 11 commits
766a07f
c13192b
82e22cd
be2a17e
f549b7c
1f0b7e1
1869fc7
88cddd0
b82570e
2fcb8ce
a2b190b
86e9a91
4afe6ac
2f69c9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,19 +151,21 @@ var dependUtil = { | |
* parse(uuid: string, json: any): { deps?: string[], nativeDep?: any } | ||
*/ | ||
parse (uuid, json) { | ||
if (!CC_EDITOR && this._depends.has(uuid)) return this._depends.get(uuid); | ||
|
||
var out = Object.create(null); | ||
var type = json.__type__; | ||
|
||
var out = null; | ||
// scene or prefab | ||
if (Array.isArray(json)) { | ||
|
||
if (this._depends.has(uuid)) return this._depends.get(uuid) | ||
out = {}; | ||
out.deps = cc.Asset._parseDepsFromJson(json); | ||
out.asyncLoadAssets = json[0].asyncLoadAssets; | ||
} | ||
// get deps from json | ||
else if (type) { | ||
var ctor = js._getClassById(type); | ||
else if (json.__type__) { | ||
|
||
if (this._depends.has(uuid)) return this._depends.get(uuid); | ||
out = {}; | ||
var ctor = js._getClassById(json.__type__); | ||
out.preventPreloadNativeObject = ctor.preventPreloadNativeObject; | ||
out.preventDeferredLoadDependents = ctor.preventDeferredLoadDependents; | ||
out.deps = ctor._parseDepsFromJson(json); | ||
|
@@ -173,6 +175,7 @@ var dependUtil = { | |
// get deps from an existing asset | ||
else { | ||
var asset = json; | ||
out = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已改 |
||
out.deps = []; | ||
out.preventPreloadNativeObject = asset.constructor.preventPreloadNativeObject; | ||
out.preventDeferredLoadDependents = asset.constructor.preventDeferredLoadDependents; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,28 +102,26 @@ var downloadBundle = function (url, options, onComplete) { | |
var version = options.version || downloader.bundleVers[bundleName]; | ||
var count = 0; | ||
var config = version ? `${url}/config.${version}.json` : `${url}/config.json`; | ||
let out = null; | ||
let out = null, error = null; | ||
downloadJson(config, options, function (err, response) { | ||
if (err) { | ||
onComplete(err); | ||
return; | ||
error = err; | ||
} | ||
out = response; | ||
count++; | ||
if (count === 2) { | ||
onComplete(null, out); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 执行一次回调就行 |
||
onComplete(error, out); | ||
} | ||
}); | ||
|
||
var js = version ? `${url}/index.${version}.js` : `${url}/index.js`; | ||
downloadScript(js, options, function (err) { | ||
if (err) { | ||
onComplete(err); | ||
return; | ||
error = err; | ||
} | ||
count++; | ||
if (count === 2) { | ||
onComplete(null, out); | ||
onComplete(error, out); | ||
} | ||
}); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,11 @@ const { files } = require('./shared'); | |
|
||
var _loading = new Cache(); | ||
|
||
function isLoading (val) { | ||
return _loading.has(val.uuid); | ||
} | ||
|
||
|
||
/** | ||
* @module cc.AssetManager | ||
*/ | ||
|
@@ -196,64 +201,53 @@ var packManager = { | |
*/ | ||
load (item, options, onComplete) { | ||
// if not in any package, download as uausl | ||
if (item.isNative || !item.info || !item.info.packs) { | ||
downloader.download(item.id, item.url, item.ext, item.options, onComplete); | ||
} | ||
else { | ||
if (files.has(item.id)) { | ||
onComplete(null, files.get(item.id)); | ||
if (item.isNative || !item.info || !item.info.packs) return downloader.download(item.id, item.url, item.ext, item.options, onComplete); | ||
|
||
if (files.has(item.id)) return onComplete(null, files.get(item.id)); | ||
|
||
var packs = item.info.packs; | ||
|
||
// find a loading package | ||
var pack = packs.find(isLoading); | ||
|
||
if (pack) return _loading.get(pack.uuid).push({ onComplete, id: item.id }); | ||
|
||
// download a new package | ||
pack = packs[0]; | ||
_loading.add(pack.uuid, [{ onComplete, id: item.id }]); | ||
|
||
let url = cc.assetManager._transform(pack.uuid, {ext: pack.ext, bundle: item.config.name}); | ||
|
||
downloader.download(pack.uuid, url, pack.ext, item.options, function (err, data) { | ||
files.remove(pack.uuid); | ||
if (err) { | ||
cc.error(err.message, err.stack); | ||
} | ||
else { | ||
var packs = item.info.packs; | ||
// find a loading package | ||
var pack = packs.find(function (val) { | ||
return _loading.has(val.uuid); | ||
}); | ||
|
||
if (pack) { | ||
_loading.get(pack.uuid).push({ onComplete, id: item.id }); | ||
// unpack package | ||
packManager.unpack(pack.packs, data, pack.ext, item.options, function (err, result) { | ||
if (!err) { | ||
for (var id in result) { | ||
files.add(id, result[id]); | ||
} | ||
} | ||
else { | ||
// download a new package | ||
pack = packs[0]; | ||
_loading.add(pack.uuid, [{ onComplete, id: item.id }]); | ||
|
||
var url = cc.assetManager._transform(pack.uuid, {ext: pack.ext, bundle: item.config.name}); | ||
var callbacks = _loading.remove(pack.uuid); | ||
for (var i = 0, l = callbacks.length; i < l; i++) { | ||
var cb = callbacks[i]; | ||
if (err) { | ||
cb.onComplete(err); | ||
continue; | ||
} | ||
|
||
downloader.download(pack.uuid, url, pack.ext, item.options, function (err, data) { | ||
files.remove(pack.uuid); | ||
if (err) { | ||
cc.error(err.message, err.stack); | ||
} | ||
// unpack package | ||
packManager.unpack(pack.packs, data, pack.ext, item.options, function (err, result) { | ||
if (!err) { | ||
for (var id in result) { | ||
files.add(id, result[id]); | ||
} | ||
} | ||
var callbacks = _loading.remove(pack.uuid); | ||
for (var i = 0, l = callbacks.length; i < l; i++) { | ||
var cb = callbacks[i]; | ||
if (err) { | ||
cb.onComplete(err); | ||
} | ||
else { | ||
var data = result[cb.id]; | ||
if (!data) { | ||
cb.onComplete(new Error('can not retrieve data from package')); | ||
} | ||
else { | ||
cb.onComplete(null, data); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 提高下可读性,全是大括号太烦 |
||
} | ||
} | ||
}); | ||
}); | ||
var data = result[cb.id]; | ||
if (!data) { | ||
cb.onComplete(new Error('can not retrieve data from package')); | ||
} | ||
else { | ||
cb.onComplete(null, data); | ||
} | ||
} | ||
} | ||
} | ||
|
||
}); | ||
}); | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,25 +198,9 @@ var releaseManager = { | |
_free (asset, force) { | ||
_toDelete.remove(asset._uuid); | ||
|
||
if (!force) { | ||
|
||
if (!CC_NATIVERENDERER) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个判断不对,_current.textureUnits 压根就不是本帧所有贴图,只是最后一个 drawcall 的贴图,没有地方能统计到本帧的,所以还是不判断了 |
||
var glTexture = null; | ||
if (asset instanceof cc.Texture2D) { | ||
glTexture = asset._texture; | ||
} | ||
|
||
if (glTexture && glTexture._glID != -1) { | ||
var textureUnits = cc.renderer.device._current.textureUnits; | ||
for (var i = 0; i < textureUnits.length; i++) { | ||
if (glTexture === textureUnits[i]) { | ||
console.error(`this texture ${asset._uuid} is being used`); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
if (!cc.isValid(asset, true)) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果资源已经释放过了,不应该再释放一次 |
||
|
||
if (!force) { | ||
if (asset.refCount > 0) { | ||
if (checkCircularReference(asset) > 0) return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -693,7 +693,7 @@ function initSys () { | |
height: 0 | ||
}; | ||
sys.capabilities = { | ||
'imageBitmap': typeof createImageBitmap !== 'undefined' && typeof Blob !== 'undefined' | ||
'imageBitmap': false | ||
}; | ||
sys.__audioSupport = {}; | ||
} | ||
|
@@ -766,7 +766,7 @@ function initSys () { | |
capabilities["touches"] = false; | ||
} | ||
|
||
capabilities['imageBitmap'] = typeof createImageBitmap !== 'undefined' && typeof Blob !== 'undefined'; | ||
capabilities['imageBitmap'] = false; | ||
|
||
sys.__audioSupport = { | ||
ONLY_ONE: false, | ||
|
@@ -992,8 +992,16 @@ function initSys () { | |
"canvas": _supportCanvas, | ||
"opengl": _supportWebGL, | ||
"webp": _supportWebp, | ||
'imageBitmap': typeof createImageBitmap !== 'undefined' && typeof Blob !== 'undefined', | ||
'imageBitmap': false, | ||
}; | ||
|
||
if (typeof createImageBitmap !== 'undefined' && typeof Blob !== 'undefined') { | ||
_tmpCanvas1.width = _tmpCanvas1.height = 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imageBitmap 在某些浏览器上,可能不支持 option 参数,所以得实际调用一次来判断是否真的支持 |
||
createImageBitmap(_tmpCanvas1, {}).then(imageBitmap => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么要使用 ImageBitmap ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTMLImageElement 在上传GPU的时候,浏览器会执行一个 decode 的操作,这个操作需要时的时间跟图像的分辨率大小成正比,而且有个严重的问题是,这个操作是同步的,所以如果图片很多的时候,会非常卡顿,而且因为是同步的,所以图片只能一张接着一张的decode,所以会很慢。而 imageBitmap 在浏览器上是在多线程中解码的,所以可以并行,会更快,而且因为少了同步的操作,卡顿也会变少。不想使用的话,可以用 cc.macro.ALLOW_IMAGE_BITMAP 来关闭使用 |
||
capabilities.imageBitmap = true; | ||
imageBitmap.close && imageBitmap.close(); | ||
}).catch(err => {}); | ||
} | ||
if (docEle['ontouchstart'] !== undefined || doc['ontouchstart'] !== undefined || nav.msPointerEnabled) | ||
capabilities["touches"] = true; | ||
if (docEle['onmouseup'] !== undefined) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,7 +465,7 @@ cc.js.mixin(View.prototype, { | |
if(cc.game.renderType === cc.game.RENDER_TYPE_WEBGL) { | ||
var cache = cc.assetManager.assets; | ||
cache.forEach(function (asset) { | ||
if (asset instanceof cc.Texture2Dx) { | ||
if (asset instanceof cc.Texture2D) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
var Filter = cc.Texture2D.Filter; | ||
if (enabled) { | ||
asset.setFilters(Filter.LINEAR, Filter.LINEAR); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vs code 不识别中括号。。。