@holoscript/engine 6.0.3 → 6.0.4
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/dist/AutoMesher-CK47F6AV.js +17 -0
- package/dist/GPUBuffers-2LHBCD7X.js +9 -0
- package/dist/WebGPUContext-TNEUYU2Y.js +11 -0
- package/dist/animation/index.cjs +38 -38
- package/dist/animation/index.d.cts +1 -1
- package/dist/animation/index.d.ts +1 -1
- package/dist/animation/index.js +1 -1
- package/dist/audio/index.cjs +16 -6
- package/dist/audio/index.d.cts +1 -1
- package/dist/audio/index.d.ts +1 -1
- package/dist/audio/index.js +1 -1
- package/dist/camera/index.cjs +23 -23
- package/dist/camera/index.d.cts +1 -1
- package/dist/camera/index.d.ts +1 -1
- package/dist/camera/index.js +1 -1
- package/dist/character/index.cjs +6 -4
- package/dist/character/index.js +1 -1
- package/dist/choreography/index.cjs +1194 -0
- package/dist/choreography/index.d.cts +687 -0
- package/dist/choreography/index.d.ts +687 -0
- package/dist/choreography/index.js +1156 -0
- package/dist/chunk-2CSNRI2N.js +217 -0
- package/dist/chunk-33T2WINR.js +266 -0
- package/dist/chunk-35R73OFM.js +1257 -0
- package/dist/chunk-4MMDSUNP.js +1256 -0
- package/dist/chunk-5V6HOU72.js +319 -0
- package/dist/chunk-6QOP6PYF.js +1038 -0
- package/dist/chunk-7KMJVHIL.js +8944 -0
- package/dist/chunk-7VPUC62U.js +1106 -0
- package/dist/chunk-A2Y6RCAT.js +1878 -0
- package/dist/chunk-AHM42MK6.js +8944 -0
- package/dist/chunk-BL7IDTHE.js +218 -0
- package/dist/chunk-CITOMSWL.js +10462 -0
- package/dist/chunk-CXDPKW2K.js +8944 -0
- package/dist/chunk-CXZPLD4S.js +223 -0
- package/dist/chunk-CZYJE7IH.js +5169 -0
- package/dist/chunk-D2OP7YC7.js +6325 -0
- package/dist/chunk-EDRVQHUU.js +1544 -0
- package/dist/chunk-EJSLOOW2.js +3589 -0
- package/dist/chunk-F53SFGW5.js +1878 -0
- package/dist/chunk-HCFPELPY.js +919 -0
- package/dist/chunk-HNEE36PY.js +93 -0
- package/dist/chunk-HYXNV36F.js +1256 -0
- package/dist/chunk-IB7KHVFY.js +821 -0
- package/dist/chunk-IBBO7YYG.js +690 -0
- package/dist/chunk-ILIBGINU.js +5470 -0
- package/dist/chunk-IS4MHLKN.js +5479 -0
- package/dist/chunk-JT2PFKWD.js +5479 -0
- package/dist/chunk-K4CUB4NY.js +1038 -0
- package/dist/chunk-KATDQXRJ.js +10462 -0
- package/dist/chunk-KBQE6ZFJ.js +8944 -0
- package/dist/chunk-KBVD5K7E.js +560 -0
- package/dist/chunk-KCDPVQRY.js +4088 -0
- package/dist/chunk-KN4QJPKN.js +8944 -0
- package/dist/chunk-KWJ3ROSI.js +8944 -0
- package/dist/chunk-L45VF6DD.js +919 -0
- package/dist/chunk-LY4T37YK.js +307 -0
- package/dist/chunk-MDN5WZXA.js +1544 -0
- package/dist/chunk-MGCDP6VU.js +928 -0
- package/dist/chunk-NCX7X6G2.js +8681 -0
- package/dist/chunk-OF54BPVD.js +913 -0
- package/dist/chunk-OWSN2Q3Q.js +690 -0
- package/dist/chunk-PRRB5TTA.js +406 -0
- package/dist/chunk-PXWVQF76.js +4086 -0
- package/dist/chunk-PYCOIDT2.js +812 -0
- package/dist/chunk-PZCSADOV.js +928 -0
- package/dist/chunk-Q2XBVS2K.js +1038 -0
- package/dist/chunk-QDZRXWN5.js +1776 -0
- package/dist/chunk-RNWOZ6WQ.js +913 -0
- package/dist/chunk-ROLFT4CJ.js +1693 -0
- package/dist/chunk-SLTJRZ2N.js +266 -0
- package/dist/chunk-SRUS5XSU.js +4088 -0
- package/dist/chunk-TKCA3WZ5.js +5409 -0
- package/dist/chunk-TNRMXYI2.js +1650 -0
- package/dist/chunk-TQB3GJGM.js +9763 -0
- package/dist/chunk-TUFGXG6K.js +510 -0
- package/dist/chunk-U6KMTGQJ.js +632 -0
- package/dist/chunk-VMGJQST6.js +8681 -0
- package/dist/chunk-X4F4TCG4.js +5470 -0
- package/dist/chunk-ZIFROE75.js +1544 -0
- package/dist/chunk-ZIJQYHSQ.js +1204 -0
- package/dist/combat/index.cjs +4 -4
- package/dist/combat/index.d.cts +1 -1
- package/dist/combat/index.d.ts +1 -1
- package/dist/combat/index.js +1 -1
- package/dist/ecs/index.cjs +1 -1
- package/dist/ecs/index.js +1 -1
- package/dist/environment/index.cjs +14 -14
- package/dist/environment/index.d.cts +1 -1
- package/dist/environment/index.d.ts +1 -1
- package/dist/environment/index.js +1 -1
- package/dist/gpu/index.cjs +4810 -0
- package/dist/gpu/index.js +3714 -0
- package/dist/hologram/index.cjs +27 -1
- package/dist/hologram/index.js +1 -1
- package/dist/index-B2PIsAmR.d.cts +2180 -0
- package/dist/index-B2PIsAmR.d.ts +2180 -0
- package/dist/index-BHySEPX7.d.cts +2921 -0
- package/dist/index-BJV21zuy.d.cts +341 -0
- package/dist/index-BJV21zuy.d.ts +341 -0
- package/dist/index-BQutTphC.d.cts +790 -0
- package/dist/index-ByIq2XrS.d.cts +3910 -0
- package/dist/index-BysHjDSO.d.cts +224 -0
- package/dist/index-BysHjDSO.d.ts +224 -0
- package/dist/index-CKwAJGck.d.ts +455 -0
- package/dist/index-CUl3QstQ.d.cts +3006 -0
- package/dist/index-CUl3QstQ.d.ts +3006 -0
- package/dist/index-CmYtNiI-.d.cts +953 -0
- package/dist/index-CmYtNiI-.d.ts +953 -0
- package/dist/index-CnRzWxi_.d.cts +522 -0
- package/dist/index-CnRzWxi_.d.ts +522 -0
- package/dist/index-CwRWbSC7.d.ts +2921 -0
- package/dist/index-CxKIBstO.d.ts +790 -0
- package/dist/index-DJ6-R8vh.d.cts +455 -0
- package/dist/index-DQKisbcI.d.cts +4968 -0
- package/dist/index-DQKisbcI.d.ts +4968 -0
- package/dist/index-DRT2zJez.d.ts +3910 -0
- package/dist/index-DfNLiAka.d.cts +192 -0
- package/dist/index-DfNLiAka.d.ts +192 -0
- package/dist/index-nMvkoRm8.d.cts +405 -0
- package/dist/index-nMvkoRm8.d.ts +405 -0
- package/dist/index-s9yOFU37.d.cts +604 -0
- package/dist/index-s9yOFU37.d.ts +604 -0
- package/dist/index.cjs +22966 -6960
- package/dist/index.d.cts +864 -20
- package/dist/index.d.ts +864 -20
- package/dist/index.js +3062 -48
- package/dist/input/index.cjs +1 -1
- package/dist/input/index.js +1 -1
- package/dist/orbital/index.cjs +3 -3
- package/dist/orbital/index.d.cts +1 -1
- package/dist/orbital/index.d.ts +1 -1
- package/dist/orbital/index.js +1 -1
- package/dist/particles/index.cjs +16 -16
- package/dist/particles/index.d.cts +1 -1
- package/dist/particles/index.d.ts +1 -1
- package/dist/particles/index.js +1 -1
- package/dist/physics/index.cjs +2377 -21
- package/dist/physics/index.d.cts +1 -1
- package/dist/physics/index.d.ts +1 -1
- package/dist/physics/index.js +35 -1
- package/dist/postfx/index.cjs +3491 -0
- package/dist/postfx/index.js +93 -0
- package/dist/procedural/index.cjs +1 -1
- package/dist/procedural/index.js +1 -1
- package/dist/puppeteer-5VF6KDVO.js +52197 -0
- package/dist/puppeteer-IZVZ3SG4.js +52197 -0
- package/dist/rendering/index.cjs +33 -32
- package/dist/rendering/index.d.cts +1 -1
- package/dist/rendering/index.d.ts +1 -1
- package/dist/rendering/index.js +8 -6
- package/dist/runtime/index.cjs +23 -13
- package/dist/runtime/index.d.cts +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +8 -6
- package/dist/runtime/protocols/index.cjs +349 -0
- package/dist/runtime/protocols/index.js +15 -0
- package/dist/scene/index.cjs +8 -8
- package/dist/scene/index.d.cts +1 -1
- package/dist/scene/index.d.ts +1 -1
- package/dist/scene/index.js +1 -1
- package/dist/shader/index.cjs +3087 -0
- package/dist/shader/index.js +3044 -0
- package/dist/simulation/index.cjs +10680 -0
- package/dist/simulation/index.d.cts +3 -0
- package/dist/simulation/index.d.ts +3 -0
- package/dist/simulation/index.js +307 -0
- package/dist/spatial/index.cjs +2443 -0
- package/dist/spatial/index.d.cts +1545 -0
- package/dist/spatial/index.d.ts +1545 -0
- package/dist/spatial/index.js +2400 -0
- package/dist/terrain/index.cjs +1 -1
- package/dist/terrain/index.d.cts +1 -1
- package/dist/terrain/index.d.ts +1 -1
- package/dist/terrain/index.js +1 -1
- package/dist/transformers.node-4NKAPD5U.js +45620 -0
- package/dist/vm/index.cjs +7 -8
- package/dist/vm/index.d.cts +1 -1
- package/dist/vm/index.d.ts +1 -1
- package/dist/vm/index.js +1 -1
- package/dist/vm-bridge/index.cjs +2 -2
- package/dist/vm-bridge/index.d.cts +2 -2
- package/dist/vm-bridge/index.d.ts +2 -2
- package/dist/vm-bridge/index.js +1 -1
- package/dist/vr/index.cjs +6 -6
- package/dist/vr/index.js +1 -1
- package/dist/world/index.cjs +3 -3
- package/dist/world/index.d.cts +1 -1
- package/dist/world/index.d.ts +1 -1
- package/dist/world/index.js +1 -1
- package/package.json +53 -21
- package/LICENSE +0 -21
|
@@ -0,0 +1,1256 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-AKLW2MUS.js";
|
|
4
|
+
|
|
5
|
+
// src/vm/index.ts
|
|
6
|
+
var vm_exports = {};
|
|
7
|
+
__export(vm_exports, {
|
|
8
|
+
AssetType: () => AssetType,
|
|
9
|
+
BodyType: () => BodyType,
|
|
10
|
+
ColliderShape: () => ColliderShape,
|
|
11
|
+
ComponentType: () => ComponentType,
|
|
12
|
+
ECSWorld: () => ECSWorld,
|
|
13
|
+
GeometryType: () => GeometryType,
|
|
14
|
+
HOLOB_MAGIC: () => HOLOB_MAGIC,
|
|
15
|
+
HOLOB_VERSION: () => HOLOB_VERSION,
|
|
16
|
+
HoloBytecodeBuilder: () => HoloBytecodeBuilder,
|
|
17
|
+
HoloFunctionBuilder: () => HoloFunctionBuilder,
|
|
18
|
+
HoloOpCode: () => HoloOpCode,
|
|
19
|
+
HoloVM: () => HoloVM,
|
|
20
|
+
HolobFlags: () => HolobFlags,
|
|
21
|
+
LightType: () => LightType,
|
|
22
|
+
SyncTier: () => SyncTier,
|
|
23
|
+
VMStatus: () => VMStatus,
|
|
24
|
+
ValueType: () => ValueType,
|
|
25
|
+
getOpcodeFamily: () => getOpcodeFamily,
|
|
26
|
+
getOpcodeName: () => getOpcodeName,
|
|
27
|
+
isControlFlow: () => isControlFlow
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// src/vm/opcodes.ts
|
|
31
|
+
var HoloOpCode = /* @__PURE__ */ ((HoloOpCode2) => {
|
|
32
|
+
HoloOpCode2[HoloOpCode2["SPAWN"] = 1] = "SPAWN";
|
|
33
|
+
HoloOpCode2[HoloOpCode2["DESPAWN"] = 2] = "DESPAWN";
|
|
34
|
+
HoloOpCode2[HoloOpCode2["CLONE"] = 3] = "CLONE";
|
|
35
|
+
HoloOpCode2[HoloOpCode2["SET_COMPONENT"] = 4] = "SET_COMPONENT";
|
|
36
|
+
HoloOpCode2[HoloOpCode2["GET_COMPONENT"] = 5] = "GET_COMPONENT";
|
|
37
|
+
HoloOpCode2[HoloOpCode2["REMOVE_COMPONENT"] = 6] = "REMOVE_COMPONENT";
|
|
38
|
+
HoloOpCode2[HoloOpCode2["SET_PARENT"] = 7] = "SET_PARENT";
|
|
39
|
+
HoloOpCode2[HoloOpCode2["QUERY"] = 8] = "QUERY";
|
|
40
|
+
HoloOpCode2[HoloOpCode2["TRANSFORM"] = 16] = "TRANSFORM";
|
|
41
|
+
HoloOpCode2[HoloOpCode2["TRANSLATE"] = 17] = "TRANSLATE";
|
|
42
|
+
HoloOpCode2[HoloOpCode2["ROTATE"] = 18] = "ROTATE";
|
|
43
|
+
HoloOpCode2[HoloOpCode2["LOOK_AT"] = 19] = "LOOK_AT";
|
|
44
|
+
HoloOpCode2[HoloOpCode2["RAYCAST"] = 20] = "RAYCAST";
|
|
45
|
+
HoloOpCode2[HoloOpCode2["QUERY_BOX"] = 21] = "QUERY_BOX";
|
|
46
|
+
HoloOpCode2[HoloOpCode2["QUERY_SPHERE"] = 22] = "QUERY_SPHERE";
|
|
47
|
+
HoloOpCode2[HoloOpCode2["FIND_PATH"] = 23] = "FIND_PATH";
|
|
48
|
+
HoloOpCode2[HoloOpCode2["GET_ZONE"] = 24] = "GET_ZONE";
|
|
49
|
+
HoloOpCode2[HoloOpCode2["ADD_RIGIDBODY"] = 32] = "ADD_RIGIDBODY";
|
|
50
|
+
HoloOpCode2[HoloOpCode2["APPLY_FORCE"] = 33] = "APPLY_FORCE";
|
|
51
|
+
HoloOpCode2[HoloOpCode2["APPLY_IMPULSE"] = 34] = "APPLY_IMPULSE";
|
|
52
|
+
HoloOpCode2[HoloOpCode2["SET_VELOCITY"] = 35] = "SET_VELOCITY";
|
|
53
|
+
HoloOpCode2[HoloOpCode2["ADD_COLLIDER"] = 36] = "ADD_COLLIDER";
|
|
54
|
+
HoloOpCode2[HoloOpCode2["ADD_JOINT"] = 37] = "ADD_JOINT";
|
|
55
|
+
HoloOpCode2[HoloOpCode2["SET_GRAVITY"] = 38] = "SET_GRAVITY";
|
|
56
|
+
HoloOpCode2[HoloOpCode2["PHYSICS_STEP"] = 39] = "PHYSICS_STEP";
|
|
57
|
+
HoloOpCode2[HoloOpCode2["SET_GEOMETRY"] = 48] = "SET_GEOMETRY";
|
|
58
|
+
HoloOpCode2[HoloOpCode2["SET_MATERIAL"] = 49] = "SET_MATERIAL";
|
|
59
|
+
HoloOpCode2[HoloOpCode2["SET_VISIBLE"] = 50] = "SET_VISIBLE";
|
|
60
|
+
HoloOpCode2[HoloOpCode2["SET_LOD"] = 51] = "SET_LOD";
|
|
61
|
+
HoloOpCode2[HoloOpCode2["SET_LIGHT"] = 52] = "SET_LIGHT";
|
|
62
|
+
HoloOpCode2[HoloOpCode2["SET_ANIMATION"] = 53] = "SET_ANIMATION";
|
|
63
|
+
HoloOpCode2[HoloOpCode2["SET_GAUSSIAN_SPLAT"] = 54] = "SET_GAUSSIAN_SPLAT";
|
|
64
|
+
HoloOpCode2[HoloOpCode2["SET_PARTICLE_SYSTEM"] = 55] = "SET_PARTICLE_SYSTEM";
|
|
65
|
+
HoloOpCode2[HoloOpCode2["APPLY_TRAIT"] = 64] = "APPLY_TRAIT";
|
|
66
|
+
HoloOpCode2[HoloOpCode2["REMOVE_TRAIT"] = 65] = "REMOVE_TRAIT";
|
|
67
|
+
HoloOpCode2[HoloOpCode2["RESOLVE_TRAITS"] = 66] = "RESOLVE_TRAITS";
|
|
68
|
+
HoloOpCode2[HoloOpCode2["EMIT_EVENT"] = 67] = "EMIT_EVENT";
|
|
69
|
+
HoloOpCode2[HoloOpCode2["ON_EVENT"] = 68] = "ON_EVENT";
|
|
70
|
+
HoloOpCode2[HoloOpCode2["EVAL_CONDITION"] = 69] = "EVAL_CONDITION";
|
|
71
|
+
HoloOpCode2[HoloOpCode2["LOAD_ASSET"] = 80] = "LOAD_ASSET";
|
|
72
|
+
HoloOpCode2[HoloOpCode2["PLAY_AUDIO"] = 81] = "PLAY_AUDIO";
|
|
73
|
+
HoloOpCode2[HoloOpCode2["NET_SYNC"] = 82] = "NET_SYNC";
|
|
74
|
+
HoloOpCode2[HoloOpCode2["NET_SEND"] = 83] = "NET_SEND";
|
|
75
|
+
HoloOpCode2[HoloOpCode2["NET_RECV"] = 84] = "NET_RECV";
|
|
76
|
+
HoloOpCode2[HoloOpCode2["XR_INPUT"] = 85] = "XR_INPUT";
|
|
77
|
+
HoloOpCode2[HoloOpCode2["HAPTIC"] = 86] = "HAPTIC";
|
|
78
|
+
HoloOpCode2[HoloOpCode2["NOP"] = 96] = "NOP";
|
|
79
|
+
HoloOpCode2[HoloOpCode2["JUMP"] = 97] = "JUMP";
|
|
80
|
+
HoloOpCode2[HoloOpCode2["JUMP_IF"] = 98] = "JUMP_IF";
|
|
81
|
+
HoloOpCode2[HoloOpCode2["CALL"] = 99] = "CALL";
|
|
82
|
+
HoloOpCode2[HoloOpCode2["RETURN"] = 100] = "RETURN";
|
|
83
|
+
HoloOpCode2[HoloOpCode2["PUSH"] = 101] = "PUSH";
|
|
84
|
+
HoloOpCode2[HoloOpCode2["POP"] = 102] = "POP";
|
|
85
|
+
HoloOpCode2[HoloOpCode2["STORE"] = 103] = "STORE";
|
|
86
|
+
HoloOpCode2[HoloOpCode2["LOAD"] = 104] = "LOAD";
|
|
87
|
+
HoloOpCode2[HoloOpCode2["HALT"] = 105] = "HALT";
|
|
88
|
+
HoloOpCode2[HoloOpCode2["YIELD"] = 106] = "YIELD";
|
|
89
|
+
HoloOpCode2[HoloOpCode2["TIMER"] = 107] = "TIMER";
|
|
90
|
+
HoloOpCode2[HoloOpCode2["ADD"] = 108] = "ADD";
|
|
91
|
+
HoloOpCode2[HoloOpCode2["SUB"] = 109] = "SUB";
|
|
92
|
+
HoloOpCode2[HoloOpCode2["MUL"] = 110] = "MUL";
|
|
93
|
+
HoloOpCode2[HoloOpCode2["DIV"] = 111] = "DIV";
|
|
94
|
+
HoloOpCode2[HoloOpCode2["AGENT_INVOKE"] = 112] = "AGENT_INVOKE";
|
|
95
|
+
HoloOpCode2[HoloOpCode2["AGENT_READ"] = 113] = "AGENT_READ";
|
|
96
|
+
HoloOpCode2[HoloOpCode2["AGENT_SUBSCRIBE"] = 114] = "AGENT_SUBSCRIBE";
|
|
97
|
+
HoloOpCode2[HoloOpCode2["DIALOG_SHOW"] = 115] = "DIALOG_SHOW";
|
|
98
|
+
HoloOpCode2[HoloOpCode2["QUEST_UPDATE"] = 116] = "QUEST_UPDATE";
|
|
99
|
+
HoloOpCode2[HoloOpCode2["CMP_EQ"] = 128] = "CMP_EQ";
|
|
100
|
+
HoloOpCode2[HoloOpCode2["CMP_LT"] = 129] = "CMP_LT";
|
|
101
|
+
HoloOpCode2[HoloOpCode2["CMP_GT"] = 130] = "CMP_GT";
|
|
102
|
+
HoloOpCode2[HoloOpCode2["NOT"] = 131] = "NOT";
|
|
103
|
+
return HoloOpCode2;
|
|
104
|
+
})(HoloOpCode || {});
|
|
105
|
+
var ComponentType = /* @__PURE__ */ ((ComponentType2) => {
|
|
106
|
+
ComponentType2[ComponentType2["Transform"] = 1] = "Transform";
|
|
107
|
+
ComponentType2[ComponentType2["Geometry"] = 2] = "Geometry";
|
|
108
|
+
ComponentType2[ComponentType2["Material"] = 3] = "Material";
|
|
109
|
+
ComponentType2[ComponentType2["RigidBody"] = 4] = "RigidBody";
|
|
110
|
+
ComponentType2[ComponentType2["Collider"] = 5] = "Collider";
|
|
111
|
+
ComponentType2[ComponentType2["Light"] = 6] = "Light";
|
|
112
|
+
ComponentType2[ComponentType2["Animation"] = 7] = "Animation";
|
|
113
|
+
ComponentType2[ComponentType2["Audio"] = 8] = "Audio";
|
|
114
|
+
ComponentType2[ComponentType2["Network"] = 9] = "Network";
|
|
115
|
+
ComponentType2[ComponentType2["Trait"] = 10] = "Trait";
|
|
116
|
+
ComponentType2[ComponentType2["ParticleSystem"] = 11] = "ParticleSystem";
|
|
117
|
+
ComponentType2[ComponentType2["GaussianSplat"] = 12] = "GaussianSplat";
|
|
118
|
+
ComponentType2[ComponentType2["LOD"] = 13] = "LOD";
|
|
119
|
+
ComponentType2[ComponentType2["Custom"] = 255] = "Custom";
|
|
120
|
+
return ComponentType2;
|
|
121
|
+
})(ComponentType || {});
|
|
122
|
+
var GeometryType = /* @__PURE__ */ ((GeometryType2) => {
|
|
123
|
+
GeometryType2[GeometryType2["Cube"] = 1] = "Cube";
|
|
124
|
+
GeometryType2[GeometryType2["Sphere"] = 2] = "Sphere";
|
|
125
|
+
GeometryType2[GeometryType2["Cylinder"] = 3] = "Cylinder";
|
|
126
|
+
GeometryType2[GeometryType2["Plane"] = 4] = "Plane";
|
|
127
|
+
GeometryType2[GeometryType2["Cone"] = 5] = "Cone";
|
|
128
|
+
GeometryType2[GeometryType2["Torus"] = 6] = "Torus";
|
|
129
|
+
GeometryType2[GeometryType2["Capsule"] = 7] = "Capsule";
|
|
130
|
+
GeometryType2[GeometryType2["Mesh"] = 8] = "Mesh";
|
|
131
|
+
GeometryType2[GeometryType2["Text3D"] = 9] = "Text3D";
|
|
132
|
+
GeometryType2[GeometryType2["Portal"] = 10] = "Portal";
|
|
133
|
+
GeometryType2[GeometryType2["Terrain"] = 11] = "Terrain";
|
|
134
|
+
GeometryType2[GeometryType2["Skybox"] = 12] = "Skybox";
|
|
135
|
+
GeometryType2[GeometryType2["Billboard"] = 13] = "Billboard";
|
|
136
|
+
GeometryType2[GeometryType2["Line"] = 14] = "Line";
|
|
137
|
+
return GeometryType2;
|
|
138
|
+
})(GeometryType || {});
|
|
139
|
+
var BodyType = /* @__PURE__ */ ((BodyType2) => {
|
|
140
|
+
BodyType2[BodyType2["Static"] = 0] = "Static";
|
|
141
|
+
BodyType2[BodyType2["Dynamic"] = 1] = "Dynamic";
|
|
142
|
+
BodyType2[BodyType2["Kinematic"] = 2] = "Kinematic";
|
|
143
|
+
return BodyType2;
|
|
144
|
+
})(BodyType || {});
|
|
145
|
+
var ColliderShape = /* @__PURE__ */ ((ColliderShape2) => {
|
|
146
|
+
ColliderShape2[ColliderShape2["Box"] = 1] = "Box";
|
|
147
|
+
ColliderShape2[ColliderShape2["Sphere"] = 2] = "Sphere";
|
|
148
|
+
ColliderShape2[ColliderShape2["Capsule"] = 3] = "Capsule";
|
|
149
|
+
ColliderShape2[ColliderShape2["Cylinder"] = 4] = "Cylinder";
|
|
150
|
+
ColliderShape2[ColliderShape2["ConvexHull"] = 5] = "ConvexHull";
|
|
151
|
+
ColliderShape2[ColliderShape2["TriMesh"] = 6] = "TriMesh";
|
|
152
|
+
return ColliderShape2;
|
|
153
|
+
})(ColliderShape || {});
|
|
154
|
+
var LightType = /* @__PURE__ */ ((LightType2) => {
|
|
155
|
+
LightType2[LightType2["Directional"] = 1] = "Directional";
|
|
156
|
+
LightType2[LightType2["Point"] = 2] = "Point";
|
|
157
|
+
LightType2[LightType2["Spot"] = 3] = "Spot";
|
|
158
|
+
LightType2[LightType2["Ambient"] = 4] = "Ambient";
|
|
159
|
+
LightType2[LightType2["Area"] = 5] = "Area";
|
|
160
|
+
return LightType2;
|
|
161
|
+
})(LightType || {});
|
|
162
|
+
var SyncTier = /* @__PURE__ */ ((SyncTier2) => {
|
|
163
|
+
SyncTier2[SyncTier2["Physics"] = 0] = "Physics";
|
|
164
|
+
SyncTier2[SyncTier2["Movement"] = 1] = "Movement";
|
|
165
|
+
SyncTier2[SyncTier2["AIAgent"] = 2] = "AIAgent";
|
|
166
|
+
SyncTier2[SyncTier2["Cosmetic"] = 3] = "Cosmetic";
|
|
167
|
+
return SyncTier2;
|
|
168
|
+
})(SyncTier || {});
|
|
169
|
+
var ValueType = /* @__PURE__ */ ((ValueType2) => {
|
|
170
|
+
ValueType2[ValueType2["Null"] = 0] = "Null";
|
|
171
|
+
ValueType2[ValueType2["Bool"] = 1] = "Bool";
|
|
172
|
+
ValueType2[ValueType2["I32"] = 2] = "I32";
|
|
173
|
+
ValueType2[ValueType2["F32"] = 3] = "F32";
|
|
174
|
+
ValueType2[ValueType2["F64"] = 4] = "F64";
|
|
175
|
+
ValueType2[ValueType2["String"] = 5] = "String";
|
|
176
|
+
ValueType2[ValueType2["Vec3"] = 6] = "Vec3";
|
|
177
|
+
ValueType2[ValueType2["Quat"] = 7] = "Quat";
|
|
178
|
+
ValueType2[ValueType2["EntityRef"] = 8] = "EntityRef";
|
|
179
|
+
ValueType2[ValueType2["Array"] = 9] = "Array";
|
|
180
|
+
return ValueType2;
|
|
181
|
+
})(ValueType || {});
|
|
182
|
+
var FAMILY_NAMES = {
|
|
183
|
+
0: "Entity",
|
|
184
|
+
1: "Spatial",
|
|
185
|
+
2: "Physics",
|
|
186
|
+
3: "Rendering",
|
|
187
|
+
4: "Trait",
|
|
188
|
+
5: "I/O",
|
|
189
|
+
6: "Control",
|
|
190
|
+
7: "Agent",
|
|
191
|
+
8: "Comparison"
|
|
192
|
+
};
|
|
193
|
+
function getOpcodeFamily(opcode) {
|
|
194
|
+
const familyByte = opcode >> 4 & 15;
|
|
195
|
+
return FAMILY_NAMES[familyByte] ?? "Unknown";
|
|
196
|
+
}
|
|
197
|
+
function getOpcodeName(opcode) {
|
|
198
|
+
return HoloOpCode[opcode] ?? `UNKNOWN_0x${opcode.toString(16).padStart(2, "0")}`;
|
|
199
|
+
}
|
|
200
|
+
function isControlFlow(opcode) {
|
|
201
|
+
return opcode === 97 /* JUMP */ || opcode === 98 /* JUMP_IF */ || opcode === 99 /* CALL */ || opcode === 100 /* RETURN */ || opcode === 105 /* HALT */ || opcode === 106 /* YIELD */;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/vm/bytecode.ts
|
|
205
|
+
var HOLOB_MAGIC = 1213156418;
|
|
206
|
+
var HOLOB_VERSION = 1;
|
|
207
|
+
var HolobFlags = /* @__PURE__ */ ((HolobFlags2) => {
|
|
208
|
+
HolobFlags2[HolobFlags2["None"] = 0] = "None";
|
|
209
|
+
HolobFlags2[HolobFlags2["Debug"] = 1] = "Debug";
|
|
210
|
+
HolobFlags2[HolobFlags2["SIMD"] = 2] = "SIMD";
|
|
211
|
+
HolobFlags2[HolobFlags2["Threads"] = 4] = "Threads";
|
|
212
|
+
HolobFlags2[HolobFlags2["Networking"] = 8] = "Networking";
|
|
213
|
+
HolobFlags2[HolobFlags2["Physics"] = 16] = "Physics";
|
|
214
|
+
return HolobFlags2;
|
|
215
|
+
})(HolobFlags || {});
|
|
216
|
+
var AssetType = /* @__PURE__ */ ((AssetType2) => {
|
|
217
|
+
AssetType2[AssetType2["Mesh"] = 1] = "Mesh";
|
|
218
|
+
AssetType2[AssetType2["Texture"] = 2] = "Texture";
|
|
219
|
+
AssetType2[AssetType2["Audio"] = 3] = "Audio";
|
|
220
|
+
AssetType2[AssetType2["Animation"] = 4] = "Animation";
|
|
221
|
+
AssetType2[AssetType2["GaussianSplat"] = 5] = "GaussianSplat";
|
|
222
|
+
AssetType2[AssetType2["Font"] = 6] = "Font";
|
|
223
|
+
AssetType2[AssetType2["Script"] = 7] = "Script";
|
|
224
|
+
return AssetType2;
|
|
225
|
+
})(AssetType || {});
|
|
226
|
+
var HoloBytecodeBuilder = class {
|
|
227
|
+
strings = /* @__PURE__ */ new Map();
|
|
228
|
+
stringList = [];
|
|
229
|
+
assets = [];
|
|
230
|
+
traits = [];
|
|
231
|
+
functions = [];
|
|
232
|
+
entities = [];
|
|
233
|
+
events = [];
|
|
234
|
+
flags = 0 /* None */;
|
|
235
|
+
/**
|
|
236
|
+
* Intern a string and return its index
|
|
237
|
+
*/
|
|
238
|
+
internString(str) {
|
|
239
|
+
const existing = this.strings.get(str);
|
|
240
|
+
if (existing !== void 0) return existing;
|
|
241
|
+
const idx = this.stringList.length;
|
|
242
|
+
this.stringList.push(str);
|
|
243
|
+
this.strings.set(str, idx);
|
|
244
|
+
return idx;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Add a feature flag
|
|
248
|
+
*/
|
|
249
|
+
addFlag(flag) {
|
|
250
|
+
this.flags |= flag;
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Add an asset reference
|
|
255
|
+
*/
|
|
256
|
+
addAsset(uri, type) {
|
|
257
|
+
const idx = this.assets.length;
|
|
258
|
+
this.assets.push({ uriIndex: this.internString(uri), type });
|
|
259
|
+
return idx;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Add a trait definition
|
|
263
|
+
*/
|
|
264
|
+
addTrait(name, deps = [], initFunc = -1) {
|
|
265
|
+
const idx = this.traits.length;
|
|
266
|
+
this.traits.push({
|
|
267
|
+
nameIndex: this.internString(name),
|
|
268
|
+
dependencies: deps,
|
|
269
|
+
initFunctionIndex: initFunc,
|
|
270
|
+
eventHandlers: /* @__PURE__ */ new Map()
|
|
271
|
+
});
|
|
272
|
+
return idx;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Begin building a function
|
|
276
|
+
*/
|
|
277
|
+
addFunction(name, paramCount = 0) {
|
|
278
|
+
const idx = this.functions.length;
|
|
279
|
+
const fn = {
|
|
280
|
+
nameIndex: this.internString(name),
|
|
281
|
+
instructions: [],
|
|
282
|
+
registerCount: 0,
|
|
283
|
+
paramCount
|
|
284
|
+
};
|
|
285
|
+
this.functions.push(fn);
|
|
286
|
+
return new HoloFunctionBuilder(fn, this, idx);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Add an entity definition
|
|
290
|
+
*/
|
|
291
|
+
addEntity(name, archetype = 0, parentIndex = -1) {
|
|
292
|
+
const idx = this.entities.length;
|
|
293
|
+
this.entities.push({
|
|
294
|
+
nameIndex: this.internString(name),
|
|
295
|
+
archetype,
|
|
296
|
+
components: [],
|
|
297
|
+
parentIndex
|
|
298
|
+
});
|
|
299
|
+
return idx;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Add component data to an entity
|
|
303
|
+
*/
|
|
304
|
+
addComponentToEntity(entityIdx, componentType, values) {
|
|
305
|
+
this.entities[entityIdx].components.push({ componentType, values });
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Add an event binding
|
|
310
|
+
*/
|
|
311
|
+
addEvent(eventType, handlerFunctionIndex, entityFilter = -1) {
|
|
312
|
+
this.events.push({ eventType, handlerFunctionIndex, entityFilter });
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Build the final bytecode module
|
|
317
|
+
*/
|
|
318
|
+
build() {
|
|
319
|
+
return {
|
|
320
|
+
magic: HOLOB_MAGIC,
|
|
321
|
+
version: HOLOB_VERSION,
|
|
322
|
+
flags: this.flags,
|
|
323
|
+
strings: [...this.stringList],
|
|
324
|
+
assets: [...this.assets],
|
|
325
|
+
traits: [...this.traits],
|
|
326
|
+
functions: [...this.functions],
|
|
327
|
+
entities: [...this.entities],
|
|
328
|
+
events: [...this.events]
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var HoloFunctionBuilder = class {
|
|
333
|
+
constructor(func, parent, index) {
|
|
334
|
+
this.func = func;
|
|
335
|
+
this.parent = parent;
|
|
336
|
+
this.index = index;
|
|
337
|
+
}
|
|
338
|
+
func;
|
|
339
|
+
parent;
|
|
340
|
+
index;
|
|
341
|
+
emit(opcode, ...operands) {
|
|
342
|
+
this.func.instructions.push({ opcode, operands });
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
// ── Entity ────────────────────────────────────────────────────────────────
|
|
346
|
+
spawn(entityType, name) {
|
|
347
|
+
return this.emit(1 /* SPAWN */, entityType, this.parent.internString(name));
|
|
348
|
+
}
|
|
349
|
+
despawn(entityId) {
|
|
350
|
+
return this.emit(2 /* DESPAWN */, entityId);
|
|
351
|
+
}
|
|
352
|
+
setComponent(entityId, compType, ...data) {
|
|
353
|
+
return this.emit(4 /* SET_COMPONENT */, entityId, compType, ...data);
|
|
354
|
+
}
|
|
355
|
+
getComponent(entityId, compType) {
|
|
356
|
+
return this.emit(5 /* GET_COMPONENT */, entityId, compType);
|
|
357
|
+
}
|
|
358
|
+
setParent(childId, parentId) {
|
|
359
|
+
return this.emit(7 /* SET_PARENT */, childId, parentId);
|
|
360
|
+
}
|
|
361
|
+
query(archetypeMask) {
|
|
362
|
+
return this.emit(8 /* QUERY */, archetypeMask);
|
|
363
|
+
}
|
|
364
|
+
// ── Spatial ───────────────────────────────────────────────────────────────
|
|
365
|
+
transform(entityId, x, y, z) {
|
|
366
|
+
return this.emit(16 /* TRANSFORM */, entityId, x, y, z, 0, 0, 0, 1, 1, 1, 1);
|
|
367
|
+
}
|
|
368
|
+
translate(entityId, dx, dy, dz) {
|
|
369
|
+
return this.emit(17 /* TRANSLATE */, entityId, dx, dy, dz);
|
|
370
|
+
}
|
|
371
|
+
rotate(entityId, qx, qy, qz, qw) {
|
|
372
|
+
return this.emit(18 /* ROTATE */, entityId, qx, qy, qz, qw);
|
|
373
|
+
}
|
|
374
|
+
lookAt(entityId, tx, ty, tz) {
|
|
375
|
+
return this.emit(19 /* LOOK_AT */, entityId, tx, ty, tz);
|
|
376
|
+
}
|
|
377
|
+
raycast(ox, oy, oz, dx, dy, dz, maxDist) {
|
|
378
|
+
return this.emit(20 /* RAYCAST */, ox, oy, oz, dx, dy, dz, maxDist);
|
|
379
|
+
}
|
|
380
|
+
// ── Physics ───────────────────────────────────────────────────────────────
|
|
381
|
+
addRigidbody(entityId, mass, bodyType) {
|
|
382
|
+
return this.emit(32 /* ADD_RIGIDBODY */, entityId, mass, bodyType);
|
|
383
|
+
}
|
|
384
|
+
applyForce(entityId, fx, fy, fz) {
|
|
385
|
+
return this.emit(33 /* APPLY_FORCE */, entityId, fx, fy, fz);
|
|
386
|
+
}
|
|
387
|
+
applyImpulse(entityId, ix, iy, iz) {
|
|
388
|
+
return this.emit(34 /* APPLY_IMPULSE */, entityId, ix, iy, iz);
|
|
389
|
+
}
|
|
390
|
+
setGravity(gx, gy, gz) {
|
|
391
|
+
return this.emit(38 /* SET_GRAVITY */, gx, gy, gz);
|
|
392
|
+
}
|
|
393
|
+
physicsStep(dt) {
|
|
394
|
+
return this.emit(39 /* PHYSICS_STEP */, dt);
|
|
395
|
+
}
|
|
396
|
+
// ── Rendering Hints ───────────────────────────────────────────────────────
|
|
397
|
+
setGeometry(entityId, geoType) {
|
|
398
|
+
return this.emit(48 /* SET_GEOMETRY */, entityId, geoType);
|
|
399
|
+
}
|
|
400
|
+
setMaterial(entityId, ...desc) {
|
|
401
|
+
return this.emit(49 /* SET_MATERIAL */, entityId, ...desc);
|
|
402
|
+
}
|
|
403
|
+
setVisible(entityId, visible) {
|
|
404
|
+
return this.emit(50 /* SET_VISIBLE */, entityId, visible ? 1 : 0);
|
|
405
|
+
}
|
|
406
|
+
setLight(entityId, lightType, ...params) {
|
|
407
|
+
return this.emit(52 /* SET_LIGHT */, entityId, lightType, ...params);
|
|
408
|
+
}
|
|
409
|
+
setAnimation(entityId, animId) {
|
|
410
|
+
return this.emit(53 /* SET_ANIMATION */, entityId, animId);
|
|
411
|
+
}
|
|
412
|
+
// ── Trait ─────────────────────────────────────────────────────────────────
|
|
413
|
+
applyTrait(entityId, traitId) {
|
|
414
|
+
return this.emit(64 /* APPLY_TRAIT */, entityId, traitId);
|
|
415
|
+
}
|
|
416
|
+
removeTrait(entityId, traitId) {
|
|
417
|
+
return this.emit(65 /* REMOVE_TRAIT */, entityId, traitId);
|
|
418
|
+
}
|
|
419
|
+
emitEvent(eventType, ...payload) {
|
|
420
|
+
return this.emit(67 /* EMIT_EVENT */, eventType, ...payload);
|
|
421
|
+
}
|
|
422
|
+
onEvent(eventType, handlerOffset) {
|
|
423
|
+
return this.emit(68 /* ON_EVENT */, eventType, handlerOffset);
|
|
424
|
+
}
|
|
425
|
+
// ── I/O ───────────────────────────────────────────────────────────────────
|
|
426
|
+
loadAsset(uri, assetType) {
|
|
427
|
+
return this.emit(80 /* LOAD_ASSET */, this.parent.internString(uri), assetType);
|
|
428
|
+
}
|
|
429
|
+
playAudio(soundId, x, y, z) {
|
|
430
|
+
return this.emit(81 /* PLAY_AUDIO */, soundId, x, y, z);
|
|
431
|
+
}
|
|
432
|
+
netSync(entityId, syncTier) {
|
|
433
|
+
return this.emit(82 /* NET_SYNC */, entityId, syncTier);
|
|
434
|
+
}
|
|
435
|
+
// ── Control Flow ──────────────────────────────────────────────────────────
|
|
436
|
+
nop() {
|
|
437
|
+
return this.emit(96 /* NOP */);
|
|
438
|
+
}
|
|
439
|
+
jump(offset) {
|
|
440
|
+
return this.emit(97 /* JUMP */, offset);
|
|
441
|
+
}
|
|
442
|
+
jumpIf(offset) {
|
|
443
|
+
return this.emit(98 /* JUMP_IF */, offset);
|
|
444
|
+
}
|
|
445
|
+
call(funcIdx) {
|
|
446
|
+
return this.emit(99 /* CALL */, funcIdx);
|
|
447
|
+
}
|
|
448
|
+
ret() {
|
|
449
|
+
return this.emit(100 /* RETURN */);
|
|
450
|
+
}
|
|
451
|
+
push(value) {
|
|
452
|
+
return this.emit(101 /* PUSH */, value);
|
|
453
|
+
}
|
|
454
|
+
pop() {
|
|
455
|
+
return this.emit(102 /* POP */);
|
|
456
|
+
}
|
|
457
|
+
store(registerIdx) {
|
|
458
|
+
this.func.registerCount = Math.max(this.func.registerCount, registerIdx + 1);
|
|
459
|
+
return this.emit(103 /* STORE */, registerIdx);
|
|
460
|
+
}
|
|
461
|
+
load(registerIdx) {
|
|
462
|
+
return this.emit(104 /* LOAD */, registerIdx);
|
|
463
|
+
}
|
|
464
|
+
halt() {
|
|
465
|
+
return this.emit(105 /* HALT */);
|
|
466
|
+
}
|
|
467
|
+
yieldTick() {
|
|
468
|
+
return this.emit(106 /* YIELD */);
|
|
469
|
+
}
|
|
470
|
+
timer(delayMs, handlerOffset) {
|
|
471
|
+
return this.emit(107 /* TIMER */, delayMs, handlerOffset);
|
|
472
|
+
}
|
|
473
|
+
// ── Arithmetic ────────────────────────────────────────────────────────────
|
|
474
|
+
add() {
|
|
475
|
+
return this.emit(108 /* ADD */);
|
|
476
|
+
}
|
|
477
|
+
sub() {
|
|
478
|
+
return this.emit(109 /* SUB */);
|
|
479
|
+
}
|
|
480
|
+
mul() {
|
|
481
|
+
return this.emit(110 /* MUL */);
|
|
482
|
+
}
|
|
483
|
+
div() {
|
|
484
|
+
return this.emit(111 /* DIV */);
|
|
485
|
+
}
|
|
486
|
+
// ── Comparison ────────────────────────────────────────────────────────────
|
|
487
|
+
cmpEq() {
|
|
488
|
+
return this.emit(128 /* CMP_EQ */);
|
|
489
|
+
}
|
|
490
|
+
cmpLt() {
|
|
491
|
+
return this.emit(129 /* CMP_LT */);
|
|
492
|
+
}
|
|
493
|
+
cmpGt() {
|
|
494
|
+
return this.emit(130 /* CMP_GT */);
|
|
495
|
+
}
|
|
496
|
+
not() {
|
|
497
|
+
return this.emit(131 /* NOT */);
|
|
498
|
+
}
|
|
499
|
+
// ── Agent Bridge ──────────────────────────────────────────────────────────
|
|
500
|
+
agentInvoke(agentId, actionIdx) {
|
|
501
|
+
return this.emit(112 /* AGENT_INVOKE */, agentId, actionIdx);
|
|
502
|
+
}
|
|
503
|
+
agentRead(agentId, fieldIdx) {
|
|
504
|
+
return this.emit(113 /* AGENT_READ */, agentId, fieldIdx);
|
|
505
|
+
}
|
|
506
|
+
dialogShow(npcId, dialogTreeId) {
|
|
507
|
+
return this.emit(115 /* DIALOG_SHOW */, npcId, dialogTreeId);
|
|
508
|
+
}
|
|
509
|
+
questUpdate(questId, state) {
|
|
510
|
+
return this.emit(116 /* QUEST_UPDATE */, questId, state);
|
|
511
|
+
}
|
|
512
|
+
/** Get the current instruction count (useful for jump targets) */
|
|
513
|
+
get instructionCount() {
|
|
514
|
+
return this.func.instructions.length;
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// src/vm/executor.ts
|
|
519
|
+
var ECSWorld = class {
|
|
520
|
+
entities = /* @__PURE__ */ new Map();
|
|
521
|
+
nextEntityId = 1;
|
|
522
|
+
archetypeIndex = /* @__PURE__ */ new Map();
|
|
523
|
+
/**
|
|
524
|
+
* Spawn a new entity
|
|
525
|
+
*/
|
|
526
|
+
spawn(name, archetype = 0) {
|
|
527
|
+
const id = this.nextEntityId++;
|
|
528
|
+
const entity = {
|
|
529
|
+
id,
|
|
530
|
+
name,
|
|
531
|
+
parentId: -1,
|
|
532
|
+
childIds: [],
|
|
533
|
+
components: /* @__PURE__ */ new Map(),
|
|
534
|
+
traits: /* @__PURE__ */ new Set(),
|
|
535
|
+
alive: true,
|
|
536
|
+
dirty: true
|
|
537
|
+
};
|
|
538
|
+
this.entities.set(id, entity);
|
|
539
|
+
if (!this.archetypeIndex.has(archetype)) {
|
|
540
|
+
this.archetypeIndex.set(archetype, /* @__PURE__ */ new Set());
|
|
541
|
+
}
|
|
542
|
+
this.archetypeIndex.get(archetype).add(id);
|
|
543
|
+
return id;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Despawn an entity and its children
|
|
547
|
+
*/
|
|
548
|
+
despawn(entityId) {
|
|
549
|
+
const entity = this.entities.get(entityId);
|
|
550
|
+
if (!entity) return false;
|
|
551
|
+
for (const childId of [...entity.childIds]) {
|
|
552
|
+
this.despawn(childId);
|
|
553
|
+
}
|
|
554
|
+
if (entity.parentId !== -1) {
|
|
555
|
+
const parent = this.entities.get(entity.parentId);
|
|
556
|
+
if (parent) {
|
|
557
|
+
parent.childIds = parent.childIds.filter((id) => id !== entityId);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
entity.alive = false;
|
|
561
|
+
this.entities.delete(entityId);
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Set a component on an entity
|
|
566
|
+
*/
|
|
567
|
+
setComponent(entityId, componentType, data) {
|
|
568
|
+
const entity = this.entities.get(entityId);
|
|
569
|
+
if (!entity) return false;
|
|
570
|
+
entity.components.set(componentType, data);
|
|
571
|
+
entity.dirty = true;
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Get a component from an entity
|
|
576
|
+
*/
|
|
577
|
+
getComponent(entityId, componentType) {
|
|
578
|
+
const entity = this.entities.get(entityId);
|
|
579
|
+
if (!entity) return void 0;
|
|
580
|
+
return entity.components.get(componentType);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Remove a component from an entity
|
|
584
|
+
*/
|
|
585
|
+
removeComponent(entityId, componentType) {
|
|
586
|
+
const entity = this.entities.get(entityId);
|
|
587
|
+
if (!entity) return false;
|
|
588
|
+
entity.dirty = true;
|
|
589
|
+
return entity.components.delete(componentType);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Set parent-child relationship
|
|
593
|
+
*/
|
|
594
|
+
setParent(childId, parentId) {
|
|
595
|
+
const child = this.entities.get(childId);
|
|
596
|
+
const parent = this.entities.get(parentId);
|
|
597
|
+
if (!child || !parent) return false;
|
|
598
|
+
if (child.parentId !== -1) {
|
|
599
|
+
const oldParent = this.entities.get(child.parentId);
|
|
600
|
+
if (oldParent) {
|
|
601
|
+
oldParent.childIds = oldParent.childIds.filter((id) => id !== childId);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
child.parentId = parentId;
|
|
605
|
+
parent.childIds.push(childId);
|
|
606
|
+
child.dirty = true;
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Query entities by archetype mask
|
|
611
|
+
*/
|
|
612
|
+
queryArchetype(mask) {
|
|
613
|
+
const set = this.archetypeIndex.get(mask);
|
|
614
|
+
return set ? [...set] : [];
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Get entity by ID
|
|
618
|
+
*/
|
|
619
|
+
getEntity(entityId) {
|
|
620
|
+
return this.entities.get(entityId);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Get all dirty entities and clear dirty flags
|
|
624
|
+
*/
|
|
625
|
+
flushDirty() {
|
|
626
|
+
const dirty = [];
|
|
627
|
+
for (const entity of this.entities.values()) {
|
|
628
|
+
if (entity.dirty) {
|
|
629
|
+
dirty.push(entity);
|
|
630
|
+
entity.dirty = false;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return dirty;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Get all living entities
|
|
637
|
+
*/
|
|
638
|
+
getAllEntities() {
|
|
639
|
+
return [...this.entities.values()];
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Get entity count
|
|
643
|
+
*/
|
|
644
|
+
get entityCount() {
|
|
645
|
+
return this.entities.size;
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
var VMStatus = /* @__PURE__ */ ((VMStatus2) => {
|
|
649
|
+
VMStatus2["Idle"] = "IDLE";
|
|
650
|
+
VMStatus2["Running"] = "RUNNING";
|
|
651
|
+
VMStatus2["Yielded"] = "YIELDED";
|
|
652
|
+
VMStatus2["Halted"] = "HALTED";
|
|
653
|
+
VMStatus2["Error"] = "ERROR";
|
|
654
|
+
return VMStatus2;
|
|
655
|
+
})(VMStatus || {});
|
|
656
|
+
var HoloVM = class {
|
|
657
|
+
// Core state
|
|
658
|
+
bytecode = null;
|
|
659
|
+
world = new ECSWorld();
|
|
660
|
+
// Execution state
|
|
661
|
+
stack = [];
|
|
662
|
+
callStack = [];
|
|
663
|
+
status = "IDLE" /* Idle */;
|
|
664
|
+
tickCount = 0;
|
|
665
|
+
// Timer system
|
|
666
|
+
timers = [];
|
|
667
|
+
currentTimeMs = 0;
|
|
668
|
+
// Event queue
|
|
669
|
+
eventQueue = [];
|
|
670
|
+
// Limits
|
|
671
|
+
maxStackSize = 4096;
|
|
672
|
+
maxCallDepth = 256;
|
|
673
|
+
maxInstructionsPerTick = 1e4;
|
|
674
|
+
/**
|
|
675
|
+
* Load a bytecode module into the VM
|
|
676
|
+
*/
|
|
677
|
+
load(bytecode) {
|
|
678
|
+
this.bytecode = bytecode;
|
|
679
|
+
this.reset();
|
|
680
|
+
this.initializeEntities();
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Reset VM state without unloading bytecode
|
|
684
|
+
*/
|
|
685
|
+
reset() {
|
|
686
|
+
this.stack = [];
|
|
687
|
+
this.callStack = [];
|
|
688
|
+
this.status = "IDLE" /* Idle */;
|
|
689
|
+
this.tickCount = 0;
|
|
690
|
+
this.timers = [];
|
|
691
|
+
this.currentTimeMs = 0;
|
|
692
|
+
this.eventQueue = [];
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Initialize entities from the bytecode's init section
|
|
696
|
+
*/
|
|
697
|
+
initializeEntities() {
|
|
698
|
+
if (!this.bytecode) return;
|
|
699
|
+
for (const entityDef of this.bytecode.entities) {
|
|
700
|
+
const name = this.bytecode.strings[entityDef.nameIndex] ?? `entity_${entityDef.nameIndex}`;
|
|
701
|
+
const entityId = this.world.spawn(name, entityDef.archetype);
|
|
702
|
+
for (const comp of entityDef.components) {
|
|
703
|
+
this.world.setComponent(entityId, comp.componentType, comp.values);
|
|
704
|
+
}
|
|
705
|
+
if (entityDef.parentIndex >= 0) {
|
|
706
|
+
this.world.setParent(entityId, entityDef.parentIndex + 1);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Execute one tick of the VM (called at ~90fps)
|
|
712
|
+
*
|
|
713
|
+
* Each tick:
|
|
714
|
+
* 1. Process expired timers
|
|
715
|
+
* 2. Dispatch queued events
|
|
716
|
+
* 3. Resume execution from yield point (or run init)
|
|
717
|
+
* 4. Return dirty entities for rendering
|
|
718
|
+
*/
|
|
719
|
+
tick(deltaMs) {
|
|
720
|
+
if (!this.bytecode) {
|
|
721
|
+
return {
|
|
722
|
+
status: "ERROR" /* Error */,
|
|
723
|
+
stackTop: null,
|
|
724
|
+
tickCount: this.tickCount,
|
|
725
|
+
entityCount: 0,
|
|
726
|
+
error: "No bytecode loaded"
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
this.tickCount++;
|
|
730
|
+
this.currentTimeMs += deltaMs;
|
|
731
|
+
this.processTimers();
|
|
732
|
+
this.dispatchEvents();
|
|
733
|
+
if (this.status === "YIELDED" /* Yielded */) {
|
|
734
|
+
this.status = "RUNNING" /* Running */;
|
|
735
|
+
this.executeInstructions();
|
|
736
|
+
} else if (this.status === "IDLE" /* Idle */ && this.bytecode.functions.length > 0) {
|
|
737
|
+
this.callFunction(0);
|
|
738
|
+
this.executeInstructions();
|
|
739
|
+
}
|
|
740
|
+
return {
|
|
741
|
+
status: this.status,
|
|
742
|
+
stackTop: this.stack.length > 0 ? this.stack[this.stack.length - 1] : null,
|
|
743
|
+
tickCount: this.tickCount,
|
|
744
|
+
entityCount: this.world.entityCount
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Main execution loop — runs until YIELD, HALT, or instruction limit
|
|
749
|
+
*/
|
|
750
|
+
executeInstructions() {
|
|
751
|
+
if (!this.bytecode) return;
|
|
752
|
+
let instructionsExecuted = 0;
|
|
753
|
+
while (this.status === "RUNNING" /* Running */ && instructionsExecuted < this.maxInstructionsPerTick) {
|
|
754
|
+
const frame = this.currentFrame;
|
|
755
|
+
if (!frame) {
|
|
756
|
+
this.status = "HALTED" /* Halted */;
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
const func = this.bytecode.functions[frame.functionIndex];
|
|
760
|
+
if (!func || frame.pc >= func.instructions.length) {
|
|
761
|
+
this.callStack.pop();
|
|
762
|
+
if (this.callStack.length === 0) {
|
|
763
|
+
this.status = "HALTED" /* Halted */;
|
|
764
|
+
}
|
|
765
|
+
break;
|
|
766
|
+
}
|
|
767
|
+
const instr = func.instructions[frame.pc];
|
|
768
|
+
frame.pc++;
|
|
769
|
+
instructionsExecuted++;
|
|
770
|
+
try {
|
|
771
|
+
this.executeInstruction(instr, frame);
|
|
772
|
+
} catch (_err) {
|
|
773
|
+
this.status = "ERROR" /* Error */;
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
if (this.status !== "RUNNING" /* Running */) break;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Execute a single instruction
|
|
781
|
+
*/
|
|
782
|
+
executeInstruction(instr, frame) {
|
|
783
|
+
const op = instr.opcode;
|
|
784
|
+
const operands = instr.operands;
|
|
785
|
+
switch (op) {
|
|
786
|
+
// ── Entity Operations ───────────────────────────────────────────────
|
|
787
|
+
case 1 /* SPAWN */: {
|
|
788
|
+
const entityType = operands[0];
|
|
789
|
+
const nameIdx = operands[1];
|
|
790
|
+
const name = this.getString(nameIdx);
|
|
791
|
+
const id = this.world.spawn(name, entityType);
|
|
792
|
+
this.push(id);
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
case 2 /* DESPAWN */: {
|
|
796
|
+
const entityId = operands[0];
|
|
797
|
+
this.world.despawn(entityId);
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
800
|
+
case 4 /* SET_COMPONENT */: {
|
|
801
|
+
const entityId = operands[0];
|
|
802
|
+
const compType = operands[1];
|
|
803
|
+
const data = operands.slice(2);
|
|
804
|
+
this.world.setComponent(entityId, compType, data);
|
|
805
|
+
break;
|
|
806
|
+
}
|
|
807
|
+
case 5 /* GET_COMPONENT */: {
|
|
808
|
+
const entityId = operands[0];
|
|
809
|
+
const compType = operands[1];
|
|
810
|
+
const data = this.world.getComponent(entityId, compType);
|
|
811
|
+
this.push(data ?? null);
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
case 6 /* REMOVE_COMPONENT */: {
|
|
815
|
+
const entityId = operands[0];
|
|
816
|
+
const compType = operands[1];
|
|
817
|
+
this.world.removeComponent(entityId, compType);
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
case 7 /* SET_PARENT */: {
|
|
821
|
+
const childId = operands[0];
|
|
822
|
+
const parentId = operands[1];
|
|
823
|
+
this.world.setParent(childId, parentId);
|
|
824
|
+
break;
|
|
825
|
+
}
|
|
826
|
+
case 8 /* QUERY */: {
|
|
827
|
+
const mask = operands[0];
|
|
828
|
+
const entities = this.world.queryArchetype(mask);
|
|
829
|
+
this.push(entities);
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
// ── Spatial Operations ──────────────────────────────────────────────
|
|
833
|
+
case 16 /* TRANSFORM */: {
|
|
834
|
+
const entityId = operands[0];
|
|
835
|
+
const transform = {
|
|
836
|
+
position: { x: operands[1], y: operands[2], z: operands[3] },
|
|
837
|
+
rotation: {
|
|
838
|
+
x: operands[4],
|
|
839
|
+
y: operands[5],
|
|
840
|
+
z: operands[6],
|
|
841
|
+
w: operands[7]
|
|
842
|
+
},
|
|
843
|
+
scale: { x: operands[8], y: operands[9], z: operands[10] }
|
|
844
|
+
};
|
|
845
|
+
this.world.setComponent(entityId, 1 /* Transform */, transform);
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
case 17 /* TRANSLATE */: {
|
|
849
|
+
const entityId = operands[0];
|
|
850
|
+
const existing = this.world.getComponent(
|
|
851
|
+
entityId,
|
|
852
|
+
1 /* Transform */
|
|
853
|
+
);
|
|
854
|
+
if (existing) {
|
|
855
|
+
existing.position.x += operands[1];
|
|
856
|
+
existing.position.y += operands[2];
|
|
857
|
+
existing.position.z += operands[3];
|
|
858
|
+
this.world.setComponent(entityId, 1 /* Transform */, existing);
|
|
859
|
+
}
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
case 18 /* ROTATE */: {
|
|
863
|
+
const entityId = operands[0];
|
|
864
|
+
this.world.setComponent(entityId, 1 /* Transform */, {
|
|
865
|
+
position: [0, 0, 0],
|
|
866
|
+
rotation: {
|
|
867
|
+
x: operands[1],
|
|
868
|
+
y: operands[2],
|
|
869
|
+
z: operands[3],
|
|
870
|
+
w: operands[4]
|
|
871
|
+
},
|
|
872
|
+
scale: { x: 1, y: 1, z: 1 }
|
|
873
|
+
});
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
case 48 /* SET_GEOMETRY */: {
|
|
877
|
+
const entityId = operands[0];
|
|
878
|
+
const geoType = operands[1];
|
|
879
|
+
this.world.setComponent(entityId, 2 /* Geometry */, { type: geoType, params: {} });
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
case 49 /* SET_MATERIAL */: {
|
|
883
|
+
const entityId = operands[0];
|
|
884
|
+
const material = {
|
|
885
|
+
color: operands[1] ?? 16777215,
|
|
886
|
+
metalness: operands[2] ?? 0,
|
|
887
|
+
roughness: operands[3] ?? 0.5,
|
|
888
|
+
emissive: operands[4] ?? 0,
|
|
889
|
+
opacity: operands[5] ?? 1
|
|
890
|
+
};
|
|
891
|
+
this.world.setComponent(entityId, 3 /* Material */, material);
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
case 50 /* SET_VISIBLE */: {
|
|
895
|
+
const entityId = operands[0];
|
|
896
|
+
const _visible = operands[1] !== 0;
|
|
897
|
+
const entity = this.world.getEntity(entityId);
|
|
898
|
+
if (entity) entity.dirty = true;
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
901
|
+
case 52 /* SET_LIGHT */: {
|
|
902
|
+
const entityId = operands[0];
|
|
903
|
+
const lightType = operands[1];
|
|
904
|
+
this.world.setComponent(entityId, 6 /* Light */, {
|
|
905
|
+
type: lightType,
|
|
906
|
+
params: operands.slice(2)
|
|
907
|
+
});
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
// ── Physics Operations ──────────────────────────────────────────────
|
|
911
|
+
case 32 /* ADD_RIGIDBODY */: {
|
|
912
|
+
const entityId = operands[0];
|
|
913
|
+
const rb = {
|
|
914
|
+
mass: operands[1],
|
|
915
|
+
bodyType: operands[2],
|
|
916
|
+
velocity: { x: 0, y: 0, z: 0 },
|
|
917
|
+
angularVelocity: { x: 0, y: 0, z: 0 }
|
|
918
|
+
};
|
|
919
|
+
this.world.setComponent(entityId, 4 /* RigidBody */, rb);
|
|
920
|
+
break;
|
|
921
|
+
}
|
|
922
|
+
case 33 /* APPLY_FORCE */: {
|
|
923
|
+
const entityId = operands[0];
|
|
924
|
+
const rb = this.world.getComponent(entityId, 4 /* RigidBody */);
|
|
925
|
+
if (rb && rb.mass > 0) {
|
|
926
|
+
const dt = 1 / 90;
|
|
927
|
+
rb.velocity.x += operands[1] / rb.mass * dt;
|
|
928
|
+
rb.velocity.y += operands[2] / rb.mass * dt;
|
|
929
|
+
rb.velocity.z += operands[3] / rb.mass * dt;
|
|
930
|
+
this.world.setComponent(entityId, 4 /* RigidBody */, rb);
|
|
931
|
+
}
|
|
932
|
+
break;
|
|
933
|
+
}
|
|
934
|
+
case 34 /* APPLY_IMPULSE */: {
|
|
935
|
+
const entityId = operands[0];
|
|
936
|
+
const rb = this.world.getComponent(entityId, 4 /* RigidBody */);
|
|
937
|
+
if (rb && rb.mass > 0) {
|
|
938
|
+
rb.velocity.x += operands[1] / rb.mass;
|
|
939
|
+
rb.velocity.y += operands[2] / rb.mass;
|
|
940
|
+
rb.velocity.z += operands[3] / rb.mass;
|
|
941
|
+
this.world.setComponent(entityId, 4 /* RigidBody */, rb);
|
|
942
|
+
}
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
case 35 /* SET_VELOCITY */: {
|
|
946
|
+
const entityId = operands[0];
|
|
947
|
+
const rb = this.world.getComponent(entityId, 4 /* RigidBody */);
|
|
948
|
+
if (rb) {
|
|
949
|
+
rb.velocity = {
|
|
950
|
+
x: operands[1],
|
|
951
|
+
y: operands[2],
|
|
952
|
+
z: operands[3]
|
|
953
|
+
};
|
|
954
|
+
this.world.setComponent(entityId, 4 /* RigidBody */, rb);
|
|
955
|
+
}
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
case 38 /* SET_GRAVITY */: {
|
|
959
|
+
this.world.setComponent(0, 255, { x: operands[0], y: operands[1], z: operands[2] });
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
// ── Trait Operations ────────────────────────────────────────────────
|
|
963
|
+
case 64 /* APPLY_TRAIT */: {
|
|
964
|
+
const entityId = operands[0];
|
|
965
|
+
const traitId = operands[1];
|
|
966
|
+
const entity = this.world.getEntity(entityId);
|
|
967
|
+
if (entity) {
|
|
968
|
+
entity.traits.add(traitId);
|
|
969
|
+
entity.dirty = true;
|
|
970
|
+
}
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
973
|
+
case 65 /* REMOVE_TRAIT */: {
|
|
974
|
+
const entityId = operands[0];
|
|
975
|
+
const traitId = operands[1];
|
|
976
|
+
const entity = this.world.getEntity(entityId);
|
|
977
|
+
if (entity) {
|
|
978
|
+
entity.traits.delete(traitId);
|
|
979
|
+
entity.dirty = true;
|
|
980
|
+
}
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
case 67 /* EMIT_EVENT */: {
|
|
984
|
+
const eventType = operands[0];
|
|
985
|
+
const payload = operands.slice(1);
|
|
986
|
+
this.eventQueue.push({ eventType, payload });
|
|
987
|
+
break;
|
|
988
|
+
}
|
|
989
|
+
// ── Control Flow ────────────────────────────────────────────────────
|
|
990
|
+
case 96 /* NOP */:
|
|
991
|
+
break;
|
|
992
|
+
case 97 /* JUMP */: {
|
|
993
|
+
frame.pc = operands[0];
|
|
994
|
+
break;
|
|
995
|
+
}
|
|
996
|
+
case 98 /* JUMP_IF */: {
|
|
997
|
+
const condition = this.pop();
|
|
998
|
+
if (condition) {
|
|
999
|
+
frame.pc = operands[0];
|
|
1000
|
+
}
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
case 99 /* CALL */: {
|
|
1004
|
+
const funcIdx = operands[0];
|
|
1005
|
+
this.callFunction(funcIdx);
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
case 100 /* RETURN */: {
|
|
1009
|
+
this.callStack.pop();
|
|
1010
|
+
if (this.callStack.length === 0) {
|
|
1011
|
+
this.status = "HALTED" /* Halted */;
|
|
1012
|
+
}
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
case 101 /* PUSH */: {
|
|
1016
|
+
this.push(operands[0]);
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
case 102 /* POP */: {
|
|
1020
|
+
this.pop();
|
|
1021
|
+
break;
|
|
1022
|
+
}
|
|
1023
|
+
case 103 /* STORE */: {
|
|
1024
|
+
const regIdx = operands[0];
|
|
1025
|
+
const value = this.pop();
|
|
1026
|
+
if (regIdx < frame.registers.length) {
|
|
1027
|
+
frame.registers[regIdx] = value;
|
|
1028
|
+
}
|
|
1029
|
+
break;
|
|
1030
|
+
}
|
|
1031
|
+
case 104 /* LOAD */: {
|
|
1032
|
+
const regIdx = operands[0];
|
|
1033
|
+
if (regIdx < frame.registers.length) {
|
|
1034
|
+
this.push(frame.registers[regIdx]);
|
|
1035
|
+
} else {
|
|
1036
|
+
this.push(null);
|
|
1037
|
+
}
|
|
1038
|
+
break;
|
|
1039
|
+
}
|
|
1040
|
+
case 105 /* HALT */: {
|
|
1041
|
+
this.status = "HALTED" /* Halted */;
|
|
1042
|
+
break;
|
|
1043
|
+
}
|
|
1044
|
+
case 106 /* YIELD */: {
|
|
1045
|
+
this.status = "YIELDED" /* Yielded */;
|
|
1046
|
+
break;
|
|
1047
|
+
}
|
|
1048
|
+
case 107 /* TIMER */: {
|
|
1049
|
+
const delayMs = operands[0];
|
|
1050
|
+
const handlerFunc = operands[1];
|
|
1051
|
+
this.timers.push({
|
|
1052
|
+
triggerTimeMs: this.currentTimeMs + delayMs,
|
|
1053
|
+
handlerFunctionIndex: handlerFunc
|
|
1054
|
+
});
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
// ── Arithmetic ──────────────────────────────────────────────────────
|
|
1058
|
+
case 108 /* ADD */: {
|
|
1059
|
+
const b = this.pop();
|
|
1060
|
+
const a = this.pop();
|
|
1061
|
+
this.push((a ?? 0) + (b ?? 0));
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
case 109 /* SUB */: {
|
|
1065
|
+
const b = this.pop();
|
|
1066
|
+
const a = this.pop();
|
|
1067
|
+
this.push((a ?? 0) - (b ?? 0));
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1070
|
+
case 110 /* MUL */: {
|
|
1071
|
+
const b = this.pop();
|
|
1072
|
+
const a = this.pop();
|
|
1073
|
+
this.push((a ?? 0) * (b ?? 0));
|
|
1074
|
+
break;
|
|
1075
|
+
}
|
|
1076
|
+
case 111 /* DIV */: {
|
|
1077
|
+
const b = this.pop();
|
|
1078
|
+
const a = this.pop();
|
|
1079
|
+
this.push(b !== 0 ? (a ?? 0) / b : 0);
|
|
1080
|
+
break;
|
|
1081
|
+
}
|
|
1082
|
+
// ── Comparison ──────────────────────────────────────────────────────
|
|
1083
|
+
case 128 /* CMP_EQ */: {
|
|
1084
|
+
const b = this.pop();
|
|
1085
|
+
const a = this.pop();
|
|
1086
|
+
this.push(a === b ? 1 : 0);
|
|
1087
|
+
break;
|
|
1088
|
+
}
|
|
1089
|
+
case 129 /* CMP_LT */: {
|
|
1090
|
+
const b = this.pop();
|
|
1091
|
+
const a = this.pop();
|
|
1092
|
+
this.push(a < b ? 1 : 0);
|
|
1093
|
+
break;
|
|
1094
|
+
}
|
|
1095
|
+
case 130 /* CMP_GT */: {
|
|
1096
|
+
const b = this.pop();
|
|
1097
|
+
const a = this.pop();
|
|
1098
|
+
this.push(a > b ? 1 : 0);
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
1101
|
+
case 131 /* NOT */: {
|
|
1102
|
+
const val = this.pop();
|
|
1103
|
+
this.push(val ? 0 : 1);
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
// ── Agent Bridge (stubs — filled in by host integration) ────────────
|
|
1107
|
+
case 112 /* AGENT_INVOKE */:
|
|
1108
|
+
case 113 /* AGENT_READ */:
|
|
1109
|
+
case 114 /* AGENT_SUBSCRIBE */:
|
|
1110
|
+
case 115 /* DIALOG_SHOW */:
|
|
1111
|
+
case 116 /* QUEST_UPDATE */:
|
|
1112
|
+
this.push(null);
|
|
1113
|
+
break;
|
|
1114
|
+
// ── I/O (stubs — filled in by host integration) ─────────────────────
|
|
1115
|
+
case 80 /* LOAD_ASSET */:
|
|
1116
|
+
case 81 /* PLAY_AUDIO */:
|
|
1117
|
+
case 82 /* NET_SYNC */:
|
|
1118
|
+
case 83 /* NET_SEND */:
|
|
1119
|
+
case 84 /* NET_RECV */:
|
|
1120
|
+
case 85 /* XR_INPUT */:
|
|
1121
|
+
case 86 /* HAPTIC */:
|
|
1122
|
+
this.push(null);
|
|
1123
|
+
break;
|
|
1124
|
+
// ── Spatial queries (stubs — need spatial index) ─────────────────────
|
|
1125
|
+
case 20 /* RAYCAST */:
|
|
1126
|
+
case 21 /* QUERY_BOX */:
|
|
1127
|
+
case 22 /* QUERY_SPHERE */:
|
|
1128
|
+
case 23 /* FIND_PATH */:
|
|
1129
|
+
case 24 /* GET_ZONE */:
|
|
1130
|
+
this.push(null);
|
|
1131
|
+
break;
|
|
1132
|
+
default:
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
// ── Stack operations ──────────────────────────────────────────────────────
|
|
1137
|
+
push(value) {
|
|
1138
|
+
if (this.stack.length >= this.maxStackSize) {
|
|
1139
|
+
this.status = "ERROR" /* Error */;
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
this.stack.push(value);
|
|
1143
|
+
}
|
|
1144
|
+
pop() {
|
|
1145
|
+
return this.stack.pop() ?? null;
|
|
1146
|
+
}
|
|
1147
|
+
// ── Call frame management ─────────────────────────────────────────────────
|
|
1148
|
+
get currentFrame() {
|
|
1149
|
+
return this.callStack[this.callStack.length - 1];
|
|
1150
|
+
}
|
|
1151
|
+
callFunction(funcIdx) {
|
|
1152
|
+
if (!this.bytecode) return;
|
|
1153
|
+
if (this.callStack.length >= this.maxCallDepth) {
|
|
1154
|
+
this.status = "ERROR" /* Error */;
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
const func = this.bytecode.functions[funcIdx];
|
|
1158
|
+
if (!func) {
|
|
1159
|
+
this.status = "ERROR" /* Error */;
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
const frame = {
|
|
1163
|
+
functionIndex: funcIdx,
|
|
1164
|
+
pc: 0,
|
|
1165
|
+
registers: new Array(func.registerCount).fill(null),
|
|
1166
|
+
stackBase: this.stack.length
|
|
1167
|
+
};
|
|
1168
|
+
this.callStack.push(frame);
|
|
1169
|
+
this.status = "RUNNING" /* Running */;
|
|
1170
|
+
}
|
|
1171
|
+
// ── Timer processing ──────────────────────────────────────────────────────
|
|
1172
|
+
processTimers() {
|
|
1173
|
+
const expired = [];
|
|
1174
|
+
this.timers = this.timers.filter((t) => {
|
|
1175
|
+
if (t.triggerTimeMs <= this.currentTimeMs) {
|
|
1176
|
+
expired.push(t);
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1179
|
+
return true;
|
|
1180
|
+
});
|
|
1181
|
+
for (const timer of expired) {
|
|
1182
|
+
this.callFunction(timer.handlerFunctionIndex);
|
|
1183
|
+
this.executeInstructions();
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
// ── Event dispatch ────────────────────────────────────────────────────────
|
|
1187
|
+
dispatchEvents() {
|
|
1188
|
+
if (!this.bytecode) return;
|
|
1189
|
+
const events = [...this.eventQueue];
|
|
1190
|
+
this.eventQueue = [];
|
|
1191
|
+
for (const event of events) {
|
|
1192
|
+
for (const binding of this.bytecode.events) {
|
|
1193
|
+
if (binding.eventType === event.eventType) {
|
|
1194
|
+
for (const p of event.payload) {
|
|
1195
|
+
this.push(p);
|
|
1196
|
+
}
|
|
1197
|
+
this.callFunction(binding.handlerFunctionIndex);
|
|
1198
|
+
this.executeInstructions();
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
// ── Utility ───────────────────────────────────────────────────────────────
|
|
1204
|
+
getString(index) {
|
|
1205
|
+
if (!this.bytecode) return "";
|
|
1206
|
+
return this.bytecode.strings[index] ?? `str_${index}`;
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Get current VM status
|
|
1210
|
+
*/
|
|
1211
|
+
getStatus() {
|
|
1212
|
+
return this.status;
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Get current stack snapshot (for debugging)
|
|
1216
|
+
*/
|
|
1217
|
+
getStack() {
|
|
1218
|
+
return [...this.stack];
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Get the tick count
|
|
1222
|
+
*/
|
|
1223
|
+
getTickCount() {
|
|
1224
|
+
return this.tickCount;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Queue an external event (e.g., from user input or network)
|
|
1228
|
+
*/
|
|
1229
|
+
queueEvent(eventType, ...payload) {
|
|
1230
|
+
this.eventQueue.push({ eventType, payload });
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
export {
|
|
1235
|
+
HoloOpCode,
|
|
1236
|
+
ComponentType,
|
|
1237
|
+
GeometryType,
|
|
1238
|
+
BodyType,
|
|
1239
|
+
ColliderShape,
|
|
1240
|
+
LightType,
|
|
1241
|
+
SyncTier,
|
|
1242
|
+
ValueType,
|
|
1243
|
+
getOpcodeFamily,
|
|
1244
|
+
getOpcodeName,
|
|
1245
|
+
isControlFlow,
|
|
1246
|
+
HOLOB_MAGIC,
|
|
1247
|
+
HOLOB_VERSION,
|
|
1248
|
+
HolobFlags,
|
|
1249
|
+
AssetType,
|
|
1250
|
+
HoloBytecodeBuilder,
|
|
1251
|
+
HoloFunctionBuilder,
|
|
1252
|
+
ECSWorld,
|
|
1253
|
+
VMStatus,
|
|
1254
|
+
HoloVM,
|
|
1255
|
+
vm_exports
|
|
1256
|
+
};
|