Updated perf
This commit is contained in:
@@ -565,6 +565,7 @@ let lastPerformanceUpdate = performance.now()
|
||||
let lastFrameTime: number | undefined
|
||||
let pack: PackOpening | undefined
|
||||
let packLoading = false
|
||||
let packUIDirty = false
|
||||
let packError: string | undefined
|
||||
|
||||
function updateMaterial() {
|
||||
@@ -684,21 +685,28 @@ function updateStatus() {
|
||||
}
|
||||
|
||||
function updatePackUI() {
|
||||
packUIDirty = false
|
||||
if (mode !== 'Pack') return
|
||||
const view = pack?.view
|
||||
packControlsElement.dataset.state = pack?.state ?? (packError ? 'error' : 'loading')
|
||||
packControlsElement.dataset.paused = String(pack?.paused ?? false)
|
||||
packTearProgress.hidden = !!pack && pack.state !== 'sealed' && pack.state !== 'opening'
|
||||
packTearProgress.value = pack?.tearProgress ?? 0
|
||||
packPrimaryButton.textContent = view?.action ?? (packError ? 'Retry loading' : 'Loading…')
|
||||
packPrimaryButton.disabled = packLoading || pack?.state === 'complete'
|
||||
packRestartButton.disabled = !pack
|
||||
packSkipButton.disabled = !pack || pack.state === 'complete'
|
||||
packSkipButton.title = 'Finish this motion or move to the next resting state'
|
||||
const state = pack?.state ?? (packError ? 'error' : 'loading')
|
||||
const paused = String(pack?.paused ?? false)
|
||||
if (packControlsElement.dataset.state !== state) packControlsElement.dataset.state = state
|
||||
if (packControlsElement.dataset.paused !== paused) packControlsElement.dataset.paused = paused
|
||||
setIfChanged(packTearProgress, 'hidden', !!pack && pack.state !== 'sealed' && pack.state !== 'opening')
|
||||
setIfChanged(packTearProgress, 'value', pack?.tearProgress ?? 0)
|
||||
setIfChanged(packPrimaryButton, 'textContent', view?.action ?? (packError ? 'Retry loading' : 'Loading…'))
|
||||
setIfChanged(packPrimaryButton, 'disabled', packLoading || pack?.state === 'complete')
|
||||
setIfChanged(packRestartButton, 'disabled', !pack)
|
||||
setIfChanged(packSkipButton, 'disabled', !pack || pack.state === 'complete')
|
||||
setIfChanged(packSkipButton, 'title', 'Finish this motion or move to the next resting state')
|
||||
const status = view?.status ?? packError ?? 'Preparing the prototype pack…'
|
||||
if (packStatusElement.textContent !== status) packStatusElement.textContent = status
|
||||
statusElement.textContent = 'Foil tear proof · 3 authored cards · no random rewards'
|
||||
hintElement.textContent = view?.hint ?? 'Local reference artwork · approved runtime card materials'
|
||||
setIfChanged(packStatusElement, 'textContent', status)
|
||||
setIfChanged(statusElement, 'textContent', 'Foil tear proof · 3 authored cards · no random rewards')
|
||||
setIfChanged(hintElement, 'textContent', view?.hint ?? 'Local reference artwork · approved runtime card materials')
|
||||
}
|
||||
|
||||
function setIfChanged<T, K extends keyof T>(target: T, key: K, value: T[K]) {
|
||||
if (target[key] !== value) target[key] = value
|
||||
}
|
||||
|
||||
async function preparePack() {
|
||||
@@ -739,7 +747,7 @@ async function preparePack() {
|
||||
normalMap,
|
||||
environment: activeEnvironment,
|
||||
lightPosition,
|
||||
onChange: updatePackUI,
|
||||
onChange: () => { packUIDirty = true },
|
||||
})
|
||||
scene.add(pack.root)
|
||||
pack.syncLighting(frontMaterial)
|
||||
@@ -1462,6 +1470,7 @@ function animate(frameTime: number) {
|
||||
}
|
||||
|
||||
if (mode === 'Pack') pack?.tick(frameTime)
|
||||
if (packUIDirty) updatePackUI()
|
||||
renderer.render(scene, mode === 'Pack' && pack ? pack.camera : camera)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user