Skip to content

Commit

Permalink
limit particle effect fps to 60
Browse files Browse the repository at this point in the history
  • Loading branch information
Steedie authored and ldunnplaymint committed Oct 28, 2024
1 parent 2f3308a commit b76df71
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/examples/spaceshooter/effects/FXExplodeQuarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ export const ExplodeFX = forwardRef<ExplodeFXHandle>((_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;
}
}
});

Expand Down
12 changes: 10 additions & 2 deletions src/examples/spaceshooter/effects/FXRespawnQuarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ export const SpawnFX = forwardRef<SpawnFXHandle>((_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;
}
}
});

Expand Down
12 changes: 10 additions & 2 deletions src/examples/spaceshooter/effects/FXShipImpactQuarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ export const ShipImpactFX = forwardRef<ShipImpactFXHandle>((_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;
}
}
});

Expand Down
12 changes: 10 additions & 2 deletions src/examples/spaceshooter/effects/FXSparksQuarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ export const SparksFX = forwardRef<SparksFXHandle>((_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;
}
}
});

Expand Down

0 comments on commit b76df71

Please sign in to comment.