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

[v3.8.6] Optimize code size by defining Constructor explicitly. #18119

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

dumganhar
Copy link
Contributor

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@dumganhar dumganhar marked this pull request as draft January 3, 2025 09:40
Copy link

github-actions bot commented Jan 3, 2025

👍 Package size ⤵ -105 bytes, old: 5245887, new: 5245782

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -582,9 +582,9 @@
          * @en All sprite frames in the sprite atlas.
          * @zh 精灵图集中的所有精灵。
          */
         spriteFrames: __private._cocos_2d_assets_sprite_atlas__ISpriteFrameList;
-        constructor();
+        constructor(name?: string);
         /**
          * @en Get the [[Texture2D]] asset of the atlas.
          * @zh 获取精灵图集的贴图。
          * @returns @en The texture2d asset. @zh 二维贴图资源。
@@ -687,8 +687,9 @@
      * @en Class for Font handling.
      * @zh 字体资源类。
      */
     export class Font extends Asset {
+        constructor(name?: string);
     }
     /**
      * @deprecated since v3.7.0, this is an engine private interface that will be removed in the future.
      */
@@ -1017,9 +1018,9 @@
         protected _customOutLine: never[];
         protected _mesh: Mesh | null;
         protected _minPos: math.Vec3;
         protected _maxPos: math.Vec3;
-        constructor();
+        constructor(name?: string);
         /**
          * @en
          * Returns whether the texture have been loaded.
          * @zh
@@ -4231,9 +4232,9 @@
          * @en morph rendering data
          * @zh 变形渲染数据
          */
         morphRendering: __private._cocos_3d_assets_morph_rendering__MorphRendering | null;
-        constructor();
+        constructor(name?: string);
         /**
          * @en complete loading callback
          * @zh 加载完成回调
          */
