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.5] Support inline enum and mangle private variables to reduce engine size. #17703

Open
wants to merge 57 commits into
base: v3.8.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d1a693c
Inline enum
dumganhar Aug 8, 2024
b0df8ec
$ suffix.
dumganhar Aug 9, 2024
562c3fe
Update
dumganhar Aug 9, 2024
47ae217
optimize
dumganhar Aug 9, 2024
2613bcf
Remove second commandbuffer.
dumganhar Aug 10, 2024
d7a24a3
Shorter state cache invocations
dumganhar Aug 10, 2024
1ab40f1
Update webgl-wapchain.ts
dumganhar Aug 10, 2024
1664022
Remove unused code in gfx/base, gfx/webgl module and mangle propertie…
dumganhar Aug 12, 2024
947d3b9
Use function reference instead of defining a function for Math.ceil a…
dumganhar Aug 12, 2024
4d8a212
Fix device-manager.ts
dumganhar Aug 13, 2024
6362bc6
Fix wrong variables
dumganhar Sep 13, 2024
eab5c82
Temp commit
dumganhar Sep 14, 2024
8f9b485
Merge branch 'v3.8.5' of https://github.com/cocos/cocos-engine into 3…
dumganhar Sep 19, 2024
3f28f59
Update WebGL2 backend.
dumganhar Sep 19, 2024
ffb3317
Merge branch '385-reduce-gfx-code' into inline-enum
dumganhar Sep 19, 2024
d7fef7e
For testing.
dumganhar Sep 19, 2024
57e230f
continue fix webgl2 backend.
dumganhar Sep 19, 2024
ad8f641
Update
dumganhar Sep 19, 2024
31577e7
optimize math library size.
dumganhar Sep 23, 2024
c32026e
revert splash-screen hack.
dumganhar Sep 23, 2024
84d7f76
smaller scheduler.ts
dumganhar Sep 23, 2024
f709b20
Update spine.
dumganhar Sep 23, 2024
932ccbb
smaller editboximpl
dumganhar Sep 23, 2024
76a1069
update prefab.ts for SUPPORT_JIT.
dumganhar Sep 23, 2024
04cd30f
Update mesh.ts and minigame Editbox.js
dumganhar Sep 23, 2024
c971773
Add ONLY_2D flag
dumganhar Sep 23, 2024
95f119b
smaller root.ts
dumganhar Sep 23, 2024
0a6c1f9
smaller minigame pal.
dumganhar Sep 23, 2024
b964b90
smaller render-scene code.
dumganhar Sep 23, 2024
dbdef07
smaller scene-global
dumganhar Sep 23, 2024
4e5fad4
smaller ui.
dumganhar Sep 23, 2024
acf6a03
smaller asset
dumganhar Sep 24, 2024
c99386a
smaller core
dumganhar Sep 24, 2024
eaadd3d
smaller game
dumganhar Sep 24, 2024
2de84fa
const enum WebGLConstants
dumganhar Sep 24, 2024
91502cf
smaller input
dumganhar Sep 24, 2024
e46bec4
smaller scene-graph
dumganhar Sep 24, 2024
bb5c015
smaller serialization
dumganhar Sep 24, 2024
07e8686
smaller zlib.min.js
dumganhar Sep 24, 2024
fb94e5b
smaller sorting-layer
dumganhar Sep 24, 2024
b9cd18c
Merge branch 'v3.8.5' of https://github.com/cocos/cocos-engine into i…
dumganhar Sep 24, 2024
e688401
Update cc.config.json, add treeshake config.
dumganhar Sep 25, 2024
e526fa2
Update ccbuild to 2.2.14.
dumganhar Sep 25, 2024
d21ce5f
Merge branch 'v3.8.5' of https://github.com/cocos/cocos-engine into i…
dumganhar Oct 11, 2024
5390acf
Fix splash-screen and don't mangle game._calculateDT
dumganhar Oct 11, 2024
8c0d452
Revert gl-constants.ts
dumganhar Oct 11, 2024
4e861d8
Fix import file extension in tmx-xml-parser.ts
dumganhar Oct 11, 2024
7ddf682
Should not mangle _exportedExts since it's used by editor.
dumganhar Oct 11, 2024
8ef55c0
Update error map.
dumganhar Oct 12, 2024
c342462
Fix SplashScreen
dumganhar Oct 12, 2024
52893fa
Update game.ts
dumganhar Oct 12, 2024
ed552cb
Fix enum export for camera.jsb.ts
dumganhar Oct 12, 2024
e086fa6
Update tiled-layer.ts
dumganhar Oct 12, 2024
e12058f
Update ccbuild to 2.2.15
dumganhar Oct 12, 2024
e2752ef
Revert ONLY_2D
dumganhar Oct 12, 2024
37fb5fc
Update model.ts
dumganhar Oct 12, 2024
851ae8b
Update root.ts and action-manager.ts
dumganhar Oct 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion EngineErrorMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,15 @@ should set resolutionPolicy

