-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cca7194
commit 65b5ae1
Showing
4 changed files
with
6 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { useFrame } from '@darkroom.engineering/hamo' | ||
import { useRef } from 'react' | ||
|
||
export function useFramerate(fps, callback) { | ||
export function useFramerate(fps, callback, priority = 0) { | ||
const timeRef = useRef(0) | ||
|
||
useFrame((time, delaTime) => { | ||
timeRef.current += delaTime | ||
|
||
if (timeRef.current > 1000 / (typeof fps === 'function' ? fps() : fps)) { | ||
timeRef.current = 0 | ||
const executionTime = 1000 / (typeof fps === 'function' ? fps() : fps) | ||
|
||
if (timeRef.current >= executionTime) { | ||
timeRef.current = timeRef.current % executionTime | ||
callback?.(time, delaTime) | ||
} | ||
}) | ||
}, priority) | ||
} |
65b5ae1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡️ Lighthouse report for the changes in this commit:
🟢 Performance: 100
🟢 Accessibility: 90
🟢 Best practices: 96
🟠 SEO: 63
Lighthouse ran on https://satus-89fjur2tc-darkroom-engineering.vercel.app/