Skip to content

Commit

Permalink
Merge branch 'v3.8.2' into v3.8.2-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Oct 9, 2023
2 parents 4dd3c8d + d79d095 commit 2d35ba9
Show file tree
Hide file tree
Showing 84 changed files with 1,812 additions and 467 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/native-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
add-to-path: false
local-cache: true
- name: Generate decorators
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
cd native
echo "Generate compile_commands.json & ninja target"
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/native-compile-platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
COCOS_ENGINE_DEV: 1
run: |
NATIVE_ROOT=$GITHUB_WORKSPACE/native
ANDORID_NDK=$ANDROID_NDK_LATEST_HOME
ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }}
NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template
echo "Compiling Android ... "
cd $GITHUB_WORKSPACE/templates/
Expand All @@ -112,7 +112,7 @@ jobs:
ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/
sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties
sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDROID_NDK@g" gradle.properties
sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties
sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties
sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties
Expand All @@ -123,7 +123,7 @@ jobs:
sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=arm64-v8a@g" gradle.properties
echo "Compile Android - cmake ..."
echo "ANDORID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}"
echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}"
# ./gradlew :CocosGame:assembleDebug --quiet
./gradlew :CocosGame:assembleRelease --quiet
echo "Compile Android Debug Done!"
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
COCOS_ENGINE_DEV: 1
run: |
NATIVE_ROOT=$GITHUB_WORKSPACE/native
ANDORID_NDK=$ANDROID_NDK_LATEST_HOME
ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }}
NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template
echo "Compiling Android ... "
cd $GITHUB_WORKSPACE/templates/
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/
sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties
sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDROID_NDK@g" gradle.properties
sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties
sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties
sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties
Expand All @@ -199,7 +199,7 @@ jobs:
sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=arm64-v8a@g" gradle.properties
echo "Compile Android - cmake ..."
echo "ANDORID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}"
echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}"
./gradlew :CocosGame:assembleDebug --quiet
df -h
./gradlew clean
Expand Down
6 changes: 6 additions & 0 deletions @types/jsb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ declare namespace jsb {
id: number;
axisInfoList: AxisInfo[],
buttonInfoList: ButtonInfo[],
touchInfoList: TouchInfo[],
}

