@vworlds/vecs-server 1.0.16

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 (90) hide show
  1. package/node_modules/@vworlds/vecs-protocol/package.json +14 -0
  2. package/node_modules/@vworlds/vecs-protocol/src/cid.d.ts +14 -0
  3. package/node_modules/@vworlds/vecs-protocol/src/cid.js +58 -0
  4. package/node_modules/@vworlds/vecs-protocol/src/cid.js.map +1 -0
  5. package/node_modules/@vworlds/vecs-protocol/src/index.d.ts +5 -0
  6. package/node_modules/@vworlds/vecs-protocol/src/index.js +5 -0
  7. package/node_modules/@vworlds/vecs-protocol/src/index.js.map +1 -0
  8. package/node_modules/@vworlds/vecs-protocol/src/messages.d.ts +42 -0
  9. package/node_modules/@vworlds/vecs-protocol/src/messages.js +149 -0
  10. package/node_modules/@vworlds/vecs-protocol/src/messages.js.map +1 -0
  11. package/node_modules/@vworlds/vecs-protocol/src/network_world.d.ts +18 -0
  12. package/node_modules/@vworlds/vecs-protocol/src/network_world.js +93 -0
  13. package/node_modules/@vworlds/vecs-protocol/src/network_world.js.map +1 -0
  14. package/node_modules/@vworlds/vecs-protocol/src/rpc.d.ts +36 -0
  15. package/node_modules/@vworlds/vecs-protocol/src/rpc.js +140 -0
  16. package/node_modules/@vworlds/vecs-protocol/src/rpc.js.map +1 -0
  17. package/node_modules/@vworlds/vecs-protocol/src/transport.d.ts +21 -0
  18. package/node_modules/@vworlds/vecs-protocol/src/transport.js +2 -0
  19. package/node_modules/@vworlds/vecs-protocol/src/transport.js.map +1 -0
  20. package/node_modules/@vworlds/vecs-wire/package.json +14 -0
  21. package/node_modules/@vworlds/vecs-wire/src/any.d.ts +27 -0
  22. package/node_modules/@vworlds/vecs-wire/src/any.js +43 -0
  23. package/node_modules/@vworlds/vecs-wire/src/any.js.map +1 -0
  24. package/node_modules/@vworlds/vecs-wire/src/decoder.d.ts +31 -0
  25. package/node_modules/@vworlds/vecs-wire/src/decoder.js +180 -0
  26. package/node_modules/@vworlds/vecs-wire/src/decoder.js.map +1 -0
  27. package/node_modules/@vworlds/vecs-wire/src/decorators.d.ts +4 -0
  28. package/node_modules/@vworlds/vecs-wire/src/decorators.js +139 -0
  29. package/node_modules/@vworlds/vecs-wire/src/decorators.js.map +1 -0
  30. package/node_modules/@vworlds/vecs-wire/src/encoder.d.ts +32 -0
  31. package/node_modules/@vworlds/vecs-wire/src/encoder.js +230 -0
  32. package/node_modules/@vworlds/vecs-wire/src/encoder.js.map +1 -0
  33. package/node_modules/@vworlds/vecs-wire/src/index.d.ts +5 -0
  34. package/node_modules/@vworlds/vecs-wire/src/index.js +5 -0
  35. package/node_modules/@vworlds/vecs-wire/src/index.js.map +1 -0
  36. package/package.json +28 -0
  37. package/vecs-protocol/src/cid.d.ts +14 -0
  38. package/vecs-protocol/src/cid.js +58 -0
  39. package/vecs-protocol/src/cid.js.map +1 -0
  40. package/vecs-protocol/src/index.d.ts +5 -0
  41. package/vecs-protocol/src/index.js +5 -0
  42. package/vecs-protocol/src/index.js.map +1 -0
  43. package/vecs-protocol/src/messages.d.ts +42 -0
  44. package/vecs-protocol/src/messages.js +149 -0
  45. package/vecs-protocol/src/messages.js.map +1 -0
  46. package/vecs-protocol/src/network_world.d.ts +18 -0
  47. package/vecs-protocol/src/network_world.js +93 -0
  48. package/vecs-protocol/src/network_world.js.map +1 -0
  49. package/vecs-protocol/src/rpc.d.ts +36 -0
  50. package/vecs-protocol/src/rpc.js +140 -0
  51. package/vecs-protocol/src/rpc.js.map +1 -0
  52. package/vecs-protocol/src/transport.d.ts +21 -0
  53. package/vecs-protocol/src/transport.js +2 -0
  54. package/vecs-protocol/src/transport.js.map +1 -0
  55. package/vecs-server/src/history.d.ts +14 -0
  56. package/vecs-server/src/history.js +104 -0
  57. package/vecs-server/src/history.js.map +1 -0
  58. package/vecs-server/src/index.d.ts +9 -0
  59. package/vecs-server/src/index.js +6 -0
  60. package/vecs-server/src/index.js.map +1 -0
  61. package/vecs-server/src/networked.d.ts +8 -0
  62. package/vecs-server/src/networked.js +13 -0
  63. package/vecs-server/src/networked.js.map +1 -0
  64. package/vecs-server/src/server_world.d.ts +34 -0
  65. package/vecs-server/src/server_world.js +215 -0
  66. package/vecs-server/src/server_world.js.map +1 -0
  67. package/vecs-server/src/vecs_listener.d.ts +11 -0
  68. package/vecs-server/src/vecs_listener.js +23 -0
  69. package/vecs-server/src/vecs_listener.js.map +1 -0
  70. package/vecs-server/src/view.d.ts +45 -0
  71. package/vecs-server/src/view.js +207 -0
  72. package/vecs-server/src/view.js.map +1 -0
  73. package/vecs-server/src/world_path.d.ts +1 -0
  74. package/vecs-server/src/world_path.js +4 -0
  75. package/vecs-server/src/world_path.js.map +1 -0
  76. package/vecs-wire/src/any.d.ts +27 -0
  77. package/vecs-wire/src/any.js +43 -0
  78. package/vecs-wire/src/any.js.map +1 -0
  79. package/vecs-wire/src/decoder.d.ts +31 -0
  80. package/vecs-wire/src/decoder.js +180 -0
  81. package/vecs-wire/src/decoder.js.map +1 -0
  82. package/vecs-wire/src/decorators.d.ts +4 -0
  83. package/vecs-wire/src/decorators.js +139 -0
  84. package/vecs-wire/src/decorators.js.map +1 -0
  85. package/vecs-wire/src/encoder.d.ts +32 -0
  86. package/vecs-wire/src/encoder.js +230 -0
  87. package/vecs-wire/src/encoder.js.map +1 -0
  88. package/vecs-wire/src/index.d.ts +5 -0
  89. package/vecs-wire/src/index.js +5 -0
  90. package/vecs-wire/src/index.js.map +1 -0
