fix: reset interpolator on change

This commit is contained in:
cha0s 2024-09-06 13:33:13 -05:00
parent 29df4c3dcb
commit b912fee2e7

View File

@ -1,6 +1,6 @@
export default class Interpolator {
duration = 0;
latest;
latest = null;
location = 0;
penultimate;
tracking = [];
@ -94,7 +94,17 @@ const interpolate = (now) => {
onmessage = async (event) => {
interpolator.accept(event.data);
if (interpolator.penultimate && 'Tick' === event.data.type) {
switch (event.data.type) {
case 'EcsChange': {
if (handle) {
cancelAnimationFrame(handle)
handle = null;
}
interpolator.latest = null;
break;
}
case 'Tick': {
if (interpolator.penultimate) {
postMessage({
type: 'Tick',
payload: {
@ -108,4 +118,7 @@ onmessage = async (event) => {
handle = requestAnimationFrame(interpolate);
}
}
break;
}
}
};