Refactor collision world rebuild logic in runtime-host.ts
This commit is contained in:
@@ -523,29 +523,22 @@ export class RuntimeHost {
|
|||||||
this.applyShadowState();
|
this.applyShadowState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async rebuildCollisionWorld(colliders: RuntimeSceneDefinition["colliders"], playerShape: RuntimeSceneDefinition["playerCollider"]) {
|
private async buildCollisionWorld(
|
||||||
const requestId = ++this.collisionWorldRequestId;
|
requestId: number,
|
||||||
|
colliders: RuntimeSceneDefinition["colliders"],
|
||||||
|
playerShape: RuntimeSceneDefinition["playerCollider"]
|
||||||
|
) {
|
||||||
|
const nextCollisionWorld = await RapierCollisionWorld.create(
|
||||||
|
colliders,
|
||||||
|
playerShape
|
||||||
|
);
|
||||||
|
|
||||||
this.clearCollisionWorld();
|
if (requestId !== this.collisionWorldRequestId) {
|
||||||
|
nextCollisionWorld.dispose();
|
||||||
try {
|
throw new Error("Scene load was superseded by a newer request.");
|
||||||
const nextCollisionWorld = await RapierCollisionWorld.create(colliders, playerShape);
|
|
||||||
|
|
||||||
if (requestId !== this.collisionWorldRequestId) {
|
|
||||||
nextCollisionWorld.dispose();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.collisionWorld = nextCollisionWorld;
|
|
||||||
} catch (error) {
|
|
||||||
if (requestId !== this.collisionWorldRequestId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = error instanceof Error ? error.message : "Runner collision initialization failed.";
|
|
||||||
this.currentRuntimeMessage = `Runner collision initialization failed: ${message}`;
|
|
||||||
this.runtimeMessageHandler?.(this.currentRuntimeMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nextCollisionWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearCollisionWorld() {
|
private clearCollisionWorld() {
|
||||||
|
|||||||
Reference in New Issue
Block a user