diff --git a/cocos/2d/assembler/label/font-utils.ts b/cocos/2d/assembler/label/font-utils.ts index af04889614..acbdfb3ad3 100644 --- a/cocos/2d/assembler/label/font-utils.ts +++ b/cocos/2d/assembler/label/font-utils.ts @@ -233,8 +233,6 @@ export class LetterRenderTexture extends Texture2D { height, format, }); - this.loaded = true; - this.emit('load'); } /** diff --git a/cocos/2d/assembler/label/letter-font.ts b/cocos/2d/assembler/label/letter-font.ts index 3e06264701..9674ee238a 100644 --- a/cocos/2d/assembler/label/letter-font.ts +++ b/cocos/2d/assembler/label/letter-font.ts @@ -69,15 +69,7 @@ export const letterFont = mixin(bmfontUtils, { let fontFamily = 'Arial'; if (!comp.useSystemFont) { if (comp.font) { - if (comp.font._nativeAsset) { - fontFamily = comp.font._nativeAsset; - } else { - assetManager.postLoadNative(comp.font, (err) => { - if (!comp.isValid) { return; } - fontFamily = comp.font!._nativeAsset || 'Arial'; - comp.updateRenderData(true); - }); - } + fontFamily = comp.font._nativeAsset || 'Arial'; } } else { fontFamily = comp.fontFamily || 'Arial'; diff --git a/cocos/2d/assembler/label/ttfUtils.ts b/cocos/2d/assembler/label/ttfUtils.ts index d34b243728..c1cf4232cb 100644 --- a/cocos/2d/assembler/label/ttfUtils.ts +++ b/cocos/2d/assembler/label/ttfUtils.ts @@ -152,16 +152,7 @@ export const ttfUtils = { _updateFontFamily (comp: Label) { if (!comp.useSystemFont) { if (comp.font) { - if (comp.font._nativeAsset) { - _fontFamily = comp.font._nativeAsset; - } else { - assetManager.postLoadNative(comp.font, (err) => { - if (!comp.isValid) { return; } - _fontFamily = comp.font!._nativeAsset || 'Arial'; - comp.updateRenderData(true); - }); - _fontFamily = 'Arial'; - } + _fontFamily = comp.font._nativeAsset || 'Arial'; } else { _fontFamily = 'Arial'; } diff --git a/cocos/2d/assets/sprite-frame.ts b/cocos/2d/assets/sprite-frame.ts index 914583e4e0..5bc1f5dc4d 100644 --- a/cocos/2d/assets/sprite-frame.ts +++ b/cocos/2d/assets/sprite-frame.ts @@ -549,9 +549,11 @@ export class SpriteFrame extends Asset { * Returns whether the texture have been loaded. * @zh * 返回是否已加载精灵帧。 + * + * @deprecated since v3.3 */ public textureLoaded () { - return this.texture && this.texture.loaded; + return !!this.texture; } /** @@ -701,7 +703,6 @@ export class SpriteFrame extends Asset { if (info) { if (info.texture) { - this.loaded = false; this._rect.x = this._rect.y = 0; this._rect.width = info.texture.width; this._rect.height = info.texture.height; @@ -783,11 +784,6 @@ export class SpriteFrame extends Asset { return true; } - public onLoaded () { - this.loaded = true; - this.emit('load'); - } - public destroy () { if (this._packable && dynamicAtlasManager) { dynamicAtlasManager.deleteAtlasSpriteFrame(this); @@ -1258,7 +1254,8 @@ export class SpriteFrame extends Asset { return sp; } - protected _textureLoaded () { + protected _refreshTexture (texture: TextureBase | RenderTexture) { + this._texture = texture; const tex = this._texture; const config: ISpriteFrameInitInfo = {}; let isReset = false; @@ -1284,15 +1281,6 @@ export class SpriteFrame extends Asset { this._checkPackable(); } - protected _refreshTexture (texture: TextureBase | RenderTexture) { - this._texture = texture; - if (texture.loaded) { - this._textureLoaded(); - } else { - texture.once('load', this._textureLoaded, this); - } - } - public initDefault (uuid?: string) { super.initDefault(uuid); const texture = new Texture2D(); diff --git a/cocos/2d/components/label.ts b/cocos/2d/components/label.ts index d24d29b5af..087ffe09eb 100644 --- a/cocos/2d/components/label.ts +++ b/cocos/2d/components/label.ts @@ -762,7 +762,7 @@ export class Label extends Renderable2D { if (font && font instanceof BitmapFont) { const spriteFrame = font.spriteFrame; // cannot be activated if texture not loaded yet - if (!spriteFrame || !spriteFrame.textureLoaded()) { + if (!spriteFrame || !spriteFrame.texture) { return false; } } @@ -790,21 +790,12 @@ export class Label extends Renderable2D { const font = this._font; if (font instanceof BitmapFont) { const spriteFrame = font.spriteFrame; - const onBMFontTextureLoaded = () => { - // TODO: old texture in material have been released by loader + if (spriteFrame && spriteFrame.texture) { this._texture = spriteFrame; this.changeMaterialForDefine(); if (this._assembler) { this._assembler.updateRenderData(this); } - }; - // cannot be activated if texture not loaded yet - if (spriteFrame) { - if (spriteFrame.loaded || spriteFrame.textureLoaded) { - onBMFontTextureLoaded(); - } else { - spriteFrame.once('load', onBMFontTextureLoaded, this); - } } } else { if (this.cacheMode === CacheMode.CHAR) { diff --git a/cocos/2d/components/mask.ts b/cocos/2d/components/mask.ts index 762192a6a8..1f625e721d 100644 --- a/cocos/2d/components/mask.ts +++ b/cocos/2d/components/mask.ts @@ -175,11 +175,6 @@ export class Mask extends Renderable2D { } set inverted (value) { - if (legacyCC.game.renderType === Game.RENDER_TYPE_CANVAS) { - warnID(4202); - return; - } - this._inverted = value; this.stencilStage = Stage.DISABLED; if (this._graphics) { diff --git a/cocos/2d/components/rich-text.ts b/cocos/2d/components/rich-text.ts index bed8d9c5c6..bc38abe8d7 100644 --- a/cocos/2d/components/rich-text.ts +++ b/cocos/2d/components/rich-text.ts @@ -537,16 +537,8 @@ export class RichText extends UIComponent { protected _onTTFLoaded () { if (this._font instanceof TTFFont) { - if (this._font._nativeAsset) { - this._layoutDirty = true; - this._updateRichText(); - } else { - assetManager.postLoadNative(this._font, (err) => { - if (!this.isValid) { return; } - this._layoutDirty = true; - this._updateRichText(); - }); - } + this._layoutDirty = true; + this._updateRichText(); } else { this._layoutDirty = true; this._updateRichText(); diff --git a/cocos/2d/components/sprite.ts b/cocos/2d/components/sprite.ts index a66754e148..6d2099ea7f 100644 --- a/cocos/2d/components/sprite.ts +++ b/cocos/2d/components/sprite.ts @@ -481,10 +481,6 @@ export class Sprite extends Renderable2D { this._resized(); this.node.on(NodeEventType.SIZE_CHANGED, this._resized, this); } - - if (this._spriteFrame) { - this._spriteFrame.once('load', this._onTextureLoaded, this); - } } // /** @@ -518,10 +514,6 @@ export class Sprite extends Renderable2D { if (EDITOR) { this.node.off(NodeEventType.SIZE_CHANGED, this._resized, this); } - - if (this._spriteFrame && !this._spriteFrame.loaded) { - this._spriteFrame.off('load', this._onTextureLoaded, this); - } super.onDestroy(); } @@ -589,23 +581,12 @@ export class Sprite extends Renderable2D { } protected _canRender () { - // if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) { - // if (!this._enabled) { return false; } - // } else { - // if (!this._enabled || !this._material) { return false; } - // } - - // const spriteFrame = this._spriteFrame; - // if (!spriteFrame || !spriteFrame.textureLoaded()) { - // return false; - // } - // return true; if (!super._canRender()) { return false; } const spriteFrame = this._spriteFrame; - if (!spriteFrame || !spriteFrame.textureLoaded()) { + if (!spriteFrame || !spriteFrame.texture) { return false; } @@ -675,65 +656,21 @@ export class Sprite extends Renderable2D { private _activateMaterial () { const spriteFrame = this._spriteFrame; const material = this.getRenderMaterial(0); - // WebGL - if (legacyCC.game.renderType !== legacyCC.game.RENDER_TYPE_CANVAS) { - if (spriteFrame) { - if (material) { - this.markForUpdateRenderData(); - } - } - - if (this._renderData) { - this._renderData.material = material; - } - } else { - this.markForUpdateRenderData(); - } - } - /* - private _applyAtlas (spriteFrame: SpriteFrame | null) { - if (!EDITOR) { - return; - } - // Set atlas if (spriteFrame) { - if (spriteFrame.atlasUuid.length > 0) { - if (!this._atlas || this._atlas._uuid !== spriteFrame.atlasUuid) { - const self = this; - assetManager.loadAny(spriteFrame.atlasUuid, (err, asset) => { - self._atlas = asset; - }); - } - }else{ - this._atlas = null; + if (material) { + this.markForUpdateRenderData(); } } - } -*/ - private _onTextureLoaded () { - if (!this.isValid) { - return; - } - this.changeMaterialForDefine(); - this._applySpriteSize(); + if (this._renderData) { + this._renderData.material = material; + } } private _applySpriteFrame (oldFrame: SpriteFrame | null) { - // if (oldFrame && oldFrame.off) { - // oldFrame.off('load', this._onTextureLoaded, this); - // } - const spriteFrame = this._spriteFrame; - // if (!spriteFrame || (this._material && this._material._texture) !== (spriteFrame && spriteFrame._texture)) { - // // disable render flow until texture is loaded - // this.markForRender(false); - // } if (this._renderData) { - if (oldFrame && !oldFrame.loaded) { - oldFrame.off('load', this._onTextureLoaded, this); - } if (!this._renderData.uvDirty) { if (oldFrame && spriteFrame) { this._renderData.uvDirty = oldFrame.uvHash !== spriteFrame.uvHash; @@ -750,15 +687,10 @@ export class Sprite extends Renderable2D { if (!oldFrame || oldFrame.texture !== spriteFrame.texture) { textureChanged = true; } - if (spriteFrame.loaded) { - if (textureChanged) { - this._onTextureLoaded(); - } else { - this._applySpriteSize(); - } - } else { - spriteFrame.once('load', this._onTextureLoaded, this); + if (textureChanged) { + this.changeMaterialForDefine(); } + this._applySpriteSize(); } /* if (EDITOR) { diff --git a/cocos/2d/utils/dynamic-atlas/atlas.ts b/cocos/2d/utils/dynamic-atlas/atlas.ts index 52bc9dc113..859658551a 100644 --- a/cocos/2d/utils/dynamic-atlas/atlas.ts +++ b/cocos/2d/utils/dynamic-atlas/atlas.ts @@ -159,8 +159,6 @@ export class DynamicAtlasTexture extends Texture2D { height, format, }); - this.loaded = true; - this.emit('load'); } /** diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 18f075e1f5..98f6a6cf85 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -188,13 +188,7 @@ export class Mesh extends Asset { } set _nativeAsset (value: ArrayBuffer) { - if (this._data.byteLength === value.byteLength) { - this._data.set(new Uint8Array(value)); - } else { - this._data = new Uint8Array(value); - } - this.loaded = true; - this.emit('load'); + this._data = new Uint8Array(value); } /** @@ -276,9 +270,6 @@ export class Mesh extends Asset { primitives: [], }; - @serializable - private _dataLength = 0; - @serializable private _hash = 0; @@ -294,7 +285,6 @@ export class Mesh extends Asset { constructor () { super(); - this.loaded = false; } public initialize () { @@ -303,13 +293,6 @@ export class Mesh extends Asset { } this._initialized = true; - - if (this._data.byteLength !== this._dataLength) { - // In the case of deferred loading, `this._data` is created before - // the actual binary buffer is loaded. - this._data = new Uint8Array(this._dataLength); - legacyCC.assetManager.postLoadNative(this); - } const { buffer } = this._data; const gfxDevice: Device = legacyCC.director.root.device; const vertexBuffers = this._createVertexBuffers(gfxDevice, buffer); @@ -352,13 +335,7 @@ export class Mesh extends Asset { if (idxView.stride !== dstStride) { ib = getIndexStrideCtor(dstStride).from(ib); } - if (this.loaded) { - indexBuffer.update(ib); - } else { - this.once('load', () => { - indexBuffer!.update(ib); - }); - } + indexBuffer.update(ib); } const vbReference = prim.vertexBundelIndices.map((idx) => vertexBuffers[idx]); @@ -433,10 +410,7 @@ export class Mesh extends Asset { this.destroyRenderingMesh(); this._struct = info.struct; this._data = info.data; - this._dataLength = this.data.byteLength; this._hash = 0; - this.loaded = true; - this.emit('load'); } /** @@ -494,7 +468,7 @@ export class Mesh extends Asset { */ public merge (mesh: Mesh, worldMatrix?: Mat4, validate?: boolean): boolean { if (validate) { - if (!this.loaded || !mesh.loaded || !this.validateMergingMesh(mesh)) { + if (!this.validateMergingMesh(mesh)) { return false; } } @@ -1023,13 +997,7 @@ export class Mesh extends Asset { )); const view = new Uint8Array(data, vertexBundle.view.offset, vertexBundle.view.length); - if (this.loaded) { - vertexBuffer.update(view); - } else { - this.once('load', () => { - vertexBuffer.update(view); - }); - } + vertexBuffer.update(view); return vertexBuffer; }); } diff --git a/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts b/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts index 930bcf0224..19cdd3aad7 100644 --- a/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts +++ b/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts @@ -488,7 +488,6 @@ export class SkinnedMeshBatchRenderer extends SkinnedMeshRenderer { height: this.atlasSize, format: PixelFormat.RGBA8888, }); - tex.loaded = true; this._textures[prop] = tex; return tex; } diff --git a/cocos/audio/audio-clip.ts b/cocos/audio/audio-clip.ts index 855c1391e2..5d8ef5c4d4 100644 --- a/cocos/audio/audio-clip.ts +++ b/cocos/audio/audio-clip.ts @@ -64,21 +64,17 @@ export class AudioClip extends Asset { constructor () { super(); - this.loaded = false; } set _nativeAsset (meta: AudioMeta | null) { this._meta = meta; if (meta) { - this.loaded = true; this._loadMode = meta.type; this._player = meta.player; - this.emit('load'); } else { this._meta = null; this._loadMode = AudioType.UNKNOWN_AUDIO; this._duration = 0; - this.loaded = false; } } diff --git a/cocos/core/asset-manager/asset-manager.ts b/cocos/core/asset-manager/asset-manager.ts index f482012f74..73b4551714 100644 --- a/cocos/core/asset-manager/asset-manager.ts +++ b/cocos/core/asset-manager/asset-manager.ts @@ -35,7 +35,6 @@ import { basename, extname } from '../utils/path'; import Bundle from './bundle'; import Cache from './cache'; import CacheManager from './cache-manager'; -import { nativeDependMap } from './depend-maps'; import dependUtil from './depend-util'; import downloader from './downloader'; import factory from './factory'; @@ -50,10 +49,8 @@ import releaseManager from './release-manager'; import RequestItem from './request-item'; import { CompleteCallbackWithData, - CompleteCallbackNoData, ProgressCallback, IBundleOptions, - INativeAssetOptions, IOptions, IRemoteOptions, presets, @@ -189,7 +186,7 @@ export class AssetManager { /** * @en - * Whether or not load asset forcely, if it is true, asset will be loaded regardless of error + * Whether or not load asset forcibly, if it is true, asset will be loaded regardless of error * * @zh * 是否强制加载资源, 如果为 true ,加载资源将会忽略报错 @@ -372,7 +369,7 @@ export class AssetManager { /** * @en - * Remove this bundle. NOTE: The asset whthin this bundle will not be released automatically, + * Remove this bundle. NOTE: The asset within this bundle will not be released automatically, * you can call {{#crossLink "Bundle/releaseAll:method"}}{{/crossLink}} manually before remove it if you need * * @zh @@ -394,7 +391,7 @@ export class AssetManager { * effect you want with combination of `requests` and `options`.It is highly recommended that you use more simple API, * such as `load`, `loadDir` etc. Every custom parameter in `options` will be distribute to each of `requests`. if request * already has same one, the parameter in request will be given priority. Besides, if request has dependencies, `options` - * will distribute to dependencies too. Every custom parameter in `requests` will be tranfered to handler of `downloader` + * will distribute to dependencies too. Every custom parameter in `requests` will be transferred to handler of `downloader` * and `parser` as `options`. You can register you own handler downloader or parser to collect these custom parameters for some effect. * * Reserved Keyword: `uuid`, `url`, `path`, `dir`, `scene`, `type`, `priority`, `preset`, `audioLoadMode`, `ext`, @@ -419,7 +416,7 @@ export class AssetManager { * @param onProgress.total - The total number of the items * @param onProgress.item - The current request item * @param onComplete - Callback invoked when finish loading - * @param onComplete.err - The error occured in loading process. + * @param onComplete.err - The error occurred in loading process. * @param onComplete.data - The loaded content * * @example @@ -476,7 +473,7 @@ export class AssetManager { * @param onProgress.total - The total number of the items * @param onProgress.item - The current request item * @param onComplete - Callback invoked when finish preloading - * @param onComplete.err - The error occured in preloading process. + * @param onComplete.err - The error occurred in preloading process. * @param onComplete.items - The preloaded content * * @example @@ -504,54 +501,6 @@ export class AssetManager { fetchPipeline.async(task); } - /** - * @en - * Load native file of asset, if you check the option 'Async Load Assets', you may need to load native file with this before you use the asset - * - * @zh - * 加载资源的原生文件,如果你勾选了'延迟加载资源'选项,你可能需要在使用资源之前调用此方法来加载原生文件 - * - * @param asset - The asset - * @param options - Some optional parameters - * @param onComplete - Callback invoked when finish loading - * @param onComplete.err - The error occured in loading process. - * - * @example - * cc.assetManager.postLoadNative(texture, (err) => console.log(err)); - * - */ - public postLoadNative (asset: Asset, options: INativeAssetOptions | null, onComplete: CompleteCallbackNoData | null): void; - public postLoadNative (asset: Asset, onComplete?: CompleteCallbackNoData | null): void; - public postLoadNative (asset: Asset, options?: INativeAssetOptions | CompleteCallbackNoData | null, onComplete?: CompleteCallbackNoData | null) { - const { options: opts, onComplete: onComp } = parseParameters(options, undefined, onComplete); - - if (!asset._native || !nativeDependMap.has(asset)) { - asyncify(onComp)(null); - return; - } - - const depend = dependUtil.getNativeDep(asset._uuid); - if (!depend) { return; } - if (!bundles.has(depend.bundle)) { - const bundle = bundles.find((b) => !!b.getAssetInfo(asset._uuid)); - if (bundle) { - depend.bundle = bundle.name; - } - } - - this.loadAny(depend, opts, (err, native) => { - if (!err) { - if (asset.isValid && nativeDependMap.has(asset)) { - asset._nativeAsset = native; - nativeDependMap.delete(asset); - } - } else { - error(err.message, err.stack); - } - if (onComp) { onComp(err); } - }); - } - /** * @en * Load remote asset with url, such as audio, image, text and so on. @@ -564,7 +513,7 @@ export class AssetManager { * @param options.audioLoadMode - Indicate which mode audio you want to load * @param options.ext - If the url does not have a extension name, you can specify one manually. * @param onComplete - Callback invoked when finish loading - * @param onComplete.err - The error occured in loading process. + * @param onComplete.err - The error occurred in loading process. * @param onComplete.asset - The loaded texture * * @example @@ -608,7 +557,7 @@ export class AssetManager { * @param options - Some optional paramter, same like downloader.downloadFile * @param options.version - The version of this bundle, you can check config.json in this bundle * @param onComplete - Callback when bundle loaded or failed - * @param onComplete.err - The occurred error, null indicetes success + * @param onComplete.err - The occurred error, null indicates success * @param onComplete.bundle - The loaded bundle * * @example @@ -668,7 +617,7 @@ export class AssetManager { /** * @en - * Release all unused assets. Refer to {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}} for detailed informations. + * Release all unused assets. Refer to {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}} for detailed information. * * @zh * 释放所有没有用到的资源。详细信息请参考 {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}} @@ -684,7 +633,7 @@ export class AssetManager { /** * @en - * Release all assets. Refer to {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}} for detailed informations. + * Release all assets. Refer to {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}} for detailed information. * * @zh * 释放所有资源。详细信息请参考 {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}} diff --git a/cocos/core/assets/asset.ts b/cocos/core/assets/asset.ts index 0b7a0f5eb4..9f72614096 100644 --- a/cocos/core/assets/asset.ts +++ b/cocos/core/assets/asset.ts @@ -78,6 +78,8 @@ export class Asset extends Eventify(CCObject) { * Whether the asset is loaded or not * @zh * 该资源是否已经成功加载。 + * + * @deprecated since v3.3 */ public loaded = true; diff --git a/cocos/core/assets/image-asset.ts b/cocos/core/assets/image-asset.ts index 83500cc11d..eb2b42ab95 100644 --- a/cocos/core/assets/image-asset.ts +++ b/cocos/core/assets/image-asset.ts @@ -165,8 +165,6 @@ export class ImageAsset extends Asset { constructor (nativeAsset?: ImageSource) { super(); - this.loaded = false; - this._nativeData = { _data: null, width: 0, @@ -192,25 +190,12 @@ export class ImageAsset extends Asset { public reset (data: ImageSource) { if (isImageBitmap(data)) { this._nativeData = data; - this._onDataComplete(); } else if (!(data instanceof HTMLElement)) { // this._nativeData = Object.create(data); this._nativeData = data; this._format = data.format; - this._onDataComplete(); } else { this._nativeData = data; - if (MINIGAME || (data as any).complete || data instanceof HTMLCanvasElement) { // todo need adatper - this._onDataComplete(); - } else { - this.loaded = false; - data.addEventListener('load', () => { - this._onDataComplete(); - }); - data.addEventListener('error', (err) => { - warnID(3119, err.message); - }); - } } } @@ -313,11 +298,6 @@ export class ImageAsset extends Asset { } } - public _onDataComplete () { - this.loaded = true; - this.emit('load'); - } - private static _sharedPlaceHolderCanvas: HTMLCanvasElement | null = null; public initDefault (uuid?: string) { @@ -347,14 +327,4 @@ function _getGlobalDevice (): Device | null { } return null; } - -/** - * @zh - * 当该资源加载成功后触发该事件。 - * @en - * This event is emitted when the asset is loaded - * - * @event load - */ - legacyCC.ImageAsset = ImageAsset; diff --git a/cocos/core/assets/material.ts b/cocos/core/assets/material.ts index 9dc71d5df5..6801eff038 100644 --- a/cocos/core/assets/material.ts +++ b/cocos/core/assets/material.ts @@ -125,7 +125,6 @@ export class Material extends Asset { constructor () { super(); - this.loaded = false; } /** @@ -253,8 +252,6 @@ export class Material extends Asset { */ public onLoaded () { this._update(); - this.loaded = true; - this.emit('load'); } /** diff --git a/cocos/core/assets/render-texture.ts b/cocos/core/assets/render-texture.ts index 1e3bff0358..33fec26153 100644 --- a/cocos/core/assets/render-texture.ts +++ b/cocos/core/assets/render-texture.ts @@ -177,8 +177,6 @@ export class RenderTexture extends Asset { public onLoaded () { this._initWindow(); - this.loaded = true; - this.emit('load'); } protected _initWindow (info?: IRenderTextureCreateInfo) { diff --git a/cocos/core/assets/simple-texture.ts b/cocos/core/assets/simple-texture.ts index dbe260b10b..0ac141a2ce 100644 --- a/cocos/core/assets/simple-texture.ts +++ b/cocos/core/assets/simple-texture.ts @@ -163,34 +163,20 @@ export class SimpleTexture extends TextureBase { } protected _assignImage (image: ImageAsset, level: number, arrayIndex?: number) { - const upload = () => { - const data = image.data; - if (!data) { - return; - } - this.uploadData(data, level, arrayIndex); - this._checkTextureLoaded(); + const data = image.data; + if (!data) { + return; + } + this.uploadData(data, level, arrayIndex); + this._checkTextureLoaded(); - if (macro.CLEANUP_IMAGE_CACHE) { - const deps = dependUtil.getDeps(this._uuid); - const index = deps.indexOf(image._uuid); - if (index !== -1) { - fastRemoveAt(deps, index); - image.decRef(); - } + if (macro.CLEANUP_IMAGE_CACHE) { + const deps = dependUtil.getDeps(this._uuid); + const index = deps.indexOf(image._uuid); + if (index !== -1) { + fastRemoveAt(deps, index); + image.decRef(); } - }; - if (image.loaded) { - upload(); - } else { - image.once('load', () => { - upload(); - }); - if (!this.isCompressed) { - const defaultImg = legacyCC.builtinResMgr.get('black-texture').image as ImageAsset; - this.uploadData(defaultImg.data as HTMLCanvasElement, level, arrayIndex); - } - legacyCC.assetManager.postLoadNative(image); } } diff --git a/cocos/core/assets/texture-2d.ts b/cocos/core/assets/texture-2d.ts index 0ff1e4d2c4..2801f4e07b 100644 --- a/cocos/core/assets/texture-2d.ts +++ b/cocos/core/assets/texture-2d.ts @@ -270,21 +270,6 @@ export class Texture2D extends SimpleTexture { return Object.assign(texInfo, presumed); } - protected _checkTextureLoaded () { - let ready = true; - for (let i = 0; i < this._mipmaps.length; ++i) { - const image = this._mipmaps[i]; - if (!image.loaded) { - ready = false; - break; - } - } - - if (ready) { - super._textureReady(); - } - } - public initDefault (uuid?: string) { super.initDefault(uuid); const imageAsset = new ImageAsset(); diff --git a/cocos/core/assets/texture-base.ts b/cocos/core/assets/texture-base.ts index ade5395a6e..18a62c8627 100644 --- a/cocos/core/assets/texture-base.ts +++ b/cocos/core/assets/texture-base.ts @@ -131,8 +131,6 @@ export class TextureBase extends Asset { // Id for generate hash in material this._id = idGenerator.getNewId(); - - this.loaded = false; this._gfxDevice = this._getGFXDevice(); this._textureHash = murmurhash2_32_gc(this._id, 666); } diff --git a/cocos/core/assets/texture-cube.ts b/cocos/core/assets/texture-cube.ts index edda8cfd72..c01116db9e 100644 --- a/cocos/core/assets/texture-cube.ts +++ b/cocos/core/assets/texture-cube.ts @@ -170,8 +170,6 @@ export class TextureCube extends SimpleTexture { public onLoaded () { this.mipmaps = this._mipmaps; - this.loaded = true; - this.emit('load'); } /** diff --git a/cocos/dragon-bones/ArmatureDisplay.ts b/cocos/dragon-bones/ArmatureDisplay.ts index f41a93dbca..e1c300ae09 100644 --- a/cocos/dragon-bones/ArmatureDisplay.ts +++ b/cocos/dragon-bones/ArmatureDisplay.ts @@ -613,7 +613,7 @@ export class ArmatureDisplay extends Renderable2D { _validateRender () { const texture = this.dragonAtlasAsset && this.dragonAtlasAsset.texture; - if (!texture || !texture.loaded) { + if (!texture) { this.disableRender(); return false; } diff --git a/cocos/particle-2d/particle-system-2d.ts b/cocos/particle-2d/particle-system-2d.ts index 9e824cf678..82144ff714 100644 --- a/cocos/particle-2d/particle-system-2d.ts +++ b/cocos/particle-2d/particle-system-2d.ts @@ -719,7 +719,6 @@ export class ParticleSystem2D extends Renderable2D { private _positionType = PositionType.FREE; private _stopped = true; - private _deferredloaded = false; private declare _previewTimer; private declare _focused: boolean; private declare _plistFile; @@ -876,37 +875,28 @@ export class ParticleSystem2D extends Renderable2D { public _applyFile () { const file = this._file; if (file) { - const applyTemp = (err: any) => { - if (err || !file) { - errorID(6029); - return; - } - if (!this.isValid) { - return; - } - this._plistFile = file.nativeUrl; - if (!this._custom) { - const isDiffFrame = this._spriteFrame !== file.spriteFrame; - if (isDiffFrame) this.spriteFrame = file.spriteFrame; - this._initWithDictionary(file._nativeAsset); - } + if (!file) { + errorID(6029); + return; + } + if (!this.isValid) { + return; + } + this._plistFile = file.nativeUrl; + if (!this._custom) { + const isDiffFrame = this._spriteFrame !== file.spriteFrame; + if (isDiffFrame) this.spriteFrame = file.spriteFrame; + this._initWithDictionary(file._nativeAsset); + } - if (!this._spriteFrame) { - if (file.spriteFrame) { - this.spriteFrame = file.spriteFrame; - } else if (this._custom) { - this._initTextureWithDictionary(file._nativeAsset); - } - } else if (!this._renderSpriteFrame && this._spriteFrame) { - this._applySpriteFrame(); + if (!this._spriteFrame) { + if (file.spriteFrame) { + this.spriteFrame = file.spriteFrame; + } else if (this._custom) { + this._initTextureWithDictionary(file._nativeAsset); } - this._deferredloaded = false; - }; - if (file._nativeAsset) { - applyTemp(null); - } else { - this._deferredloaded = true; - assetManager.postLoadNative(file, applyTemp); + } else if (!this._renderSpriteFrame && this._spriteFrame) { + this._applySpriteFrame(); } } } @@ -1096,14 +1086,6 @@ export class ParticleSystem2D extends Renderable2D { return true; } - public _onTextureLoaded () { - this._simulator.updateUVs(true); - this._syncAspect(); - this._updateMaterial(); - this._stopped = false; - this._renderFlag = this._canRender(); - } - public _syncAspect () { if (this._renderSpriteFrame) { const frameRect = this._renderSpriteFrame.rect; @@ -1114,10 +1096,12 @@ export class ParticleSystem2D extends Renderable2D { public _applySpriteFrame () { this._renderSpriteFrame = this._renderSpriteFrame || this._spriteFrame; if (this._renderSpriteFrame) { - if (this._renderSpriteFrame.textureLoaded()) { - this._onTextureLoaded(); - } else { - this._renderSpriteFrame.once('load', this._onTextureLoaded, this); + if (this._renderSpriteFrame.texture) { + this._simulator.updateUVs(true); + this._syncAspect(); + this._updateMaterial(); + this._stopped = false; + this._renderFlag = this._canRender(); } } else { this.resetSystem(); @@ -1149,7 +1133,7 @@ export class ParticleSystem2D extends Renderable2D { } protected _canRender () { - return super._canRender() && !this._stopped && !this._deferredloaded && this._renderSpriteFrame !== null; + return super._canRender() && !this._stopped && this._renderSpriteFrame !== null; } protected _render (render: Batcher2D) { diff --git a/cocos/spine/skeleton-data.ts b/cocos/spine/skeleton-data.ts index b044c61e7d..93293136c6 100644 --- a/cocos/spine/skeleton-data.ts +++ b/cocos/spine/skeleton-data.ts @@ -148,43 +148,6 @@ export class SkeletonData extends Asset { } } - public ensureTexturesLoaded (loaded: null | ((x: boolean) => void), caller: any) { - const textures = this.textures; - const texsLen = textures.length; - if (texsLen === 0) { - if (loaded) loaded.call(caller, false); - return; - } - let loadedCount = 0; - const loadedItem = () => { - loadedCount++; - if (loadedCount >= texsLen) { - if (loaded) loaded.call(caller, true); - loaded = null; - } - }; - for (let i = 0; i < texsLen; i++) { - const tex = textures[i]; - if (tex.loaded) { - loadedItem(); - } else { - tex.once('load', loadedItem); - } - } - } - - public isTexturesLoaded () { - const textures = this.textures; - const texsLen = textures.length; - for (let i = 0; i < texsLen; i++) { - const tex = textures[i]; - if (!tex.loaded) { - return false; - } - } - return true; - } - /** * @en Get the included SkeletonData used in spine runtime.
* Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.SkeletonData object. diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 5188ebde2d..22fab614d5 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -1485,7 +1485,7 @@ export class Skeleton extends Renderable2D { protected _validateRender () { const skeletonData = this.skeletonData; - if (!skeletonData || !skeletonData.isTexturesLoaded()) { + if (!skeletonData) { this.disableRender(); } } diff --git a/cocos/terrain/terrain-asset.ts b/cocos/terrain/terrain-asset.ts index cae412cfd6..4ee17226a0 100644 --- a/cocos/terrain/terrain-asset.ts +++ b/cocos/terrain/terrain-asset.ts @@ -248,7 +248,6 @@ export class TerrainAsset extends Asset { constructor () { super(); - this.loaded = false; } get _nativeAsset (): ArrayBuffer { @@ -263,8 +262,6 @@ export class TerrainAsset extends Asset { } this._loadNativeData(this._data); - this.loaded = true; - this.emit('load'); } /** diff --git a/cocos/tiledmap/tiled-layer.ts b/cocos/tiledmap/tiled-layer.ts index 13f2972c74..da133f01d9 100644 --- a/cocos/tiledmap/tiled-layer.ts +++ b/cocos/tiledmap/tiled-layer.ts @@ -45,7 +45,7 @@ import { MixedGID, GID, Orientation, TiledTextureGrids, TMXTilesetInfo, RenderOrder, StaggerAxis, StaggerIndex, TileFlag, GIDFlags, TiledGrid, TiledAnimationType, PropertiesInfo, TMXLayerInfo, } from './tiled-types'; -import { fillTextureGrids, loadAllTextures } from './tiled-utils'; +import { fillTextureGrids } from './tiled-utils'; import { NodeEventType } from '../core/scene-graph/node-event'; const _mat4_temp = new Mat4(); @@ -1282,14 +1282,12 @@ export class TiledLayer extends Renderable2D { } } - loadAllTextures(textures, () => { - for (let i = 0, l = tilesets.length; i < l; ++i) { - const tilesetInfo = tilesets[i]; - if (!tilesetInfo) continue; - fillTextureGrids(tilesetInfo, texGrids, tilesetInfo.sourceImage); - } - this._prepareToRender(); - }); + for (let i = 0, l = tilesets.length; i < l; ++i) { + const tilesetInfo = tilesets[i]; + if (!tilesetInfo) continue; + fillTextureGrids(tilesetInfo, texGrids, tilesetInfo.sourceImage); + } + this._prepareToRender(); } public init (layerInfo: TMXLayerInfo, mapInfo: TMXMapInfo, tilesets: TMXTilesetInfo[], textures: SpriteFrame[], texGrids: TiledTextureGrids) { diff --git a/cocos/tiledmap/tiled-map.ts b/cocos/tiledmap/tiled-map.ts index 26d884b899..9a58aece5e 100644 --- a/cocos/tiledmap/tiled-map.ts +++ b/cocos/tiledmap/tiled-map.ts @@ -39,7 +39,7 @@ import { TiledLayer } from './tiled-layer'; import { TiledObjectGroup } from './tiled-object-group'; import { TiledMapAsset } from './tiled-map-asset'; import { Sprite } from '../2d/components/sprite'; -import { fillTextureGrids, loadAllTextures } from './tiled-utils'; +import { fillTextureGrids } from './tiled-utils'; import { Size, Vec2, Node, logID, Color, sys } from '../core'; import { SpriteFrame } from '../2d/assets'; import { NodeEventType } from '../core/scene-graph/node-event'; @@ -593,14 +593,12 @@ export class TiledMap extends Component { totalTextures.push(imageLayer.sourceImage); } - loadAllTextures(totalTextures, () => { - this._buildLayerAndGroup(); - if (this.cleanupImageCache) { - this._textures.forEach((tex) => { - this.doCleanupImageCache(tex); - }); - } - }); + this._buildLayerAndGroup(); + if (this.cleanupImageCache) { + this._textures.forEach((tex) => { + this.doCleanupImageCache(tex); + }); + } } doCleanupImageCache (texture) { diff --git a/cocos/tiledmap/tiled-utils.ts b/cocos/tiledmap/tiled-utils.ts index b215ea9948..38b0378731 100644 --- a/cocos/tiledmap/tiled-utils.ts +++ b/cocos/tiledmap/tiled-utils.ts @@ -139,30 +139,3 @@ export function fillTextureGrids (tileset: TMXTilesetInfo, texGrids: TiledTextur texGrids.set(gid as unknown as GID, grid); } } - -export function loadAllTextures (textures: SpriteFrame[], loadedCallback: any) { - const totalNum = textures.length; - if (totalNum === 0) { - loadedCallback(); - return; - } - - let curNum = 0; - const itemCallback = () => { - curNum++; - if (curNum >= totalNum) { - loadedCallback(); - } - }; - - for (let i = 0; i < totalNum; i++) { - const tex = textures[i]; - if (!tex.loaded) { - tex.once('load', () => { - itemCallback(); - }); - } else { - itemCallback(); - } - } -} diff --git a/cocos/video/assets/video-clip.ts b/cocos/video/assets/video-clip.ts index a2b31884ad..243a57ab1f 100644 --- a/cocos/video/assets/video-clip.ts +++ b/cocos/video/assets/video-clip.ts @@ -45,17 +45,14 @@ export class VideoClip extends Asset { constructor () { super(); - this.loaded = false; } set _nativeAsset (clip: HTMLVideoElement | null) { this._video = clip; if (clip) { this._duration = clip.duration; - this.loaded = true; } else { this._duration = 0; - this.loaded = false; } }