Skip to content

Commit

Permalink
[v3.8.6] Optimize code size for physics-2d-builtin backend
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Jan 12, 2025
1 parent d1ab113 commit c873ffa
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cocos/physics-2d/builtin/builtin-contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import { BuiltinCircleShape } from './shapes/circle-shape-2d';
import { error } from '../../core';
import { Contact2DType } from '../framework';

/** @mangle */
export class BuiltinContact {
shape1?: BuiltinShape2D;
shape2?: BuiltinShape2D;

// eslint-disable-next-line @typescript-eslint/ban-types
testFunc?: Function;
touching = false;

Expand Down Expand Up @@ -85,7 +87,8 @@ export class BuiltinContact {
} else if (this.testFunc === Intersection2D.polygonCircle) {
return Intersection2D.polygonCircle(
(s1 as BuiltinPolygonShape).worldPoints,
(s2 as BuiltinCircleShape).worldPosition, (s2 as BuiltinCircleShape).worldRadius,
(s2 as BuiltinCircleShape).worldPosition,
(s2 as BuiltinCircleShape).worldRadius,
);
}

Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/builtin/builtin-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { director } from '../../game';
const contactResults: BuiltinContact[] = [];
const testIntersectResults: Collider2D[] = [];

/** @mangle */
export class BuiltinPhysicsWorld implements IPhysicsWorld {
private _contacts: BuiltinContact[] = [];
private _shapes: BuiltinShape2D[] = [];
Expand Down
3 changes: 2 additions & 1 deletion cocos/physics-2d/builtin/shapes/box-shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import { Vec2, Rect } from '../../../core';
import { BoxCollider2D } from '../../framework';
import Intersection2D from '../intersection-2d';

/** @mangle */
export class BuiltinBoxShape extends BuiltinShape2D {
private _worldPoints = [new Vec2(), new Vec2(), new Vec2(), new Vec2()]
private _worldPoints = [new Vec2(), new Vec2(), new Vec2(), new Vec2()];
get worldPoints (): Readonly<Vec2[]> {
return this._worldPoints;
}
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/builtin/shapes/circle-shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Intersection2D from '../intersection-2d';
const tempVec2 = new Vec2();
const tempMat4 = new Mat4();

/** @mangle */
export class BuiltinCircleShape extends BuiltinShape2D {
private _worldPosition = new Vec2();
get worldPosition (): Readonly<Vec2> {
Expand Down
3 changes: 2 additions & 1 deletion cocos/physics-2d/builtin/shapes/polygon-shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import Intersection2D from '../intersection-2d';

const tempVec2 = new Vec2();

/** @mangle */
export class BuiltinPolygonShape extends BuiltinShape2D {
private _worldPoints: Vec2[] = []
private _worldPoints: Vec2[] = [];
get worldPoints (): Readonly<Vec2[]> {
return this._worldPoints;
}
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/builtin/shapes/shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Rect, Vec2 } from '../../../core';
import { BuiltinPhysicsWorld } from '../builtin-world';
import { BuiltinContact } from '../builtin-contact';

/** @mangle */
export class BuiltinShape2D implements IBaseShape {
protected _collider: Collider2D | null = null;

Expand Down

0 comments on commit c873ffa

Please sign in to comment.