feat(3d-nds): lag detection
This commit is contained in:
28
app/components/LagModal.vue
Normal file
28
app/components/LagModal.vue
Normal file
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
const emit = defineEmits<{ close: [] }>();
|
||||
|
||||
const app = useAppStore();
|
||||
|
||||
const keep3d = () => {
|
||||
app.lagDetected = false;
|
||||
emit("close");
|
||||
};
|
||||
|
||||
const switch2d = () => {
|
||||
app.setRenderingMode("2d");
|
||||
emit("close");
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UModal :open="true" :dismissible="false" :title="$t('lagModal.title')" :ui="{ footer: 'justify-end' }">
|
||||
<template #body>
|
||||
{{ $t('lagModal.body') }}
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<UButton variant="ghost" color="neutral" :label="$t('lagModal.keep3d')" @click="keep3d" />
|
||||
<UButton color="neutral" :label="$t('lagModal.switch2d')" @click="switch2d" />
|
||||
</template>
|
||||
</UModal>
|
||||
</template>
|
||||
@@ -195,7 +195,12 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const { onRender } = useLoop();
|
||||
const { onRender, onBeforeRender } = useLoop();
|
||||
|
||||
const LAG_FPS_THRESHOLD = 440;
|
||||
const LAG_DURATION_SECS = 1;
|
||||
let lagSeconds = 0;
|
||||
let lagCheckDone = false;
|
||||
|
||||
const HINT_SPRITE_SCALE = 2;
|
||||
const HINT_SPRITE_DPR = 4;
|
||||
@@ -337,10 +342,30 @@ useKeyUp(({ ndsButton }) => {
|
||||
}
|
||||
});
|
||||
|
||||
onRender(({ delta }) => {
|
||||
// lag detection
|
||||
onBeforeRender(({ delta }) => {
|
||||
if (!lagCheckDone) {
|
||||
const fps = 1 / delta;
|
||||
if (fps < LAG_FPS_THRESHOLD) {
|
||||
lagSeconds += delta;
|
||||
if (lagSeconds >= LAG_DURATION_SECS) {
|
||||
lagCheckDone = true;
|
||||
app.lagDetected = true;
|
||||
}
|
||||
} else {
|
||||
lagSeconds = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// upate screens
|
||||
onRender(() => {
|
||||
if (topScreenTexture) topScreenTexture.needsUpdate = true;
|
||||
if (bottomScreenTexture) bottomScreenTexture.needsUpdate = true;
|
||||
});
|
||||
|
||||
// update physical buttons
|
||||
onBeforeRender(({ delta }) => {
|
||||
// cross
|
||||
const crossButton = meshes.get(CROSS_BUTTON);
|
||||
if (crossButton) {
|
||||
|
||||
Reference in New Issue
Block a user