### 2300

The touches is more than MAX_TOUCHES, nUnusedIndex = %s
The touches is more than MAX_TOUCHES.

### 2301

Cannot create the same touch object.

### 2302

The touches is more than MAX_TOUCHES, release touch id %s.

### 2400

Expand Down Expand Up @@ -3837,6 +3845,10 @@ ProgressBar non-FILLED mode only works when barSprite's Type is non-FILLED!

CopyTextureToBuffers: not supported texture target.

### 16400

Limit values to be greater than 0

### 16401

beginRenderPass: Only primary command buffer is supported.
Expand All @@ -3856,3 +3868,7 @@ Block '%s' does not bound
### 16405

This device does not support WebGL2

### 16406

Can't find the spriteFrame of tilesets %s
9 changes: 8 additions & 1 deletion cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,14 @@
"dynamic": true
},


"DEBUG": {
"comment": "Running debug mode.",
"type": "boolean",
"value": true,
"ccGlobal": true,
"internal": false
},

"SERVER_MODE": {
"comment": "Running in the server mode.",
"type": "boolean",
Expand Down Expand Up @@ -713,5 +713,12 @@
"readOnly", "displayName", "tooltip", "group", "range", "rangeMin", "rangeMax", "rangeStep", "slide",
"displayOrder", "unit", "radian", "multiline", "disallowAnimation"
]
},

