mirror of
https://github.com/nvms/prsm.git
synced 2025-12-16 16:10:54 +00:00
- formatting
- allow system to return null to break pipe chain
This commit is contained in:
parent
91152871d3
commit
9ad1eeeeb9
@ -90,7 +90,13 @@ var createWorld = () => {
|
||||
let raf = null;
|
||||
let craf = null;
|
||||
if (typeof window !== "undefined") {
|
||||
raf = requestAnimationFrame;
|
||||
let now = performance.now();
|
||||
raf = (cb) => {
|
||||
return requestAnimationFrame((timestamp) => {
|
||||
now = timestamp;
|
||||
cb(now);
|
||||
});
|
||||
};
|
||||
craf = cancelAnimationFrame;
|
||||
} else {
|
||||
let now = 0;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,5 +1,6 @@
|
||||
export { Component, createWorld, Entity, QueryConfig, type ComponentInstance, type WorldState } from "./ngn";
|
||||
export { create2D, createCanvas, CreateCanvasOptions, createDraw, type Vector2 } from "./packages/2d";
|
||||
export * from "./packages/input";
|
||||
export { onGamepadConnected, onGamepadDisconnected } from "./packages/input/devices/gamepad";
|
||||
export { GamepadMapping, PlayStation4, PlayStation5, SCUFVantage2, Xbox } from "./packages/input/devices/mappings/gamepad";
|
||||
export { KeyboardKey, KeyboardMapping, StandardKeyboard } from "./packages/input/devices/mappings/keyboard";
|
||||
|
||||
@ -146,28 +146,28 @@ export const createWorld = () => {
|
||||
* Fake requestAnimationFrame and cancelAnimationFrame
|
||||
* so that we can run tests for this in node.
|
||||
*/
|
||||
if (typeof window !== "undefined") {
|
||||
let now = performance.now();
|
||||
raf = (cb: FrameRequestCallback): number => {
|
||||
return requestAnimationFrame((timestamp) => {
|
||||
now = timestamp;
|
||||
cb(now);
|
||||
});
|
||||
};
|
||||
craf = cancelAnimationFrame;
|
||||
} else {
|
||||
let now = 0;
|
||||
raf = (cb: FrameRequestCallback): number => {
|
||||
return setTimeout(() => {
|
||||
now += 16.67;
|
||||
cb(now);
|
||||
}, 16.67) as unknown as number;
|
||||
};
|
||||
if (typeof window !== "undefined") {
|
||||
let now = performance.now();
|
||||
raf = (cb: FrameRequestCallback): number => {
|
||||
return requestAnimationFrame((timestamp) => {
|
||||
now = timestamp;
|
||||
cb(now);
|
||||
});
|
||||
};
|
||||
craf = cancelAnimationFrame;
|
||||
} else {
|
||||
let now = 0;
|
||||
raf = (cb: FrameRequestCallback): number => {
|
||||
return setTimeout(() => {
|
||||
now += 16.67;
|
||||
cb(now);
|
||||
}, 16.67) as unknown as number;
|
||||
};
|
||||
|
||||
craf = (id: number) => {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
craf = (id: number) => {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
|
||||
let xfps = 1;
|
||||
const xtimes = [];
|
||||
@ -216,7 +216,9 @@ export const createWorld = () => {
|
||||
|
||||
function step() {
|
||||
for (const system of state[$systems]) {
|
||||
system(state);
|
||||
if (system(state) === null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,14 +16,6 @@ export interface GamepadButtonState extends ButtonState {
|
||||
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;
|
||||
|
||||
const setDefaultStates = () => {
|
||||
@ -53,14 +45,14 @@ export const destroyInput = () => {
|
||||
};
|
||||
|
||||
const bindEvents = () => {
|
||||
$mousemove = window.addEventListener("mousemove", onMouseMove);
|
||||
$mousedown = window.addEventListener("mousedown", onMouseDown);
|
||||
$mouseup = window.addEventListener("mouseup", onMouseUp);
|
||||
$mousewheel = window.addEventListener("mousewheel", onMouseWheel);
|
||||
$keydown = window.addEventListener("keydown", onKeyDown);
|
||||
$keyup = window.addEventListener("keyup", onKeyUp);
|
||||
$gamepadconnected = window.addEventListener("gamepadconnected", onGamepadConnected);
|
||||
$gamepaddisconnected = window.addEventListener("gamepaddisconnected", onGamepadDisconnected);
|
||||
window.addEventListener("mousemove", onMouseMove);
|
||||
window.addEventListener("mousedown", onMouseDown);
|
||||
window.addEventListener("mouseup", onMouseUp);
|
||||
window.addEventListener("mousewheel", onMouseWheel);
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
window.addEventListener("keyup", onKeyUp);
|
||||
window.addEventListener("gamepadconnected", onGamepadConnected);
|
||||
window.addEventListener("gamepaddisconnected", onGamepadDisconnected);
|
||||
};
|
||||
|
||||
const destroyEvents = () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user