fix(3d-nds): wrong lag detection
All checks were successful
Build and Push Docker Image / build (push) Successful in 3m47s
All checks were successful
Build and Push Docker Image / build (push) Successful in 3m47s
This commit is contained in:
@@ -200,9 +200,10 @@ watch(
|
|||||||
const { onRender, onBeforeRender } = useLoop();
|
const { onRender, onBeforeRender } = useLoop();
|
||||||
|
|
||||||
const LAG_FPS_THRESHOLD = 40;
|
const LAG_FPS_THRESHOLD = 40;
|
||||||
const LAG_DURATION_SECS = 1;
|
const LAG_DURATION_SECS = 5;
|
||||||
let lagSeconds = 0;
|
let lagSeconds = 0;
|
||||||
let lagCheckDone = false;
|
let lagCheckDone = false;
|
||||||
|
let lastFrameTime = Date.now();
|
||||||
|
|
||||||
const HINT_SPRITE_SCALE = 2;
|
const HINT_SPRITE_SCALE = 2;
|
||||||
const HINT_SPRITE_DPR = 4;
|
const HINT_SPRITE_DPR = 4;
|
||||||
@@ -345,8 +346,17 @@ useKeyUp(({ ndsButton }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// lag detection
|
// lag detection
|
||||||
onBeforeRender(({ delta }) => {
|
onBeforeRender(() => {
|
||||||
if (!lagCheckDone) {
|
if (!lagCheckDone) {
|
||||||
|
const now = Date.now();
|
||||||
|
const delta = (now - lastFrameTime) / 1000;
|
||||||
|
lastFrameTime = now;
|
||||||
|
|
||||||
|
if (document.hidden || delta > 0.5) {
|
||||||
|
lagSeconds = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const fps = 1 / delta;
|
const fps = 1 / delta;
|
||||||
if (fps < LAG_FPS_THRESHOLD) {
|
if (fps < LAG_FPS_THRESHOLD) {
|
||||||
lagSeconds += delta;
|
lagSeconds += delta;
|
||||||
|
|||||||
Reference in New Issue
Block a user