"treeShake": {
"noSideEffectFiles": [
"cocos/serialization/instantiate-jit.ts",
"cocos/game/splash-screen.ts"
]
}
}
19 changes: 19 additions & 0 deletions cc.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"optimizeDecorators": {
"$ref": "#/definitions/IOptimizeDecorators",
"description": "The decorators to be optimize when build engine."
},
"treeShake": {
"$ref": "#/definitions/ITreeShakeConfig",
"description": "The TreeShake config"
}
},
"required": [
Expand Down Expand Up @@ -193,6 +197,21 @@
],
"type": "object"
},
"ITreeShakeConfig": {
"additionalProperties": false,
"properties": {
"noSideEffectFiles": {
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"noSideEffectFiles"
],
"type": "object"
},
"IndexConfig": {
"additionalProperties": false,
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/assembler/label/font-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ImageAsset, Texture2D } from '../../../asset/assets';
import { PixelFormat } from '../../../asset/assets/asset-enum';
import { BufferTextureCopy } from '../../../gfx';
import { safeMeasureText, BASELINE_RATIO, MIDDLE_RATIO, getBaselineOffset, getSymbolCodeAt } from '../../utils/text-utils';
import { director, Director } from '../../../game/director';
import { director, Director, DirectorEvent } from '../../../game/director';
import { ccwindow } from '../../../core/global-exports';

export interface ISharedLabelData {
Expand Down Expand Up @@ -278,7 +278,7 @@ export class LetterAtlas {
this._halfBleed = bleed / 2;
this._width = width;
this._height = height;
director.on(Director.EVENT_BEFORE_SCENE_LAUNCH, this.beforeSceneLoad, this);
director.on(DirectorEvent.BEFORE_SCENE_LAUNCH, this.beforeSceneLoad, this);
}

public insertLetterTexture (letterTexture: LetterTexture): FontLetterDefinition | null {
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/assembler/label/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import { BitmapFont } from '../../assets';
import { Label } from '../../components';
import { CacheMode, Label } from '../../components';
import { IAssemblerManager } from '../../renderer/base';
import { bmfont } from './bmfont';
import { letter } from './letter';
Expand All @@ -36,7 +36,7 @@ const labelAssembler: IAssemblerManager = {

if (comp.font instanceof BitmapFont) {
assembler = bmfont;
} else if (comp.cacheMode === Label.CacheMode.CHAR) {
} else if (comp.cacheMode === CacheMode.CHAR) {
assembler = letter;
}

Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/assembler/label/ttfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { Label } from '../../components';
import { CacheMode, Label } from '../../components';
import { ISharedLabelData } from './font-utils';
import { UITransform } from '../../framework/ui-transform';
import { dynamicAtlasManager } from '../../utils/dynamic-atlas/atlas-manager';
Expand Down Expand Up @@ -207,14 +207,14 @@ export const ttfUtils = {
},

_calDynamicAtlas (comp: Label, outputLayoutData: TextOutputLayoutData): void {
if (comp.cacheMode !== Label.CacheMode.BITMAP || outputLayoutData.canvasSize.width <= 0 || outputLayoutData.canvasSize.height <= 0) return;
if (comp.cacheMode !== CacheMode.BITMAP || outputLayoutData.canvasSize.width <= 0 || outputLayoutData.canvasSize.height <= 0) return;
const frame = comp.ttfSpriteFrame!;
dynamicAtlasManager.packToDynamicAtlas(comp, frame);
// TODO update material and uv
},

_resetDynamicAtlas (comp: Label): void {
if (comp.cacheMode !== Label.CacheMode.BITMAP) return;
if (comp.cacheMode !== CacheMode.BITMAP) return;
const frame = comp.ttfSpriteFrame!;
dynamicAtlasManager.deleteAtlasSpriteFrame(frame);
frame._resetDynamicAtlasFrame();
Expand Down
8 changes: 6 additions & 2 deletions cocos/2d/assets/sprite-frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export interface ISpriteFrameInitInfo {

const temp_uvs: IUV[] = [{ u: 0, v: 0 }, { u: 0, v: 0 }, { u: 0, v: 0 }, { u: 0, v: 0 }];

export enum SpriteFrameEvent {
UV_UPDATED = 'uv_updated',
}

/**
* @en
* A `SpriteFrame` support several types.
Expand Down Expand Up @@ -262,7 +266,7 @@ export class SpriteFrame extends Asset {
* @en uv update event.
* @zh uv 更新事件。
*/
public static EVENT_UV_UPDATED = 'uv_updated';
public static EVENT_UV_UPDATED = SpriteFrameEvent.UV_UPDATED;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only inline enums, doesn't support to inline static const varibles in class.
So define a enum for those constants.

public static MeshType = MeshType;

/**
Expand Down Expand Up @@ -999,7 +1003,7 @@ export class SpriteFrame extends Asset {

// UV update event for components to update uv buffer
// CalculateUV will trigger _calculateSlicedUV so it's enough to emit here
this.emit(SpriteFrame.EVENT_UV_UPDATED, this);
this.emit(SpriteFrameEvent.UV_UPDATED, this);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions cocos/2d/components/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range, editable, serializable, visible } from 'cc.decorator';
import { BUILD, EDITOR } from 'internal:constants';
import { SpriteAtlas } from '../assets/sprite-atlas';
import { SpriteFrame } from '../assets/sprite-frame';
import { SpriteFrame, SpriteFrameEvent } from '../assets/sprite-frame';
import { Vec2, cclegacy, ccenum, clamp, warnID } from '../../core';
import { IBatcher } from '../renderer/i-batcher';
import { UIRenderer, InstanceMaterialType } from '../framework/ui-renderer';
Expand Down Expand Up @@ -151,7 +151,7 @@
}
ccenum(SizeMode);

enum EventType {
export enum SpriteEventType {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The functionality of inline enum doesn't allow the same name, so add a prefix.

SPRITE_FRAME_CHANGED = 'spriteframe-changed',
}

Expand Down Expand Up @@ -214,7 +214,7 @@
this.markForUpdateRenderData();
this._applySpriteFrame(lastSprite);
if (EDITOR) {
this.node.emit(EventType.SPRITE_FRAME_CHANGED, this);
this.node.emit(SpriteEventType.SPRITE_FRAME_CHANGED, this);
}
}

Expand Down Expand Up @@ -369,7 +369,7 @@
* sprite.trim = true;
* ```
*/
@visible(function (this: Sprite) {

Check warning on line 372 in cocos/2d/components/sprite.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return this._type === SpriteType.SIMPLE;
})
@displayOrder(8)
Expand Down Expand Up @@ -458,7 +458,7 @@
* @en Event types for sprite.
* @zh sprite 的事件类型。
*/
public static EventType = EventType;
public static EventType = SpriteEventType;

@serializable
protected _spriteFrame: SpriteFrame | null = null;
Expand Down Expand Up @@ -500,15 +500,15 @@
if (spriteFrame) {
this._updateUVs();
if (this._type === SpriteType.SLICED) {
spriteFrame.on(SpriteFrame.EVENT_UV_UPDATED, this._updateUVs, this);
spriteFrame.on(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this);
}
}
}

public onDisable (): void {
super.onDisable();
if (this._spriteFrame && this._type === SpriteType.SLICED) {
this._spriteFrame.off(SpriteFrame.EVENT_UV_UPDATED, this._updateUVs, this);
this._spriteFrame.off(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this);
}
}

Expand Down Expand Up @@ -616,9 +616,9 @@
// Only Sliced type need update uv when sprite frame insets changed
if (this._spriteFrame) {
if (this._type === SpriteType.SLICED) {
this._spriteFrame.on(SpriteFrame.EVENT_UV_UPDATED, this._updateUVs, this);
this._spriteFrame.on(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this);
} else {
this._spriteFrame.off(SpriteFrame.EVENT_UV_UPDATED, this._updateUVs, this);
this._spriteFrame.off(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this);
}
}
}
Expand Down Expand Up @@ -686,7 +686,7 @@
const spriteFrame = this._spriteFrame;

if (oldFrame && this._type === SpriteType.SLICED) {
oldFrame.off(SpriteFrame.EVENT_UV_UPDATED, this._updateUVs, this);
oldFrame.off(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this);
}

let textureChanged = false;
Expand All @@ -706,7 +706,7 @@
}
this._applySpriteSize();
if (this._type === SpriteType.SLICED) {
spriteFrame.on(SpriteFrame.EVENT_UV_UPDATED, this._updateUVs, this);
spriteFrame.on(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions cocos/2d/event/pointer-event-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ import { InputEventType } from '../../input/types/event-enum';
import { EventDispatcherPriority, IEventDispatcher } from '../../input/input';

const mouseEvents = [
Input.EventType.MOUSE_DOWN,
Input.EventType.MOUSE_MOVE,
Input.EventType.MOUSE_UP,
Input.EventType.MOUSE_WHEEL,
Input.EventType.MOUSE_LEAVE,
Input.EventType.MOUSE_ENTER,
InputEventType.MOUSE_DOWN,
InputEventType.MOUSE_MOVE,
InputEventType.MOUSE_UP,
InputEventType.MOUSE_WHEEL,
InputEventType.MOUSE_LEAVE,
InputEventType.MOUSE_ENTER,
];
const touchEvents = [
Input.EventType.TOUCH_START,
Input.EventType.TOUCH_MOVE,
Input.EventType.TOUCH_END,
Input.EventType.TOUCH_CANCEL,
InputEventType.TOUCH_START,
InputEventType.TOUCH_MOVE,
InputEventType.TOUCH_END,
InputEventType.TOUCH_CANCEL,
];

class PointerEventDispatcher implements IEventDispatcher {
Expand Down
8 changes: 4 additions & 4 deletions cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { ccclass, help, disallowMultiple, executeInEditMode,
executionOrder, menu, tooltip, type, serializable } from 'cc.decorator';
import { EDITOR } from 'internal:constants';
import { Camera } from '../../misc/camera-component';
import { Camera, CameraEvent } from '../../misc/camera-component';
import { Widget } from '../../ui/widget';
import { Vec3, screen, Enum, cclegacy, visibleRect } from '../../core';
import { view } from '../../ui/view';
Expand Down Expand Up @@ -182,7 +182,7 @@ export class Canvas extends RenderRoot2D {
if (!EDITOR) {
if (this._cameraComponent) {
this._cameraComponent._createCamera();
this._cameraComponent.node.on(Camera.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
this._cameraComponent.node.on(CameraEvent.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
}
}

Expand All @@ -203,14 +203,14 @@ export class Canvas extends RenderRoot2D {
public onEnable (): void {
super.onEnable();
if (!EDITOR && this._cameraComponent) {
this._cameraComponent.node.on(Camera.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
this._cameraComponent.node.on(CameraEvent.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
}
}

public onDisable (): void {
super.onDisable();
if (this._cameraComponent) {
this._cameraComponent.node.off(Camera.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
this._cameraComponent.node.off(CameraEvent.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
}
}

Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/framework/ui-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, displa
import { EDITOR } from 'internal:constants';
import { Component, Node } from '../../scene-graph';
import { Mat4, Rect, Size, Vec2, Vec3, geometry, warnID, visibleRect, approx, EPSILON } from '../../core';
import { Director, director } from '../../game/director';
import { director, DirectorEvent } from '../../game/director';
import { NodeEventType } from '../../scene-graph/node-event';
import { IMask } from '../../scene-graph/node-event-processor';
import { Mask } from '../components/mask';
Expand Down Expand Up @@ -815,5 +815,5 @@ export class UITransform extends Component {
}

// HACK
director.on(Director.EVENT_AFTER_UPDATE, UITransform._sortSiblings);
director.on(Director.EVENT_BEFORE_SCENE_LAUNCH, UITransform._cleanChangeMap);
director.on(DirectorEvent.AFTER_UPDATE, UITransform._sortSiblings);
director.on(DirectorEvent.BEFORE_SCENE_LAUNCH, UITransform._cleanChangeMap);
Loading
Loading