@@ -4562,9 +4563,9 @@
      * @en The skeleton asset. It stores the path related to [[SkinnedMeshRenderer.skinningRoot]] of all bones and its bind pose matrix.
      * @zh 骨骼资源。骨骼资源记录了每个关节(相对于 [[SkinnedMeshRenderer.skinningRoot]])的路径以及它的绑定姿势矩阵。
      */
     export class Skeleton extends Asset {
-        constructor();
+        constructor(name?: string);
         /**
          * @en The path of all bones, the length always equals the length of [[bindposes]]
          * @zh 所有关节的路径。该数组的长度始终与 [[bindposes]] 的长度相同。
          */
@@ -5722,8 +5723,9 @@
          * Normally this flag is enabled for model animation and disabled for other case.
          * @internal This is an internal slot. Never use it in your code.
          */
         enableTrsBlending: boolean;
+        constructor(name?: string);
         /**
          * @zh 动画的周期。
          * @en Animation duration.
          */
@@ -7464,9 +7466,9 @@
         static AudioType: typeof __private._pal_audio_type__AudioType;
         protected _duration: number;
         protected _loadMode: __private._pal_audio_type__AudioType;
         protected _meta: __private._cocos_audio_audio_clip__AudioMeta | null;
-        constructor();
+        constructor(name?: string);
         destroy(): boolean;
         /**
          * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
          */
@@ -9503,8 +9505,9 @@
          * @en GFX Device.
          * @zh GFX 设备。
          */
         export abstract class Device {
+            constructor();
             /**
              * @en Current rendering API.
              * @zh 当前 GFX 使用的渲染 API。
              */
@@ -10421,8 +10424,9 @@
         /**
          * @internal
          */
         export class DeviceManager {
+            constructor();
             get gfxDevice(): Device;
             get swapchain(): Swapchain;
             init(canvas: HTMLCanvasElement | null, bindingMappingInfo: BindingMappingInfo): boolean | Promise<boolean>;
         }
@@ -11788,8 +11792,9 @@
                 protected _instancedAttributeBlock: IInstancedAttributeBlock;
                 protected _instancedWorldMatrixIndex: number;
                 protected _instancedSHIndex: number;
                 protected _useReflectionProbeType: number;
+                constructor();
                 /**
                  * @en
                  * sub model's passes
                  * @zh
@@ -12429,8 +12434,9 @@
              * @en The fog representation in the render scene.
              * @zh 渲染场景中的全局雾效配置
              */
             export class Fog {
+                constructor();
                 /**
                  * @zh 是否启用全局雾效
                  * @en Enable global fog
                  */
@@ -19973,8 +19979,9 @@
      * @en The base class of all value types.
      * @zh 所有值类型的基类。
      */
     export class ValueType {
+        constructor();
         /**
          * @en
          * Clone the current object. The clone result of the object should be equal to the current object,
          * i.e. satisfy `this.equals(this, value.clone())`.
@@ -23025,8 +23032,9 @@
      * You can access this single instance of the module via [settings].
      */
     export class Settings {
         static Category: typeof SettingsCategory;
+        constructor();
         /**
          * Initialization
          * @internal
          */
@@ -25823,32 +25831,38 @@
             export function expandPrefabInstanceNode(node: Node, recursively?: boolean): void;
             export function expandNestedPrefabInstanceNode(node: Node): void;
             export function applyNodeAndComponentId(prefabInstanceNode: Node, rootId: string): void;
             export class TargetInfo {
+                constructor();
                 localID: string[];
             }
             export class TargetOverrideInfo {
+                constructor();
                 source: Component | Node | null;
                 sourceInfo: TargetInfo | null;
                 propertyPath: string[];
                 target: Node | null;
                 targetInfo: TargetInfo | null;
             }
             export class CompPrefabInfo {
+                constructor();
                 fileId: string;
             }
             export class PropertyOverrideInfo {
+                constructor();
                 targetInfo: TargetInfo | null;
                 propertyPath: string[];
                 value: any;
                 isTarget(localID: string[], propPath: string[]): boolean | undefined;
             }
             export class MountedChildrenInfo {
+                constructor();
                 targetInfo: TargetInfo | null;
                 nodes: Node[];
                 isTarget(localID: string[]): boolean | undefined;
             }
             export class MountedComponentsInfo {
+                constructor();
                 targetInfo: TargetInfo | null;
                 components: Component[];
                 isTarget(localID: string[]): boolean | undefined;
             }
@@ -25856,8 +25870,9 @@
              * Prefab实例类
              * @internal
              */
             export class PrefabInstance {
+                constructor();
                 fileId: string;
                 prefabRootNode?: Node;
                 mountedChildren: MountedChildrenInfo[];
                 mountedComponents: MountedComponentsInfo[];
@@ -25875,8 +25890,9 @@
             export interface TargetMap {
                 [k: string]: TargetMap | Node | Component;
             }
             export class PrefabInfo {
+                constructor();
                 root?: Node;
                 asset?: Prefab;
                 fileId: string;
                 instance?: PrefabInstance;
@@ -28684,9 +28700,9 @@
      * @zh
      * `BufferAsset` 是一类资产,其内部数据是一段内存缓冲,你可以通过 [[BufferAsset.buffer]] 函数获取其内部数据。
      */
     export class BufferAsset extends Asset {
-        constructor();
+        constructor(name?: string);
         /**
          * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
          */
         get _nativeAsset(): ArrayBuffer | ArrayBufferView;
@@ -28817,9 +28833,9 @@
          * @en The scene node
          * @zh 场景节点。
          */
         scene: Scene | null;
-        constructor();
+        constructor(name?: string);
         initDefault(uuid?: string): void;
         validate(): boolean;
     }
     /**
@@ -28832,9 +28848,9 @@
          * @zh 此资源包含的文本。
          */
         text: string;
         toString(): string;
-        constructor();
+        constructor(name?: string);
     }
     /**
      * @en Json asset, it will automatically parse the json to a JS object.
      * @zh Json 资源。
@@ -28845,9 +28861,9 @@
          * @en The parsed JS object
          * @zh 解析后的对象。
          */
         json: Record<string, any> | null;
-        constructor();
+        constructor(name?: string);
     }
     /**
      * @en Image Asset. The image resource stores the raw data of the image and you can use this resource to create any Texture resource.
      * @zh 图像资源。图像资源存储了图像的原始数据,你可以使用此资源来创建任意 [[TextureBase]] 资源。
@@ -28930,9 +28946,9 @@
      * @en The 2D texture asset. It supports mipmap, each level of mipmap use an [[ImageAsset]].
      * @zh 二维贴图资源。二维贴图资源的每个 Mipmap 层级都为一张 [[ImageAsset]]。
      */
     export class Texture2D extends __private._cocos_asset_assets_simple_texture__SimpleTexture {
-        constructor();
+        constructor(name?: string);
         /**
          * @en All levels of mipmap images, be noted, automatically generated mipmaps are not included.
          * When setup mipmap, the size of the texture and pixel format could be modified.
          * @zh 所有层级 Mipmap,注意,这里不包含自动生成的 Mipmap。
@@ -29027,9 +29043,9 @@
         static FaceIndex: typeof __private._cocos_asset_assets_texture_cube__FaceIndex;
         isRGBE: boolean;
         _mipmapAtlas: __private._cocos_asset_assets_texture_cube__ITextureCubeMipmapAtlas | null;
         _mipmapMode: __private._cocos_asset_assets_texture_cube__MipmapMode;
-        constructor();
+        constructor(name?: string);
         /**
          * @en All levels of mipmap images, be noted, automatically generated mipmaps are not included.
          * When setup mipmap, the size of the texture and pixel format could be modified.
          * @zh 所有层级 Mipmap,注意,这里不包含自动生成的 Mipmap。
@@ -29181,9 +29197,9 @@
          * @en Whether to hide in editor mode.
          * @zh 是否在编辑器内隐藏。
          */
         hideInEditor: boolean;
-        constructor();
+        constructor(name?: string);
         /**
          * @en The loaded callback which should be invoked by the [[AssetManager]], will automatically register the effect.
          * @zh 通过 [[AssetManager]] 加载完成时的回调,将自动注册 effect 资源。
          */
@@ -29428,9 +29444,9 @@
         /**
          * @internal
          */
         protected _hash: number;
-        constructor();
+        constructor(name?: string);
         /**
          * @en The current [[EffectAsset]].
          * @zh 当前使用的 [[EffectAsset]] 资源。
          */
@@ -29561,9 +29577,9 @@
      * the render pipeline will use its `RenderWindow` as the target of the rendering process.
      * @zh 渲染贴图是 [[Camera]] 或 [[Canvas]] 组件的渲染目标对象,渲染管线会使用它的 `RenderWindow` 作为渲染的目标窗口。
      */
     export class RenderTexture extends __private._cocos_asset_assets_texture_base__TextureBase {
-        constructor();
+        constructor(name?: string);
         /**
          * @en The render window for the render pipeline, it's created internally and cannot be modified.
          * @zh 渲染管线所使用的渲染窗口,内部逻辑创建,无法被修改。
          */
@@ -29638,20 +29654,23 @@
      * @en The script asset base class
      * @zh 脚本资源基类。
      */
     export class Script extends Asset {
+        constructor(name?: string);
     }
     /**
      * @en JavaScript asset.
      * @zh JavaScript 脚本资源。
      */
     export class JavaScript extends Script {
+        constructor(name?: string);
     }
     /**
      * @en TypeScript asset
      * @zh TypeScript 脚本资源。
      */
     export class TypeScript extends Script {
+        constructor(name?: string);
     }
     /**
      * @en `assetManager` is a global singleton instance of [[AssetManager]].
      * The engine uses `assetManager` to manage all asset and asset bundle, including loading, releasing, etc.
@@ -30782,8 +30801,9 @@
          * 一个包含一定数量资源(包括场景)的包,你可以加载,预加载,释放此包内的资源。
          *
          */
         export class Bundle {
+            constructor();
             /**
              * @en
              * The name of this bundle.
              *
@@ -32220,8 +32240,9 @@
     export const url: {};
     export class BuiltinResMgr {
         protected _resources: Record<string, Asset>;
         protected _materialsToBeCompiled: Material[];
+        constructor();
         init(): void;
         addAsset(key: string, asset: Asset): void;
         get<T extends Asset>(uuid: string): T;
         /**
@@ -60790,9 +60811,9 @@
              * @en The texture filter mode enum.
              * @zh 纹理过滤模式枚举类型。
              */
             static Filter: typeof _cocos_asset_assets_asset_enum__TextureFilter;
-            constructor();
+            constructor(name?: string);
             /**
              * @en Gets the id of the texture.
              * @zh 获取标识符。
              * @returns @en The id of this texture. @zh 此贴图的 id。
@@ -64259,8 +64280,9 @@
         export class _cocos_core_event_callbacks_invoker__CallbackInfo {
             callback: __types_globals__AnyFunction;
             target: unknown;
             once: boolean;
+            constructor();
             set(callback: __types_globals__AnyFunction, target?: unknown, once?: boolean): void;
             reset(): void;
             check(): boolean;
         }
@@ -64271,8 +64293,9 @@
         export class _cocos_core_event_callbacks_invoker__CallbackList {
             callbackInfos: Array<_cocos_core_event_callbacks_invoker__CallbackInfo | null>;
             isInvoking: boolean;
             containCanceled: boolean;
+            constructor();
             /**
              * @zh 从列表中移除与指定目标相同回调函数的事件。
              * @en Remove the event listeners with the given callback from the list
              *
@@ -64321,8 +64344,9 @@
             /**
              * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
              */
             _callbackTable: _cocos_core_event_callbacks_invoker__ICallbackTable;
+            constructor();
             /**
              * @zh 向一个事件名注册一个新的事件监听器,包含回调函数和调用者
              * @en Register an event listener to a given event key with callback and target.
              *
@@ -64635,10 +64659,10 @@
              * @deprecated since v3.4
              */
             static markOpacityTree(node: any, isDirty?: boolean): void;
         }
+        export type _cocos_scene_graph_component_scheduler__InvokeFunc = (...args: unknown[]) => void;
         function _cocos_scene_graph_component_scheduler__stableRemoveInactive(iterator: any, flagToClear: any): void;
-        export type _cocos_scene_graph_component_scheduler__InvokeFunc = (...args: unknown[]) => void;
         export class _cocos_scene_graph_component_scheduler__LifeCycleInvoker {
             static stableRemoveInactive: typeof _cocos_scene_graph_component_scheduler__stableRemoveInactive;
             protected _zero: js.array.MutableForwardIterator<any>;
             protected _neg: js.array.MutableForwardIterator<any>;
@@ -64646,8 +64670,9 @@
             protected _invoke: _cocos_scene_graph_component_scheduler__InvokeFunc;
             constructor(invokeFunc: _cocos_scene_graph_component_scheduler__InvokeFunc);
         }
         export class _cocos_scene_graph_node_activator__UnsortedInvoker extends _cocos_scene_graph_component_scheduler__LifeCycleInvoker {
+            constructor(invokeFunc: _cocos_scene_graph_component_scheduler__InvokeFunc);
             add(comp: Component): void;
             remove(comp: Component): void;
             cancelInactive(flagToClear: number): void;
             invoke(): void;
@@ -64698,8 +64723,9 @@
         export const _cocos_misc_camera_component__Aperture: typeof renderer.scene.CameraAperture;
         export const _cocos_misc_camera_component__Shutter: typeof renderer.scene.CameraShutter;
         export const _cocos_misc_camera_component__ISO: typeof renderer.scene.CameraISO;
         export class _cocos_scene_graph_component_scheduler__ReusableInvoker extends _cocos_scene_graph_component_scheduler__LifeCycleInvoker {
+            constructor(invokeFunc: _cocos_scene_graph_component_scheduler__InvokeFunc);
             add(comp: Component): void;
             remove(comp: Component): void;
             invoke(dt: number): void;
         }
@@ -65176,9 +65202,9 @@
          * 简单贴图内部创建了 GFX 贴图和该贴图上的 GFX 贴图视图。
          * 简单贴图允许指定不同的 Mipmap 层级。
          */
         export class _cocos_asset_assets_simple_texture__SimpleTexture extends _cocos_asset_assets_texture_base__TextureBase {
-            constructor();
+            constructor(name?: string);
             /**
              * @en The mipmap level of the texture.
              * @zh 贴图中的 Mipmap 层级数量。
              */
@@ -65610,8 +65636,9 @@
             load(item: AssetManager.RequestItem, options: Record<string, any> | null, onComplete: ((err: Error | null, data?: any) => void)): void;
         }
         export type _cocos_asset_asset_manager_factory__CreateHandler = (id: string, data: any, options: Record<string, any>, onComplete: ((err: Error | null, data?: Asset | AssetManager.Bundle | null) => void)) => void;
         export class _cocos_asset_asset_manager_factory__Factory {
+            constructor();
             register(type: string | Record<string, _cocos_asset_asset_manager_factory__CreateHandler>, handler?: _cocos_asset_asset_manager_factory__CreateHandler): void;
             create(id: string, data: any, type: string, options: Record<string, any>, onComplete: ((err: Error | null, data?: Asset | AssetManager.Bundle | null) => void)): void;
         }
         export function _cocos_asset_asset_manager_preprocess__default(task: AssetManager.Task, done: ((err?: Error | null) => void)): void;

@dumganhar dumganhar closed this Jan 3, 2025
@dumganhar dumganhar reopened this Jan 3, 2025
@dumganhar dumganhar requested a review from minggo January 13, 2025 09:17
@dumganhar dumganhar marked this pull request as ready for review January 13, 2025 09:17
@minggo minggo merged commit 515244b into cocos:v3.8.6 Jan 13, 2025
12 checks 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.

2 participants