@vulfram/engine 0.14.8-alpha → 0.17.1-alpha

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.
Files changed (54) hide show
  1. package/README.md +106 -0
  2. package/package.json +55 -4
  3. package/src/core.ts +14 -0
  4. package/src/ecs.ts +1 -0
  5. package/src/engine/api.ts +234 -23
  6. package/src/engine/bridge/dispatch.ts +265 -40
  7. package/src/engine/bridge/guards.ts +4 -1
  8. package/src/engine/bridge/protocol.ts +69 -52
  9. package/src/engine/ecs/index.ts +185 -42
  10. package/src/engine/state.ts +133 -2
  11. package/src/engine/systems/command-intent.ts +153 -3
  12. package/src/engine/systems/constraint-solve.ts +167 -0
  13. package/src/engine/systems/core-command-builder.ts +9 -268
  14. package/src/engine/systems/diagnostics.ts +20 -19
  15. package/src/engine/systems/index.ts +3 -1
  16. package/src/engine/systems/input-mirror.ts +101 -3
  17. package/src/engine/systems/resource-upload.ts +96 -44
  18. package/src/engine/systems/response-decode.ts +69 -15
  19. package/src/engine/systems/scene-sync.ts +306 -0
  20. package/src/engine/systems/ui-bridge.ts +360 -0
  21. package/src/engine/systems/utils.ts +43 -1
  22. package/src/engine/systems/world-lifecycle.ts +37 -102
  23. package/src/engine/window/manager.ts +168 -0
  24. package/src/engine/world/entities.ts +821 -78
  25. package/src/engine/world/mount.ts +174 -0
  26. package/src/engine/world/types.ts +71 -0
  27. package/src/engine/world/world-ui.ts +266 -0
  28. package/src/engine/world/world3d.ts +280 -0
  29. package/src/index.ts +30 -1
  30. package/src/mount.ts +2 -0
  31. package/src/types/cmds/audio.ts +73 -48
  32. package/src/types/cmds/camera.ts +12 -8
  33. package/src/types/cmds/environment.ts +9 -3
  34. package/src/types/cmds/geometry.ts +13 -14
  35. package/src/types/cmds/index.ts +198 -168
  36. package/src/types/cmds/light.ts +12 -11
  37. package/src/types/cmds/material.ts +9 -11
  38. package/src/types/cmds/model.ts +17 -15
  39. package/src/types/cmds/realm.ts +25 -0
  40. package/src/types/cmds/system.ts +19 -0
  41. package/src/types/cmds/target.ts +82 -0
  42. package/src/types/cmds/texture.ts +13 -3
  43. package/src/types/cmds/ui.ts +220 -0
  44. package/src/types/cmds/window.ts +41 -204
  45. package/src/types/events/index.ts +4 -1
  46. package/src/types/events/pointer.ts +42 -13
  47. package/src/types/events/system.ts +144 -30
  48. package/src/types/events/ui.ts +21 -0
  49. package/src/types/index.ts +1 -0
  50. package/src/types/json.ts +15 -0
  51. package/src/window.ts +8 -0
  52. package/src/world-ui.ts +2 -0
  53. package/src/world3d.ts +10 -0
  54. package/tsconfig.json +0 -29
