@series-inc/rundot-kinetix 0.0.0-bootstrap.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.
Files changed (58) hide show
  1. package/README.md +77 -0
  2. package/authoring.d.ts +30 -0
  3. package/index.d.ts +221 -0
  4. package/native/component_runtime.cpp +341 -0
  5. package/native/component_runtime.hpp +112 -0
  6. package/native/deterministic_math.cpp +594 -0
  7. package/native/deterministic_math.hpp +21 -0
  8. package/native/kinetix-f64-native-profile.cpp +406 -0
  9. package/native/kinetix-f64-native-profile.hpp +5 -0
  10. package/native/kinetix-fixed1000-native-profile.cpp +777 -0
  11. package/native/kinetix-fixed1000-native-profile.hpp +58 -0
  12. package/native/kinetix-fixed1000-physics.cpp +887 -0
  13. package/native/kinetix-fixed1000-physics.hpp +28 -0
  14. package/native/kinetix-installed-f64-renderer.cpp +344 -0
  15. package/native/kinetix-installed-f64-renderer.hpp +35 -0
  16. package/native/kinetix-installed-f64-runtime.cpp +1085 -0
  17. package/native/kinetix-installed-f64-runtime.hpp +141 -0
  18. package/native/kinetix-installed-fixed1000-data.hpp +77 -0
  19. package/native/kinetix-native-main.cpp +37 -0
  20. package/native/kinetix-native-runtime.cpp +20 -0
  21. package/native/kinetix-native-runtime.hpp +25 -0
  22. package/native/kinetix-render-projection.cpp +20 -0
  23. package/native/kinetix-render-projection.hpp +14 -0
  24. package/package.json +65 -0
  25. package/runtime.d.ts +76 -0
  26. package/scripts/build-native.mjs +67 -0
  27. package/scripts/emit-product-digests.mjs +33 -0
  28. package/scripts/preflight.mjs +76 -0
  29. package/src/index.mjs +57 -0
  30. package/src/kinetix-authoring.mjs +69 -0
  31. package/src/kinetix-baker.mjs +587 -0
  32. package/src/kinetix-deterministic-math.mjs +1044 -0
  33. package/src/kinetix-fixed1000-runtime-adapter.mjs +33 -0
  34. package/src/kinetix-fixed1000-runtime.mjs +954 -0
  35. package/src/kinetix-installed-f64-reference.mjs +157 -0
  36. package/src/kinetix-installed-f64-render-frames.mjs +53 -0
  37. package/src/kinetix-installed-f64-renderer.mjs +240 -0
  38. package/src/kinetix-installed-f64-runtime-adapter.mjs +68 -0
  39. package/src/kinetix-installed-f64-runtime.mjs +607 -0
  40. package/src/kinetix-installed-mechanics.mjs +377 -0
  41. package/src/kinetix-installed-systems.mjs +181 -0
  42. package/src/kinetix-native-product.mjs +72 -0
  43. package/src/kinetix-product-contract.mjs +121 -0
  44. package/src/kinetix-project-compiler.mjs +1017 -0
  45. package/src/kinetix-render-projection.mjs +28 -0
  46. package/src/kinetix-runtime-adapter-utils.mjs +168 -0
  47. package/src/kinetix-runtime-contract.mjs +54 -0
  48. package/src/kinetix-session-config.mjs +170 -0
  49. package/src/kinetix-source-snapshot.mjs +24 -0
  50. package/src/kinetix-survival-runtime-adapter.mjs +305 -0
  51. package/src/kinetix-survival-runtime.generated.mjs +1 -0
  52. package/src/kinetix-world-kernel.mjs +580 -0
  53. package/src/kinetix-world-runtime.mjs +171 -0
  54. package/src/runtime.mjs +14 -0
  55. package/src/shared/f64-bits.mjs +14 -0
  56. package/src/shared/kinetix-envelope-v1.mjs +589 -0
  57. package/src/shared/render-records-v1.mjs +168 -0
  58. package/src/shared/sha256.mjs +73 -0
