chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-06 14:25:11 -07:00
parent 94cf5c4706
commit 6336eac4b5
477 changed files with 59087 additions and 74961 deletions

View File

@@ -3,7 +3,7 @@
* @argument time Time of the current frame in milliseconds
*/
export interface FrameRequestCallback {
(time: number): void;
(time: number): void;
}
/**

View File

@@ -1,8 +1,8 @@
import { FPSCallback } from "../fps-meter/fps-native";
import { getTimeInFrameBase } from "./animation-native";
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,52 +13,50 @@ 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,3 +1,3 @@
export function getTimeInFrameBase(): number {
return java.lang.System.nanoTime() / 1000000;
return java.lang.System.nanoTime() / 1000000;
}

View File

@@ -1,3 +1,3 @@
import { time } from "../profiling";
import { time } from '../profiling';
export const getTimeInFrameBase = time;