- formatting

- allow system to return null to break pipe chain
This commit is contained in:
nvms 2024-09-24 14:09:10 -04:00
parent 91152871d3
commit 9ad1eeeeb9
5 changed files with 42 additions and 41 deletions

View File

@ -90,7 +90,13 @@ var createWorld = () => {
let raf = null; let raf = null;
let craf = null; let craf = null;
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
raf = requestAnimationFrame; let now = performance.now();
raf = (cb) => {
return requestAnimationFrame((timestamp) => {
now = timestamp;
cb(now);
});
};
craf = cancelAnimationFrame; craf = cancelAnimationFrame;
} else { } else {
let now = 0; let now = 0;

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
export { Component, createWorld, Entity, QueryConfig, type ComponentInstance, type WorldState } from "./ngn"; export { Component, createWorld, Entity, QueryConfig, type ComponentInstance, type WorldState } from "./ngn";
export { create2D, createCanvas, CreateCanvasOptions, createDraw, type Vector2 } from "./packages/2d"; export { create2D, createCanvas, CreateCanvasOptions, createDraw, type Vector2 } from "./packages/2d";
export * from "./packages/input";
export { onGamepadConnected, onGamepadDisconnected } from "./packages/input/devices/gamepad"; export { onGamepadConnected, onGamepadDisconnected } from "./packages/input/devices/gamepad";
export { GamepadMapping, PlayStation4, PlayStation5, SCUFVantage2, Xbox } from "./packages/input/devices/mappings/gamepad"; export { GamepadMapping, PlayStation4, PlayStation5, SCUFVantage2, Xbox } from "./packages/input/devices/mappings/gamepad";
export { KeyboardKey, KeyboardMapping, StandardKeyboard } from "./packages/input/devices/mappings/keyboard"; export { KeyboardKey, KeyboardMapping, StandardKeyboard } from "./packages/input/devices/mappings/keyboard";

View File

@ -146,28 +146,28 @@ export const createWorld = () => {
* Fake requestAnimationFrame and cancelAnimationFrame * Fake requestAnimationFrame and cancelAnimationFrame
* so that we can run tests for this in node. * so that we can run tests for this in node.
*/ */
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
let now = performance.now(); let now = performance.now();
raf = (cb: FrameRequestCallback): number => { raf = (cb: FrameRequestCallback): number => {
return requestAnimationFrame((timestamp) => { return requestAnimationFrame((timestamp) => {
now = timestamp; now = timestamp;
cb(now); cb(now);
}); });
}; };
craf = cancelAnimationFrame; craf = cancelAnimationFrame;
} else { } else {
let now = 0; let now = 0;
raf = (cb: FrameRequestCallback): number => { raf = (cb: FrameRequestCallback): number => {
return setTimeout(() => { return setTimeout(() => {
now += 16.67; now += 16.67;
cb(now); cb(now);
}, 16.67) as unknown as number; }, 16.67) as unknown as number;
}; };
craf = (id: number) => { craf = (id: number) => {
clearTimeout(id); clearTimeout(id);
}; };
} }
let xfps = 1; let xfps = 1;
const xtimes = []; const xtimes = [];
@ -216,7 +216,9 @@ export const createWorld = () => {
function step() { function step() {
for (const system of state[$systems]) { for (const system of state[$systems]) {
system(state); if (system(state) === null) {
break;
}
} }
} }

View File

@ -16,14 +16,6 @@ export interface GamepadButtonState extends ButtonState {
value: number; value: number;
} }
let $mousemove = null;
let $mousedown = null;
let $mouseup = null;
let $mousewheel = null;
let $keydown = null;
let $keyup = null;
let $gamepadconnected = null;
let $gamepaddisconnected = null;
let boundEvents = false; let boundEvents = false;
const setDefaultStates = () => { const setDefaultStates = () => {
@ -53,14 +45,14 @@ export const destroyInput = () => {
}; };
const bindEvents = () => { const bindEvents = () => {
$mousemove = window.addEventListener("mousemove", onMouseMove); window.addEventListener("mousemove", onMouseMove);
$mousedown = window.addEventListener("mousedown", onMouseDown); window.addEventListener("mousedown", onMouseDown);
$mouseup = window.addEventListener("mouseup", onMouseUp); window.addEventListener("mouseup", onMouseUp);
$mousewheel = window.addEventListener("mousewheel", onMouseWheel); window.addEventListener("mousewheel", onMouseWheel);
$keydown = window.addEventListener("keydown", onKeyDown); window.addEventListener("keydown", onKeyDown);
$keyup = window.addEventListener("keyup", onKeyUp); window.addEventListener("keyup", onKeyUp);
$gamepadconnected = window.addEventListener("gamepadconnected", onGamepadConnected); window.addEventListener("gamepadconnected", onGamepadConnected);
$gamepaddisconnected = window.addEventListener("gamepaddisconnected", onGamepadDisconnected); window.addEventListener("gamepaddisconnected", onGamepadDisconnected);
}; };
const destroyEvents = () => { const destroyEvents = () => {