Skip to content

Commit e3198ee

Browse files
committed
hotfix: support multiple scenes in world (#6099)
* support multiple scenes in world * dont wait to attach transport to set the worker on the local storage # Conflicts: # browser-interface/packages/shared/world/SceneWorker.ts
1 parent 9db7282 commit e3198ee

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

browser-interface/packages/shared/scene-loader/world-loader-impl/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ function getParcels(position: Vector2, loadingRadius: number): string[] {
2222
export async function createWorldLoader(options: { urns: string[] }): Promise<ISceneLoader> {
2323
const mappingScene = new Map<string, LoadableScene>()
2424
const scenes = await Promise.all(options.urns.map((urn) => getPortableExperienceFromUrn(urn)))
25-
26-
for (const parcel of scenes[0].entity.metadata.scene.parcels) {
27-
mappingScene.set(parcel, scenes[0])
25+
for (const scene of scenes) {
26+
for (const parcel of scene.entity.metadata.scene.parcels) {
27+
mappingScene.set(parcel, scene)
28+
}
2829
}
2930

3031
const emptyParcelController = new EmptyParcelController({ rootUrl: getResourcesURL('.') })

browser-interface/packages/shared/world/SceneWorker.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getAssetBundlesBaseUrl,
1313
PIPE_SCENE_CONSOLE,
1414
playerHeight,
15+
PREVIEW,
1516
WSS_ENABLED
1617
} from 'config'
1718
import { gridToWorld } from 'lib/decentraland/parcels/gridToWorld'
@@ -42,6 +43,8 @@ import { joinBuffers } from 'lib/javascript/uint8arrays'
4243
import { nativeMsgBridge } from 'unity-interface/nativeMessagesBridge'
4344
import { _INTERNAL_WEB_TRANSPORT_ALLOC_SIZE } from 'renderer-protocol/transports/webTransport'
4445
import { createInternalEngine } from './runtime-7/engine'
46+
import { initSourcemap } from './runtime-7/sourcemap'
47+
import { forceStopScene } from './parcelSceneManager'
4548

4649
export enum SceneWorkerReadyState {
4750
LOADING = 1 << 0,
@@ -114,7 +117,6 @@ export class SceneWorker {
114117
private rpcServer!: RpcServer<PortContext>
115118

116119
private sceneStarted: boolean = false
117-
118120
private position: Vector3 = new Vector3()
119121
private readonly lastSentPosition = new Vector3(0, 0, 0)
120122
private readonly lastSentRotation = new Quaternion(0, 0, 0, 1)
@@ -130,7 +132,7 @@ export class SceneWorker {
130132
const sceneNumber = globalSceneNumberCounter
131133
const scenePort = await rpcClient.createPort(`scene-${sceneNumber}`)
132134
const worker = new SceneWorker(loadableScene, sceneNumber, scenePort)
133-
await worker.attachTransport()
135+
worker.attachTransport().catch(() => forceStopScene(loadableScene.id))
134136
return worker
135137
}
136138

@@ -194,7 +196,8 @@ export class SceneWorker {
194196
readFile: this.readFile.bind(this),
195197
initialEntitiesTick0: Uint8Array.of(),
196198
hasMainCrdt: false,
197-
internalEngine: undefined
199+
internalEngine: undefined,
200+
sourcemap: undefined
198201
}
199202

200203
// if the scene metadata has a base parcel, then we set it as the position
@@ -230,7 +233,27 @@ export class SceneWorker {
230233
}
231234
}
232235

233-
async readFile(fileName: string) {
236+
async loadSourcemap() {
237+
try {
238+
// Only sdk7 scenes
239+
if (!this.rpcContext.sdk7) return
240+
241+
// Only preview or production scenes with the DEBUG_MOD or DEBUG_SCENE_LOG param
242+
if (!PREVIEW && !DEBUG_SCENE_LOG) return
243+
244+
const mainFile = PREVIEW
245+
? this.loadableScene.entity.metadata.main
246+
: `${this.loadableScene.entity.metadata.main}.map`
247+
const file = await this.readFile(mainFile, 'text')
248+
if (!file?.content) return
249+
return (await initSourcemap(file.content, PREVIEW)) ?? undefined
250+
} catch (_) {}
251+
}
252+
253+
async readFile<T extends 'text' | 'arraybuffer' = 'arraybuffer'>(
254+
fileName: string,
255+
type?: T
256+
): Promise<T extends 'text' ? { hash: string; content: string } : { hash: string; content: Uint8Array }> {
234257
// filenames are lower cased as per https://adr.decentraland.org/adr/ADR-80
235258
const normalized = fileName.toLowerCase()
236259

@@ -245,8 +268,11 @@ export class SceneWorker {
245268
const response = await fetch(url)
246269

247270
if (!response.ok) throw new Error(`Error fetching file ${file} from ${url}`)
271+
if (!type || type === 'arraybuffer') {
272+
return { hash, content: new Uint8Array(await response.arrayBuffer()) } as any
273+
}
248274

249-
return { hash, content: new Uint8Array(await response.arrayBuffer()) }
275+
return { hash, content: await response.text() } as any
250276
}
251277
}
252278

@@ -407,6 +433,7 @@ export class SceneWorker {
407433
this.metadata.scene.parcels,
408434
showAsPortableExperience
409435
)
436+
this.rpcContext.sourcemap = await this.loadSourcemap()
410437
}
411438
sceneEvents.emit(SCENE_LOAD, signalSceneLoad(this.loadableScene))
412439
}

0 commit comments

Comments
 (0)