|
@@ -3,20 +3,12 @@ import { Clock } from 'three'
|
|
|
|
|
|
export interface RafLoopContext { delta: number, elapsed: number }
|
|
|
|
|
|
-type LoopFunction = (notifySuccess: () => void) => void
|
|
|
-
|
|
|
/**
|
|
|
- * @param defaultFunction the default function that is called before after the after event hook is triggered and after the before is triggered.
|
|
|
- * @param notifySuccess a callback that should be called to indicate a successfull cycle.
|
|
|
+ * @param cycleFn the function that is called before the after event hook is triggered and after the before event hook is triggered.
|
|
|
*/
|
|
|
-export const useCreateRafLoop = (
|
|
|
- defaultFunction: LoopFunction,
|
|
|
- notifySuccess: () => void,
|
|
|
-) => {
|
|
|
+export const useCreateRafLoop = (cycleFn: () => void) => {
|
|
|
const clock = new Clock()
|
|
|
|
|
|
- let cycleFn: LoopFunction = defaultFunction
|
|
|
-
|
|
|
const eventHooks = {
|
|
|
before: createEventHook<RafLoopContext>(),
|
|
|
after: createEventHook<RafLoopContext>(),
|
|
@@ -29,7 +21,7 @@ export const useCreateRafLoop = (
|
|
|
})
|
|
|
|
|
|
eventHooks.before.trigger(getContextWithClock())
|
|
|
- cycleFn(notifySuccess)
|
|
|
+ cycleFn()
|
|
|
eventHooks.after.trigger(getContextWithClock())
|
|
|
}, {
|
|
|
immediate: false,
|
|
@@ -45,16 +37,11 @@ export const useCreateRafLoop = (
|
|
|
pause()
|
|
|
}
|
|
|
|
|
|
- const replaceLoopFunction = (fn: LoopFunction) => {
|
|
|
- cycleFn = fn
|
|
|
- }
|
|
|
-
|
|
|
return {
|
|
|
start,
|
|
|
stop,
|
|
|
isActive,
|
|
|
onBeforeLoop: eventHooks.before.on,
|
|
|
onLoop: eventHooks.after.on,
|
|
|
- replaceLoopFunction,
|
|
|
}
|
|
|
}
|