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

fixed #17867: [bug] b2RigidBody2D was not removed from b2PhysicsWorld _animatedBodies container if its type was changed. #17873

Merged
merged 3 commits into from
Nov 18, 2024
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
8 changes: 4 additions & 4 deletions cocos/particle-2d/particle-system-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,9 @@
private _positionType = PositionType.FREE;

private _stopped = true;
private declare _previewTimer;
private declare _previewTimer: number | null;
private declare _focused: boolean;
private declare _plistFile;
private declare _plistFile: string;
private declare _tiffReader;
private _useFile: boolean;

Expand Down Expand Up @@ -849,7 +849,7 @@
}
}

protected lateUpdate (dt): void {
protected lateUpdate (dt: number): void {
if (!this._simulator.finished) {
this._simulator.step(dt);
}
Expand Down Expand Up @@ -938,7 +938,7 @@
public _initTextureWithDictionary (dict: any): boolean {
if (dict.spriteFrameUuid) {
const spriteFrameUuid = dict.spriteFrameUuid;
assetManager.loadAny(spriteFrameUuid, (err: Error, spriteFrame: SpriteFrame): void => {

Check failure on line 941 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string | string[] | IRequest | IRequest[]`
if (err) {
dict.spriteFrameUuid = undefined;
this._initTextureWithDictionary(dict);
Expand All @@ -949,7 +949,7 @@
});
} else {
// texture
const imgPath = path.changeBasename(this._plistFile, dict.textureFileName || '');

Check failure on line 952 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
if (dict.textureFileName) {
// Try to get the texture from the cache
assetManager.loadRemote<ImageAsset>(imgPath, (err: Error | null, imageAsset: ImageAsset): void => {
Expand All @@ -967,7 +967,7 @@
}
});
} else if (dict.textureImageData) {
const textureData = dict.textureImageData;
const textureData = dict.textureImageData as string;

if (textureData && textureData.length > 0) {
let imgPathName = imgPath;
Expand Down Expand Up @@ -1025,11 +1025,11 @@
*/
public _initWithDictionary (dict: any): boolean {
this._useFile = true;
this.totalParticles = parseInt(dict.maxParticles || 0);

Check failure on line 1028 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

// life span
this.life = parseFloat(dict.particleLifespan || 0);

Check failure on line 1031 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
this.lifeVar = parseFloat(dict.particleLifespanVariance || 0);

Check failure on line 1032 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

// emission Rate
const _tempEmissionRate = dict.emissionRate;
Expand All @@ -1040,16 +1040,16 @@
}

// duration
this.duration = parseFloat(dict.duration || 0);

Check failure on line 1043 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

// blend function // remove when component remove blend function
this._srcBlendFactor = parseInt(dict.blendFuncSource || BlendFactor.SRC_ALPHA);

Check failure on line 1046 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
this._dstBlendFactor = parseInt(dict.blendFuncDestination || BlendFactor.ONE_MINUS_SRC_ALPHA);

Check failure on line 1047 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

// color
const locStartColor = this._startColor;
locStartColor.r = parseFloat(dict.startColorRed || 0) * 255;

Check failure on line 1051 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
locStartColor.g = parseFloat(dict.startColorGreen || 0) * 255;

Check failure on line 1052 in cocos/particle-2d/particle-system-2d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
locStartColor.b = parseFloat(dict.startColorBlue || 0) * 255;
locStartColor.a = parseFloat(dict.startColorAlpha || 0) * 255;

Expand Down
13 changes: 13 additions & 0 deletions cocos/physics-2d/box2d-wasm/physics-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ export class B2PhysicsWorld implements IPhysicsWorld {
}
}

public _updateBodyType$ (body: B2RigidBody2D): void {
const animatedBodies = this._animatedBodies;
const comp = body.rigidBody;
if (comp.type !== ERigidBody2DType.Animated) {
js.array.remove(animatedBodies, body);
} else {
if (animatedBodies.includes(body)) {
return;
}
animatedBodies.push(body);
}
}

registerContactFixture (fixture: number): void { //B2.Fixture ptr
this._contactListener.registerContactFixture(fixture);
}
Expand Down
1 change: 1 addition & 0 deletions cocos/physics-2d/box2d-wasm/rigid-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class B2RigidBody2D implements IRigidBody2D {
}

setType (v: ERigidBody2DType): void {
(PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld)._updateBodyType$(this);
if (v === ERigidBody2DType.Dynamic) {
this._body!.SetType(B2.BodyType.b2_dynamicBody as B2.BodyType);
} else if (v === ERigidBody2DType.Kinematic) {
Expand Down
13 changes: 13 additions & 0 deletions cocos/physics-2d/box2d/physics-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@ export class b2PhysicsWorld implements IPhysicsWorld {
}
}

public _updateBodyType$ (body: b2RigidBody2D): void {
const animatedBodies = this._animatedBodies;
const comp = body.rigidBody;
if (comp.type !== ERigidBody2DType.Animated) {
js.array.remove(animatedBodies, body);
} else {
if (animatedBodies.includes(body)) {
return;
}
animatedBodies.push(body);
}
}

registerContactFixture (fixture: b2.Fixture): void {
this._contactListener.registerContactFixture(fixture);
}
Expand Down
6 changes: 4 additions & 2 deletions cocos/physics-2d/box2d/rigid-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { PHYSICS_2D_PTM_RATIO, ERigidBody2DType } from '../framework/physics-typ

import { Node } from '../../scene-graph/node';
import { Collider2D } from '../framework';
import { TransformBit } from '../../scene-graph/node-enum';

const tempVec3 = new Vec3();

Expand Down Expand Up @@ -82,7 +83,7 @@ export class b2RigidBody2D implements IRigidBody2D {
this.setActive(false);
}

nodeTransformChanged (type): void {
nodeTransformChanged (type: TransformBit): void {
if (PhysicsSystem2D.instance.stepping) {
return;
}
Expand Down Expand Up @@ -160,7 +161,7 @@ export class b2RigidBody2D implements IRigidBody2D {

const pos = this._rigidBody.node.worldPosition;

let temp;
let temp: b2.Vec2;
const bodyType = this._rigidBody.type;
if (bodyType === ERigidBody2DType.Animated) {
temp = b2body.GetLinearVelocity();
Expand Down Expand Up @@ -207,6 +208,7 @@ export class b2RigidBody2D implements IRigidBody2D {
}

setType (v: ERigidBody2DType): void {
(PhysicsSystem2D.instance.physicsWorld as b2PhysicsWorld)._updateBodyType$(this);
this._body!.SetType(v as number);
}
setLinearDamping (v: number): void {
Expand Down
2 changes: 1 addition & 1 deletion cocos/physics-2d/framework/physics-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import { BUILD, EDITOR_NOT_IN_PREVIEW, LOAD_BOX2D_MANUALLY } from 'internal:constants';
import { System, Vec2, IVec2Like, Rect, Eventify, Enum, Settings, settings, cclegacy, SettingsCategory } from '../../core';
import { System, Vec2, IVec2Like, Rect, Eventify, Enum, settings, cclegacy, SettingsCategory } from '../../core';
import { createPhysicsWorld, selector, IPhysicsSelector } from './physics-selector';

import { DelayEvent } from './physics-internal-types';
Expand Down
Loading