Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
fix: setting timeout before setting scene as failed
Browse files Browse the repository at this point in the history
  • Loading branch information
moliva committed Aug 22, 2019
1 parent 6822d8b commit d4361b2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class PositionLifecycleController extends EventEmitter {

constructor(public parcelController: ParcelLifeCycleController, public sceneController: SceneLifeCycleController) {
super()
sceneController.on('Scene ready', () => this.checkPositionSettlement())
sceneController.on('Scene status', () => this.checkPositionSettlement())
}

async reportCurrentPosition(position: Vector2Component, teleported: boolean) {
Expand Down Expand Up @@ -45,7 +45,7 @@ export class PositionLifecycleController extends EventEmitter {

private checkPositionSettlement() {
if (!this.positionSettled) {
const settling = this.currentlySightedScenes.every($ => this.sceneController.isReady($))
const settling = this.currentlySightedScenes.every($ => this.sceneController.isRenderable($))

if (settling) {
this.positionSettled = settling
Expand Down
6 changes: 3 additions & 3 deletions packages/decentraland-loader/lifecycle/controllers/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ export class SceneLifeCycleController extends EventEmitter {
}
}

isReady(sceneId: SceneId): boolean {
isRenderable(sceneId: SceneId): boolean {
const status = this.sceneStatus.get(sceneId)
return !!status && status.isReady()
return !!status && (status.isReady() || status.isFailed())
}

reportStatus(sceneId: string, status: SceneLifeCycleStatusType) {
Expand All @@ -114,7 +114,7 @@ export class SceneLifeCycleController extends EventEmitter {
}
lifeCycleStatus.status = status

this.emit('Scene ready', sceneId)
this.emit('Scene status', { sceneId, status })
}

async requestSceneId(position: string): Promise<string | undefined> {
Expand Down
6 changes: 5 additions & 1 deletion packages/decentraland-loader/lifecycle/lib/scene.status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ILand } from 'shared/types'

export type SceneLifeCycleStatusType = 'unloaded' | 'awake' | 'loaded' | 'ready'
export type SceneLifeCycleStatusType = 'unloaded' | 'awake' | 'loaded' | 'ready' | 'failed'

export class SceneLifeCycleStatus {
status: SceneLifeCycleStatusType = 'unloaded'
Expand All @@ -18,4 +18,8 @@ export class SceneLifeCycleStatus {
isReady() {
return this.status === 'ready'
}

isFailed() {
return this.status === 'failed'
}
}
16 changes: 11 additions & 5 deletions packages/scene-system/scene.system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,16 @@ export default class GamekitScene extends Script {
try {
await customEval((source as any) as string, getES5Context({ dcl }))

this.events.push({
type: 'InitMessagesFinished',
tag: 'scene',
payload: '{}'
})
this.events.push(this.initMessagesFinished())

this.onStartFunctions.push(() => {
const engine: IEngineAPI = this.engine as any
engine.startSignal().catch((e: Error) => this.onError(e))
})
} catch (e) {
that.onError(e)

this.events.push(this.initMessagesFinished())
}

this.sendBatch()
Expand All @@ -431,6 +429,14 @@ export default class GamekitScene extends Script {
this.sendBatch()
}

private initMessagesFinished(): EntityAction {
return {
type: 'InitMessagesFinished',
tag: 'scene',
payload: '{}'
}
}

private sendBatch() {
try {
if (this.events.length) {
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/world/SceneWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class SceneWorker {
public persistent = false
public readonly onDisposeObservable = new Observable<SceneWorker>()

public sceneStarted: boolean = false

public readonly position: Vector3 = new Vector3()
private readonly lastSentPosition = new Vector3(0, 0, 0)
private readonly lastSentRotation = new Quaternion(0, 0, 0, 1)
Expand All @@ -61,7 +63,6 @@ export class SceneWorker {
private worldRunningObserver: Observer<any> | null = null

private sceneReady: boolean = false
private sceneStarted: boolean = false

constructor(public parcelScene: ParcelSceneAPI, transport?: ScriptingTransport) {
parcelScene.registerWorker(this)
Expand Down
26 changes: 19 additions & 7 deletions packages/shared/world/parcelSceneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,34 @@ export async function enableParcelSceneLoading(options: EnableParcelSceneLoading
})

ret.on('Scene.shouldStart', async (opts: { sceneId: string }) => {
const parcelSceneToStart = await ret.getParcelData(opts.sceneId)
const sceneId = opts.sceneId
const parcelSceneToStart = await ret.getParcelData(sceneId)

// create the worker if don't exist
if (!getSceneWorkerBySceneID(opts.sceneId)) {
if (!getSceneWorkerBySceneID(sceneId)) {
const parcelScene = new options.parcelSceneClass(ILandToLoadableParcelScene(parcelSceneToStart))
loadParcelScene(parcelScene)
}

const observer = sceneLifeCycleObservable.add(sceneStatus => {
if (sceneStatus.sceneId === sceneId) {
ret.notify('Scene.status', sceneStatus)
}
sceneLifeCycleObservable.remove(observer)
})

// tell the engine to load the parcel scene
if (options.onLoadParcelScenes) {
options.onLoadParcelScenes([await ret.getParcelData(opts.sceneId)])
options.onLoadParcelScenes([await ret.getParcelData(sceneId)])
}

setTimeout(() => {
const worker = getSceneWorkerBySceneID(sceneId)
if (worker && !worker.sceneStarted) {
sceneLifeCycleObservable.remove(observer)
ret.notify('Scene.status', { sceneId, status: 'failed' })
}
}, 30000)
})

ret.on('Scene.shouldUnload', async (opts: { sceneId: string }) => {
Expand Down Expand Up @@ -126,8 +142,4 @@ export async function enableParcelSceneLoading(options: EnableParcelSceneLoading
worldToGrid(obj.position, position)
ret.notify('User.setPosition', { position, teleported: false })
})

sceneLifeCycleObservable.add(sceneStatus => {
ret.notify('Scene.status', sceneStatus)
})
}

0 comments on commit d4361b2

Please sign in to comment.