@al8b/runtime 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -0
- package/dist/assets/constructors.d.mts +6 -0
- package/dist/assets/constructors.d.ts +6 -0
- package/dist/assets/constructors.js +40 -0
- package/dist/assets/constructors.js.map +1 -0
- package/dist/assets/constructors.mjs +12 -0
- package/dist/assets/constructors.mjs.map +1 -0
- package/dist/assets/index.d.mts +11 -0
- package/dist/assets/index.d.ts +11 -0
- package/dist/assets/index.js +276 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/index.mjs +247 -0
- package/dist/assets/index.mjs.map +1 -0
- package/dist/assets/loader.d.mts +83 -0
- package/dist/assets/loader.d.ts +83 -0
- package/dist/assets/loader.js +260 -0
- package/dist/assets/loader.js.map +1 -0
- package/dist/assets/loader.mjs +237 -0
- package/dist/assets/loader.mjs.map +1 -0
- package/dist/browser/index.js +16599 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/index.min.js +171 -0
- package/dist/constants.d.mts +16 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +49 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +18 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core/api-factory.d.mts +63 -0
- package/dist/core/api-factory.d.ts +63 -0
- package/dist/core/api-factory.js +239 -0
- package/dist/core/api-factory.js.map +1 -0
- package/dist/core/api-factory.mjs +214 -0
- package/dist/core/api-factory.mjs.map +1 -0
- package/dist/core/assets-registry.d.mts +14 -0
- package/dist/core/assets-registry.d.ts +14 -0
- package/dist/core/assets-registry.js +64 -0
- package/dist/core/assets-registry.js.map +1 -0
- package/dist/core/assets-registry.mjs +41 -0
- package/dist/core/assets-registry.mjs.map +1 -0
- package/dist/core/controller.d.mts +109 -0
- package/dist/core/controller.d.ts +109 -0
- package/dist/core/controller.js +1782 -0
- package/dist/core/controller.js.map +1 -0
- package/dist/core/controller.mjs +1758 -0
- package/dist/core/controller.mjs.map +1 -0
- package/dist/core/debug-logger.d.mts +35 -0
- package/dist/core/debug-logger.d.ts +35 -0
- package/dist/core/debug-logger.js +177 -0
- package/dist/core/debug-logger.js.map +1 -0
- package/dist/core/debug-logger.mjs +154 -0
- package/dist/core/debug-logger.mjs.map +1 -0
- package/dist/core/error-handler.d.mts +25 -0
- package/dist/core/error-handler.d.ts +25 -0
- package/dist/core/error-handler.js +106 -0
- package/dist/core/error-handler.js.map +1 -0
- package/dist/core/error-handler.mjs +81 -0
- package/dist/core/error-handler.mjs.map +1 -0
- package/dist/core/index.d.mts +14 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.js +1782 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +1757 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/hot-reload/index.d.mts +7 -0
- package/dist/hot-reload/index.d.ts +7 -0
- package/dist/hot-reload/index.js +103 -0
- package/dist/hot-reload/index.js.map +1 -0
- package/dist/hot-reload/index.mjs +78 -0
- package/dist/hot-reload/index.mjs.map +1 -0
- package/dist/hot-reload/updater.d.mts +33 -0
- package/dist/hot-reload/updater.d.ts +33 -0
- package/dist/hot-reload/updater.js +101 -0
- package/dist/hot-reload/updater.js.map +1 -0
- package/dist/hot-reload/updater.mjs +78 -0
- package/dist/hot-reload/updater.mjs.map +1 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +1859 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1817 -0
- package/dist/index.mjs.map +1 -0
- package/dist/input/index.d.mts +2 -0
- package/dist/input/index.d.ts +2 -0
- package/dist/input/index.js +79 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input/index.mjs +54 -0
- package/dist/input/index.mjs.map +1 -0
- package/dist/input/manager.d.mts +37 -0
- package/dist/input/manager.d.ts +37 -0
- package/dist/input/manager.js +77 -0
- package/dist/input/manager.js.map +1 -0
- package/dist/input/manager.mjs +54 -0
- package/dist/input/manager.mjs.map +1 -0
- package/dist/loop/game-loop.d.mts +63 -0
- package/dist/loop/game-loop.d.ts +63 -0
- package/dist/loop/game-loop.js +156 -0
- package/dist/loop/game-loop.js.map +1 -0
- package/dist/loop/game-loop.mjs +131 -0
- package/dist/loop/game-loop.mjs.map +1 -0
- package/dist/loop/index.d.mts +1 -0
- package/dist/loop/index.d.ts +1 -0
- package/dist/loop/index.js +156 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/index.mjs +131 -0
- package/dist/loop/index.mjs.map +1 -0
- package/dist/storage/index.d.mts +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +31 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.mjs +6 -0
- package/dist/storage/index.mjs.map +1 -0
- package/dist/system/api.d.mts +28 -0
- package/dist/system/api.d.ts +28 -0
- package/dist/system/api.js +126 -0
- package/dist/system/api.js.map +1 -0
- package/dist/system/api.mjs +101 -0
- package/dist/system/api.mjs.map +1 -0
- package/dist/system/index.d.mts +2 -0
- package/dist/system/index.d.ts +2 -0
- package/dist/system/index.js +126 -0
- package/dist/system/index.js.map +1 -0
- package/dist/system/index.mjs +101 -0
- package/dist/system/index.mjs.map +1 -0
- package/dist/types/assets.d.mts +43 -0
- package/dist/types/assets.d.ts +43 -0
- package/dist/types/assets.js +19 -0
- package/dist/types/assets.js.map +1 -0
- package/dist/types/assets.mjs +1 -0
- package/dist/types/assets.mjs.map +1 -0
- package/dist/types/bridge.d.mts +66 -0
- package/dist/types/bridge.d.ts +66 -0
- package/dist/types/bridge.js +19 -0
- package/dist/types/bridge.js.map +1 -0
- package/dist/types/bridge.mjs +1 -0
- package/dist/types/bridge.mjs.map +1 -0
- package/dist/types/index.d.mts +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/runtime.d.mts +71 -0
- package/dist/types/runtime.d.ts +71 -0
- package/dist/types/runtime.js +19 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/runtime.mjs +1 -0
- package/dist/types/runtime.mjs.map +1 -0
- package/dist/types/vm.d.mts +1 -0
- package/dist/types/vm.d.ts +1 -0
- package/dist/types/vm.js +19 -0
- package/dist/types/vm.js.map +1 -0
- package/dist/types/vm.mjs +1 -0
- package/dist/types/vm.mjs.map +1 -0
- package/dist/utils/deep-clone.d.mts +14 -0
- package/dist/utils/deep-clone.d.ts +14 -0
- package/dist/utils/deep-clone.js +42 -0
- package/dist/utils/deep-clone.js.map +1 -0
- package/dist/utils/deep-clone.mjs +19 -0
- package/dist/utils/deep-clone.mjs.map +1 -0
- package/dist/utils/index.d.mts +3 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +156 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +129 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/object-pool.d.mts +66 -0
- package/dist/utils/object-pool.d.ts +66 -0
- package/dist/utils/object-pool.js +113 -0
- package/dist/utils/object-pool.js.map +1 -0
- package/dist/utils/object-pool.mjs +90 -0
- package/dist/utils/object-pool.mjs.map +1 -0
- package/dist/utils/shallow-equal.d.mts +15 -0
- package/dist/utils/shallow-equal.d.ts +15 -0
- package/dist/utils/shallow-equal.js +53 -0
- package/dist/utils/shallow-equal.js.map +1 -0
- package/dist/utils/shallow-equal.mjs +30 -0
- package/dist/utils/shallow-equal.mjs.map +1 -0
- package/dist/vm/index.d.mts +1 -0
- package/dist/vm/index.d.ts +1 -0
- package/dist/vm/index.js +37 -0
- package/dist/vm/index.js.map +1 -0
- package/dist/vm/index.mjs +9 -0
- package/dist/vm/index.mjs.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/loop/index.ts","../../src/constants.ts","../../src/loop/game-loop.ts"],"sourcesContent":["/**\n * Game loop exports\n */\n\nexport type {\n\tGameLoopCallbacks,\n\tGameLoopState,\n} from \"./game-loop\";\nexport { GameLoop } from \"./game-loop\";\n","/** Default frames per second */\nexport const DEFAULT_FPS = 60;\n\n/** Default update rate (updates per second) */\nexport const DEFAULT_UPDATE_RATE = 60;\n\n/** Frame time in milliseconds at 60 FPS */\nexport const FRAME_TIME_MS = 1000 / DEFAULT_FPS;\n\n/** Threshold in ms to detect long pauses (tab switch, etc.) */\nexport const PAUSE_THRESHOLD_MS = 160;\n\n/** Default tile/block size in pixels */\nexport const DEFAULT_BLOCK_SIZE = 16;\n\n/** Minimum interval between loading bar redraws in ms (~60fps) */\nexport const LOADING_BAR_THROTTLE_MS = 16;\n\n/** Timeout in ms for individual asset loads (sprite/map HTTP requests) */\nexport const ASSET_LOAD_TIMEOUT_MS = 30_000;\n","import { DEFAULT_FPS, DEFAULT_UPDATE_RATE, FRAME_TIME_MS, LOADING_BAR_THROTTLE_MS, PAUSE_THRESHOLD_MS } from \"../constants\";\n\n/**\n * GameLoop - Manages the game update/draw cycle\n *\n * Responsibilities:\n * - requestAnimationFrame loop\n * - Delta time calculation\n * - FPS calculation\n * - Update rate management\n * - Frame skipping for catch-up\n */\n\nexport interface GameLoopCallbacks {\n\tonUpdate: () => void;\n\tonDraw: () => void;\n\tonTick?: () => void;\n\tonWatchStep?: () => void;\n\tgetUpdateRate?: () => number | undefined;\n\tsetFPS?: (fps: number) => void;\n}\n\nexport interface GameLoopState {\n\tcurrentFrame: number;\n\tfloatingFrame: number;\n\tdt: number;\n\tlastTime: number;\n\tfps: number;\n\tupdateRate: number;\n}\n\nexport class GameLoop {\n\tprivate callbacks: GameLoopCallbacks;\n\tprivate state: GameLoopState;\n\tprivate stopped = false;\n\tprivate animationFrameId: number | null = null;\n\n\tconstructor(callbacks: GameLoopCallbacks) {\n\t\tthis.callbacks = callbacks;\n\t\tthis.state = {\n\t\t\tcurrentFrame: 0,\n\t\t\tfloatingFrame: 0,\n\t\t\tdt: FRAME_TIME_MS,\n\t\t\tlastTime: performance.now(),\n\t\t\tfps: DEFAULT_FPS,\n\t\t\tupdateRate: DEFAULT_UPDATE_RATE,\n\t\t};\n\t\t// Bind loop once\n\t\tthis.loop = this.loop.bind(this);\n\t}\n\n\t/**\n\t * Start the game loop\n\t */\n\tstart(): void {\n\t\tthis.stopped = false;\n\t\tthis.state.lastTime = performance.now();\n\t\tthis.state.currentFrame = 0;\n\t\tthis.state.floatingFrame = 0;\n\t\tthis.loop();\n\t}\n\n\t/**\n\t * Stop the game loop\n\t */\n\tstop(): void {\n\t\tthis.stopped = true;\n\t\tif (this.animationFrameId !== null) {\n\t\t\tcancelAnimationFrame(this.animationFrameId);\n\t\t\tthis.animationFrameId = null;\n\t\t}\n\t}\n\n\t/**\n\t * Resume the game loop\n\t */\n\tresume(): void {\n\t\tif (!this.stopped) return;\n\t\tthis.stopped = false;\n\t\tthis.state.lastTime = performance.now();\n\t\tthis.loop();\n\t}\n\n\t/**\n\t * Main game loop\n\t */\n\tprivate loop(): void {\n\t\tif (this.stopped) return;\n\n\t\t// Schedule next frame\n\t\tthis.animationFrameId = requestAnimationFrame(this.loop);\n\n\t\tconst time = performance.now();\n\n\t\t// Recover from long pause (tab switch, etc)\n\t\tif (Math.abs(time - this.state.lastTime) > PAUSE_THRESHOLD_MS) {\n\t\t\tthis.state.lastTime = time - LOADING_BAR_THROTTLE_MS;\n\t\t}\n\n\t\t// Calculate delta time\n\t\tconst dt = time - this.state.lastTime;\n\t\tthis.state.dt = this.state.dt * 0.9 + dt * 0.1; // Smooth with exponential moving average\n\t\tthis.state.lastTime = time;\n\n\t\t// Calculate FPS and update in global context\n\t\tconst fps = Math.round(1000 / this.state.dt);\n\t\tthis.state.fps = fps;\n\t\tif (this.callbacks.setFPS) {\n\t\t\tthis.callbacks.setFPS(fps);\n\t\t}\n\n\t\t// Read update_rate from global context each frame\n\t\tlet updateRate = this.state.updateRate; // Default\n\t\tif (this.callbacks.getUpdateRate) {\n\t\t\tconst rate = this.callbacks.getUpdateRate();\n\t\t\tif (rate != null && rate > 0 && Number.isFinite(rate)) {\n\t\t\t\tupdateRate = rate;\n\t\t\t}\n\t\t}\n\n\t\t// Calculate how many update steps needed\n\t\tthis.state.floatingFrame += (this.state.dt * updateRate) / 1000;\n\t\tlet ds = Math.min(10, Math.round(this.state.floatingFrame - this.state.currentFrame));\n\n\t\t// Correction for 60fps (reduce jitter)\n\t\tif ((ds === 0 || ds === 2) && updateRate === DEFAULT_UPDATE_RATE && Math.abs(fps - DEFAULT_FPS) < 2) {\n\t\t\tds = 1;\n\t\t\tthis.state.floatingFrame = this.state.currentFrame + 1;\n\t\t}\n\n\t\t// Call update() multiple times if needed (catch up)\n\t\t// Loop from 1 to ds (inclusive), not 0 to steps-1\n\t\tfor (let i = 1; i <= ds; i++) {\n\t\t\tthis.callbacks.onUpdate();\n\n\t\t\t// Tick between updates (for threads/coroutines)\n\t\t\tif (i < ds && this.callbacks.onTick) {\n\t\t\t\tthis.callbacks.onTick();\n\t\t\t}\n\t\t}\n\n\t\t// Update current frame\n\t\tthis.state.currentFrame += ds;\n\n\t\t// Call draw() once per frame\n\t\tthis.callbacks.onDraw();\n\n\t\t// Tick after draw\n\t\tif (this.callbacks.onTick) {\n\t\t\tthis.callbacks.onTick();\n\t\t}\n\n\t\t// Watch step after draw if ds > 0\n\t\tif (ds > 0 && this.callbacks.onWatchStep) {\n\t\t\tthis.callbacks.onWatchStep();\n\t\t}\n\t}\n\n\t/**\n\t * Get current state\n\t */\n\tgetState(): GameLoopState {\n\t\treturn this.state;\n\t}\n\n\t/**\n\t * Set update rate\n\t */\n\tsetUpdateRate(rate: number): void {\n\t\tif (rate > 0 && Number.isFinite(rate)) {\n\t\t\tthis.state.updateRate = rate;\n\t\t}\n\t}\n\n\t/**\n\t * Get FPS\n\t */\n\tgetFPS(): number {\n\t\treturn this.state.fps;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACCO,IAAMA,cAAc;AAGpB,I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EACD;;;;EAKAY,SAAiB;AAChB,WAAO,KAAKzC,MAAMU;EACnB;AACD;","names":["DEFAULT_FPS","DEFAULT_UPDATE_RATE","FRAME_TIME_MS","PAUSE_THRESHOLD_MS","LOADING_BAR_THROTTLE_MS","GameLoop","callbacks","state","stopped","animationFrameId","currentFrame","floatingFrame","dt","FRAME_TIME_MS","lastTime","performance","now","fps","DEFAULT_FPS","updateRate","DEFAULT_UPDATE_RATE","loop","bind","start","stop","cancelAnimationFrame","resume","requestAnimationFrame","time","Math","abs","PAUSE_THRESHOLD_MS","LOADING_BAR_THROTTLE_MS","round","setFPS","getUpdateRate","rate","Number","isFinite","ds","min","i","onUpdate","onTick","onDraw","onWatchStep","getState","setUpdateRate","getFPS"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/constants.ts
|
|
5
|
+
var DEFAULT_FPS = 60;
|
|
6
|
+
var DEFAULT_UPDATE_RATE = 60;
|
|
7
|
+
var FRAME_TIME_MS = 1e3 / DEFAULT_FPS;
|
|
8
|
+
var PAUSE_THRESHOLD_MS = 160;
|
|
9
|
+
var LOADING_BAR_THROTTLE_MS = 16;
|
|
10
|
+
|
|
11
|
+
// src/loop/game-loop.ts
|
|
12
|
+
var GameLoop = class {
|
|
13
|
+
static {
|
|
14
|
+
__name(this, "GameLoop");
|
|
15
|
+
}
|
|
16
|
+
callbacks;
|
|
17
|
+
state;
|
|
18
|
+
stopped = false;
|
|
19
|
+
animationFrameId = null;
|
|
20
|
+
constructor(callbacks) {
|
|
21
|
+
this.callbacks = callbacks;
|
|
22
|
+
this.state = {
|
|
23
|
+
currentFrame: 0,
|
|
24
|
+
floatingFrame: 0,
|
|
25
|
+
dt: FRAME_TIME_MS,
|
|
26
|
+
lastTime: performance.now(),
|
|
27
|
+
fps: DEFAULT_FPS,
|
|
28
|
+
updateRate: DEFAULT_UPDATE_RATE
|
|
29
|
+
};
|
|
30
|
+
this.loop = this.loop.bind(this);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Start the game loop
|
|
34
|
+
*/
|
|
35
|
+
start() {
|
|
36
|
+
this.stopped = false;
|
|
37
|
+
this.state.lastTime = performance.now();
|
|
38
|
+
this.state.currentFrame = 0;
|
|
39
|
+
this.state.floatingFrame = 0;
|
|
40
|
+
this.loop();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Stop the game loop
|
|
44
|
+
*/
|
|
45
|
+
stop() {
|
|
46
|
+
this.stopped = true;
|
|
47
|
+
if (this.animationFrameId !== null) {
|
|
48
|
+
cancelAnimationFrame(this.animationFrameId);
|
|
49
|
+
this.animationFrameId = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resume the game loop
|
|
54
|
+
*/
|
|
55
|
+
resume() {
|
|
56
|
+
if (!this.stopped) return;
|
|
57
|
+
this.stopped = false;
|
|
58
|
+
this.state.lastTime = performance.now();
|
|
59
|
+
this.loop();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Main game loop
|
|
63
|
+
*/
|
|
64
|
+
loop() {
|
|
65
|
+
if (this.stopped) return;
|
|
66
|
+
this.animationFrameId = requestAnimationFrame(this.loop);
|
|
67
|
+
const time = performance.now();
|
|
68
|
+
if (Math.abs(time - this.state.lastTime) > PAUSE_THRESHOLD_MS) {
|
|
69
|
+
this.state.lastTime = time - LOADING_BAR_THROTTLE_MS;
|
|
70
|
+
}
|
|
71
|
+
const dt = time - this.state.lastTime;
|
|
72
|
+
this.state.dt = this.state.dt * 0.9 + dt * 0.1;
|
|
73
|
+
this.state.lastTime = time;
|
|
74
|
+
const fps = Math.round(1e3 / this.state.dt);
|
|
75
|
+
this.state.fps = fps;
|
|
76
|
+
if (this.callbacks.setFPS) {
|
|
77
|
+
this.callbacks.setFPS(fps);
|
|
78
|
+
}
|
|
79
|
+
let updateRate = this.state.updateRate;
|
|
80
|
+
if (this.callbacks.getUpdateRate) {
|
|
81
|
+
const rate = this.callbacks.getUpdateRate();
|
|
82
|
+
if (rate != null && rate > 0 && Number.isFinite(rate)) {
|
|
83
|
+
updateRate = rate;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
this.state.floatingFrame += this.state.dt * updateRate / 1e3;
|
|
87
|
+
let ds = Math.min(10, Math.round(this.state.floatingFrame - this.state.currentFrame));
|
|
88
|
+
if ((ds === 0 || ds === 2) && updateRate === DEFAULT_UPDATE_RATE && Math.abs(fps - DEFAULT_FPS) < 2) {
|
|
89
|
+
ds = 1;
|
|
90
|
+
this.state.floatingFrame = this.state.currentFrame + 1;
|
|
91
|
+
}
|
|
92
|
+
for (let i = 1; i <= ds; i++) {
|
|
93
|
+
this.callbacks.onUpdate();
|
|
94
|
+
if (i < ds && this.callbacks.onTick) {
|
|
95
|
+
this.callbacks.onTick();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.state.currentFrame += ds;
|
|
99
|
+
this.callbacks.onDraw();
|
|
100
|
+
if (this.callbacks.onTick) {
|
|
101
|
+
this.callbacks.onTick();
|
|
102
|
+
}
|
|
103
|
+
if (ds > 0 && this.callbacks.onWatchStep) {
|
|
104
|
+
this.callbacks.onWatchStep();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get current state
|
|
109
|
+
*/
|
|
110
|
+
getState() {
|
|
111
|
+
return this.state;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Set update rate
|
|
115
|
+
*/
|
|
116
|
+
setUpdateRate(rate) {
|
|
117
|
+
if (rate > 0 && Number.isFinite(rate)) {
|
|
118
|
+
this.state.updateRate = rate;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get FPS
|
|
123
|
+
*/
|
|
124
|
+
getFPS() {
|
|
125
|
+
return this.state.fps;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export {
|
|
129
|
+
GameLoop
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts","../../src/loop/game-loop.ts"],"sourcesContent":["/** Default frames per second */\nexport const DEFAULT_FPS = 60;\n\n/** Default update rate (updates per second) */\nexport const DEFAULT_UPDATE_RATE = 60;\n\n/** Frame time in milliseconds at 60 FPS */\nexport const FRAME_TIME_MS = 1000 / DEFAULT_FPS;\n\n/** Threshold in ms to detect long pauses (tab switch, etc.) */\nexport const PAUSE_THRESHOLD_MS = 160;\n\n/** Default tile/block size in pixels */\nexport const DEFAULT_BLOCK_SIZE = 16;\n\n/** Minimum interval between loading bar redraws in ms (~60fps) */\nexport const LOADING_BAR_THROTTLE_MS = 16;\n\n/** Timeout in ms for individual asset loads (sprite/map HTTP requests) */\nexport const ASSET_LOAD_TIMEOUT_MS = 30_000;\n","import { DEFAULT_FPS, DEFAULT_UPDATE_RATE, FRAME_TIME_MS, LOADING_BAR_THROTTLE_MS, PAUSE_THRESHOLD_MS } from \"../constants\";\n\n/**\n * GameLoop - Manages the game update/draw cycle\n *\n * Responsibilities:\n * - requestAnimationFrame loop\n * - Delta time calculation\n * - FPS calculation\n * - Update rate management\n * - Frame skipping for catch-up\n */\n\nexport interface GameLoopCallbacks {\n\tonUpdate: () => void;\n\tonDraw: () => void;\n\tonTick?: () => void;\n\tonWatchStep?: () => void;\n\tgetUpdateRate?: () => number | undefined;\n\tsetFPS?: (fps: number) => void;\n}\n\nexport interface GameLoopState {\n\tcurrentFrame: number;\n\tfloatingFrame: number;\n\tdt: number;\n\tlastTime: number;\n\tfps: number;\n\tupdateRate: number;\n}\n\nexport class GameLoop {\n\tprivate callbacks: GameLoopCallbacks;\n\tprivate state: GameLoopState;\n\tprivate stopped = false;\n\tprivate animationFrameId: number | null = null;\n\n\tconstructor(callbacks: GameLoopCallbacks) {\n\t\tthis.callbacks = callbacks;\n\t\tthis.state = {\n\t\t\tcurrentFrame: 0,\n\t\t\tfloatingFrame: 0,\n\t\t\tdt: FRAME_TIME_MS,\n\t\t\tlastTime: performance.now(),\n\t\t\tfps: DEFAULT_FPS,\n\t\t\tupdateRate: DEFAULT_UPDATE_RATE,\n\t\t};\n\t\t// Bind loop once\n\t\tthis.loop = this.loop.bind(this);\n\t}\n\n\t/**\n\t * Start the game loop\n\t */\n\tstart(): void {\n\t\tthis.stopped = false;\n\t\tthis.state.lastTime = performance.now();\n\t\tthis.state.currentFrame = 0;\n\t\tthis.state.floatingFrame = 0;\n\t\tthis.loop();\n\t}\n\n\t/**\n\t * Stop the game loop\n\t */\n\tstop(): void {\n\t\tthis.stopped = true;\n\t\tif (this.animationFrameId !== null) {\n\t\t\tcancelAnimationFrame(this.animationFrameId);\n\t\t\tthis.animationFrameId = null;\n\t\t}\n\t}\n\n\t/**\n\t * Resume the game loop\n\t */\n\tresume(): void {\n\t\tif (!this.stopped) return;\n\t\tthis.stopped = false;\n\t\tthis.state.lastTime = performance.now();\n\t\tthis.loop();\n\t}\n\n\t/**\n\t * Main game loop\n\t */\n\tprivate loop(): void {\n\t\tif (this.stopped) return;\n\n\t\t// Schedule next frame\n\t\tthis.animationFrameId = requestAnimationFrame(this.loop);\n\n\t\tconst time = performance.now();\n\n\t\t// Recover from long pause (tab switch, etc)\n\t\tif (Math.abs(time - this.state.lastTime) > PAUSE_THRESHOLD_MS) {\n\t\t\tthis.state.lastTime = time - LOADING_BAR_THROTTLE_MS;\n\t\t}\n\n\t\t// Calculate delta time\n\t\tconst dt = time - this.state.lastTime;\n\t\tthis.state.dt = this.state.dt * 0.9 + dt * 0.1; // Smooth with exponential moving average\n\t\tthis.state.lastTime = time;\n\n\t\t// Calculate FPS and update in global context\n\t\tconst fps = Math.round(1000 / this.state.dt);\n\t\tthis.state.fps = fps;\n\t\tif (this.callbacks.setFPS) {\n\t\t\tthis.callbacks.setFPS(fps);\n\t\t}\n\n\t\t// Read update_rate from global context each frame\n\t\tlet updateRate = this.state.updateRate; // Default\n\t\tif (this.callbacks.getUpdateRate) {\n\t\t\tconst rate = this.callbacks.getUpdateRate();\n\t\t\tif (rate != null && rate > 0 && Number.isFinite(rate)) {\n\t\t\t\tupdateRate = rate;\n\t\t\t}\n\t\t}\n\n\t\t// Calculate how many update steps needed\n\t\tthis.state.floatingFrame += (this.state.dt * updateRate) / 1000;\n\t\tlet ds = Math.min(10, Math.round(this.state.floatingFrame - this.state.currentFrame));\n\n\t\t// Correction for 60fps (reduce jitter)\n\t\tif ((ds === 0 || ds === 2) && updateRate === DEFAULT_UPDATE_RATE && Math.abs(fps - DEFAULT_FPS) < 2) {\n\t\t\tds = 1;\n\t\t\tthis.state.floatingFrame = this.state.currentFrame + 1;\n\t\t}\n\n\t\t// Call update() multiple times if needed (catch up)\n\t\t// Loop from 1 to ds (inclusive), not 0 to steps-1\n\t\tfor (let i = 1; i <= ds; i++) {\n\t\t\tthis.callbacks.onUpdate();\n\n\t\t\t// Tick between updates (for threads/coroutines)\n\t\t\tif (i < ds && this.callbacks.onTick) {\n\t\t\t\tthis.callbacks.onTick();\n\t\t\t}\n\t\t}\n\n\t\t// Update current frame\n\t\tthis.state.currentFrame += ds;\n\n\t\t// Call draw() once per frame\n\t\tthis.callbacks.onDraw();\n\n\t\t// Tick after draw\n\t\tif (this.callbacks.onTick) {\n\t\t\tthis.callbacks.onTick();\n\t\t}\n\n\t\t// Watch step after draw if ds > 0\n\t\tif (ds > 0 && this.callbacks.onWatchStep) {\n\t\t\tthis.callbacks.onWatchStep();\n\t\t}\n\t}\n\n\t/**\n\t * Get current state\n\t */\n\tgetState(): GameLoopState {\n\t\treturn this.state;\n\t}\n\n\t/**\n\t * Set update rate\n\t */\n\tsetUpdateRate(rate: number): void {\n\t\tif (rate > 0 && Number.isFinite(rate)) {\n\t\t\tthis.state.updateRate = rate;\n\t\t}\n\t}\n\n\t/**\n\t * Get FPS\n\t */\n\tgetFPS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AAO,KAAKC,OAAOC,SAASF,IAAAA,GAAO;AACtC,WAAK7B,MAAMY,aAAaiB;IACzB;EACD;;;;EAKAY,SAAiB;AAChB,WAAO,KAAKzC,MAAMU;EACnB;AACD;","names":["DEFAULT_FPS","DEFAULT_UPDATE_RATE","FRAME_TIME_MS","PAUSE_THRESHOLD_MS","LOADING_BAR_THROTTLE_MS","GameLoop","callbacks","state","stopped","animationFrameId","currentFrame","floatingFrame","dt","FRAME_TIME_MS","lastTime","performance","now","fps","DEFAULT_FPS","updateRate","DEFAULT_UPDATE_RATE","loop","bind","start","stop","cancelAnimationFrame","resume","requestAnimationFrame","time","Math","abs","PAUSE_THRESHOLD_MS","LOADING_BAR_THROTTLE_MS","round","setFPS","getUpdateRate","rate","Number","isFinite","ds","min","i","onUpdate","onTick","onDraw","onWatchStep","getState","setUpdateRate","getFPS"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StorageService } from '@al8b/io';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StorageService } from '@al8b/io';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/storage/index.ts
|
|
21
|
+
var storage_exports = {};
|
|
22
|
+
__export(storage_exports, {
|
|
23
|
+
StorageService: () => import_io.StorageService
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(storage_exports);
|
|
26
|
+
var import_io = require("@al8b/io");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
StorageService
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/storage/index.ts"],"sourcesContent":["export { StorageService } from \"@al8b/io\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,gBAA+B;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/storage/index.ts"],"sourcesContent":["export { StorageService } from \"@al8b/io\";\n"],"mappings":";AAAA,SAASA,sBAAsB;","names":["StorageService"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SystemAPI } from '@al8b/vm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* System API - System information and control
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
declare class System {
|
|
8
|
+
private systemAPI;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Get system API for game code
|
|
12
|
+
*/
|
|
13
|
+
getAPI(): SystemAPI;
|
|
14
|
+
/**
|
|
15
|
+
* Update FPS
|
|
16
|
+
*/
|
|
17
|
+
setFPS(fps: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Update CPU load
|
|
20
|
+
*/
|
|
21
|
+
setCPULoad(load: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Update loading progress
|
|
24
|
+
*/
|
|
25
|
+
setLoading(progress: number): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { System };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SystemAPI } from '@al8b/vm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* System API - System information and control
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
declare class System {
|
|
8
|
+
private systemAPI;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Get system API for game code
|
|
12
|
+
*/
|
|
13
|
+
getAPI(): SystemAPI;
|
|
14
|
+
/**
|
|
15
|
+
* Update FPS
|
|
16
|
+
*/
|
|
17
|
+
setFPS(fps: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Update CPU load
|
|
20
|
+
*/
|
|
21
|
+
setCPULoad(load: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Update loading progress
|
|
24
|
+
*/
|
|
25
|
+
setLoading(progress: number): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { System };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/system/api.ts
|
|
22
|
+
var api_exports = {};
|
|
23
|
+
__export(api_exports, {
|
|
24
|
+
System: () => System
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(api_exports);
|
|
27
|
+
|
|
28
|
+
// src/constants.ts
|
|
29
|
+
var DEFAULT_FPS = 60;
|
|
30
|
+
var DEFAULT_UPDATE_RATE = 60;
|
|
31
|
+
var FRAME_TIME_MS = 1e3 / DEFAULT_FPS;
|
|
32
|
+
|
|
33
|
+
// src/system/api.ts
|
|
34
|
+
var System = class {
|
|
35
|
+
static {
|
|
36
|
+
__name(this, "System");
|
|
37
|
+
}
|
|
38
|
+
systemAPI;
|
|
39
|
+
constructor() {
|
|
40
|
+
this.systemAPI = {
|
|
41
|
+
// Time
|
|
42
|
+
get time() {
|
|
43
|
+
return Date.now();
|
|
44
|
+
},
|
|
45
|
+
// FPS
|
|
46
|
+
fps: DEFAULT_FPS,
|
|
47
|
+
// CPU load
|
|
48
|
+
cpu_load: 0,
|
|
49
|
+
// Update rate
|
|
50
|
+
update_rate: DEFAULT_UPDATE_RATE,
|
|
51
|
+
// Language
|
|
52
|
+
get language() {
|
|
53
|
+
return typeof navigator !== "undefined" ? navigator.language : "en";
|
|
54
|
+
},
|
|
55
|
+
// Input availability
|
|
56
|
+
inputs: {
|
|
57
|
+
get keyboard() {
|
|
58
|
+
return 1;
|
|
59
|
+
},
|
|
60
|
+
get mouse() {
|
|
61
|
+
return 1;
|
|
62
|
+
},
|
|
63
|
+
get touch() {
|
|
64
|
+
return typeof window !== "undefined" && "ontouchstart" in window ? 1 : 0;
|
|
65
|
+
},
|
|
66
|
+
get gamepad() {
|
|
67
|
+
return typeof navigator !== "undefined" && typeof navigator.getGamepads === "function" ? 1 : 0;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
// Loading progress
|
|
71
|
+
loading: 0,
|
|
72
|
+
// Utility functions
|
|
73
|
+
prompt: /* @__PURE__ */ __name((text, callback) => {
|
|
74
|
+
if (typeof window !== "undefined") {
|
|
75
|
+
const result = window.prompt(text);
|
|
76
|
+
if (result !== null && callback) {
|
|
77
|
+
callback(result);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, "prompt"),
|
|
81
|
+
say: /* @__PURE__ */ __name((text) => {
|
|
82
|
+
if (typeof window !== "undefined") {
|
|
83
|
+
window.alert(text);
|
|
84
|
+
}
|
|
85
|
+
}, "say"),
|
|
86
|
+
// File drop support
|
|
87
|
+
file: {
|
|
88
|
+
dropped: 0
|
|
89
|
+
},
|
|
90
|
+
// JavaScript interop (placeholder for future use)
|
|
91
|
+
javascript: {},
|
|
92
|
+
// Additional flags
|
|
93
|
+
disable_autofullscreen: 0,
|
|
94
|
+
preemptive: 1
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get system API for game code
|
|
99
|
+
*/
|
|
100
|
+
getAPI() {
|
|
101
|
+
return this.systemAPI;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Update FPS
|
|
105
|
+
*/
|
|
106
|
+
setFPS(fps) {
|
|
107
|
+
this.systemAPI.fps = fps;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Update CPU load
|
|
111
|
+
*/
|
|
112
|
+
setCPULoad(load) {
|
|
113
|
+
this.systemAPI.cpu_load = load;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Update loading progress
|
|
117
|
+
*/
|
|
118
|
+
setLoading(progress) {
|
|
119
|
+
this.systemAPI.loading = progress;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
System
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/system/api.ts","../../src/constants.ts"],"sourcesContent":["/**\n * System API - System information and control\n */\n\nimport type { SystemAPI } from \"@al8b/vm\";\nimport { DEFAULT_FPS, DEFAULT_UPDATE_RATE } from \"../constants\";\n\nexport class System {\n\tprivate systemAPI: SystemAPI;\n\n\tconstructor() {\n\t\t// Create system API with mutable state\n\t\tthis.systemAPI = {\n\t\t\t// Time\n\t\t\tget time() {\n\t\t\t\treturn Date.now();\n\t\t\t},\n\n\t\t\t// FPS\n\t\t\tfps: DEFAULT_FPS,\n\n\t\t\t// CPU load\n\t\t\tcpu_load: 0,\n\n\t\t\t// Update rate\n\t\t\tupdate_rate: DEFAULT_UPDATE_RATE,\n\n\t\t\t// Language\n\t\t\tget language() {\n\t\t\t\treturn typeof navigator !== \"undefined\" ? navigator.language : \"en\";\n\t\t\t},\n\n\t\t\t// Input availability\n\t\t\tinputs: {\n\t\t\t\tget keyboard() {\n\t\t\t\t\treturn 1;\n\t\t\t\t},\n\t\t\t\tget mouse() {\n\t\t\t\t\treturn 1;\n\t\t\t\t},\n\t\t\t\tget touch() {\n\t\t\t\t\treturn typeof window !== \"undefined\" && \"ontouchstart\" in window ? 1 : 0;\n\t\t\t\t},\n\t\t\t\tget gamepad() {\n\t\t\t\t\treturn typeof navigator !== \"undefined\" && typeof navigator.getGamepads === \"function\" ? 1 : 0;\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Loading progress\n\t\t\tloading: 0,\n\n\t\t\t// Utility functions\n\t\t\tprompt: (text: string, callback: (result: string) => void) => {\n\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\tconst result = window.prompt(text);\n\t\t\t\t\tif (result !== null && callback) {\n\t\t\t\t\t\tcallback(result);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tsay: (text: string) => {\n\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\twindow.alert(text);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\t// File drop support\n\t\t\tfile: {\n\t\t\t\tdropped: 0,\n\t\t\t},\n\n\t\t\t// JavaScript interop (placeholder for future use)\n\t\t\tjavascript: {},\n\n\t\t\t// Additional flags\n\t\t\tdisable_autofullscreen: 0,\n\t\t\tpreemptive: 1,\n\t\t};\n\t}\n\n\t/**\n\t * Get system API for game code\n\t */\n\tgetAPI(): SystemAPI {\n\t\treturn this.systemAPI;\n\t}\n\n\t/**\n\t * Update FPS\n\t */\n\tsetFPS(fps: number): void {\n\t\tthis.systemAPI.fps = fps;\n\t}\n\n\t/**\n\t * Update CPU load\n\t */\n\tsetCPULoad(load: number): void {\n\t\tthis.systemAPI.cpu_load = load;\n\t}\n\n\t/**\n\t * Update loading progress\n\t */\n\tsetLoading(progress: number): void {\n\t\tthis.systemAPI.loading = progress;\n\t}\n}\n","/** Default frames per second */\nexport const DEFAULT_FPS = 60;\n\n/** Default update rate (updates per second) */\nexport const DEFAULT_UPDATE_RATE = 60;\n\n/** Frame time in milliseconds at 60 FPS */\nexport const FRAME_TIME_MS = 1000 / DEFAULT_FPS;\n\n/** Threshold in ms to detect long pauses (tab switch, etc.) */\nexport const PAUSE_THRESHOLD_MS = 160;\n\n/** Default tile/block size in pixels */\nexport const DEFAULT_BLOCK_SIZE = 16;\n\n/** Minimum interval between loading bar redraws in ms (~60fps) */\nexport const LOADING_BAR_THROTTLE_MS = 16;\n\n/** Timeout in ms for individual asset loads (sprite/map HTTP requests) */\nexport const ASSET_LOAD_TIMEOUT_MS = 30_000;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACCO,IAAMA,cAAc;AAGpB,IAAMC,sBAAsB;AAG5B,IAAMC,gBAAgB,MAAOF;;;ADA7B,IAAMG,SAAN,MAAMA;EAPb,OAOaA;;;EACJC;EAER,cAAc;AAEb,SAAKA,YAAY;;MAEhB,IAAIC,OAAO;AACV,eAAOC,KAAKC,IAAG;MAChB;;MAGAC,KAAKC;;MAGLC,UAAU;;MAGVC,aAAaC;;MAGb,IAAIC,WAAW;AACd,eAAO,OAAOC,cAAc,cAAcA,UAAUD,WAAW;MAChE;;MAGAE,QAAQ;QACP,IAAIC,WAAW;AACd,iBAAO;QACR;QACA,IAAIC,QAAQ;AACX,iBAAO;QACR;QACA,IAAIC,QAAQ;AACX,iBAAO,OAAOC,WAAW,eAAe,kBAAkBA,SAAS,IAAI;QACxE;QACA,IAAIC,UAAU;AACb,iBAAO,OAAON,cAAc,eAAe,OAAOA,UAAUO,gBAAgB,aAAa,IAAI;QAC9F;MACD;;MAGAC,SAAS;;MAGTC,QAAQ,wBAACC,MAAcC,aAAAA;AACtB,YAAI,OAAON,WAAW,aAAa;AAClC,gBAAMO,SAASP,OAAOI,OAAOC,IAAAA;AAC7B,cAAIE,WAAW,QAAQD,UAAU;AAChCA,qBAASC,MAAAA;UACV;QACD;MACD,GAPQ;MASRC,KAAK,wBAACH,SAAAA;AACL,YAAI,OAAOL,WAAW,aAAa;AAClCA,iBAAOS,MAAMJ,IAAAA;QACd;MACD,GAJK;;MAOLK,MAAM;QACLC,SAAS;MACV;;MAGAC,YAAY,CAAC;;MAGbC,wBAAwB;MACxBC,YAAY;IACb;EACD;;;;EAKAC,SAAoB;AACnB,WAAO,KAAK9B;EACb;;;;EAKA+B,OAAO3B,KAAmB;AACzB,SAAKJ,UAAUI,MAAMA;EACtB;;;;EAKA4B,WAAWC,MAAoB;AAC9B,SAAKjC,UAAUM,WAAW2B;EAC3B;;;;EAKAC,WAAWC,UAAwB;AAClC,SAAKnC,UAAUkB,UAAUiB;EAC1B;AACD;","names":["DEFAULT_FPS","DEFAULT_UPDATE_RATE","FRAME_TIME_MS","System","systemAPI","time","Date","now","fps","DEFAULT_FPS","cpu_load","update_rate","DEFAULT_UPDATE_RATE","language","navigator","inputs","keyboard","mouse","touch","window","gamepad","getGamepads","loading","prompt","text","callback","result","say","alert","file","dropped","javascript","disable_autofullscreen","preemptive","getAPI","setFPS","setCPULoad","load","setLoading","progress"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/constants.ts
|
|
5
|
+
var DEFAULT_FPS = 60;
|
|
6
|
+
var DEFAULT_UPDATE_RATE = 60;
|
|
7
|
+
var FRAME_TIME_MS = 1e3 / DEFAULT_FPS;
|
|
8
|
+
|
|
9
|
+
// src/system/api.ts
|
|
10
|
+
var System = class {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "System");
|
|
13
|
+
}
|
|
14
|
+
systemAPI;
|
|
15
|
+
constructor() {
|
|
16
|
+
this.systemAPI = {
|
|
17
|
+
// Time
|
|
18
|
+
get time() {
|
|
19
|
+
return Date.now();
|
|
20
|
+
},
|
|
21
|
+
// FPS
|
|
22
|
+
fps: DEFAULT_FPS,
|
|
23
|
+
// CPU load
|
|
24
|
+
cpu_load: 0,
|
|
25
|
+
// Update rate
|
|
26
|
+
update_rate: DEFAULT_UPDATE_RATE,
|
|
27
|
+
// Language
|
|
28
|
+
get language() {
|
|
29
|
+
return typeof navigator !== "undefined" ? navigator.language : "en";
|
|
30
|
+
},
|
|
31
|
+
// Input availability
|
|
32
|
+
inputs: {
|
|
33
|
+
get keyboard() {
|
|
34
|
+
return 1;
|
|
35
|
+
},
|
|
36
|
+
get mouse() {
|
|
37
|
+
return 1;
|
|
38
|
+
},
|
|
39
|
+
get touch() {
|
|
40
|
+
return typeof window !== "undefined" && "ontouchstart" in window ? 1 : 0;
|
|
41
|
+
},
|
|
42
|
+
get gamepad() {
|
|
43
|
+
return typeof navigator !== "undefined" && typeof navigator.getGamepads === "function" ? 1 : 0;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
// Loading progress
|
|
47
|
+
loading: 0,
|
|
48
|
+
// Utility functions
|
|
49
|
+
prompt: /* @__PURE__ */ __name((text, callback) => {
|
|
50
|
+
if (typeof window !== "undefined") {
|
|
51
|
+
const result = window.prompt(text);
|
|
52
|
+
if (result !== null && callback) {
|
|
53
|
+
callback(result);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, "prompt"),
|
|
57
|
+
say: /* @__PURE__ */ __name((text) => {
|
|
58
|
+
if (typeof window !== "undefined") {
|
|
59
|
+
window.alert(text);
|
|
60
|
+
}
|
|
61
|
+
}, "say"),
|
|
62
|
+
// File drop support
|
|
63
|
+
file: {
|
|
64
|
+
dropped: 0
|
|
65
|
+
},
|
|
66
|
+
// JavaScript interop (placeholder for future use)
|
|
67
|
+
javascript: {},
|
|
68
|
+
// Additional flags
|
|
69
|
+
disable_autofullscreen: 0,
|
|
70
|
+
preemptive: 1
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get system API for game code
|
|
75
|
+
*/
|
|
76
|
+
getAPI() {
|
|
77
|
+
return this.systemAPI;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Update FPS
|
|
81
|
+
*/
|
|
82
|
+
setFPS(fps) {
|
|
83
|
+
this.systemAPI.fps = fps;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Update CPU load
|
|
87
|
+
*/
|
|
88
|
+
setCPULoad(load) {
|
|
89
|
+
this.systemAPI.cpu_load = load;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Update loading progress
|
|
93
|
+
*/
|
|
94
|
+
setLoading(progress) {
|
|
95
|
+
this.systemAPI.loading = progress;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
System
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=api.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts","../../src/system/api.ts"],"sourcesContent":["/** Default frames per second */\nexport const DEFAULT_FPS = 60;\n\n/** Default update rate (updates per second) */\nexport const DEFAULT_UPDATE_RATE = 60;\n\n/** Frame time in milliseconds at 60 FPS */\nexport const FRAME_TIME_MS = 1000 / DEFAULT_FPS;\n\n/** Threshold in ms to detect long pauses (tab switch, etc.) */\nexport const PAUSE_THRESHOLD_MS = 160;\n\n/** Default tile/block size in pixels */\nexport const DEFAULT_BLOCK_SIZE = 16;\n\n/** Minimum interval between loading bar redraws in ms (~60fps) */\nexport const LOADING_BAR_THROTTLE_MS = 16;\n\n/** Timeout in ms for individual asset loads (sprite/map HTTP requests) */\nexport const ASSET_LOAD_TIMEOUT_MS = 30_000;\n","/**\n * System API - System information and control\n */\n\nimport type { SystemAPI } from \"@al8b/vm\";\nimport { DEFAULT_FPS, DEFAULT_UPDATE_RATE } from \"../constants\";\n\nexport class System {\n\tprivate systemAPI: SystemAPI;\n\n\tconstructor() {\n\t\t// Create system API with mutable state\n\t\tthis.systemAPI = {\n\t\t\t// Time\n\t\t\tget time() {\n\t\t\t\treturn Date.now();\n\t\t\t},\n\n\t\t\t// FPS\n\t\t\tfps: DEFAULT_FPS,\n\n\t\t\t// CPU load\n\t\t\tcpu_load: 0,\n\n\t\t\t// Update rate\n\t\t\tupdate_rate: DEFAULT_UPDATE_RATE,\n\n\t\t\t// Language\n\t\t\tget language() {\n\t\t\t\treturn typeof navigator !== \"undefined\" ? navigator.language : \"en\";\n\t\t\t},\n\n\t\t\t// Input availability\n\t\t\tinputs: {\n\t\t\t\tget keyboard() {\n\t\t\t\t\treturn 1;\n\t\t\t\t},\n\t\t\t\tget mouse() {\n\t\t\t\t\treturn 1;\n\t\t\t\t},\n\t\t\t\tget touch() {\n\t\t\t\t\treturn typeof window !== \"undefined\" && \"ontouchstart\" in window ? 1 : 0;\n\t\t\t\t},\n\t\t\t\tget gamepad() {\n\t\t\t\t\treturn typeof navigator !== \"undefined\" && typeof navigator.getGamepads === \"function\" ? 1 : 0;\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Loading progress\n\t\t\tloading: 0,\n\n\t\t\t// Utility functions\n\t\t\tprompt: (text: string, callback: (result: string) => void) => {\n\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\tconst result = window.prompt(text);\n\t\t\t\t\tif (result !== null && callback) {\n\t\t\t\t\t\tcallback(result);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tsay: (text: string) => {\n\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\twindow.alert(text);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\t// File drop support\n\t\t\tfile: {\n\t\t\t\tdropped: 0,\n\t\t\t},\n\n\t\t\t// JavaScript interop (placeholder for future use)\n\t\t\tjavascript: {},\n\n\t\t\t// Additional flags\n\t\t\tdisable_autofullscreen: 0,\n\t\t\tpreemptive: 1,\n\t\t};\n\t}\n\n\t/**\n\t * Get system API for game code\n\t */\n\tgetAPI(): SystemAPI {\n\t\treturn this.systemAPI;\n\t}\n\n\t/**\n\t * Update FPS\n\t */\n\tsetFPS(fps: number): void {\n\t\tthis.systemAPI.fps = fps;\n\t}\n\n\t/**\n\t * Update CPU load\n\t */\n\tsetCPULoad(load: number): void {\n\t\tthis.systemAPI.cpu_load = load;\n\t}\n\n\t/**\n\t * Update loading progress\n\t */\n\tsetLoading(progress: number): void {\n\t\tthis.systemAPI.loading = progress;\n\t}\n}\n"],"mappings":";;;;AACO,IAAMA,cAAc;AAGpB,IAAMC,sBAAsB;AAG5B,IAAMC,gBAAgB,MAAOF;;;ACA7B,IAAMG,SAAN,MAAMA;EAPb,OAOaA;;;EACJC;EAER,cAAc;AAEb,SAAKA,YAAY;;MAEhB,IAAIC,OAAO;AACV,eAAOC,KAAKC,IAAG;MAChB;;MAGAC,KAAKC;;MAGLC,UAAU;;MAGVC,aAAaC;;MAGb,IAAIC,WAAW;AACd,eAAO,OAAOC,cAAc,cAAcA,UAAUD,WAAW;MAChE;;MAGAE,QAAQ;QACP,IAAIC,WAAW;AACd,iBAAO;QACR;QACA,IAAIC,QAAQ;AACX,iBAAO;QACR;QACA,IAAIC,QAAQ;AACX,iBAAO,OAAOC,WAAW,eAAe,kBAAkBA,SAAS,IAAI;QACxE;QACA,IAAIC,UAAU;AACb,iBAAO,OAAON,cAAc,eAAe,OAAOA,UAAUO,gBAAgB,aAAa,IAAI;QAC9F;MACD;;MAGAC,SAAS;;MAGTC,QAAQ,wBAACC,MAAcC,aAAAA;AACtB,YAAI,OAAON,WAAW,aAAa;AAClC,gBAAMO,SAASP,OAAOI,OAAOC,IAAAA;AAC7B,cAAIE,WAAW,QAAQD,UAAU;AAChCA,qBAASC,MAAAA;UACV;QACD;MACD,GAPQ;MASRC,KAAK,wBAACH,SAAAA;AACL,YAAI,OAAOL,WAAW,aAAa;AAClCA,iBAAOS,MAAMJ,IAAAA;QACd;MACD,GAJK;;MAOLK,MAAM;QACLC,SAAS;MACV;;MAGAC,YAAY,CAAC;;MAGbC,wBAAwB;MACxBC,YAAY;IACb;EACD;;;;EAKAC,SAAoB;AACnB,WAAO,KAAK9B;EACb;;;;EAKA+B,OAAO3B,KAAmB;AACzB,SAAKJ,UAAUI,MAAMA;EACtB;;;;EAKA4B,WAAWC,MAAoB;AAC9B,SAAKjC,UAAUM,WAAW2B;EAC3B;;;;EAKAC,WAAWC,UAAwB;AAClC,SAAKnC,UAAUkB,UAAUiB;EAC1B;AACD;","names":["DEFAULT_FPS","DEFAULT_UPDATE_RATE","FRAME_TIME_MS","System","systemAPI","time","Date","now","fps","DEFAULT_FPS","cpu_load","update_rate","DEFAULT_UPDATE_RATE","language","navigator","inputs","keyboard","mouse","touch","window","gamepad","getGamepads","loading","prompt","text","callback","result","say","alert","file","dropped","javascript","disable_autofullscreen","preemptive","getAPI","setFPS","setCPULoad","load","setLoading","progress"]}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/system/index.ts
|
|
22
|
+
var system_exports = {};
|
|
23
|
+
__export(system_exports, {
|
|
24
|
+
System: () => System
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(system_exports);
|
|
27
|
+
|
|
28
|
+
// src/constants.ts
|
|
29
|
+
var DEFAULT_FPS = 60;
|
|
30
|
+
var DEFAULT_UPDATE_RATE = 60;
|
|
31
|
+
var FRAME_TIME_MS = 1e3 / DEFAULT_FPS;
|
|
32
|
+
|
|
33
|
+
// src/system/api.ts
|
|
34
|
+
var System = class {
|
|
35
|
+
static {
|
|
36
|
+
__name(this, "System");
|
|
37
|
+
}
|
|
38
|
+
systemAPI;
|
|
39
|
+
constructor() {
|
|
40
|
+
this.systemAPI = {
|
|
41
|
+
// Time
|
|
42
|
+
get time() {
|
|
43
|
+
return Date.now();
|
|
44
|
+
},
|
|
45
|
+
// FPS
|
|
46
|
+
fps: DEFAULT_FPS,
|
|
47
|
+
// CPU load
|
|
48
|
+
cpu_load: 0,
|
|
49
|
+
// Update rate
|
|
50
|
+
update_rate: DEFAULT_UPDATE_RATE,
|
|
51
|
+
// Language
|
|
52
|
+
get language() {
|
|
53
|
+
return typeof navigator !== "undefined" ? navigator.language : "en";
|
|
54
|
+
},
|
|
55
|
+
// Input availability
|
|
56
|
+
inputs: {
|
|
57
|
+
get keyboard() {
|
|
58
|
+
return 1;
|
|
59
|
+
},
|
|
60
|
+
get mouse() {
|
|
61
|
+
return 1;
|
|
62
|
+
},
|
|
63
|
+
get touch() {
|
|
64
|
+
return typeof window !== "undefined" && "ontouchstart" in window ? 1 : 0;
|
|
65
|
+
},
|
|
66
|
+
get gamepad() {
|
|
67
|
+
return typeof navigator !== "undefined" && typeof navigator.getGamepads === "function" ? 1 : 0;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
// Loading progress
|
|
71
|
+
loading: 0,
|
|
72
|
+
// Utility functions
|
|
73
|
+
prompt: /* @__PURE__ */ __name((text, callback) => {
|
|
74
|
+
if (typeof window !== "undefined") {
|
|
75
|
+
const result = window.prompt(text);
|
|
76
|
+
if (result !== null && callback) {
|
|
77
|
+
callback(result);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, "prompt"),
|
|
81
|
+
say: /* @__PURE__ */ __name((text) => {
|
|
82
|
+
if (typeof window !== "undefined") {
|
|
83
|
+
window.alert(text);
|
|
84
|
+
}
|
|
85
|
+
}, "say"),
|
|
86
|
+
// File drop support
|
|
87
|
+
file: {
|
|
88
|
+
dropped: 0
|
|
89
|
+
},
|
|
90
|
+
// JavaScript interop (placeholder for future use)
|
|
91
|
+
javascript: {},
|
|
92
|
+
// Additional flags
|
|
93
|
+
disable_autofullscreen: 0,
|
|
94
|
+
preemptive: 1
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get system API for game code
|
|
99
|
+
*/
|
|
100
|
+
getAPI() {
|
|
101
|
+
return this.systemAPI;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Update FPS
|
|
105
|
+
*/
|
|
106
|
+
setFPS(fps) {
|
|
107
|
+
this.systemAPI.fps = fps;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Update CPU load
|
|
111
|
+
*/
|
|
112
|
+
setCPULoad(load) {
|
|
113
|
+
this.systemAPI.cpu_load = load;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Update loading progress
|
|
117
|
+
*/
|
|
118
|
+
setLoading(progress) {
|
|
119
|
+
this.systemAPI.loading = progress;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
System
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=index.js.map
|