Skip to content

Commit

Permalink
Merge branch 'v3.8.2' of github.com:cocos/cocos-engine into __editor__
Browse files Browse the repository at this point in the history
  • Loading branch information
hana-alice committed Oct 20, 2023
2 parents 97deb16 + 9cecd05 commit df979e4
Show file tree
Hide file tree
Showing 43 changed files with 715 additions and 279 deletions.
3 changes: 2 additions & 1 deletion cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@
"8f6ac413-2f1e-4b88-b26f-54556b5dd510",
"45e7c0c8-2699-4912-b45f-d42bb8384189",
"84ac6f69-3086-455a-86a4-561da8ee710b",
"5c601d96-e4c7-4698-991b-7ee674b11079"
"5c601d96-e4c7-4698-991b-7ee674b11079",
"bf0a6d94-58f0-4ad2-bdf2-c4a31c7dd856"
]
},
"websocket": {
Expand Down
8 changes: 8 additions & 0 deletions cocos/native-binding/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ export function patch_cc_ShadowsInfo(ctx: cc_ShadowsInfo_Context_Args, apply = d
const shadowColorDescriptor = Object.getOwnPropertyDescriptor(ShadowsInfo.prototype, 'shadowColor');
const planeDirectionDescriptor = Object.getOwnPropertyDescriptor(ShadowsInfo.prototype, 'planeDirection');
const planeHeightDescriptor = Object.getOwnPropertyDescriptor(ShadowsInfo.prototype, 'planeHeight');
const planeBiasDescriptor = Object.getOwnPropertyDescriptor(ShadowsInfo.prototype, 'planeBias');
const maxReceivedDescriptor = Object.getOwnPropertyDescriptor(ShadowsInfo.prototype, 'maxReceived');
const shadowMapSizeDescriptor = Object.getOwnPropertyDescriptor(ShadowsInfo.prototype, 'shadowMapSize');
apply(() => { $.tooltip('i18n:shadow.enabled')(ShadowsInfo.prototype, 'enabled', enabledDescriptor); }, 'tooltip', 'enabled');
Expand All @@ -954,6 +955,12 @@ export function patch_cc_ShadowsInfo(ctx: cc_ShadowsInfo_Context_Args, apply = d
apply(() => { $.editable(ShadowsInfo.prototype, 'planeHeight', planeHeightDescriptor); }, 'editable', 'planeHeight');
apply(() => { $.tooltip('i18n:shadow.planeHeight')(ShadowsInfo.prototype, 'planeHeight', planeHeightDescriptor); }, 'tooltip', 'planeHeight');
apply(() => { $.visible(function (this: ShadowsInfo) {
return this._type === ShadowType.Planar;
})(ShadowsInfo.prototype, 'planeBias', planeBiasDescriptor); }, 'visible', 'planeBias');
apply(() => { $.type(CCFloat)(ShadowsInfo.prototype, 'planeBias', planeBiasDescriptor); }, 'type', 'planeBias');
apply(() => { $.editable(ShadowsInfo.prototype, 'planeBias', planeBiasDescriptor); }, 'editable', 'planeBias');
apply(() => { $.tooltip('i18n:shadow.planeBias')(ShadowsInfo.prototype, 'planeBias', planeBiasDescriptor); }, 'tooltip', 'planeBias');
apply(() => { $.visible(function (this: ShadowsInfo) {
return this._type === ShadowType.ShadowMap;
})(ShadowsInfo.prototype, 'maxReceived', maxReceivedDescriptor); }, 'visible', 'maxReceived');
apply(() => { $.type(CCInteger)(ShadowsInfo.prototype, 'maxReceived', maxReceivedDescriptor); }, 'type', 'maxReceived');
Expand All @@ -967,6 +974,7 @@ export function patch_cc_ShadowsInfo(ctx: cc_ShadowsInfo_Context_Args, apply = d
apply(() => { $.serializable(ShadowsInfo.prototype, '_type', () => { return ShadowType.Planar; }); }, 'serializable', '_type');
apply(() => { $.serializable(ShadowsInfo.prototype, '_normal', () => { return new Vec3(0, 1, 0); }); }, 'serializable', '_normal');
apply(() => { $.serializable(ShadowsInfo.prototype, '_distance', () => { return 0; }); }, 'serializable', '_distance');
apply(() => { $.serializable(ShadowsInfo.prototype, '_planeBias', () => { return 1.0; }); }, 'serializable', '_planeBias');
apply(() => { $.serializable(ShadowsInfo.prototype, '_shadowColor', () => { return new Color(0, 0, 0, 76); }); }, 'serializable', '_shadowColor');
apply(() => { $.serializable(ShadowsInfo.prototype, '_maxReceived', () => { return 4; }); }, 'serializable', '_maxReceived');
apply(() => { $.serializable(ShadowsInfo.prototype, '_size', () => { return new Vec2(1024, 1024); }); }, 'serializable', '_size');
Expand Down
30 changes: 0 additions & 30 deletions cocos/physics-2d/box2d-wasm/box2d.asmjs.ts

This file was deleted.

28 changes: 0 additions & 28 deletions cocos/physics-2d/box2d-wasm/box2d.null.ts

This file was deleted.

31 changes: 0 additions & 31 deletions cocos/physics-2d/box2d-wasm/box2d.wasmjs.ts

This file was deleted.

60 changes: 37 additions & 23 deletions cocos/physics-2d/box2d-wasm/instantiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
THE SOFTWARE.
*/

import { instantiateWasm, fetchBuffer } from 'pal/wasm';
import { JSB, WASM_SUPPORT_MODE, CULL_ASM_JS_MODULE, EDITOR, TEST } from 'internal:constants';
import { wasmFactory, box2dWasmUrl } from './box2d.wasmjs';
import { asmFactory } from './box2d.asmjs';
import { instantiateWasm, fetchBuffer, ensureWasmModuleReady } from 'pal/wasm';
import { WASM_SUPPORT_MODE, CULL_ASM_JS_MODULE, EDITOR, TEST } from 'internal:constants';

import { game } from '../../game';
import { getError, error, sys, debug, IVec2Like } from '../../core';
import { error, sys, debug, IVec2Like, getError, log } from '../../core';
import { WebAssemblySupportMode } from '../../misc/webassembly-support';

// eslint-disable-next-line import/no-mutable-exports
Expand Down Expand Up @@ -56,6 +54,7 @@ export const enum B2ObjectType {
* B2.Joint pointer --> B2Joint
* ...
*/
//todo: combine WASM_OBJECT_PTR_2_TS_OBJECT and WASM_OBJECT_PTR_2_WASM_OBJECT
const WASM_OBJECT_PTR_2_TS_OBJECT = new Map<B2ObjectType, Map<number, any>>();

export function addImplPtrReference (Type: B2ObjectType, TSObject: any, implPtr: number): void {
Expand Down Expand Up @@ -95,6 +94,7 @@ export function getTSObjectFromWASMObjectPtr<T> (Type: B2ObjectType, implPtr: nu
* B2.Joint pointer --> B2.Joint
* ...
*/
//todo: combine WASM_OBJECT_PTR_2_TS_OBJECT and WASM_OBJECT_PTR_2_WASM_OBJECT
const WASM_OBJECT_PTR_2_WASM_OBJECT = new Map<B2ObjectType, Map<number, any>>();
export function addImplPtrReferenceWASM (Type: B2ObjectType, WASMObject: any, implPtr: number): void {
if (implPtr) {
Expand Down Expand Up @@ -134,7 +134,7 @@ export function b2Mul (T: any, v: IVec2Like, out: IVec2Like): void {
}

///////////////////////////////////////////////////////////////////////////////////////////////////
function initWasm (wasmUrl: string): Promise<void> {
function initWasm (wasmFactory, wasmUrl: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
const errorMessage = (err: any): string => `[box2d]: box2d wasm lib load failed: ${err}`;
wasmFactory({
Expand All @@ -148,38 +148,52 @@ function initWasm (wasmUrl: string): Promise<void> {
}).catch((err) => reject(errorMessage(err)));
},
}).then((Instance: any) => {
if (!EDITOR && !TEST) debug('[box2d]:box2d wasm lib loaded.');
log('[box2d]:box2d wasm lib loaded.');
B2 = Instance;
}).then(resolve).catch((err: any) => reject(errorMessage(err)));
});
}

function initAsm (): Promise<void> {
if (asmFactory != null) {
return asmFactory().then((instance: any) => {
if (!EDITOR && !TEST) debug('[box2d]:box2d asm lib loaded.');
function initAsm (asmFactory): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (CULL_ASM_JS_MODULE) {
reject(getError(4601));
return;
}
asmFactory().then((instance: any) => {
log('[box2d]:box2d asm lib loaded.');
B2 = instance;
});
});
}

function shouldUseWasmModule (): boolean {
if (WASM_SUPPORT_MODE === WebAssemblySupportMode.MAYBE_SUPPORT as number) {
return sys.hasFeature(sys.Feature.WASM);
} else if (WASM_SUPPORT_MODE === WebAssemblySupportMode.SUPPORT as number) {
return true;
} else {
return new Promise<void>((resolve, reject) => {
resolve();
});
return false;
}
}

export function waitForBox2dWasmInstantiation (): Promise<void> {
const errorReport = (msg: any): void => { error(msg); };
if ((WASM_SUPPORT_MODE as WebAssemblySupportMode) === WebAssemblySupportMode.MAYBE_SUPPORT) {
if (sys.hasFeature(sys.Feature.WASM)) {
return initWasm(box2dWasmUrl).catch(errorReport);
return ensureWasmModuleReady().then(() => Promise.all([
import('external:emscripten/box2d/box2d.release.wasm.js'),
import('external:emscripten/box2d/box2d.release.wasm.wasm'),
import('external:emscripten/box2d/box2d.release.asm.js'),
]).then(([
{ default: wasmFactory },
{ default: wasmUrl },
{ default: asmFactory },
]) => {
if (shouldUseWasmModule()) {
return initWasm(wasmFactory, wasmUrl);
} else {
return initAsm().catch(errorReport);
return initAsm(asmFactory);
}
} else if ((WASM_SUPPORT_MODE as WebAssemblySupportMode) === WebAssemblySupportMode.SUPPORT) {
return initWasm(box2dWasmUrl).catch(errorReport);
} else {
return initAsm().catch(errorReport);
}
})).catch(errorReport);
}

game.onPostInfrastructureInitDelegate.add(waitForBox2dWasmInstantiation);
4 changes: 2 additions & 2 deletions cocos/physics/bullet/bullet-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { Collider, TriggerEventType, CollisionEventType, IContactEquation, CharacterController } from '../../../exports/physics-framework';
import { Vec3, Quat, Mat4, Color } from '../../core';
import { CharacterTriggerEventType } from '../framework';
import { bt } from './instantiated';
import { bt, btCache } from './instantiated';

export const TriggerEventObject = {
type: 'onTriggerEnter' as unknown as TriggerEventType,
Expand Down Expand Up @@ -90,4 +90,4 @@ export const CC_MAT4_0 = new Mat4();
export const CC_MAT4_1 = new Mat4();
export const CC_COLOR_0 = new Color();

bt.CACHE = BulletCache;
btCache.CACHE = BulletCache;
26 changes: 7 additions & 19 deletions cocos/physics/bullet/bullet-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,31 @@
THE SOFTWARE.
*/

// Wasm Memory Page Size is 65536
export const pageSize = 65536; // 64KiB

// How many pages of the wasm memory
// TODO: let this can be canfiguable by user.
export const pageCount = 250;

// How mush memory size of the wasm memory
export const memorySize = pageSize * pageCount; // 16 MiB
import { btCache } from './instantiated';

// The import function used in c++ code, same as DLL Import
export const importFunc = {
syncPhysicsToGraphics (id: number): void {
const bt = globalThis.Bullet;
const body = bt.CACHE.getWrapper(id, bt.BODY_CACHE_NAME);
const body = btCache.CACHE.getWrapper(id, btCache.BODY_CACHE_NAME);
body.syncPhysicsToGraphics();
},
onShapeHitExt (hit: number, controller: number): void {
const bt = globalThis.Bullet;
const cct = bt.CACHE.getWrapper(controller, bt.CCT_CACHE_NAME);
const cct = btCache.CACHE.getWrapper(controller, btCache.CCT_CACHE_NAME);
cct.onShapeHitExt(hit);
},
onDebugDrawLine (from: number, to: number, color: number): void {
const bt = globalThis.Bullet;
const world = bt.CACHE.world;
const world = btCache.CACHE.world;
if (world) {
world.onDebugDrawLine(from, to, color);
}
},
onClearLines (): void {
const bt = globalThis.Bullet;
const world = bt.CACHE.world;
clearLines (): void {
const world = btCache.CACHE.world;
if (world) {
world.onClearLines();
}
},
onFlushLines (): void {
flushLines (): void {
//empty
},
};
Loading

0 comments on commit df979e4

Please sign in to comment.