@@ -0,0 +1,168 @@
1
+ // Render-record stream v1 encoder (docs/render-records-v1.md). Browser-safe,
2
+ // dependency-free; the C++ render core transliterates this exactly — the two
3
+ // serializations are byte-compared by GATE R.
4
+
5
+ export const RENDER_RECORDS_MAGIC = 0x52524331; // 'RRC1'
6
+
7
+ export const RECORD_CLEAR = 1;
8
+ export const RECORD_DRAW = 2;
9
+ export const RECORD_UPLOAD_TEXTURE = 3;
10
+ export const RECORD_DYNAMIC_BUFFER = 4;
11
+
12
+ class ByteWriter {
13
+ constructor() {
14
+ this.chunks = [];
15
+ this.length = 0;
16
+ }
17
+ push(bytes) {
18
+ this.chunks.push(bytes);
19
+ this.length += bytes.byteLength;
20
+ }
21
+ u8(value) {
22
+ this.push(Uint8Array.of(value & 0xff));
23
+ }
24
+ u32(value) {
25
+ const view = new DataView(new ArrayBuffer(4));
26
+ view.setUint32(0, value >>> 0, true);
27
+ this.push(new Uint8Array(view.buffer));
28
+ }
29
+ i32(value) {
30
+ const view = new DataView(new ArrayBuffer(4));
31
+ view.setInt32(0, value | 0, true);
32
+ this.push(new Uint8Array(view.buffer));
33
+ }
34
+ f32(value) {
35
+ const view = new DataView(new ArrayBuffer(4));
36
+ view.setFloat32(0, Math.fround(value), true);
37
+ this.push(new Uint8Array(view.buffer));
38
+ }
39
+ string(value) {
40
+ const bytes = new TextEncoder().encode(String(value));
41
+ this.u32(bytes.byteLength);
42
+ this.push(bytes);
43
+ }
44
+ bytes(bytes) {
45
+ this.u32(bytes.byteLength);
46
+ this.push(new Uint8Array(bytes.buffer ?? bytes, bytes.byteOffset ?? 0, bytes.byteLength));
47
+ }
48
+ concat() {
49
+ const out = new Uint8Array(this.length);
50
+ let offset = 0;
51
+ for (const chunk of this.chunks) {
52
+ out.set(chunk, offset);
53
+ offset += chunk.byteLength;
54
+ }
55
+ return out;
56
+ }
57
+ }
58
+
59
+ function writeBufferRef(writer, ref) {
60
+ if (ref.staticSha256) {
61
+ writer.u8(1);
62
+ writer.string(ref.staticSha256);
63
+ } else if (ref.dynamicSlot) {
64
+ writer.u8(2);
65
+ writer.string(ref.dynamicSlot);
66
+ } else {
67
+ throw new Error(`buffer ref needs staticSha256 or dynamicSlot: ${JSON.stringify(ref)}`);
68
+ }
69
+ }
70
+
71
+ function writeCommand(writer, command) {
72
+ writer.u8(command.kind);
73
+ if (command.kind === RECORD_CLEAR) {
74
+ writer.i32(command.fbId);
75
+ writer.u32(command.mask);
76
+ writer.u8(command.color ? 1 : 0);
77
+ if (command.color) for (const c of command.color) writer.f32(c);
78
+ writer.u8(command.depth === null || command.depth === undefined ? 0 : 1);
79
+ if (command.depth !== null && command.depth !== undefined) writer.f32(command.depth);
80
+ return;
81
+ }
82
+ if (command.kind === RECORD_DRAW) {
83
+ writer.string(command.programKey);
84
+ writer.i32(command.fbId);
85
+ writer.u32(command.mode);
86
+ writer.u32(command.count);
87
+ writer.u32(command.instanceCount ?? 1);
88
+ writer.u8(command.indexed ? 1 : 0);
89
+ if (command.indexed) {
90
+ writer.u32(command.indexType);
91
+ writer.u32(command.indexOffset ?? 0);
92
+ writeBufferRef(writer, command.elementBuffer);
93
+ }
94
+ writer.u8(command.blendOn ? 1 : 0);
95
+ writer.u8(command.frontFaceCW ? 1 : 0);
96
+ // v2 additions (magic stays 'RRC1'; all streams carry these)
97
+ writer.u8(command.cullEnabled ? 1 : 0);
98
+ writer.u8(command.depthTest ? 1 : 0);
99
+ writer.u8(command.depthMask ? 1 : 0);
100
+ if (typeof command.depthFunc !== 'number') throw new Error(`DRAW record missing depthFunc: ${command.programKey}`);
101
+ writer.u32(command.depthFunc);
102
+ for (const v of command.viewport) writer.u32(v);
103
+ writer.u32(command.uniforms.length);
104
+ for (const uniform of command.uniforms) {
105
+ writer.string(uniform.name);
106
+ writer.u32(uniform.glType);
107
+ writer.u32(uniform.values.length);
108
+ for (const value of uniform.values) writer.f32(value);
109
+ }
110
+ writer.u32(command.samplers.length);
111
+ for (const sampler of command.samplers) {
112
+ writer.string(sampler.name);
113
+ writer.u32(sampler.unit);
114
+ writer.string(sampler.textureKey);
115
+ }
116
+ writer.u32(command.attribs.length);
117
+ for (const attrib of command.attribs) {
118
+ writer.u32(attrib.location);
119
+ writer.u32(attrib.size);
120
+ writer.u32(attrib.glType);
121
+ writer.u8(attrib.normalized ? 1 : 0);
122
+ writer.u32(attrib.stride);
123
+ writer.u32(attrib.offset);
124
+ writer.u32(attrib.divisor);
125
+ writer.u8(attrib.integer ? 1 : 0);
126
+ writeBufferRef(writer, attrib.buffer);
127
+ }
128
+ return;
129
+ }
130
+ if (command.kind === RECORD_UPLOAD_TEXTURE) {
131
+ writer.string(command.textureKey);
132
+ writer.u32(command.width);
133
+ writer.u32(command.height);
134
+ writer.u32(command.format);
135
+ writer.u32(command.type);
136
+ writer.u32(command.internalformat);
137
+ writer.u8(command.flipY ? 1 : 0);
138
+ writer.u8(command.premultiply ? 1 : 0);
139
+ writer.u32(command.unpackAlignment);
140
+ writer.u32(command.minFilter);
141
+ writer.u32(command.magFilter);
142
+ writer.u32(command.wrapS);
143
+ writer.u32(command.wrapT);
144
+ writer.u8(command.generateMipmap ? 1 : 0); // v2
145
+ writer.bytes(command.bytes);
146
+ return;
147
+ }
148
+ if (command.kind === RECORD_DYNAMIC_BUFFER) {
149
+ writer.string(command.slotKey);
150
+ writer.bytes(command.bytes);
151
+ return;
152
+ }
153
+ throw new Error(`unknown record kind ${command.kind}`);
154
+ }
155
+
156
+ export function encodeRenderRecordStream(stream) {
157
+ const writer = new ByteWriter();
158
+ writer.u32(RENDER_RECORDS_MAGIC);
159
+ writer.u32(stream.viewport.width);
160
+ writer.u32(stream.viewport.height);
161
+ writer.u32(stream.frames.length);
162
+ for (const frame of stream.frames) {
163
+ writer.u32(frame.frameIndex);
164
+ writer.u32(frame.commands.length);
165
+ for (const command of frame.commands) writeCommand(writer, command);
166
+ }
167
+ return writer.concat();
168
+ }
@@ -0,0 +1,73 @@
1
+ const SHA256_K = new Uint32Array([
2
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
3
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
4
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
5
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
6
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
7
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
8
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
9
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
10
+ ]);
11
+
12
+ function rotr(x, n) {
13
+ return ((x >>> n) | (x << (32 - n))) >>> 0;
14
+ }
15
+
16
+ export function sha256Hex(bytes) {
17
+ const len = bytes.length;
18
+ const paddedLen = (((len + 8) >> 6) + 1) << 6;
19
+ const padded = new Uint8Array(paddedLen);
20
+ padded.set(bytes);
21
+ padded[len] = 0x80;
22
+ const dv = new DataView(padded.buffer);
23
+ dv.setUint32(paddedLen - 8, Math.floor(len / 0x20000000), false);
24
+ dv.setUint32(paddedLen - 4, (len << 3) >>> 0, false);
25
+
26
+ const h = new Uint32Array([
27
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
28
+ ]);
29
+ const w = new Uint32Array(64);
30
+ for (let offset = 0; offset < paddedLen; offset += 64) {
31
+ for (let i = 0; i < 16; i += 1) w[i] = dv.getUint32(offset + i * 4, false);
32
+ for (let i = 16; i < 64; i += 1) {
33
+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
34
+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
35
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
36
+ }
37
+ let a = h[0];
38
+ let b = h[1];
39
+ let cc = h[2];
40
+ let d = h[3];
41
+ let e = h[4];
42
+ let f = h[5];
43
+ let g = h[6];
44
+ let hh = h[7];
45
+ for (let i = 0; i < 64; i += 1) {
46
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
47
+ const ch = (e & f) ^ (~e & g);
48
+ const t1 = (hh + S1 + ch + SHA256_K[i] + w[i]) >>> 0;
49
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
50
+ const maj = (a & b) ^ (a & cc) ^ (b & cc);
51
+ const t2 = (S0 + maj) >>> 0;
52
+ hh = g;
53
+ g = f;
54
+ f = e;
55
+ e = (d + t1) >>> 0;
56
+ d = cc;
57
+ cc = b;
58
+ b = a;
59
+ a = (t1 + t2) >>> 0;
60
+ }
61
+ h[0] = (h[0] + a) >>> 0;
62
+ h[1] = (h[1] + b) >>> 0;
63
+ h[2] = (h[2] + cc) >>> 0;
64
+ h[3] = (h[3] + d) >>> 0;
65
+ h[4] = (h[4] + e) >>> 0;
66
+ h[5] = (h[5] + f) >>> 0;
67
+ h[6] = (h[6] + g) >>> 0;
68
+ h[7] = (h[7] + hh) >>> 0;
69
+ }
70
+ let hex = '';
71
+ for (let i = 0; i < 8; i += 1) hex += h[i].toString(16).padStart(8, '0');
72
+ return hex;
73
+ }