Skip to content

Commit 9db7282

Browse files
authored
Merge pull request #6092 from decentraland/release/release-20240219
Release: 20240219
2 parents 33b7e01 + 919875c commit 9db7282

File tree

1 file changed

+42
-2
lines changed
  • browser-interface/packages/shared/scene-loader/world-loader-impl

1 file changed

+42
-2
lines changed

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,54 @@
11
import { getPortableExperienceFromUrn } from 'unity-interface/portableExperiencesUtils'
22
import { ISceneLoader } from '../types'
3+
import { encodeParcelPosition } from '../../../lib/decentraland'
4+
import { Vector2 } from '@dcl/ecs-math'
5+
import { getResourcesURL } from '../../location'
6+
import { EmptyParcelController } from '../genesis-city-loader-impl/emptyParcelController'
7+
import { LoadableScene } from '../../types'
8+
9+
function getParcels(position: Vector2, loadingRadius: number): string[] {
10+
const parcels: string[] = []
11+
for (let x = position.x - loadingRadius; x < position.x + loadingRadius; x++) {
12+
for (let y = position.y - loadingRadius; y < position.y + loadingRadius; y++) {
13+
const v = new Vector2(x, y)
14+
if (v.subtract(position).length() < loadingRadius) {
15+
parcels.push(encodeParcelPosition(v))
16+
}
17+
}
18+
}
19+
return parcels
20+
}
321

422
export async function createWorldLoader(options: { urns: string[] }): Promise<ISceneLoader> {
23+
const mappingScene = new Map<string, LoadableScene>()
524
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])
28+
}
29+
30+
const emptyParcelController = new EmptyParcelController({ rootUrl: getResourcesURL('.') })
31+
632
return {
733
async fetchScenesByLocation(_parcels) {
834
return { scenes }
935
},
10-
async reportPosition(_positionReport) {
11-
return { scenes }
36+
async reportPosition(positionReport) {
37+
const newScenes: Set<LoadableScene> = new Set()
38+
for await (const parcel of getParcels(
39+
new Vector2(positionReport.position.x, positionReport.position.y),
40+
positionReport.loadingRadius
41+
)) {
42+
if (mappingScene.has(parcel)) {
43+
newScenes.add(mappingScene.get(parcel)!)
44+
} else {
45+
const scene = await emptyParcelController.createFakeEntity(parcel)
46+
47+
mappingScene.set(parcel, scene)
48+
newScenes.add(scene)
49+
}
50+
}
51+
return { scenes: Array.from(newScenes) }
1252
},
1353
async stop() {},
1454
invalidateCache(_) {}

0 commit comments

Comments
 (0)