export interface AxisInfo {
Expand All @@ -92,6 +93,11 @@ declare namespace jsb {
isPressed: boolean,
}

export interface TouchInfo {
code: number,
value: number,
}

export let onControllerInput: (infoList: ControllerInfo[]) => void | undefined;
export let onHandleInput: (infoList: ControllerInfo[]) => void | undefined;
export let onControllerChange: (controllerIds: number[]) => void | undefined;
Expand Down
7 changes: 4 additions & 3 deletions cocos/physics-2d/box2d-wasm/instantiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { game } from '../../game';
import { getError, error, sys, debug, IVec2Like } from '../../core';
import { WebAssemblySupportMode } from '../../misc/webassembly-support';

export const B2 = {} as any;
// eslint-disable-next-line import/no-mutable-exports
export let B2 = {} as any;

export function getImplPtr (wasmObject: any): number {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
Expand Down Expand Up @@ -113,7 +114,7 @@ function initWasm (wasmUrl: string): Promise<void> {
},
}).then((Instance: any) => {
if (!EDITOR && !TEST) debug('[box2d]:box2d wasm lib loaded.');
Object.assign(B2, Instance);
B2 = Instance;
}).then(resolve).catch((err: any) => reject(errorMessage(err)));
});
}
Expand All @@ -122,7 +123,7 @@ function initAsm (): Promise<void> {
if (asmFactory != null) {
return asmFactory().then((instance: any) => {
if (!EDITOR && !TEST) debug('[box2d]:box2d asm lib loaded.');
Object.assign(B2, instance);
B2 = instance;
});
} else {
return new Promise<void>((resolve, reject) => {
Expand Down
17 changes: 6 additions & 11 deletions cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';

export class B2FixedJoint extends B2Joint implements IFixedJoint {
setFrequency (v: number): void {
this.updateStiffnessAndDamping();
if (this._b2joint) {
(this._b2joint as B2.WeldJoint).SetFrequency(v);
}
}
setDampingRatio (v: number): void {
this.updateStiffnessAndDamping();
}
updateStiffnessAndDamping (): void {
if (this._b2joint) {
B2.SetLinearFrequencyAndDampingRatio(
this._b2joint,
(this._jointComp as FixedJoint2D).frequency,
(this._jointComp as FixedJoint2D).dampingRatio,
);
(this._b2joint as B2.WeldJoint).SetDampingRatio(v);
}
}

Expand All @@ -51,8 +46,8 @@ export class B2FixedJoint extends B2Joint implements IFixedJoint {
def.localAnchorA = { x: comp.anchor.x / PHYSICS_2D_PTM_RATIO, y: comp.anchor.y / PHYSICS_2D_PTM_RATIO };
def.localAnchorB = { x: comp.connectedAnchor.x / PHYSICS_2D_PTM_RATIO, y: comp.connectedAnchor.y / PHYSICS_2D_PTM_RATIO };
def.referenceAngle = 0;
def.damping = 0;//comp.dampingRatio;
def.stiffness = 1;//comp.frequency;
def.dampingRatio = comp.dampingRatio;
def.frequencyHz = comp.frequency;
return def;
}
}
6 changes: 0 additions & 6 deletions cocos/physics-2d/box2d-wasm/joints/joint-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ export class B2Joint implements IJoint2D {
addImplPtrReference(this, getImplPtr(this._b2joint));
addImplPtrReferenceWASM(this._b2joint, getImplPtr(this._b2joint));

this.updateStiffnessAndDamping();

this._inited = true;
}

Expand All @@ -131,8 +129,4 @@ export class B2Joint implements IJoint2D {
isValid (): Joint2D | null {
return this._b2joint && this._body && this._body.impl && this._jointComp;
}

updateStiffnessAndDamping (): void {
// do nothing
}
}
19 changes: 8 additions & 11 deletions cocos/physics-2d/box2d-wasm/joints/spring-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';

export class B2SpringJoint extends B2Joint implements ISpringJoint {
setFrequency (v: number): void {
this.updateStiffnessAndDamping();
if (this._b2joint) {
(this._b2joint as B2.DistanceJoint).SetFrequency(v);
}
}

setDampingRatio (v: number): void {
this.updateStiffnessAndDamping();
}
updateStiffnessAndDamping (): void {
if (this._b2joint) {
B2.SetLinearFrequencyAndDampingRatio(
this._b2joint,
(this._jointComp as SpringJoint2D).frequency,
(this._jointComp as SpringJoint2D).dampingRatio,
);
(this._b2joint as B2.DistanceJoint).SetDampingRatio(v);
}
}

setDistance (v: number): void {
if (this._b2joint) {
(this._b2joint as B2.DistanceJoint).SetLength(v);
Expand All @@ -56,8 +53,8 @@ export class B2SpringJoint extends B2Joint implements ISpringJoint {
def.localAnchorA = { x: comp.anchor.x / PHYSICS_2D_PTM_RATIO, y: comp.anchor.y / PHYSICS_2D_PTM_RATIO };
def.localAnchorB = { x: comp.connectedAnchor.x / PHYSICS_2D_PTM_RATIO, y: comp.connectedAnchor.y / PHYSICS_2D_PTM_RATIO };
def.length = comp.distance / PHYSICS_2D_PTM_RATIO;
def.damping = 0;//comp.dampingRatio;
def.stiffness = 1;//comp.frequency;
def.dampingRatio = comp.dampingRatio;
def.frequencyHz = comp.frequency;
return def;
}
}
17 changes: 6 additions & 11 deletions cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ import { toRadian } from '../../../core';

export class B2WheelJoint extends B2Joint implements IWheelJoint {
setFrequency (v: number): void {
this.updateStiffnessAndDamping();
if (this._b2joint) {
(this._b2joint as B2.WheelJoint as any).SetSpringFrequencyHz(v);
}
}
setDampingRatio (v: number): void {
this.updateStiffnessAndDamping();
}
updateStiffnessAndDamping (): void {
if (this._b2joint) {
B2.SetLinearFrequencyAndDampingRatio(
this._b2joint,
(this._jointComp as WheelJoint2D).frequency,
(this._jointComp as WheelJoint2D).dampingRatio,
);
(this._b2joint as B2.WheelJoint as any).SetSpringDampingRatio(v);
}
}

Expand Down Expand Up @@ -73,8 +68,8 @@ export class B2WheelJoint extends B2Joint implements IWheelJoint {
def.maxMotorTorque = comp.maxMotorTorque;
def.motorSpeed = toRadian(comp.motorSpeed);
def.enableMotor = comp.enableMotor;
def.damping = 0;//comp.dampingRatio;
def.stiffness = 1;//comp.frequency;
def.dampingRatio = comp.dampingRatio;
def.frequencyHz = comp.frequency;
return def;
}
}
7 changes: 4 additions & 3 deletions cocos/physics-2d/box2d-wasm/platform/physics-debug-draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ export class PhysicsDebugDraw {// extends B2.Draw {
}

static _DrawCircle (center: B2.Vec2, radius: number): void {
const p = PhysicsDebugDraw._xf.p;
b2Mul(PhysicsDebugDraw._xf, center, _tmp_vec3);
//scale?
PhysicsDebugDraw._drawer!.circle(
(center.x + p.x) * PHYSICS_2D_PTM_RATIO,
(center.y + p.y) * PHYSICS_2D_PTM_RATIO,
_tmp_vec3.x * PHYSICS_2D_PTM_RATIO,
_tmp_vec3.y * PHYSICS_2D_PTM_RATIO,
radius * PHYSICS_2D_PTM_RATIO,
);
}
Expand Down
9 changes: 8 additions & 1 deletion cocos/physics-2d/box2d-wasm/rigid-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,15 @@ export class B2RigidBody2D implements IRigidBody2D {
}

setType (v: ERigidBody2DType): void {
this._body!.SetType(v as number);
if (v === ERigidBody2DType.Dynamic) {
this._body!.SetType(B2.BodyType.b2_dynamicBody as B2.BodyType);
} else if (v === ERigidBody2DType.Kinematic) {
this._body!.SetType(B2.BodyType.b2_kinematicBody as B2.BodyType);
} else if (v === ERigidBody2DType.Static) {
this._body!.SetType(B2.BodyType.b2_staticBody as B2.BodyType);
}
}

setLinearDamping (v: number): void {
this._body!.SetLinearDamping(v);
}
Expand Down
3 changes: 1 addition & 2 deletions cocos/physics-2d/box2d-wasm/shapes/circle-shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export class B2CircleShape extends B2Shape2D implements ICircleShape {

const shape = new B2.CircleShape();
shape.m_radius = comp.radius / PHYSICS_2D_PTM_RATIO * scaleX;
shape.m_p.x = offsetX;
shape.m_p.y = offsetY;
shape.m_p = { x: offsetX, y: offsetY };

return [shape as unknown as B2.CircleShape];
}
Expand Down
11 changes: 7 additions & 4 deletions cocos/physics-2d/box2d/platform/physics-debug-draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
*/

import b2 from '@cocos/box2d';
import b2, { Vec2 } from '@cocos/box2d';
import { Color } from '../../../core';
import { PHYSICS_2D_PTM_RATIO } from '../../framework';
import { Graphics } from '../../../2d';
Expand All @@ -48,7 +48,7 @@ export class PhysicsDebugDraw extends b2.Draw {
const drawer = this._drawer!;

for (let i = 0; i < vertexCount; i++) {
b2.Transform.MulXV(this._xf, vertices[i], _tmp_vec2);
b2.Transform.MulXV(this._xf, vertices[i] as Vec2, _tmp_vec2);
const x = _tmp_vec2.x * PHYSICS_2D_PTM_RATIO;
const y = _tmp_vec2.y * PHYSICS_2D_PTM_RATIO;
if (i === 0) drawer.moveTo(x, y);
Expand All @@ -74,8 +74,9 @@ export class PhysicsDebugDraw extends b2.Draw {
}

_DrawCircle (center: b2.Vec2, radius: number): void {
const p = this._xf.p;
this._drawer!.circle((center.x + p.x) * PHYSICS_2D_PTM_RATIO, (center.y + p.y) * PHYSICS_2D_PTM_RATIO, radius * PHYSICS_2D_PTM_RATIO);
b2.Transform.MulXV(this._xf, center, _tmp_vec2);
//scale?
this._drawer!.circle((_tmp_vec2.x) * PHYSICS_2D_PTM_RATIO, (_tmp_vec2.y) * PHYSICS_2D_PTM_RATIO, radius * PHYSICS_2D_PTM_RATIO);
}

DrawCircle (center: b2.Vec2, radius: number, color): void {
Expand Down Expand Up @@ -137,9 +138,11 @@ export class PhysicsDebugDraw extends b2.Draw {
}

DrawPoint (center, radius, color): void {
//empty
}

DrawParticles (): void {
//empty
}

_applyStrokeColor (color): void {
Expand Down
3 changes: 2 additions & 1 deletion cocos/physics/bullet/bullet-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import { Collider, TriggerEventType, CollisionEventType, IContactEquation, CharacterController } from '../../../exports/physics-framework';
import { Vec3, Quat, Mat4 } from '../../core';
import { Vec3, Quat, Mat4, Color } from '../../core';
import { CharacterTriggerEventType } from '../framework';
import { bt } from './instantiated';

Expand Down Expand Up @@ -88,5 +88,6 @@ export const CC_QUAT_0 = new Quat();
export const CC_QUAT_1 = new Quat();
export const CC_MAT4_0 = new Mat4();
export const CC_MAT4_1 = new Mat4();
export const CC_COLOR_0 = new Color();

bt.CACHE = BulletCache;
17 changes: 17 additions & 0 deletions cocos/physics/bullet/bullet-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,21 @@ export const importFunc = {
const cct = bt.CACHE.getWrapper(controller, bt.CCT_CACHE_NAME);
cct.onShapeHitExt(hit);
},
onDebugDrawLine (from: number, to: number, color: number): void {
const bt = globalThis.Bullet;
const world = bt.CACHE.world;
if (world) {
world.onDebugDrawLine(from, to, color);
}
},
onClearLines (): void {
const bt = globalThis.Bullet;
const world = bt.CACHE.world;
if (world) {
world.onClearLines();
}
},
onFlushLines (): void {
//empty
},
};
Loading

0 comments on commit 2d35ba9

Please sign in to comment.