@@ -0,0 +1,230 @@
1
+ import { AnyType, TagSize } from "./any.js";
2
+ function canBeFloat(value) {
3
+ if (value === 0 || !Number.isFinite(value) || Number.isNaN(value)) {
4
+ return true;
5
+ }
6
+ const floatMin = -3.4028235e38;
7
+ const floatMax = 3.4028235e38;
8
+ if (value < floatMin || value > floatMax) {
9
+ return false;
10
+ }
11
+ return value === Math.fround(value);
12
+ }
13
+ function assertBigIntRange(value, min, max, method) {
14
+ if (value < min || value > max) {
15
+ throw new RangeError(`vecs-wire/encoder ${method}: value ${value} is out of range`);
16
+ }
17
+ }
18
+ function assertIntegerRange(value, min, max, method) {
19
+ if (!Number.isInteger(value) || value < min || value > max) {
20
+ throw new RangeError(`vecs-wire/encoder ${method}: value ${value} is out of range`);
21
+ }
22
+ }
23
+ export class Encoder {
24
+ constructor(buffer) {
25
+ this._cursor = 0;
26
+ this._buffer = buffer;
27
+ }
28
+ getBuffer() {
29
+ return this._buffer.subarray(0, this._cursor);
30
+ }
31
+ reset() {
32
+ this._cursor = 0;
33
+ }
34
+ get length() {
35
+ return this._cursor;
36
+ }
37
+ write_varint_u32(value) {
38
+ assertIntegerRange(value, 0, 0xffffffff, "write_varint_u32");
39
+ while (value > 0x7f) {
40
+ if (this._cursor >= this._buffer.length) {
41
+ throw new RangeError("vecs-wire/encoder write_varint_u32: Attempt to write beyond buffer size");
42
+ }
43
+ this._buffer[this._cursor++] = (value & 0x7f) | 0x80;
44
+ value >>>= 7;
45
+ }
46
+ if (this._cursor >= this._buffer.length) {
47
+ throw new RangeError("vecs-wire/encoder write_varint_u32: Attempt to write beyond buffer size");
48
+ }
49
+ this._buffer[this._cursor++] = value;
50
+ }
51
+ write_varint_u64(value) {
52
+ assertBigIntRange(value, 0n, 0xffffffffffffffffn, "write_varint_u64");
53
+ while (value > 0x7fn) {
54
+ if (this._cursor >= this._buffer.length) {
55
+ throw new RangeError("vecs-wire/encoder write_varint_u64: Attempt to write beyond buffer size");
56
+ }
57
+ this._buffer[this._cursor++] = Number((value & 0x7fn) | 0x80n);
58
+ value >>= 7n;
59
+ }
60
+ if (this._cursor >= this._buffer.length) {
61
+ throw new RangeError("vecs-wire/encoder write_varint_u64: Attempt to write beyond buffer size");
62
+ }
63
+ this._buffer[this._cursor++] = Number(value);
64
+ }
65
+ encode_zz_u32(value) {
66
+ return ((value << 1) ^ (value >> 31)) >>> 0;
67
+ }
68
+ encode_zz_u64(value) {
69
+ return (value << 1n) ^ (value >> 63n);
70
+ }
71
+ write_u8(value) {
72
+ assertIntegerRange(value, 0, 0xff, "write_u8");
73
+ if (this._cursor >= this._buffer.length) {
74
+ throw new RangeError("vecs-wire/encoder write_u8: Attempt to write beyond buffer size");
75
+ }
76
+ this._buffer[this._cursor++] = value;
77
+ }
78
+ write_i8(value) {
79
+ assertIntegerRange(value, -0x80, 0x7f, "write_i8");
80
+ this.write_u8(value & 0xff);
81
+ }
82
+ write_bool(value) {
83
+ this.write_u8(value ? 1 : 0);
84
+ }
85
+ write_u16(value) {
86
+ assertIntegerRange(value, 0, 0xffff, "write_u16");
87
+ this.write_varint_u32(value);
88
+ }
89
+ write_u32(value) {
90
+ assertIntegerRange(value, 0, 0xffffffff, "write_u32");
91
+ this.write_varint_u32(value);
92
+ }
93
+ write_u64(value) {
94
+ assertBigIntRange(value, 0n, 0xffffffffffffffffn, "write_u64");
95
+ this.write_varint_u64(value);
96
+ }
97
+ write_i16(value) {
98
+ assertIntegerRange(value, -0x8000, 0x7fff, "write_i16");
99
+ this.write_varint_u32(this.encode_zz_u32(value));
100
+ }
101
+ write_i32(value) {
102
+ assertIntegerRange(value, -0x80000000, 0x7fffffff, "write_i32");
103
+ this.write_varint_u32(this.encode_zz_u32(value));
104
+ }
105
+ write_enum(value) {
106
+ this.write_i32(value);
107
+ }
108
+ write_i64(value) {
109
+ assertBigIntRange(value, -0x8000000000000000n, 0x7fffffffffffffffn, "write_i64");
110
+ this.write_varint_u64(this.encode_zz_u64(value));
111
+ }
112
+ write_f32(value) {
113
+ if (this._cursor + 4 > this._buffer.length) {
114
+ throw new RangeError("vecs-wire/encoder write_f32: Attempt to write beyond buffer size");
115
+ }
116
+ new DataView(this._buffer.buffer, this._buffer.byteOffset + this._cursor, 4).setFloat32(0, value, true);
117
+ this._cursor += 4;
118
+ }
119
+ write_f64(value) {
120
+ if (this._cursor + 8 > this._buffer.length) {
121
+ throw new RangeError("vecs-wire/encoder write_f64: Attempt to write beyond buffer size");
122
+ }
123
+ new DataView(this._buffer.buffer, this._buffer.byteOffset + this._cursor, 8).setFloat64(0, value, true);
124
+ this._cursor += 8;
125
+ }
126
+ _write_buffer_raw(data, len = data.length) {
127
+ if (this._cursor + len > this._buffer.length) {
128
+ throw new RangeError("vecs-wire/encoder write_buffer: Attempt to write beyond buffer size");
129
+ }
130
+ this._buffer.set(data.subarray(0, len), this._cursor);
131
+ this._cursor += len;
132
+ }
133
+ write_buffer(data, len = data.length) {
134
+ this.write_u32(len);
135
+ this._write_buffer_raw(data, len);
136
+ }
137
+ write_string(value) {
138
+ const encodedString = new TextEncoder().encode(value);
139
+ this.write_u32(encodedString.length);
140
+ this._write_buffer_raw(encodedString, encodedString.length);
141
+ }
142
+ write_any(value) {
143
+ switch (typeof value) {
144
+ case "undefined":
145
+ this.write(new TagSize(AnyType.undefined, 1));
146
+ break;
147
+ case "boolean":
148
+ this.write(new TagSize(AnyType.boolean, value ? 1 : 2));
149
+ break;
150
+ case "string": {
151
+ const encodedString = new TextEncoder().encode(value);
152
+ if (encodedString.length === 0) {
153
+ this.write(new TagSize(AnyType.empty_string, 1));
154
+ }
155
+ else {
156
+ this.write(new TagSize(AnyType.string, encodedString.length));
157
+ this._write_buffer_raw(encodedString, encodedString.length);
158
+ }
159
+ break;
160
+ }
161
+ case "number":
162
+ if (Number.isInteger(value)) {
163
+ this.write(new TagSize(AnyType.number_integer, 8));
164
+ this.write_i64(BigInt(value));
165
+ }
166
+ else if (canBeFloat(value)) {
167
+ this.write(new TagSize(AnyType.number_float, 4));
168
+ this.write_f32(value);
169
+ }
170
+ else {
171
+ this.write(new TagSize(AnyType.number_float, 8));
172
+ this.write_f64(value);
173
+ }
174
+ break;
175
+ case "bigint":
176
+ if (value < 0n) {
177
+ this.write(new TagSize(AnyType.bigint_integer, 8));
178
+ this.write_i64(value);
179
+ }
180
+ else {
181
+ this.write(new TagSize(AnyType.bigint_unsigned, 8));
182
+ this.write_u64(value);
183
+ }
184
+ break;
185
+ case "object":
186
+ if (value === null) {
187
+ this.write(new TagSize(AnyType.null, 1));
188
+ }
189
+ else if (value instanceof Uint8Array) {
190
+ this.write(new TagSize(AnyType.binary, value.length));
191
+ this._write_buffer_raw(value);
192
+ }
193
+ else if (Array.isArray(value)) {
194
+ if (value.length === 0) {
195
+ this.write(new TagSize(AnyType.empty_array, 1));
196
+ }
197
+ else {
198
+ this.write(new TagSize(AnyType.array, value.length));
199
+ value.forEach((v) => {
200
+ this.write_any(v);
201
+ });
202
+ }
203
+ }
204
+ else {
205
+ const entries = Object.entries(value);
206
+ if (entries.length === 0) {
207
+ this.write(new TagSize(AnyType.empty_object, 1));
208
+ }
209
+ else {
210
+ this.write(new TagSize(AnyType.object, entries.length));
211
+ entries.forEach(([key, entryValue]) => {
212
+ this.write_string(key);
213
+ this.write_any(entryValue);
214
+ });
215
+ }
216
+ }
217
+ break;
218
+ default:
219
+ throw new Error(`Unsupported type ${typeof value} encoding any`);
220
+ }
221
+ }
222
+ write(value) {
223
+ const encodable = value;
224
+ if (typeof encodable.wireEncode !== "function") {
225
+ throw new TypeError("vecs-wire/encoder write requires a wireEncode method");
226
+ }
227
+ encodable.wireEncode(this);
228
+ }
229
+ }
230
+ //# sourceMappingURL=encoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../../../vecs-wire/src/encoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAM5C,SAAS,UAAU,CAAC,KAAa;IAC/B,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,YAAY,CAAC;IAC/B,MAAM,QAAQ,GAAG,YAAY,CAAC;IAC9B,IAAI,KAAK,GAAG,QAAQ,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;QACzC,OAAO,KAAK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CAAC,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export { AnyType, TagSize } from "./any.js";
2
+ export { type } from "./decorators.js";
3
+ export type { WireConstructor, WireScalarType, WireTypeSpec } from "./decorators.js";
4
+ export { Decoder, type DecodableType, type IDecodable } from "./decoder.js";
5
+ export { Encoder, type IEncodable } from "./encoder.js";
@@ -0,0 +1,5 @@
1
+ export { AnyType, TagSize } from "./any.js";
2
+ export { type } from "./decorators.js";
3
+ export { Decoder } from "./decoder.js";
4
+ export { Encoder } from "./encoder.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../vecs-wire/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAuC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAmB,MAAM,cAAc,CAAC"}
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@vworlds/vecs-server",
3
+ "version": "1.0.16",
4
+ "type": "module",
5
+ "main": "./vecs-server/src/index.js",
6
+ "types": "./vecs-server/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./vecs-server/src/index.d.ts",
10
+ "default": "./vecs-server/src/index.js"
11
+ }
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/vworlds/vecs.git"
16
+ },
17
+ "dependencies": {
18
+ "@vworlds/vecs": "1.0.16",
19
+ "@vworlds/vecs-protocol": "1.0.16",
20
+ "@vworlds/vecs-wire": "1.0.16",
21
+ "@vworlds/dgram-server": "^1.0.7"
22
+ },
23
+ "bundleDependencies": [
24
+ "@vworlds/vecs-protocol",
25
+ "@vworlds/vecs-wire"
26
+ ],
27
+ "license": "UNLICENSED"
28
+ }
@@ -0,0 +1,14 @@
1
+ /** A component id packs an entity id and component type id into a uint32. */
2
+ export type CID = number;
3
+ /** Component type ids below this value can fit into packed wire component ids. */
4
+ export declare let LOCAL_COMPONENT_MIN: number;
5
+ /** Protocol removal marker for all components on an entity. */
6
+ export declare const ALL_COMPONENTS = 0;
7
+ /** Return the configured local component minimum after validating its alignment. */
8
+ export declare function getLocalComponentMin(): number;
9
+ /** Configure the local component type range before constructing networked worlds. */
10
+ export declare function setLocalComponentMin(value: number): void;
11
+ /** Pack an entity id and component type id into a uint32 component id. */
12
+ export declare function cid_pack(eid: number, type: number): CID;
13
+ /** Unpack a uint32 component id into [entity id, component type id]. */
14
+ export declare function cid_unpack(cid: CID): [eid: number, type: number];
@@ -0,0 +1,58 @@
1
+ /** Component type ids below this value can fit into packed wire component ids. */
2
+ export let LOCAL_COMPONENT_MIN = 256;
3
+ /** Protocol removal marker for all components on an entity. */
4
+ export const ALL_COMPONENTS = 0;
5
+ let componentTypeMask = LOCAL_COMPONENT_MIN - 1;
6
+ let componentTypeShift = Math.log2(LOCAL_COMPONENT_MIN);
7
+ let MAX_ENTITY_ID = 2 ** (32 - componentTypeShift) - 1;
8
+ let MAX_COMPONENT_TYPE = componentTypeMask;
9
+ function validateLocalComponentMin(value) {
10
+ if (!isAlignedLocalComponentMin(value)) {
11
+ throw new Error("LOCAL_COMPONENT_MIN must be a power-of-two safe integer >= 2");
12
+ }
13
+ if (Math.log2(value) > 31) {
14
+ throw new Error("LOCAL_COMPONENT_MIN must reserve fewer than 32 component type bits");
15
+ }
16
+ }
17
+ function isAlignedLocalComponentMin(value) {
18
+ return Number.isSafeInteger(value) && value >= 2 && (value & (value - 1)) === 0;
19
+ }
20
+ /** Return the configured local component minimum after validating its alignment. */
21
+ export function getLocalComponentMin() {
22
+ validateLocalComponentMin(LOCAL_COMPONENT_MIN);
23
+ return LOCAL_COMPONENT_MIN;
24
+ }
25
+ /** Configure the local component type range before constructing networked worlds. */
26
+ export function setLocalComponentMin(value) {
27
+ LOCAL_COMPONENT_MIN = value;
28
+ if (isAlignedLocalComponentMin(value)) {
29
+ getLocalComponentMin();
30
+ componentTypeMask = LOCAL_COMPONENT_MIN - 1;
31
+ componentTypeShift = Math.log2(LOCAL_COMPONENT_MIN);
32
+ MAX_ENTITY_ID = 2 ** (32 - componentTypeShift) - 1;
33
+ MAX_COMPONENT_TYPE = componentTypeMask;
34
+ }
35
+ }
36
+ /** Pack an entity id and component type id into a uint32 component id. */
37
+ export function cid_pack(eid, type) {
38
+ if (eid < 0) {
39
+ throw new Error(`cid_pack: entity id must be non-negative, got ${eid}`);
40
+ }
41
+ if (eid > MAX_ENTITY_ID) {
42
+ throw new Error(`cid_pack: entity id ${eid} exceeds maximum ${MAX_ENTITY_ID} for LOCAL_COMPONENT_MIN=${LOCAL_COMPONENT_MIN}. ` +
43
+ `Increase LOCAL_COMPONENT_MIN or use a smaller entity id.`);
44
+ }
45
+ if (type < 0) {
46
+ throw new Error(`cid_pack: type id must be non-negative, got ${type}`);
47
+ }
48
+ if (type > MAX_COMPONENT_TYPE) {
49
+ throw new Error(`cid_pack: type id ${type} exceeds maximum component type ${MAX_COMPONENT_TYPE}. ` +
50
+ `Ensure type id is less than LOCAL_COMPONENT_MIN=${LOCAL_COMPONENT_MIN}.`);
51
+ }
52
+ return ((eid << componentTypeShift) | (type & componentTypeMask)) >>> 0;
53
+ }
54
+ /** Unpack a uint32 component id into [entity id, component type id]. */
55
+ export function cid_unpack(cid) {
56
+ return [cid >>> componentTypeShift, cid & componentTypeMask];
57
+ }
58
+ //# sourceMappingURL=cid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cid.js","sourceRoot":"","sources":["../../../../vecs-protocol/src/cid.ts"],"names":[],"mappings":"AAGA,kFAAkF;AAClF,MAAM,CAAC,IAAI,mBAAmB,GAAG,GAAG,CAAC;AAErC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,IAAI,iBAAiB,GA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AC;IACzC,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,QAAQ,CAAC,GAAW,EAAE,IAAY;IAChD,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,iDAAiD,GAAG,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,GAAG,GAAG,aAAa,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,uBAAuB,GAAG,oBAAoB,aAAa,4BAA4B,mBAAmB,IAAI;YAC5G,0DAA0D,CAC7D,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,IAAI,GAAG,kBAAkB,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,mCAAmC,kBAAkB,IAAI;YAChF,mDAAmD,mBAAmB,GAAG,CAC5E,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,IAAI,kBAAkB,CAAC,GAAG,CAAC,IAAI,GAAG,iBAAiB,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,OAAO,CAAC,GAAG,KAAK,kBAAkB,EAAE,GAAG,GAAG,iBAAiB,CAAC,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { ALL_COMPONENTS, LOCAL_COMPONENT_MIN, cid_pack, cid_unpack, getLocalComponentMin, setLocalComponentMin, type CID, } from "./cid.js";
2
+ export { NetworkWorld, type NetworkWorldOptions, type RegisteredNetworkComponent, } from "./network_world.js";
3
+ export { Client2Server, ComponentSnapshot, EncodedSnapshot, Server2Client, StateDiff, type RemovedComponent, } from "./messages.js";
4
+ export { FIRST_USER_RPC_ID, RPC, RPC_RESPONSE_ID, RPC_TIMEOUT_ERROR, SessionRPC, type RPCHandler, } from "./rpc.js";
5
+ export type { ConnectionError, VecsSocket, VecsSocketEvents, VecsSocketListener, VecsSocketListenerEvents, } from "./transport.js";
@@ -0,0 +1,5 @@
1
+ export { ALL_COMPONENTS, LOCAL_COMPONENT_MIN, cid_pack, cid_unpack, getLocalComponentMin, setLocalComponentMin, } from "./cid.js";
2
+ export { NetworkWorld, } from "./network_world.js";
3
+ export { Client2Server, ComponentSnapshot, EncodedSnapshot, Server2Client, StateDiff, } from "./messages.js";
4
+ export { FIRST_USER_RPC_ID, RPC, RPC_RESPONSE_ID, RPC_TIMEOUT_ERROR, SessionRPC, } from "./rpc.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../vecs-protocol/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,UAAU,EACV,oBAAoB,EACpB,oBAAoB,GAErB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,GAAG,EACH,eAAe,EACf,iBAAiB,EACjB,UAAU,GAEX,MAAM,UAAU,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { Decoder, Encoder, type IEncodable } from "@vworlds/vecs-wire";
2
+ import { RPC } from "./rpc.js";
3
+ export declare class ComponentSnapshot implements IEncodable {
4
+ eid: number;
5
+ type: number;
6
+ payload: Uint8Array;
7
+ constructor(values?: Partial<ComponentSnapshot>);
8
+ wireEncode(encoder: Encoder): void;
9
+ static wireDecode(decoder: Decoder): ComponentSnapshot;
10
+ }
11
+ export declare class EncodedSnapshot {
12
+ bytes: Uint8Array;
13
+ eid: number;
14
+ type: number;
15
+ constructor(bytes: Uint8Array, // contains an already-encoded ComponentSnapshot
16
+ eid?: number, type?: number);
17
+ }
18
+ export type RemovedComponent = [eid: number, type: number];
19
+ export declare class StateDiff implements IEncodable {
20
+ toFrame: number;
21
+ fromFrame: number;
22
+ snapshots: EncodedSnapshot[];
23
+ removed: RemovedComponent[];
24
+ constructor(values?: Partial<StateDiff>);
25
+ wireEncode(encoder: Encoder): void;
26
+ static wireDecode(decoder: Decoder): StateDiff;
27
+ }
28
+ export declare class Server2Client implements IEncodable {
29
+ diff: StateDiff | undefined;
30
+ rpc: RPC[];
31
+ constructor(values?: Partial<Server2Client>);
32
+ wireEncode(encoder: Encoder): void;
33
+ static wireDecode(decoder: Decoder): Server2Client;
34
+ }
35
+ export declare class Client2Server implements IEncodable {
36
+ ackFrame: number;
37
+ input: unknown | undefined;
38
+ rpc: RPC[];
39
+ constructor(values?: Partial<Client2Server>);
40
+ wireEncode(encoder: Encoder): void;
41
+ static wireDecode(decoder: Decoder): Client2Server;
42
+ }
@@ -0,0 +1,149 @@
1
+ import { cid_pack, cid_unpack } from "./cid.js";
2
+ import { RPC } from "./rpc.js";
3
+ const FIELD_DIFF = 1;
4
+ const FIELD_RPC = 2;
5
+ const FIELD_INPUT = 3;
6
+ export class ComponentSnapshot {
7
+ constructor(values) {
8
+ this.eid = 0;
9
+ this.type = 0;
10
+ this.payload = new Uint8Array();
11
+ if (values) {
12
+ Object.assign(this, values);
13
+ }
14
+ }
15
+ wireEncode(encoder) {
16
+ encoder.write_u32(cid_pack(this.eid, this.type));
17
+ encoder.write_buffer(this.payload);
18
+ }
19
+ static wireDecode(decoder) {
20
+ const [eid, type] = cid_unpack(decoder.read_u32());
21
+ return new ComponentSnapshot({
22
+ eid,
23
+ type,
24
+ payload: decoder.read_bytes(),
25
+ });
26
+ }
27
+ }
28
+ export class EncodedSnapshot {
29
+ constructor(bytes, // contains an already-encoded ComponentSnapshot
30
+ eid = 0, type = 0) {
31
+ this.bytes = bytes;
32
+ this.eid = eid;
33
+ this.type = type;
34
+ }
35
+ }
36
+ export class StateDiff {
37
+ constructor(values) {
38
+ this.toFrame = 0;
39
+ this.fromFrame = 0;
40
+ this.snapshots = [];
41
+ this.removed = [];
42
+ if (values) {
43
+ Object.assign(this, values);
44
+ }
45
+ }
46
+ wireEncode(encoder) {
47
+ encoder.write_u32(this.toFrame);
48
+ encoder.write_u32(this.fromFrame);
49
+ encoder.write_u32(this.snapshots.length);
50
+ this.snapshots.forEach((snapshot) => encoder.write_buffer(snapshot.bytes));
51
+ encoder.write_u32(this.removed.length);
52
+ this.removed.forEach(([eid, type]) => encoder.write_u32(cid_pack(eid, type)));
53
+ }
54
+ static wireDecode(decoder) {
55
+ const diff = new StateDiff({ toFrame: decoder.read_u32(), fromFrame: decoder.read_u32() });
56
+ const snapshotCount = decoder.read_u32();
57
+ for (let i = 0; i < snapshotCount; i++) {
58
+ diff.snapshots.push(new EncodedSnapshot(decoder.read_bytes()));
59
+ }
60
+ const removedCount = decoder.read_u32();
61
+ for (let i = 0; i < removedCount; i++) {
62
+ diff.removed.push(cid_unpack(decoder.read_u32()));
63
+ }
64
+ return diff;
65
+ }
66
+ }
67
+ export class Server2Client {
68
+ constructor(values) {
69
+ this.rpc = [];
70
+ if (values) {
71
+ Object.assign(this, values);
72
+ }
73
+ }
74
+ wireEncode(encoder) {
75
+ if (this.diff) {
76
+ encoder.write_u8(FIELD_DIFF);
77
+ encoder.write(this.diff);
78
+ }
79
+ if (this.rpc.length > 0) {
80
+ encoder.write_u8(FIELD_RPC);
81
+ encoder.write_u32(this.rpc.length);
82
+ this.rpc.forEach((rpc) => encoder.write(rpc));
83
+ }
84
+ }
85
+ static wireDecode(decoder) {
86
+ const message = new Server2Client();
87
+ while (!decoder.EOF) {
88
+ const tag = decoder.read_u8();
89
+ switch (tag) {
90
+ case FIELD_DIFF:
91
+ message.diff = decoder.read(StateDiff);
92
+ break;
93
+ case FIELD_RPC: {
94
+ const count = decoder.read_u32();
95
+ for (let i = 0; i < count; i++) {
96
+ message.rpc.push(decoder.read(RPC));
97
+ }
98
+ break;
99
+ }
100
+ default:
101
+ throw new Error(`Invalid Server2Client field tag ${tag}`);
102
+ }
103
+ }
104
+ return message;
105
+ }
106
+ }
107
+ export class Client2Server {
108
+ constructor(values) {
109
+ this.ackFrame = 0;
110
+ this.rpc = [];
111
+ if (values) {
112
+ Object.assign(this, values);
113
+ }
114
+ }
115
+ wireEncode(encoder) {
116
+ encoder.write_u32(this.ackFrame);
117
+ if (this.input !== undefined) {
118
+ encoder.write_u8(FIELD_INPUT);
119
+ encoder.write_any(this.input);
120
+ }
121
+ if (this.rpc.length > 0) {
122
+ encoder.write_u8(FIELD_RPC);
123
+ encoder.write_u32(this.rpc.length);
124
+ this.rpc.forEach((rpc) => encoder.write(rpc));
125
+ }
126
+ }
127
+ static wireDecode(decoder) {
128
+ const message = new Client2Server({ ackFrame: decoder.read_u32() });
129
+ while (!decoder.EOF) {
130
+ const tag = decoder.read_u8();
131
+ switch (tag) {
132
+ case FIELD_INPUT:
133
+ message.input = decoder.read_any();
134
+ break;
135
+ case FIELD_RPC: {
136
+ const count = decoder.read_u32();
137
+ for (let i = 0; i < count; i++) {
138
+ message.rpc.push(decoder.read(RPC));
139
+ }
140
+ break;
141
+ }
142
+ default:
143
+ throw new Error(`Invalid Client2Server field tag ${tag}`);
144
+ }
145
+ }
146
+ return message;
147
+ }
148
+ }
149
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../../vecs-protocol/src/messages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,MAAM,OAAO,iBAAiB;IAK5B,YAAmB,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AC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACpE,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;YACpB,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YAC9B,QAAQ,GAAG,EAAE,CAAC;gBACZ,KAAK,WAAW;oBACd,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;oBACnC,MAAM;gBACR,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;oBACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;wBAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;oBACtC,CAAC;oBACD,MAAM;gBACR,CAAC;gBACD;oBACE,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,EAAE,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import { World, type ComponentClass, type WorldOptions } from "@vworlds/vecs";
2
+ export interface RegisteredNetworkComponent {
3
+ Class: ComponentClass;
4
+ type: number;
5
+ }
6
+ export interface NetworkWorldOptions extends Omit<WorldOptions, "idPools"> {
7
+ networkComponents?: readonly ComponentClass[];
8
+ entityIdStart?: number;
9
+ localEntityIdStart?: number;
10
+ networkEntityReuseWaitFrames?: number;
11
+ }
12
+ export declare class NetworkWorld extends World {
13
+ readonly localComponentMin: number;
14
+ readonly networkComponents: readonly RegisteredNetworkComponent[];
15
+ private readonly _networkComponentsByType;
16
+ constructor(options?: NetworkWorldOptions);
17
+ getNetworkComponent(type: number): RegisteredNetworkComponent | undefined;
18
+ }