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 for box2d-wasm backend. #18168

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/distance-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { B2Joint } from './joint-2d';
import { DistanceJoint2D } from '../../framework';
import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';

/** @mangle */
export class B2DistanceJoint extends B2Joint implements IDistanceJoint {
setMaxLength (v: number): void {
if (this._b2joint) {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { B2Joint } from './joint-2d';
import { FixedJoint2D } from '../../framework';
import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';

/** @mangle */
export class B2FixedJoint extends B2Joint implements IFixedJoint {
setFrequency (v: number): void {
if (this._b2joint) {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/hinge-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { B2Joint } from './joint-2d';
import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';
import { toRadian } from '../../../core';

/** @mangle */
export class B2HingeJoint extends B2Joint implements IHingeJoint {
enableLimit (v: boolean): void {
if (this._b2joint) {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/joint-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
THE SOFTWARE.
*/

import { B2, B2ObjectType, addImplPtrReference, addImplPtrReferenceWASM, getImplPtr, removeImplPtrReference, removeImplPtrReferenceWASM } from '../instantiated';

Check warning on line 25 in cocos/physics-2d/box2d-wasm/joints/joint-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 161. Maximum allowed is 150
import { IJoint2D } from '../../spec/i-physics-joint';
import { Joint2D, PhysicsSystem2D, RigidBody2D } from '../../framework';
import { B2PhysicsWorld } from '../physics-world';
import { warn } from '../../../core';

/** @mangle */
export class B2Joint implements IJoint2D {
get impl (): B2.Joint | null {
return this._b2joint;
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/mouse-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { find } from '../../../scene-graph';

const tempB2Vec2 = { x: 0, y: 0 };//new b2.Vec2();

/** @mangle */
export class B2MouseJoint extends B2Joint implements IMouseJoint {
_touchPoint = new Vec2();
_isTouched = false;
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/relative-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Vec2, toRadian } from '../../../core';

const tempB2Vec2 = { x: 0, y: 0 };//new b2.Vec2();

/** @mangle */
export class B2RelativeJoint extends B2Joint implements IRelativeJoint {
setMaxForce (v: number): void {
if (this._b2joint) {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/slider-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { SliderJoint2D } from '../../framework';
import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';
import { toRadian } from '../../../core';

/** @mangle */
export class B2SliderJoint extends B2Joint implements ISliderJoint {
// limit
enableLimit (v: boolean): void {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/spring-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { B2Joint } from './joint-2d';
import { SpringJoint2D } from '../../framework';
import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';

/** @mangle */
export class B2SpringJoint extends B2Joint implements ISpringJoint {
setFrequency (v: number): void {
if (this._b2joint) {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { B2Joint } from './joint-2d';
import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';
import { toRadian } from '../../../core';

/** @mangle */
export class B2WheelJoint extends B2Joint implements IWheelJoint {
setFrequency (v: number): void {
if (this._b2joint) {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/physics-contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const impulse: IPhysics2DImpulse = {
tangentImpulses: [] as number[],
};

/** @mangle */
export class PhysicsContact implements IPhysics2DContact {
static get (b2contact: number): PhysicsContact {
let c = pools.pop();
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/physics-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const tempVec2_2 = new Vec2();

const testResults: Collider2D[] = [];

/** @mangle */
export class B2PhysicsWorld implements IPhysicsWorld {
protected _world: B2.World;
protected _bodies: B2RigidBody2D[] = [];
Expand Down
13 changes: 9 additions & 4 deletions cocos/physics-2d/box2d-wasm/platform/physics-contact-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
THE SOFTWARE.
*/

type BeginContactCallback = (contact: number) => void;
type EndContactCallback = (contact: number) => void;
type PreSolveCallback = (contact: number, oldManifold: number) => void;
type PostSolveCallback = (contact: number, impulse: number) => void;

export class PhysicsContactListener {
static _BeginContact: Function | null = null;
static _EndContact: Function | null = null;
static _PreSolve: Function | null = null;
static _PostSolve: Function | null = null;
static _BeginContact: BeginContactCallback | null = null;
static _EndContact: EndContactCallback | null = null;
static _PreSolve: PreSolveCallback | null = null;
static _PostSolve: PostSolveCallback | null = null;

static BeginContact (contact: number): void {
if (this._BeginContact) {
Expand Down
2 changes: 2 additions & 0 deletions cocos/physics-2d/box2d-wasm/rigid-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import { B2Joint } from './joints/joint-2d';
const tempVec3 = new Vec3();
const tempVec2_1 = { x: 0, y: 0 };//new B2.Vec2(0, 0);
const tempVec2_2 = { x: 0, y: 0 };

/** @mangle */
export class B2RigidBody2D implements IRigidBody2D {
get impl (): B2.Body | null {
return this._body;
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/shapes/box-shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Vec2, Rect } from '../../../core';

const tempAabb = new Rect();

/** @mangle */
export class B2BoxShape extends B2Shape2D implements IBoxShape {
_worldPoints: Vec2[] = [new Vec2(), new Vec2(), new Vec2(), new Vec2()];
get worldPoints (): Readonly<Vec2>[] {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/shapes/circle-shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';
import { ICircleShape } from '../../spec/i-physics-shape';
import { Vec2 } from '../../../core';

/** @mangle */
export class B2CircleShape extends B2Shape2D implements ICircleShape {
get worldRadius (): number {
return B2.CircleShapeGetRadius(this._shapes[0]) * PHYSICS_2D_PTM_RATIO;
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/shapes/polygon-shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';
import { IPolygonShape } from '../../spec/i-physics-shape';
import { Vec2, warn } from '../../../core';

/** @mangle */
export class B2PolygonShape extends B2Shape2D implements IPolygonShape {
_worldPoints: Vec2[] = [];
get worldPoints (): Readonly<Vec2>[] {
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/shapes/shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function getFilter (shape: B2Shape2D): B2.Filter {
return tempFilter;
}

/** @mangle */
export class B2Shape2D implements IBaseShape {
protected _shapes: number[] = [];
protected _fixtures: number[] = [];//B2.Fixture ptr
Expand Down
Loading