From c6d6e35e9359c31f29b30fd6a4148d164d087143 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 29 Dec 2024 16:10:07 -0800 Subject: [PATCH] Pass initialSceneTime through to SceneContext --- src/SceneBase.ts | 1 + src/main.ts | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/SceneBase.ts b/src/SceneBase.ts index 2cfdd0ece..b24557dd2 100644 --- a/src/SceneBase.ts +++ b/src/SceneBase.ts @@ -27,6 +27,7 @@ export interface SceneContext { destroyablePool: Destroyable[]; inputManager: InputManager; viewerInput: ViewerRenderInput; + initialSceneTime: number; } export interface SceneDesc { diff --git a/src/main.ts b/src/main.ts index d3fd88fb8..3f52760b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -440,7 +440,9 @@ class Main { private setIsPlaying(v: boolean): void { this.isPlaying = v; this.ui.playPauseButton.setIsPlaying(v); - this._saveCurrentTimeState(this._getCurrentSceneDescId()!); + + if (IS_DEVELOPMENT) + this._saveCurrentTimeState(this._getCurrentSceneDescId()!); } private _decodeHashString(hashString: string): [string, string] { @@ -694,16 +696,20 @@ class Main { return this.sceneDatabase.getSceneDescId(this.currentSceneDesc); } - private _loadTimeState(sceneDescId: string): void { + private _applyTimeState(timeState: TimeState): void { + this.setIsPlaying(timeState.isPlaying); + this.sceneTimeScale = timeState.sceneTimeScale; + this.viewer.sceneTime = timeState.sceneTime; + } + + private _loadTimeState(sceneDescId: string): TimeState | null { const timeStateKey = `TimeState/${sceneDescId}`; const timeStateStr = this.saveManager.loadStateFromLocation(timeStateKey, SaveStateLocation.SessionStorage); if (!timeStateStr) - return; + return null; const timeState = JSON.parse(timeStateStr) as TimeState; - this.setIsPlaying(timeState.isPlaying); - this.sceneTimeScale = timeState.sceneTimeScale; - this.viewer.sceneTime = timeState.sceneTime; + return timeState; } private _saveCurrentTimeState(sceneDescId: string): void { @@ -762,6 +768,7 @@ class Main { if (scene.createPanels) scenePanels = scene.createPanels(); this.ui.setScenePanels(scenePanels); + // Force time to play when loading a map. this.setIsPlaying(true); @@ -773,8 +780,11 @@ class Main { if (this.viewer.cameraController === null) this.viewer.setCameraController(new FPSCameraController()); - if (IS_DEVELOPMENT) - this._loadTimeState(this._getCurrentSceneDescId()!); + if (IS_DEVELOPMENT) { + const timeState = this._loadTimeState(this._getCurrentSceneDescId()!); + if (timeState !== null) + this._applyTimeState(timeState); + } if (!this._loadSceneSaveState(sceneStateStr)) { const camera = this.viewer.camera; @@ -855,8 +865,12 @@ class Main { const inputManager = this.viewer.inputManager; inputManager.reset(); const viewerInput = this.viewer.viewerRenderInput; + + const timeState = this._loadTimeState(this.sceneDatabase.getSceneDescId(sceneDesc)); + const initialSceneTime = timeState !== null ? timeState.sceneTime : 0; + const context: SceneContext = { - device, dataFetcher, dataShare, uiContainer, destroyablePool, inputManager, viewerInput, + device, dataFetcher, dataShare, uiContainer, destroyablePool, inputManager, viewerInput, initialSceneTime, }; // The age delta on pruneOldObjects determines whether any resources willf be shared at all.