From b76df71357682013c4c8405177413d5681cd6360 Mon Sep 17 00:00:00 2001 From: Steedie Date: Mon, 28 Oct 2024 15:30:56 +0000 Subject: [PATCH] limit particle effect fps to 60 --- src/examples/spaceshooter/effects/FXExplodeQuarks.ts | 12 ++++++++++-- src/examples/spaceshooter/effects/FXRespawnQuarks.ts | 12 ++++++++++-- .../spaceshooter/effects/FXShipImpactQuarks.ts | 12 ++++++++++-- src/examples/spaceshooter/effects/FXSparksQuarks.ts | 12 ++++++++++-- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/examples/spaceshooter/effects/FXExplodeQuarks.ts b/src/examples/spaceshooter/effects/FXExplodeQuarks.ts index c2e345e0..11a5ef6b 100644 --- a/src/examples/spaceshooter/effects/FXExplodeQuarks.ts +++ b/src/examples/spaceshooter/effects/FXExplodeQuarks.ts @@ -45,9 +45,17 @@ export const ExplodeFX = forwardRef((_props, ref) => { }, })); - useFrame((_state, delta) => { + let lastUpdateTime = performance.now(); + const fpsInterval = 1000 / 60; + + useFrame((_state, _) => { if (activeExplosions > 0) { - batchRenderer.update(delta); + const now = performance.now(); + const elapsed = now - lastUpdateTime; + if (elapsed >= fpsInterval) { + batchRenderer.update(elapsed / 1000); + lastUpdateTime = now; + } } }); diff --git a/src/examples/spaceshooter/effects/FXRespawnQuarks.ts b/src/examples/spaceshooter/effects/FXRespawnQuarks.ts index eec63845..ff5d70e4 100644 --- a/src/examples/spaceshooter/effects/FXRespawnQuarks.ts +++ b/src/examples/spaceshooter/effects/FXRespawnQuarks.ts @@ -33,9 +33,17 @@ export const SpawnFX = forwardRef((_props, ref) => { }, })); - useFrame((_state, delta) => { + let lastUpdateTime = performance.now(); + const fpsInterval = 1000 / 60; + + useFrame((_state, _) => { if (activeSpawns > 0) { - batchRenderer.update(delta); + const now = performance.now(); + const elapsed = now - lastUpdateTime; + if (elapsed >= fpsInterval) { + batchRenderer.update(elapsed / 1000); + lastUpdateTime = now; + } } }); diff --git a/src/examples/spaceshooter/effects/FXShipImpactQuarks.ts b/src/examples/spaceshooter/effects/FXShipImpactQuarks.ts index bc909b2f..2c3253be 100644 --- a/src/examples/spaceshooter/effects/FXShipImpactQuarks.ts +++ b/src/examples/spaceshooter/effects/FXShipImpactQuarks.ts @@ -32,9 +32,17 @@ export const ShipImpactFX = forwardRef((_props, ref) => { }, })); - useFrame((_state, delta) => { + let lastUpdateTime = performance.now(); + const fpsInterval = 1000 / 60; + + useFrame((_state, _) => { if (activeImpacts > 0) { - batchRenderer.update(delta); + const now = performance.now(); + const elapsed = now - lastUpdateTime; + if (elapsed >= fpsInterval) { + batchRenderer.update(elapsed / 1000); + lastUpdateTime = now; + } } }); diff --git a/src/examples/spaceshooter/effects/FXSparksQuarks.ts b/src/examples/spaceshooter/effects/FXSparksQuarks.ts index 4ac54e44..ea497791 100644 --- a/src/examples/spaceshooter/effects/FXSparksQuarks.ts +++ b/src/examples/spaceshooter/effects/FXSparksQuarks.ts @@ -32,9 +32,17 @@ export const SparksFX = forwardRef((_props, ref) => { }, })); - useFrame((_state, delta) => { + let lastUpdateTime = performance.now(); + const fpsInterval = 1000 / 60; + + useFrame((_state, _) => { if (activeSparks > 0) { - batchRenderer.update(delta); + const now = performance.now(); + const elapsed = now - lastUpdateTime; + if (elapsed >= fpsInterval) { + batchRenderer.update(elapsed / 1000); + lastUpdateTime = now; + } } });