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

@@ -3,14 +3,14 @@
* @argument time Time of the current frame in milliseconds
*/
export interface FrameRequestCallback {
(time: number): void;
(time: number): void;
}
/**
* Requests an animation frame and returns the timer ID
* @param cb Callback to be called on frame
*/
export function requestAnimationFrame(cb: FrameRequestCallback): number
export function requestAnimationFrame(cb: FrameRequestCallback): number;
/**
* Cancels a previously scheduled animation frame request

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];
}

View File

@@ -1,4 +1,3 @@
export function getTimeInFrameBase(): number {
return java.lang.System.nanoTime() / 1000000;
return java.lang.System.nanoTime() / 1000000;
}

View File

@@ -1,4 +1,4 @@
/**
* Gets the time in millisseconds in the same base as frames
*/
export function getTimeInFrameBase(): number;
export function getTimeInFrameBase(): number;