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

@@ -7,87 +7,89 @@ let framesRendered = 0;
let frameStartTime = 0;
function doFrame(currentTimeMillis: number) {
let fps = 0;
if (frameStartTime > 0) {
// take the span in milliseconds
const timeSpan = (currentTimeMillis - frameStartTime);
framesRendered++;
let fps = 0;
if (frameStartTime > 0) {
// take the span in milliseconds
const timeSpan = currentTimeMillis - frameStartTime;
framesRendered++;
if (timeSpan > 1000) {
fps = framesRendered * 1000 / timeSpan;
if (fps < _minFps) {
_minFps = fps;
}
if (timeSpan > 1000) {
fps = (framesRendered * 1000) / timeSpan;
if (fps < _minFps) {
_minFps = fps;
}
notify(fps);
notify(fps);
frameStartTime = currentTimeMillis;
framesRendered = 0;
}
} else {
frameStartTime = currentTimeMillis;
}
frameStartTime = currentTimeMillis;
framesRendered = 0;
}
} else {
frameStartTime = currentTimeMillis;
}
}
let native: fpsNative.FPSCallback;
function ensureNative() {
if (!native) {
native = new fpsNative.FPSCallback(doFrame);
}
if (!native) {
native = new fpsNative.FPSCallback(doFrame);
}
}
export function reset() {
_minFps = 1000;
frameStartTime = 0;
framesRendered = 0;
_minFps = 1000;
frameStartTime = 0;
framesRendered = 0;
}
export function running(): boolean {
if (!native) {
return false;
}
if (!native) {
return false;
}
return native.running;
return native.running;
}
export function minFps(): number {
return _minFps;
return _minFps;
}
export function start() {
ensureNative();
native.start();
ensureNative();
native.start();
}
export function stop() {
if (!native) {
return;
}
if (!native) {
return;
}
native.stop();
reset();
native.stop();
reset();
}
export function addCallback(callback: (fps: number, minFps?: number) => void): number {
const id = idCounter;
export function addCallback(
callback: (fps: number, minFps?: number) => void
): number {
const id = idCounter;
// Wrap all calback in zonedCallback so that they work with the current zone.
callbacks[id] = zonedCallback(callback);
idCounter++;
// Wrap all calback in zonedCallback so that they work with the current zone.
callbacks[id] = zonedCallback(callback);
idCounter++;
return id;
return id;
}
export function removeCallback(id: number) {
if (id in callbacks) {
delete callbacks[id];
}
if (id in callbacks) {
delete callbacks[id];
}
}
function notify(fps) {
let callback: Function;
for (let id in callbacks) {
callback = callbacks[id];
callback(fps, _minFps);
}
let callback: Function;
for (let id in callbacks) {
callback = callbacks[id];
callback(fps, _minFps);
}
}