@ringozz/godot 4.7.2-626 → 4.7.2-628

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/src/runtime.ts CHANGED
@@ -1,107 +1,107 @@
1
- /**********************************************************************
2
- Copyright (c) Vladimir Davidovich. All rights reserved.
3
- ***********************************************************************/
4
-
5
- /** Shared runtime: platform-specific native-module selection lives in
6
- * `boot.ts` (desktop) / `boot.browser.ts` (web, via the `exports` `./boot`
7
- * entry's `browser` condition). `_mod` is the native module — the desktop
8
- * addon's `module.exports` or the wasm module's `.default`.
9
- *
10
- * The boot leaf is imported by **package self-reference** (`@ringozz/godot/boot`),
11
- * not by relative path: a bare specifier resolves through this package's own
12
- * `exports` map (whose `./boot` entry's `browser` condition selects
13
- * `boot.browser.ts` on web) exactly like the entrypoint's
14
- * `import { preloadGodot } from '@ringozz/godot/boot'`, so both sides land on the
15
- * same absolute path and share ONE `boot.browser.ts` module instance. (A relative
16
- * `./boot.ts` import would let a consumer's bundler realpath it into
17
- * `node_modules/.bun/...` while the entrypoint keeps the `node_modules/@ringozz/godot`
18
- * path — two instances, and the preload handoff below would read `null`.)
19
- */
20
- import { getNativeModule } from '@ringozz/godot/boot';
21
- const { default: _mod } = getNativeModule() as any;
22
-
23
- /** Godot instance */
24
- import type { GodotInstance } from '../gen/classes/GodotInstance.ts';
25
- export const getGodot = _mod.getGodot as () => GodotInstance;
26
-
27
- /** Base constructor for all Godot object wrappers. */
28
- export interface GodotVar {
29
- free(): void;
30
- }
31
- export const GodotVar = _mod.GodotVar as (new (...args: unknown[]) => GodotVar) & {
32
- assign<T extends GodotVar>(target: T, props: Record<string, unknown>): T;
33
- };
34
-
35
- /** Unified entry point:
36
- * - _C(this, methodId, ...args) → instance method
37
- * - _C(classId, methodId, ...args) → static method
38
- * - _C(null, methodId, ...args) → singleton lookup (_getInstance) or internal
39
- * - _C(0n, methodId, ...args) → utility function (BigInt tags the call;
40
- * arg types resolve by name at runtime)
41
- */
42
- export const _C = _mod._C as (...args: unknown[]) => unknown;
43
-
44
- /** Resolve a string name to its integer handle. */
45
- export const _S = _mod._S as (name: string) => number;
46
-
47
- /** Register Godot object wrapper. */
48
- export const _R = _mod._R as (typeId: number, ctor: Function) => string;
49
-
50
- /**
51
- * Value-type dispatch on tuple receivers: `_V(typeId, methodId, receiver, ...args)`.
52
- * `methodId == SX_valueCtor` constructs (`_V(typeId, ctorSentinel, ctorIndex, ...args)`),
53
- * negative ids are operators, non-negative ids are builtin methods.
54
- */
55
- export const _V = _mod._V as (...args: unknown[]) => unknown;
56
-
57
- /**
58
- * Build a typed value-type Variant for a Variant-typed slot by resolving the
59
- * property's type from the node; returns a GodotVar carrier the consuming `_C`
60
- * unwraps. Used by react-hooks' useTween (tweenProperty final_val).
61
- */
62
- export const toValueType = _mod.toValueType as (node: GodotVar, propName: string, value: unknown) => unknown;
63
-
64
- /** Stage bytes into the web MEMFS (Godot's `copyToFS`); undefined on desktop. */
65
- export const stageFile = (_mod as any).stageFile as ((path: string, bytes: Uint8Array) => void) | undefined;
66
-
67
- /** Get a Signal value from an Object by signal name, or connect a callback when 3rd arg given. */
68
- export const _G = _mod._G as (target: GodotVar, signalNameId: number, callback?: unknown) => unknown;
69
-
70
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame) */
71
- export const requestAnimationFrame = _mod.requestAnimationFrame as typeof globalThis.requestAnimationFrame ?? globalThis.requestAnimationFrame;
72
-
73
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/cancelAnimationFrame) */
74
- export const cancelAnimationFrame = _mod.cancelAnimationFrame as typeof globalThis.cancelAnimationFrame ?? globalThis.cancelAnimationFrame;
75
-
76
- // One-shot callbacks of in-flight `_P` awaits. The connection's JSCallable holds
77
- // only a weak reference to the callback, so without this the function could be
78
- // GC'd before the signal fires. A module root is the only retention Bun reliably
79
- // traces: neither `_P`'s closure cells nor a Set attached to the signal's object
80
- // wrapper survive a full GC while the await is pending (the await machinery
81
- // discards the promise `_P` returns, and Bun may collect the emitter's wrapper).
82
- // Removed as soon as the signal fires or the connect fails.
83
- const pendingCallbacks = new Set<(...args: any[]) => void>();
84
-
85
- /** Make a Signal PromiseLike: connects a one-shot callback that resolves with the args tuple. */
86
- export function _P(signal: any, onfulfilled?: any, onrejected?: any) {
87
- return new Promise<any>((resolve, reject) => {
88
- if (signal.isNull()) {
89
- reject(new Error('Cannot await a null Signal'));
90
- return;
91
- }
92
- const cb = (...args: any[]) => {
93
- pendingCallbacks.delete(cb);
94
- signal.disconnect(cb);
95
- resolve(args);
96
- };
97
- pendingCallbacks.add(cb);
98
- const res = signal.connect(cb);
99
- if (res !== 0) {
100
- pendingCallbacks.delete(cb);
101
- reject(new Error('Failed to connect signal: error code ' + res));
102
- }
103
- }).then(onfulfilled, onrejected);
104
- }
105
-
106
- /** Cleanup callbacks run once by `runGodot` just before the engine is freed; may be async. */
107
- export const cleanupHooks: Set<() => void | Promise<void>> = new Set();
1
+ /**********************************************************************
2
+ Copyright (c) Vladimir Davidovich. All rights reserved.
3
+ ***********************************************************************/
4
+
5
+ /** Shared runtime: platform-specific native-module selection lives in
6
+ * `boot.ts` (desktop) / `boot.browser.ts` (web, via the `exports` `./boot`
7
+ * entry's `browser` condition). `_mod` is the native module — the desktop
8
+ * addon's `module.exports` or the wasm module's `.default`.
9
+ *
10
+ * The boot leaf is imported by **package self-reference** (`@ringozz/godot/boot`),
11
+ * not by relative path: a bare specifier resolves through this package's own
12
+ * `exports` map (whose `./boot` entry's `browser` condition selects
13
+ * `boot.browser.ts` on web) exactly like the entrypoint's
14
+ * `import { preloadGodot } from '@ringozz/godot/boot'`, so both sides land on the
15
+ * same absolute path and share ONE `boot.browser.ts` module instance. (A relative
16
+ * `./boot.ts` import would let a consumer's bundler realpath it into
17
+ * `node_modules/.bun/...` while the entrypoint keeps the `node_modules/@ringozz/godot`
18
+ * path — two instances, and the preload handoff below would read `null`.)
19
+ */
20
+ import { getNativeModule } from '@ringozz/godot/boot';
21
+ const { default: _mod } = getNativeModule() as any;
22
+
23
+ /** Godot instance */
24
+ import type { GodotInstance } from '../gen/classes/GodotInstance.ts';
25
+ export const getGodot = _mod.getGodot as () => GodotInstance;
26
+
27
+ /** Base constructor for all Godot object wrappers. */
28
+ export interface GodotVar {
29
+ free(): void;
30
+ }
31
+ export const GodotVar = _mod.GodotVar as (new (...args: unknown[]) => GodotVar) & {
32
+ assign<T extends GodotVar>(target: T, props: Record<string, unknown>): T;
33
+ };
34
+
35
+ /** Unified entry point:
36
+ * - _C(this, methodId, ...args) → instance method
37
+ * - _C(classId, methodId, ...args) → static method
38
+ * - _C(null, methodId, ...args) → singleton lookup (_getInstance) or internal
39
+ * - _C(0n, methodId, ...args) → utility function (BigInt tags the call;
40
+ * arg types resolve by name at runtime)
41
+ */
42
+ export const _C = _mod._C as (...args: unknown[]) => unknown;
43
+
44
+ /** Resolve a string name to its integer handle. */
45
+ export const _S = _mod._S as (name: string) => number;
46
+
47
+ /** Register Godot object wrapper. */
48
+ export const _R = _mod._R as (typeId: number, ctor: Function) => string;
49
+
50
+ /**
51
+ * Value-type dispatch on tuple receivers: `_V(typeId, methodId, receiver, ...args)`.
52
+ * `methodId == SX_valueCtor` constructs (`_V(typeId, ctorSentinel, ctorIndex, ...args)`),
53
+ * negative ids are operators, non-negative ids are builtin methods.
54
+ */
55
+ export const _V = _mod._V as (...args: unknown[]) => unknown;
56
+
57
+ /**
58
+ * Build a typed value-type Variant for a Variant-typed slot by resolving the
59
+ * property's type from the node; returns a GodotVar carrier the consuming `_C`
60
+ * unwraps. Used by react-hooks' useTween (tweenProperty final_val).
61
+ */
62
+ export const toValueType = _mod.toValueType as (node: GodotVar, propName: string, value: unknown) => unknown;
63
+
64
+ /** Stage bytes into the web MEMFS (Godot's `copyToFS`); undefined on desktop. */
65
+ export const stageFile = (_mod as any).stageFile as ((path: string, bytes: Uint8Array) => void) | undefined;
66
+
67
+ /** Get a Signal value from an Object by signal name, or connect a callback when 3rd arg given. */
68
+ export const _G = _mod._G as (target: GodotVar, signalNameId: number, callback?: unknown) => unknown;
69
+
70
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame) */
71
+ export const requestAnimationFrame = _mod.requestAnimationFrame as typeof globalThis.requestAnimationFrame ?? globalThis.requestAnimationFrame;
72
+
73
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/cancelAnimationFrame) */
74
+ export const cancelAnimationFrame = _mod.cancelAnimationFrame as typeof globalThis.cancelAnimationFrame ?? globalThis.cancelAnimationFrame;
75
+
76
+ // One-shot callbacks of in-flight `_P` awaits. The connection's JSCallable holds
77
+ // only a weak reference to the callback, so without this the function could be
78
+ // GC'd before the signal fires. A module root is the only retention Bun reliably
79
+ // traces: neither `_P`'s closure cells nor a Set attached to the signal's object
80
+ // wrapper survive a full GC while the await is pending (the await machinery
81
+ // discards the promise `_P` returns, and Bun may collect the emitter's wrapper).
82
+ // Removed as soon as the signal fires or the connect fails.
83
+ const pendingCallbacks = new Set<(...args: any[]) => void>();
84
+
85
+ /** Make a Signal PromiseLike: connects a one-shot callback that resolves with the args tuple. */
86
+ export function _P(signal: any, onfulfilled?: any, onrejected?: any) {
87
+ return new Promise<any>((resolve, reject) => {
88
+ if (signal.isNull()) {
89
+ reject(new Error('Cannot await a null Signal'));
90
+ return;
91
+ }
92
+ const cb = (...args: any[]) => {
93
+ pendingCallbacks.delete(cb);
94
+ signal.disconnect(cb);
95
+ resolve(args);
96
+ };
97
+ pendingCallbacks.add(cb);
98
+ const res = signal.connect(cb);
99
+ if (res !== 0) {
100
+ pendingCallbacks.delete(cb);
101
+ reject(new Error('Failed to connect signal: error code ' + res));
102
+ }
103
+ }).then(onfulfilled, onrejected);
104
+ }
105
+
106
+ /** Cleanup callbacks run once by `runGodot` just before the engine is freed; may be async. */
107
+ export const cleanupHooks: Set<() => void | Promise<void>> = new Set();
@@ -0,0 +1,28 @@
1
+ /**********************************************************************
2
+ Copyright (c) Vladimir Davidovich. All rights reserved.
3
+ ***********************************************************************/
4
+
5
+ // Browser condition of `@ringozz/godot/transcoder` (see `exports` `./transcoder`):
6
+ // resolves the spark.js-backed transcoder from the web platform package, handing
7
+ // it the container helpers it needs (see that package's `CtexHelpers`). This is
8
+ // the only place the platform package is referenced, and a desktop bundle resolves
9
+ // `transcoder.ts` instead — so it and `@ludicon/spark.js` never appear in a desktop
10
+ // build.
11
+ //
12
+ // The (large, all-format) encoder chunk is fetched as soon as this module is
13
+ // evaluated — i.e. with the app, alongside the engine boot and the asset fetches —
14
+ // rather than starting when the first `.ctex` arrives, so it stays off the
15
+ // time-to-first-texture critical path. The WebGPU device and shaders are still
16
+ // created lazily, on the first transcode.
17
+
18
+ import * as ctex from './web-image.ts';
19
+ import type { CtexTranscoder } from './web-image.ts';
20
+
21
+ /** Resolves to the spark.js-backed transcoder, or `null` if it can't load (so staging keeps the raw RGBA8 decode). */
22
+ export const transcoder: Promise<CtexTranscoder | null> = import('@ringozz/godot-web-wasm32/spark').then(
23
+ ({ createSparkTranscoder }) => createSparkTranscoder(ctex),
24
+ (err) => {
25
+ console.warn('[godot] built-in texture transcoder unavailable; web textures stay raw RGBA8:', err);
26
+ return null;
27
+ },
28
+ );
@@ -0,0 +1,15 @@
1
+ /**********************************************************************
2
+ Copyright (c) Vladimir Davidovich. All rights reserved.
3
+ ***********************************************************************/
4
+
5
+ // Desktop (default) condition of `@ringozz/godot/transcoder`: there is no web
6
+ // texture transcoder, so `.ctex` staging — which only runs on web anyway — keeps
7
+ // the raw RGBA8 decode. The `browser` condition swaps in `transcoder.browser.ts`
8
+ // (see `exports` `./transcoder`), which resolves the spark.js-backed transcoder
9
+ // from the web platform package; keeping this in its own module means a desktop
10
+ // bundle resolves this file and never references either.
11
+
12
+ import type { CtexTranscoder } from './web-image.ts';
13
+
14
+ /** Resolves to the platform's `.ctex` transcoder, or `null` when it has none. */
15
+ export const transcoder: Promise<CtexTranscoder | null> = Promise.resolve(null);