chore: format

This commit is contained in:
Nathan Walker
2020-07-05 14:57:06 -07:00
parent 8f2900ad0b
commit da3c0b973d
379 changed files with 71587 additions and 54582 deletions

View File

@@ -2,7 +2,7 @@ import { FPSCallback } from "../fps-meter/fps-native";
import { getTimeInFrameBase } from "./animation-native";
export interface FrameRequestCallback {
(time: number): void;
(time: number): void;
}
let animationId = 0;
@@ -13,50 +13,52 @@ let fpsCallback: FPSCallback;
let lastFrameTime = 0;
function getNewId() {
return animationId++;
return animationId++;
}
function ensureNative() {
if (fpsCallback) {
return;
}
fpsCallback = new FPSCallback(doFrame);
if (fpsCallback) {
return;
}
fpsCallback = new FPSCallback(doFrame);
}
function doFrame(currentTimeMillis: number) {
lastFrameTime = currentTimeMillis;
shouldStop = true;
const thisFrameCbs = nextFrameAnimationCallbacks;
nextFrameAnimationCallbacks = {};
inAnimationFrame = true;
for (const animationId in thisFrameCbs) {
if (thisFrameCbs[animationId]) {
thisFrameCbs[animationId](lastFrameTime);
}
}
inAnimationFrame = false;
if (shouldStop) {
fpsCallback.stop(); // TODO: check performance without stopping to allow consistent frame times
}
lastFrameTime = currentTimeMillis;
shouldStop = true;
const thisFrameCbs = nextFrameAnimationCallbacks;
nextFrameAnimationCallbacks = {};
inAnimationFrame = true;
for (const animationId in thisFrameCbs) {
if (thisFrameCbs[animationId]) {
thisFrameCbs[animationId](lastFrameTime);
}
}
inAnimationFrame = false;
if (shouldStop) {
fpsCallback.stop(); // TODO: check performance without stopping to allow consistent frame times
}
}
export function requestAnimationFrame(cb: FrameRequestCallback): number {
if (!inAnimationFrame) {
inAnimationFrame = true;
zonedCallback(cb)(getTimeInFrameBase()); // TODO: store and use lastFrameTime
inAnimationFrame = false;
if (!inAnimationFrame) {
inAnimationFrame = true;
zonedCallback(cb)(getTimeInFrameBase()); // TODO: store and use lastFrameTime
inAnimationFrame = false;
return getNewId();
}
ensureNative();
const animId = getNewId();
nextFrameAnimationCallbacks[animId] = zonedCallback(cb) as FrameRequestCallback;
shouldStop = false;
fpsCallback.start();
return getNewId();
}
ensureNative();
const animId = getNewId();
nextFrameAnimationCallbacks[animId] = zonedCallback(
cb
) as FrameRequestCallback;
shouldStop = false;
fpsCallback.start();
return animId;
return animId;
}
export function cancelAnimationFrame(id: number) {
delete nextFrameAnimationCallbacks[id];
delete nextFrameAnimationCallbacks[id];
}