@@ -0,0 +1,168 @@
1
+ import type { CmdWindowCloseArgs, CmdWindowCreateArgs } from '../../types/cmds/window';
2
+ import type {
3
+ CursorGrabMode,
4
+ CursorIcon,
5
+ UserAttentionType,
6
+ WindowState,
7
+ } from '../../types/kinds';
8
+ import { enqueueGlobalCommand } from '../bridge/dispatch';
9
+ import { requireInitialized } from '../bridge/guards';
10
+ import { engineState } from '../state';
11
+ import type { CommandId, WindowId } from '../world/types';
12
+ import { asCommandId, asWindowId } from '../world/types';
13
+
14
+ export interface WindowProps {
15
+ title?: string;
16
+ position?: [number, number];
17
+ size?: [number, number];
18
+ state?: WindowState;
19
+ resizable?: boolean;
20
+ decorations?: boolean;
21
+ cursorVisible?: boolean;
22
+ cursorGrab?: CursorGrabMode;
23
+ icon?: number;
24
+ cursorIcon?: CursorIcon;
25
+ }
26
+
27
+ export interface CreateWindowProps {
28
+ title: string;
29
+ size: [number, number];
30
+ position: [number, number];
31
+ canvasId?: string;
32
+ borderless?: boolean;
33
+ resizable?: boolean;
34
+ transparent?: boolean;
35
+ initialState?: WindowState;
36
+ }
37
+
38
+ function allocateWindowId(): WindowId {
39
+ while (engineState.usedWindowIds.has(engineState.nextWindowId)) {
40
+ engineState.nextWindowId++;
41
+ }
42
+ const id = engineState.nextWindowId++;
43
+ engineState.usedWindowIds.add(id);
44
+ return asWindowId(id);
45
+ }
46
+
47
+ /**
48
+ * Creates a window and returns a typed window id plus the command id.
49
+ *
50
+ * IDs are auto-generated by default to avoid collisions. You can pass `windowId`
51
+ * only when integrating with an existing host-level ID contract.
52
+ */
53
+ export function createWindow(
54
+ props: CreateWindowProps,
55
+ windowId?: WindowId,
56
+ ): { windowId: WindowId; commandId: CommandId } {
57
+ requireInitialized();
58
+ const resolvedWindowId = windowId ?? allocateWindowId();
59
+ if (windowId !== undefined) {
60
+ engineState.usedWindowIds.add(windowId as number);
61
+ }
62
+ const payload: CmdWindowCreateArgs = {
63
+ windowId: resolvedWindowId as number,
64
+ title: props.title,
65
+ size: props.size,
66
+ position: props.position,
67
+ canvasId: props.canvasId,
68
+ borderless: props.borderless ?? false,
69
+ resizable: props.resizable ?? true,
70
+ transparent: props.transparent ?? false,
71
+ initialState: props.initialState ?? 'windowed',
72
+ };
73
+ const commandId = enqueueGlobalCommand('cmd-window-create', payload);
74
+ engineState.pendingWindowCreateByCommandId.set(
75
+ commandId,
76
+ resolvedWindowId as number,
77
+ );
78
+ return { windowId: resolvedWindowId, commandId: asCommandId(commandId) };
79
+ }
80
+
81
+ export function closeWindow(windowId: WindowId): CommandId {
82
+ requireInitialized();
83
+ const payload: CmdWindowCloseArgs = { windowId: windowId as number };
84
+ const commandId = enqueueGlobalCommand('cmd-window-close', payload);
85
+ engineState.pendingWindowCloseByCommandId.set(commandId, windowId as number);
86
+ return asCommandId(commandId);
87
+ }
88
+
89
+ /**
90
+ * Applies partial window updates.
91
+ *
92
+ * Depending on the provided fields, this may enqueue up to three commands
93
+ * (`measurement`, `state`, `cursor`) and returns all resulting command ids.
94
+ */
95
+ export function updateWindow(windowId: WindowId, props: WindowProps): CommandId[] {
96
+ requireInitialized();
97
+ const commandIds: CommandId[] = [];
98
+
99
+ if (props.position !== undefined || props.size !== undefined) {
100
+ commandIds.push(asCommandId(
101
+ enqueueGlobalCommand('cmd-window-measurement', {
102
+ windowId: windowId as number,
103
+ position: props.position,
104
+ size: props.size,
105
+ }),
106
+ ));
107
+ }
108
+ if (
109
+ props.title !== undefined ||
110
+ props.state !== undefined ||
111
+ props.resizable !== undefined ||
112
+ props.decorations !== undefined ||
113
+ props.icon !== undefined
114
+ ) {
115
+ commandIds.push(asCommandId(
116
+ enqueueGlobalCommand('cmd-window-state', {
117
+ windowId: windowId as number,
118
+ title: props.title,
119
+ state: props.state,
120
+ resizable: props.resizable,
121
+ decorations: props.decorations,
122
+ iconBufferId: props.icon,
123
+ }),
124
+ ));
125
+ }
126
+ if (
127
+ props.cursorVisible !== undefined ||
128
+ props.cursorGrab !== undefined ||
129
+ props.cursorIcon !== undefined
130
+ ) {
131
+ commandIds.push(asCommandId(
132
+ enqueueGlobalCommand('cmd-window-cursor', {
133
+ windowId: windowId as number,
134
+ visible: props.cursorVisible,
135
+ mode: props.cursorGrab,
136
+ icon: props.cursorIcon,
137
+ }),
138
+ ));
139
+ }
140
+
141
+ return commandIds;
142
+ }
143
+
144
+ /**
145
+ * Requests user attention for a window.
146
+ *
147
+ * This does not guarantee foreground focus; behavior depends on host platform policy.
148
+ */
149
+ export function requestAttention(
150
+ windowId: WindowId,
151
+ attentionType?: UserAttentionType,
152
+ ): CommandId {
153
+ requireInitialized();
154
+ return asCommandId(enqueueGlobalCommand('cmd-window-state', {
155
+ windowId: windowId as number,
156
+ action: 'request-attention',
157
+ attentionType,
158
+ }));
159
+ }
160
+
161
+ /** Requests input focus for a window. */
162
+ export function focusWindow(windowId: WindowId): CommandId {
163
+ requireInitialized();
164
+ return asCommandId(enqueueGlobalCommand('cmd-window-state', {
165
+ windowId: windowId as number,
166
+ action: 'focus',
167
+ }));
168
+ }