@dcl/ecs 1.0.0-20220506152015.commit-2dd9f0a
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/README.md +18 -0
- package/dist/built-in-types/ArrayType.d.ts +3 -0
- package/dist/built-in-types/ArrayType.d.ts.map +1 -0
- package/dist/built-in-types/ArrayType.js +23 -0
- package/dist/built-in-types/ArrayType.js.map +1 -0
- package/dist/built-in-types/EcsType.d.ts +6 -0
- package/dist/built-in-types/EcsType.d.ts.map +1 -0
- package/dist/built-in-types/EcsType.js +3 -0
- package/dist/built-in-types/EcsType.js.map +1 -0
- package/dist/built-in-types/MapType.d.ts +10 -0
- package/dist/built-in-types/MapType.d.ts.map +1 -0
- package/dist/built-in-types/MapType.js +24 -0
- package/dist/built-in-types/MapType.js.map +1 -0
- package/dist/built-in-types/Optional.d.ts +3 -0
- package/dist/built-in-types/Optional.d.ts.map +1 -0
- package/dist/built-in-types/Optional.js +24 -0
- package/dist/built-in-types/Optional.js.map +1 -0
- package/dist/built-in-types/basic/Boolean.d.ts +3 -0
- package/dist/built-in-types/basic/Boolean.d.ts.map +1 -0
- package/dist/built-in-types/basic/Boolean.js +12 -0
- package/dist/built-in-types/basic/Boolean.js.map +1 -0
- package/dist/built-in-types/basic/Enum.d.ts +3 -0
- package/dist/built-in-types/basic/Enum.d.ts.map +1 -0
- package/dist/built-in-types/basic/Enum.js +15 -0
- package/dist/built-in-types/basic/Enum.js.map +1 -0
- package/dist/built-in-types/basic/Float.d.ts +4 -0
- package/dist/built-in-types/basic/Float.d.ts.map +1 -0
- package/dist/built-in-types/basic/Float.js +20 -0
- package/dist/built-in-types/basic/Float.js.map +1 -0
- package/dist/built-in-types/basic/Integer.d.ts +6 -0
- package/dist/built-in-types/basic/Integer.d.ts.map +1 -0
- package/dist/built-in-types/basic/Integer.js +44 -0
- package/dist/built-in-types/basic/Integer.js.map +1 -0
- package/dist/built-in-types/basic/String.d.ts +4 -0
- package/dist/built-in-types/basic/String.d.ts.map +1 -0
- package/dist/built-in-types/basic/String.js +13 -0
- package/dist/built-in-types/basic/String.js.map +1 -0
- package/dist/built-in-types/index.d.ts +10 -0
- package/dist/built-in-types/index.d.ts.map +1 -0
- package/dist/built-in-types/index.js +26 -0
- package/dist/built-in-types/index.js.map +1 -0
- package/dist/built-in-types/typing.d.ts +17 -0
- package/dist/built-in-types/typing.d.ts.map +1 -0
- package/dist/built-in-types/typing.js +3 -0
- package/dist/built-in-types/typing.js.map +1 -0
- package/dist/components/definitions/BoxShape.proto +13 -0
- package/dist/components/definitions/README.md +0 -0
- package/dist/components/definitions/Transform.md +0 -0
- package/dist/components/generated/BoxShape.d.ts +5 -0
- package/dist/components/generated/BoxShape.d.ts.map +1 -0
- package/dist/components/generated/BoxShape.js +17 -0
- package/dist/components/generated/BoxShape.js.map +1 -0
- package/dist/components/generated/index.d.ts +5 -0
- package/dist/components/generated/index.d.ts.map +1 -0
- package/dist/components/generated/index.js +34 -0
- package/dist/components/generated/index.js.map +1 -0
- package/dist/components/generated/pb/BoxShape.d.ts +13 -0
- package/dist/components/generated/pb/BoxShape.d.ts.map +1 -0
- package/dist/components/generated/pb/BoxShape.js +91 -0
- package/dist/components/generated/pb/BoxShape.js.map +1 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +26 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/legacy/Transform.d.ts +10 -0
- package/dist/components/legacy/Transform.d.ts.map +1 -0
- package/dist/components/legacy/Transform.js +29 -0
- package/dist/components/legacy/Transform.js.map +1 -0
- package/dist/components/legacy/index.d.ts +10 -0
- package/dist/components/legacy/index.d.ts.map +1 -0
- package/dist/components/legacy/index.js +14 -0
- package/dist/components/legacy/index.js.map +1 -0
- package/dist/components/legacy/types.d.ts +52 -0
- package/dist/components/legacy/types.d.ts.map +1 -0
- package/dist/components/legacy/types.js +57 -0
- package/dist/components/legacy/types.js.map +1 -0
- package/dist/components/types.d.ts +4 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/types.js +8 -0
- package/dist/components/types.js.map +1 -0
- package/dist/ecs.api.json +418 -0
- package/dist/engine/component.d.ts +26 -0
- package/dist/engine/component.d.ts.map +1 -0
- package/dist/engine/component.js +103 -0
- package/dist/engine/component.js.map +1 -0
- package/dist/engine/entity-utils.d.ts +8 -0
- package/dist/engine/entity-utils.d.ts.map +1 -0
- package/dist/engine/entity-utils.js +22 -0
- package/dist/engine/entity-utils.js.map +1 -0
- package/dist/engine/entity.d.ts +18 -0
- package/dist/engine/entity.d.ts.map +1 -0
- package/dist/engine/entity.js +80 -0
- package/dist/engine/entity.js.map +1 -0
- package/dist/engine/index.d.ts +46 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +139 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/types.d.ts +10 -0
- package/dist/engine/types.d.ts.map +1 -0
- package/dist/engine/types.js +3 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/engine/utils.d.ts +4 -0
- package/dist/engine/utils.d.ts.map +1 -0
- package/dist/engine/utils.js +17 -0
- package/dist/engine/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/serialization/ByteBuffer/index.d.ts +120 -0
- package/dist/serialization/ByteBuffer/index.d.ts.map +1 -0
- package/dist/serialization/ByteBuffer/index.js +272 -0
- package/dist/serialization/ByteBuffer/index.js.map +1 -0
- package/dist/serialization/crdt/componentOperation.d.ts +26 -0
- package/dist/serialization/crdt/componentOperation.d.ts.map +1 -0
- package/dist/serialization/crdt/componentOperation.js +46 -0
- package/dist/serialization/crdt/componentOperation.js.map +1 -0
- package/dist/serialization/wireMessage.d.ts +40 -0
- package/dist/serialization/wireMessage.d.ts.map +1 -0
- package/dist/serialization/wireMessage.js +57 -0
- package/dist/serialization/wireMessage.js.map +1 -0
- package/dist/systems/crdt/index.d.ts +12 -0
- package/dist/systems/crdt/index.d.ts.map +1 -0
- package/dist/systems/crdt/index.js +121 -0
- package/dist/systems/crdt/index.js.map +1 -0
- package/dist/systems/crdt/transport.d.ts +2 -0
- package/dist/systems/crdt/transport.d.ts.map +1 -0
- package/dist/systems/crdt/transport.js +8 -0
- package/dist/systems/crdt/transport.js.map +1 -0
- package/dist/systems/crdt/utils.d.ts +14 -0
- package/dist/systems/crdt/utils.d.ts.map +1 -0
- package/dist/systems/crdt/utils.js +54 -0
- package/dist/systems/crdt/utils.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +45 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createByteBuffer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Take the max between currentSize and intendedSize and then plus 1024. Then,
|
|
6
|
+
* find the next nearer multiple of 1024.
|
|
7
|
+
* @param currentSize - number
|
|
8
|
+
* @param intendedSize - number
|
|
9
|
+
* @returns the calculated number
|
|
10
|
+
*/
|
|
11
|
+
function getNextSize(currentSize, intendedSize) {
|
|
12
|
+
const minNewSize = Math.max(currentSize, intendedSize) + 1024;
|
|
13
|
+
return Math.ceil(minNewSize / 1024) * 1024;
|
|
14
|
+
}
|
|
15
|
+
const defaultInitialCapacity = 10240;
|
|
16
|
+
/**
|
|
17
|
+
* ByteBuffer is a wrapper of DataView which also adds a read and write offset.
|
|
18
|
+
* Also in a write operation it resizes the buffer is being used if it needs.
|
|
19
|
+
*
|
|
20
|
+
* - Use read and write function to generate or consume data.
|
|
21
|
+
* - Use set and get only if you are sure that you're doing.
|
|
22
|
+
*/
|
|
23
|
+
function createByteBuffer(options = {}) {
|
|
24
|
+
const initialROffset = options.reading?.currentOffset || 0;
|
|
25
|
+
let initialBuffer = null;
|
|
26
|
+
let initialWOffset = 0;
|
|
27
|
+
if (options.writing) {
|
|
28
|
+
initialBuffer = options.writing.buffer;
|
|
29
|
+
if (options.writing.currentOffset) {
|
|
30
|
+
initialWOffset = options.writing.currentOffset;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (options.reading) {
|
|
34
|
+
initialBuffer = options.reading.buffer;
|
|
35
|
+
initialWOffset = options.reading.length || options.reading.buffer.length;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
initialBuffer = new Uint8Array(options.initialCapacity || defaultInitialCapacity);
|
|
39
|
+
}
|
|
40
|
+
let buffer = initialBuffer;
|
|
41
|
+
let view = new DataView(buffer.buffer, buffer.byteOffset);
|
|
42
|
+
let woffset = initialWOffset;
|
|
43
|
+
let roffset = initialROffset;
|
|
44
|
+
/**
|
|
45
|
+
* Increement the write offset and resize the buffer if it needs.
|
|
46
|
+
*/
|
|
47
|
+
const woAdd = (amount) => {
|
|
48
|
+
if (woffset + amount > buffer.byteLength) {
|
|
49
|
+
const newsize = getNextSize(buffer.byteLength, woffset + amount);
|
|
50
|
+
const newBuffer = new Uint8Array(newsize);
|
|
51
|
+
newBuffer.set(buffer);
|
|
52
|
+
buffer = newBuffer;
|
|
53
|
+
view = new DataView(buffer.buffer);
|
|
54
|
+
}
|
|
55
|
+
woffset += amount;
|
|
56
|
+
return woffset - amount;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Increment the read offset and throw an error if it's trying to read
|
|
60
|
+
* outside the bounds.
|
|
61
|
+
*/
|
|
62
|
+
const roAdd = (amount) => {
|
|
63
|
+
if (roffset + amount > woffset) {
|
|
64
|
+
throw new Error('Outside of the bounds of writen data.');
|
|
65
|
+
}
|
|
66
|
+
roffset += amount;
|
|
67
|
+
return roffset - amount;
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
/**
|
|
71
|
+
* @returns The entire current Uint8Array.
|
|
72
|
+
*
|
|
73
|
+
* WARNING: if the buffer grows, the view had changed itself,
|
|
74
|
+
* and the reference will be a invalid one.
|
|
75
|
+
*/
|
|
76
|
+
buffer() {
|
|
77
|
+
return buffer;
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* @returns The capacity of the current buffer
|
|
81
|
+
*/
|
|
82
|
+
bufferLength() {
|
|
83
|
+
return buffer.length;
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Reading purpose
|
|
87
|
+
* Returns the previuos offsset size before incrementing
|
|
88
|
+
*/
|
|
89
|
+
incrementReadOffset(amount) {
|
|
90
|
+
return roAdd(amount);
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* @returns The current read offset.
|
|
94
|
+
*/
|
|
95
|
+
currentReadOffset() {
|
|
96
|
+
return roffset;
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* @returns How many bytes are available to read.
|
|
100
|
+
*/
|
|
101
|
+
remainingBytes() {
|
|
102
|
+
return woffset - roffset;
|
|
103
|
+
},
|
|
104
|
+
readFloat32() {
|
|
105
|
+
return view.getFloat32(roAdd(4));
|
|
106
|
+
},
|
|
107
|
+
readFloat64() {
|
|
108
|
+
return view.getFloat64(roAdd(8));
|
|
109
|
+
},
|
|
110
|
+
readInt8() {
|
|
111
|
+
return view.getInt8(roAdd(1));
|
|
112
|
+
},
|
|
113
|
+
readInt16() {
|
|
114
|
+
return view.getInt16(roAdd(2));
|
|
115
|
+
},
|
|
116
|
+
readInt32() {
|
|
117
|
+
return view.getInt32(roAdd(4));
|
|
118
|
+
},
|
|
119
|
+
readInt64() {
|
|
120
|
+
return view.getBigInt64(roAdd(8));
|
|
121
|
+
},
|
|
122
|
+
readUint8() {
|
|
123
|
+
return view.getUint8(roAdd(1));
|
|
124
|
+
},
|
|
125
|
+
readUint16() {
|
|
126
|
+
return view.getUint16(roAdd(2));
|
|
127
|
+
},
|
|
128
|
+
readUint32() {
|
|
129
|
+
return view.getUint32(roAdd(4));
|
|
130
|
+
},
|
|
131
|
+
readUint64() {
|
|
132
|
+
return view.getBigUint64(roAdd(8));
|
|
133
|
+
},
|
|
134
|
+
readBuffer() {
|
|
135
|
+
const length = view.getUint32(roAdd(4));
|
|
136
|
+
return buffer.subarray(roAdd(length), roAdd(0));
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Writing purpose
|
|
140
|
+
*/
|
|
141
|
+
/**
|
|
142
|
+
* Increment offset
|
|
143
|
+
* @param amount - how many bytes
|
|
144
|
+
* @returns The offset when this reserving starts.
|
|
145
|
+
*/
|
|
146
|
+
incrementWriteOffset(amount) {
|
|
147
|
+
return woAdd(amount);
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* @returns The total number of bytes writen in the buffer.
|
|
151
|
+
*/
|
|
152
|
+
size() {
|
|
153
|
+
return woffset;
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* @returns The subarray from 0 to offset.
|
|
157
|
+
*/
|
|
158
|
+
toBinary() {
|
|
159
|
+
return buffer.subarray(0, woffset);
|
|
160
|
+
},
|
|
161
|
+
writeBuffer(value, writeLength = true) {
|
|
162
|
+
if (writeLength) {
|
|
163
|
+
this.writeUint32(value.byteLength);
|
|
164
|
+
}
|
|
165
|
+
const o = woAdd(value.buffer.byteLength);
|
|
166
|
+
buffer.set(value, o);
|
|
167
|
+
},
|
|
168
|
+
writeFloat32(value) {
|
|
169
|
+
const o = woAdd(4);
|
|
170
|
+
view.setFloat32(o, value);
|
|
171
|
+
},
|
|
172
|
+
writeFloat64(value) {
|
|
173
|
+
const o = woAdd(8);
|
|
174
|
+
view.setFloat64(o, value);
|
|
175
|
+
},
|
|
176
|
+
writeInt8(value) {
|
|
177
|
+
const o = woAdd(1);
|
|
178
|
+
view.setInt8(o, value);
|
|
179
|
+
},
|
|
180
|
+
writeInt16(value) {
|
|
181
|
+
const o = woAdd(2);
|
|
182
|
+
view.setInt16(o, value);
|
|
183
|
+
},
|
|
184
|
+
writeInt32(value) {
|
|
185
|
+
const o = woAdd(4);
|
|
186
|
+
view.setInt32(o, value);
|
|
187
|
+
},
|
|
188
|
+
writeInt64(value) {
|
|
189
|
+
const o = woAdd(8);
|
|
190
|
+
view.setBigInt64(o, value);
|
|
191
|
+
},
|
|
192
|
+
writeUint8(value) {
|
|
193
|
+
const o = woAdd(1);
|
|
194
|
+
view.setUint8(o, value);
|
|
195
|
+
},
|
|
196
|
+
writeUint16(value) {
|
|
197
|
+
const o = woAdd(2);
|
|
198
|
+
view.setUint16(o, value);
|
|
199
|
+
},
|
|
200
|
+
writeUint32(value) {
|
|
201
|
+
const o = woAdd(4);
|
|
202
|
+
view.setUint32(o, value);
|
|
203
|
+
},
|
|
204
|
+
writeUint64(value) {
|
|
205
|
+
const o = woAdd(8);
|
|
206
|
+
view.setBigUint64(o, value);
|
|
207
|
+
},
|
|
208
|
+
// Dataview Proxy
|
|
209
|
+
getFloat32(offset) {
|
|
210
|
+
return view.getFloat32(offset);
|
|
211
|
+
},
|
|
212
|
+
getFloat64(offset) {
|
|
213
|
+
return view.getFloat64(offset);
|
|
214
|
+
},
|
|
215
|
+
getInt8(offset) {
|
|
216
|
+
return view.getInt8(offset);
|
|
217
|
+
},
|
|
218
|
+
getInt16(offset) {
|
|
219
|
+
return view.getInt16(offset);
|
|
220
|
+
},
|
|
221
|
+
getInt32(offset) {
|
|
222
|
+
return view.getInt32(offset);
|
|
223
|
+
},
|
|
224
|
+
getInt64(offset) {
|
|
225
|
+
return view.getBigInt64(offset);
|
|
226
|
+
},
|
|
227
|
+
getUint8(offset) {
|
|
228
|
+
return view.getUint8(offset);
|
|
229
|
+
},
|
|
230
|
+
getUint16(offset) {
|
|
231
|
+
return view.getUint16(offset);
|
|
232
|
+
},
|
|
233
|
+
getUint32(offset) {
|
|
234
|
+
return view.getUint32(offset);
|
|
235
|
+
},
|
|
236
|
+
getUint64(offset) {
|
|
237
|
+
return view.getBigUint64(offset);
|
|
238
|
+
},
|
|
239
|
+
setFloat32(offset, value) {
|
|
240
|
+
view.setFloat32(offset, value);
|
|
241
|
+
},
|
|
242
|
+
setFloat64(offset, value) {
|
|
243
|
+
view.setFloat64(offset, value);
|
|
244
|
+
},
|
|
245
|
+
setInt8(offset, value) {
|
|
246
|
+
view.setInt8(offset, value);
|
|
247
|
+
},
|
|
248
|
+
setInt16(offset, value) {
|
|
249
|
+
view.setInt16(offset, value);
|
|
250
|
+
},
|
|
251
|
+
setInt32(offset, value) {
|
|
252
|
+
view.setInt32(offset, value);
|
|
253
|
+
},
|
|
254
|
+
setInt64(offset, value) {
|
|
255
|
+
view.setBigInt64(offset, value);
|
|
256
|
+
},
|
|
257
|
+
setUint8(offset, value) {
|
|
258
|
+
view.setUint8(offset, value);
|
|
259
|
+
},
|
|
260
|
+
setUint16(offset, value) {
|
|
261
|
+
view.setUint16(offset, value);
|
|
262
|
+
},
|
|
263
|
+
setUint32(offset, value) {
|
|
264
|
+
view.setUint32(offset, value);
|
|
265
|
+
},
|
|
266
|
+
setUint64(offset, value) {
|
|
267
|
+
view.setBigUint64(offset, value);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
exports.createByteBuffer = createByteBuffer;
|
|
272
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/serialization/ByteBuffer/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,WAAmB,EAAE,YAAoB;IAC5D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,IAAI,CAAA;IAC7D,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;AAC5C,CAAC;AA+BD,MAAM,sBAAsB,GAAG,KAAK,CAAA;AAEpC;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,UAAmC,EAAE;IACpE,MAAM,cAAc,GAAW,OAAO,CAAC,OAAO,EAAE,aAAa,IAAI,CAAC,CAAA;IAClE,IAAI,aAAa,G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,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAChC,CAAC;QAED,OAAO,CAAC,MAAc,EAAE,KAAa;YACnC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC7B,CAAC;QAED,QAAQ,CAAC,MAAc,EAAE,KAAa;YACpC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC9B,CAAC;QAED,QAAQ,CAAC,MAAc,EAAE,KAAa;YACpC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC9B,CAAC;QAED,QAAQ,CAAC,MAAc,EAAE,KAAa;YACpC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACjC,CAAC;QAED,QAAQ,CAAC,MAAc,EAAE,KAAa;YACpC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC9B,CAAC;QAED,SAAS,CAAC,MAAc,EAAE,KAAa;YACrC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC/B,CAAC;QAED,SAAS,CAAC,MAAc,EAAE,KAAa;YACrC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAC/B,CAAC;QAED,SAAS,CAAC,MAAc,EAAE,KAAa;YACrC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QAClC,CAAC;KACF,CAAA;AACH,CAAC;AA7SD,4CA6SC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ComponentDefinition } from '../../engine/component';
|
|
2
|
+
import { Entity } from '../../engine/entity';
|
|
3
|
+
import { ByteBuffer } from '../ByteBuffer';
|
|
4
|
+
import WireMessage from '../wireMessage';
|
|
5
|
+
export declare namespace PutComponentOperation {
|
|
6
|
+
/**
|
|
7
|
+
* @param entityId - Uint32 number of the entity
|
|
8
|
+
* @param componentId - Uint32 number of id
|
|
9
|
+
* @param timestamp - Uint64 Lamport timestamp
|
|
10
|
+
* @param data - Uint8[] data of component
|
|
11
|
+
*/
|
|
12
|
+
type Type = {
|
|
13
|
+
entityId: Entity;
|
|
14
|
+
componentId: number;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
data: Uint8Array;
|
|
17
|
+
};
|
|
18
|
+
const MESSAGE_HEADER_LENGTH = 20;
|
|
19
|
+
/**
|
|
20
|
+
* Call this function for an optimal writing data passing the ByteBuffer
|
|
21
|
+
* already allocated
|
|
22
|
+
*/
|
|
23
|
+
function write(entityId: Entity, timestamp: number, componentDefinition: ComponentDefinition, buf: ByteBuffer): void;
|
|
24
|
+
function read(buf: ByteBuffer): (WireMessage.Header & Type) | null;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=componentOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentOperation.d.ts","sourceRoot":"","sources":["../../../src/serialization/crdt/componentOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,WAAW,MAAM,gBAAgB,CAAA;AAExC,yBAAiB,qBAAqB,CAAC;IACrC;;;;;OAKG;IACH,KAAY,IAAI,GAAG;QACjB,QAAQ,EAAE,MAAM,CAAA;QAChB,WAAW,EAAE,MAAM,CAAA;QACnB,SAAS,EAAE,MAAM,CAAA;QACjB,IAAI,EAAE,UAAU,CAAA;KACjB,CAAA;IAEM,MAAM,qBAAqB,KAAK,CAAA;IACvC;;;OAGG;IACH,SAAgB,KAAK,CACnB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,mBAAmB,EAAE,mBAAmB,EACxC,GAAG,EAAE,UAAU,QAuBhB;IAED,SAAgB,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,CAcxE;CACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PutComponentOperation = void 0;
|
|
7
|
+
const wireMessage_1 = __importDefault(require("../wireMessage"));
|
|
8
|
+
var PutComponentOperation;
|
|
9
|
+
(function (PutComponentOperation) {
|
|
10
|
+
PutComponentOperation.MESSAGE_HEADER_LENGTH = 20;
|
|
11
|
+
/**
|
|
12
|
+
* Call this function for an optimal writing data passing the ByteBuffer
|
|
13
|
+
* already allocated
|
|
14
|
+
*/
|
|
15
|
+
function write(entityId, timestamp, componentDefinition, buf) {
|
|
16
|
+
// reserve the beginning
|
|
17
|
+
const startMessageOffset = buf.incrementWriteOffset(wireMessage_1.default.HEADER_LENGTH + PutComponentOperation.MESSAGE_HEADER_LENGTH);
|
|
18
|
+
// write body
|
|
19
|
+
componentDefinition.writeToByteBuffer(entityId, buf);
|
|
20
|
+
const messageLength = buf.size() - startMessageOffset;
|
|
21
|
+
// Write WireMessage header
|
|
22
|
+
buf.setUint32(startMessageOffset, messageLength);
|
|
23
|
+
buf.setUint32(startMessageOffset + 4, wireMessage_1.default.Enum.PUT_COMPONENT);
|
|
24
|
+
// Write ComponentOperation header
|
|
25
|
+
buf.setUint32(startMessageOffset + 8, entityId);
|
|
26
|
+
buf.setUint32(startMessageOffset + 12, componentDefinition._id);
|
|
27
|
+
buf.setUint64(startMessageOffset + 16, BigInt(timestamp));
|
|
28
|
+
buf.setUint32(startMessageOffset + 24, messageLength - PutComponentOperation.MESSAGE_HEADER_LENGTH - wireMessage_1.default.HEADER_LENGTH);
|
|
29
|
+
}
|
|
30
|
+
PutComponentOperation.write = write;
|
|
31
|
+
function read(buf) {
|
|
32
|
+
const header = wireMessage_1.default.readHeader(buf);
|
|
33
|
+
if (!header) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
...header,
|
|
38
|
+
entityId: buf.readUint32(),
|
|
39
|
+
componentId: buf.readInt32(),
|
|
40
|
+
timestamp: Number(buf.readUint64()),
|
|
41
|
+
data: buf.readBuffer()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
PutComponentOperation.read = read;
|
|
45
|
+
})(PutComponentOperation = exports.PutComponentOperation || (exports.PutComponentOperation = {}));
|
|
46
|
+
//# sourceMappingURL=componentOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentOperation.js","sourceRoot":"","sources":["../../../src/serialization/crdt/componentOperation.ts"],"names":[],"mappings":";;;;;;AAGA,iEAAwC;AAExC,IAAiB,qBAAqB,CA+DrC;AA/DD,WAAiB,qBAAqB;IAcvB,2CAAqB,GAAG,EAAE,CAAA;IACvC;;;OAGG;IACH,SAAgB,KAAK,CACnB,QAAgB,EAChB,SAAiB,EACjB,mBAAwC,EACxC,GAAe;QAEf,wBAAwB;QACxB,MAAM,kBAAkB,GAAG,GAAG,CAAC,oBAAoB,CACjD,qBAAW,CAAC,aAAa,GAAG,sBAAA,qBAAqB,CAClD,CAAA;QAED,aAAa;QACb,mBAAmB,CAAC,iBAAiB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;QACpD,MAAM,aAAa,GAAG,GAAG,CAAC,IAAI,EAAE,GAAG,kBAAkB,CAAA;QAErD,2BAA2B;QAC3B,GAAG,CAAC,SAAS,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAA;QAChD,GAAG,CAAC,SAAS,CAAC,kBAAkB,GAAG,CAAC,EAAE,qBAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAErE,kCAAkC;QAClC,GAAG,CAAC,SAAS,CAAC,kBAAkB,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAA;QAC/C,GAAG,CAAC,SAAS,CAAC,kBAAkB,GAAG,EAAE,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAA;QAC/D,GAAG,CAAC,SAAS,CAAC,kBAAkB,GAAG,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;QACzD,GAAG,CAAC,SAAS,CACX,kBAAkB,GAAG,EAAE,EACvB,aAAa,GAAG,sBAAA,qBAAqB,GAAG,qBAAW,CAAC,aAAa,CAClE,CAAA;IACH,CAAC;IA3Be,2BAAK,QA2BpB,CAAA;IAED,SAAgB,IAAI,CAAC,GAAe;QAClC,MAAM,MAAM,GAAG,qBAAW,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QAE1C,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,IAAI,CAAA;SACZ;QAED,OAAO;YACL,GAAG,MAAM;YACT,QAAQ,EAAE,GAAG,CAAC,UAAU,EAAY;YACpC,WAAW,EAAE,GAAG,CAAC,SAAS,EAAE;YAC5B,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;YACnC,IAAI,EAAE,GAAG,CAAC,UAAU,EAAE;SACvB,CAAA;IACH,CAAC;IAde,0BAAI,OAcnB,CAAA;AACH,CAAC,EA/DgB,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QA+DrC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire message is the top-level message that can be packed
|
|
3
|
+
* inside it can contain a data with another structure or protocol
|
|
4
|
+
*
|
|
5
|
+
* Each wire message has three primitive property that it'll never change
|
|
6
|
+
* ---> length uint32 (message size up to 4,294,967,295)
|
|
7
|
+
* ---> version uint32 (for now just a number which is zero)
|
|
8
|
+
* ---> message type uint32
|
|
9
|
+
* The length indicates how many bytes are above self, the version in
|
|
10
|
+
* combination with message type defines the set of handlers that will be
|
|
11
|
+
* available to process the message
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
import { ByteBuffer } from './ByteBuffer';
|
|
15
|
+
declare type Uint32 = number;
|
|
16
|
+
export declare namespace WireMessage {
|
|
17
|
+
enum Enum {
|
|
18
|
+
RESERVED = 0,
|
|
19
|
+
PUT_COMPONENT = 1,
|
|
20
|
+
DELETE_COMPONENT = 2,
|
|
21
|
+
MAX_MESSAGE_TYPE = 3
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @param length - Uint32 the length of all message (including the header)
|
|
25
|
+
* @param type - define the function which handles the data
|
|
26
|
+
*/
|
|
27
|
+
type Header = {
|
|
28
|
+
length: Uint32;
|
|
29
|
+
type: Uint32;
|
|
30
|
+
};
|
|
31
|
+
const HEADER_LENGTH = 8;
|
|
32
|
+
/**
|
|
33
|
+
* Validate if the message incoming is completed
|
|
34
|
+
* @param buf
|
|
35
|
+
*/
|
|
36
|
+
function validate(buf: ByteBuffer): boolean;
|
|
37
|
+
function readHeader(buf: ByteBuffer): Header | null;
|
|
38
|
+
}
|
|
39
|
+
export default WireMessage;
|
|
40
|
+
//# sourceMappingURL=wireMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wireMessage.d.ts","sourceRoot":"","sources":["../../src/serialization/wireMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,aAAK,MAAM,GAAG,MAAM,CAAA;AAEpB,yBAAiB,WAAW,CAAC;IAC3B,KAAY,IAAI;QACd,QAAQ,IAAI;QAGZ,aAAa,IAAI;QACjB,gBAAgB,IAAI;QAGpB,gBAAgB,IAAA;KACjB;IAED;;;OAGG;IACH,KAAY,MAAM,GAAG;QACnB,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IAEM,MAAM,aAAa,IAAI,CAAA;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,WAYvC;IAED,SAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CASzD;CACF;AAED,eAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The wire message is the top-level message that can be packed
|
|
4
|
+
* inside it can contain a data with another structure or protocol
|
|
5
|
+
*
|
|
6
|
+
* Each wire message has three primitive property that it'll never change
|
|
7
|
+
* ---> length uint32 (message size up to 4,294,967,295)
|
|
8
|
+
* ---> version uint32 (for now just a number which is zero)
|
|
9
|
+
* ---> message type uint32
|
|
10
|
+
* The length indicates how many bytes are above self, the version in
|
|
11
|
+
* combination with message type defines the set of handlers that will be
|
|
12
|
+
* available to process the message
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.WireMessage = void 0;
|
|
17
|
+
var WireMessage;
|
|
18
|
+
(function (WireMessage) {
|
|
19
|
+
let Enum;
|
|
20
|
+
(function (Enum) {
|
|
21
|
+
Enum[Enum["RESERVED"] = 0] = "RESERVED";
|
|
22
|
+
// Component Operation
|
|
23
|
+
Enum[Enum["PUT_COMPONENT"] = 1] = "PUT_COMPONENT";
|
|
24
|
+
Enum[Enum["DELETE_COMPONENT"] = 2] = "DELETE_COMPONENT";
|
|
25
|
+
// TODO: ?
|
|
26
|
+
Enum[Enum["MAX_MESSAGE_TYPE"] = 3] = "MAX_MESSAGE_TYPE";
|
|
27
|
+
})(Enum = WireMessage.Enum || (WireMessage.Enum = {}));
|
|
28
|
+
WireMessage.HEADER_LENGTH = 8;
|
|
29
|
+
/**
|
|
30
|
+
* Validate if the message incoming is completed
|
|
31
|
+
* @param buf
|
|
32
|
+
*/
|
|
33
|
+
function validate(buf) {
|
|
34
|
+
const rem = buf.remainingBytes();
|
|
35
|
+
if (rem < WireMessage.HEADER_LENGTH) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const messageLength = buf.getUint32(buf.currentReadOffset());
|
|
39
|
+
if (rem < messageLength) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
WireMessage.validate = validate;
|
|
45
|
+
function readHeader(buf) {
|
|
46
|
+
if (!validate(buf)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
length: buf.readUint32(),
|
|
51
|
+
type: buf.readUint32()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
WireMessage.readHeader = readHeader;
|
|
55
|
+
})(WireMessage = exports.WireMessage || (exports.WireMessage = {}));
|
|
56
|
+
exports.default = WireMessage;
|
|
57
|
+
//# sourceMappingURL=wireMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wireMessage.js","sourceRoot":"","sources":["../../src/serialization/wireMessage.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAMH,IAAiB,WAAW,CAkD3B;AAlDD,WAAiB,WAAW;IAC1B,IAAY,IASX;IATD,WAAY,IAAI;QACd,uCAAY,CAAA;QAEZ,sBAAsB;QACtB,iDAAiB,CAAA;QACjB,uDAAoB,CAAA;QAEpB,UAAU;QACV,uDAAgB,CAAA;IAClB,CAAC,EATW,IAAI,GAAJ,gBAAI,KAAJ,gBAAI,QASf;IAWY,yBAAa,GAAG,CAAC,CAAA;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CAAC,GAAe;QACtC,MAAM,GAAG,GAAG,GAAG,CAAC,cAAc,EAAE,CAAA;QAChC,IAAI,GAAG,GAAG,YAAA,aAAa,EAAE;YACvB,OAAO,KAAK,CAAA;SACb;QAED,MAAM,aAAa,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAA;QAC5D,IAAI,GAAG,GAAG,aAAa,EAAE;YACvB,OAAO,KAAK,CAAA;SACb;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAZe,oBAAQ,WAYvB,CAAA;IAED,SAAgB,UAAU,CAAC,GAAe;QACxC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAClB,OAAO,IAAI,CAAA;SACZ;QAED,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE;YACxB,IAAI,EAAE,GAAG,CAAC,UAAU,EAAU;SAC/B,CAAA;IACH,CAAC;IATe,sBAAU,aASzB,CAAA;AACH,CAAC,EAlDgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAkD3B;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PreEngine } from '../../engine';
|
|
2
|
+
import { Entity } from '../../engine/entity';
|
|
3
|
+
/**
|
|
4
|
+
* TODO:
|
|
5
|
+
* What about when we remove the SyncComponent ? Should we notify all the clients? How ?
|
|
6
|
+
* Where do we create the transport and process the received messages?
|
|
7
|
+
*/
|
|
8
|
+
export declare function crdtSceneSystem(engine: PreEngine): {
|
|
9
|
+
send: (dirtyMap: Map<Entity, Set<number>>) => void;
|
|
10
|
+
processMessages: () => void;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/systems/crdt/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAQ5C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS;qBAiEvB,IAAI,MAAM,EAAE,IAAI,MAAM,CAAC,CAAC;;EA4BjD"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.crdtSceneSystem = void 0;
|
|
7
|
+
const crdt_1 = require("@dcl/crdt");
|
|
8
|
+
const entity_utils_1 = __importDefault(require("../../engine/entity-utils"));
|
|
9
|
+
const ByteBuffer_1 = require("../../serialization/ByteBuffer");
|
|
10
|
+
const componentOperation_1 = require("../../serialization/crdt/componentOperation");
|
|
11
|
+
const wireMessage_1 = __importDefault(require("../../serialization/wireMessage"));
|
|
12
|
+
const transport_1 = require("./transport");
|
|
13
|
+
const utils_1 = __importDefault(require("./utils"));
|
|
14
|
+
/**
|
|
15
|
+
* TODO:
|
|
16
|
+
* What about when we remove the SyncComponent ? Should we notify all the clients? How ?
|
|
17
|
+
* Where do we create the transport and process the received messages?
|
|
18
|
+
*/
|
|
19
|
+
function crdtSceneSystem(engine) {
|
|
20
|
+
const crdtClient = (0, crdt_1.crdtProtocol)();
|
|
21
|
+
const messages = [];
|
|
22
|
+
const crdtEntities = new Map();
|
|
23
|
+
const transport = (0, transport_1.createTransport)();
|
|
24
|
+
transport.onmessage = parseChunkMessage;
|
|
25
|
+
function parseChunkMessage(chunkMessage) {
|
|
26
|
+
if (!chunkMessage.data?.length)
|
|
27
|
+
return;
|
|
28
|
+
const buffer = (0, ByteBuffer_1.createByteBuffer)({
|
|
29
|
+
reading: { buffer: chunkMessage.data, currentOffset: 0 }
|
|
30
|
+
});
|
|
31
|
+
while (wireMessage_1.default.validate(buffer)) {
|
|
32
|
+
const message = componentOperation_1.PutComponentOperation.read(buffer);
|
|
33
|
+
const { entityId, componentId, data, timestamp } = message;
|
|
34
|
+
messages.push({
|
|
35
|
+
key: utils_1.default.getKey(entityId, componentId),
|
|
36
|
+
data,
|
|
37
|
+
timestamp
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function getMessages() {
|
|
42
|
+
const messagesToProcess = Array.from(messages);
|
|
43
|
+
messages.length = 0;
|
|
44
|
+
return messagesToProcess;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This messages will be processed on every tick.
|
|
48
|
+
*/
|
|
49
|
+
function processMessages() {
|
|
50
|
+
const buffer = (0, ByteBuffer_1.createByteBuffer)();
|
|
51
|
+
const messagesToProcess = getMessages();
|
|
52
|
+
for (const message of messagesToProcess) {
|
|
53
|
+
const [entity, componentId] = utils_1.default.parseKey(message.key);
|
|
54
|
+
const msg = crdtClient.processMessage(message);
|
|
55
|
+
const component = engine.getComponent(componentId);
|
|
56
|
+
// CRDT outdated message. Resend this message through the wire
|
|
57
|
+
// TODO: perf transactor
|
|
58
|
+
if (msg !== message) {
|
|
59
|
+
componentOperation_1.PutComponentOperation.write(entity, msg.timestamp, component, buffer);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const bb = (0, ByteBuffer_1.createByteBuffer)({
|
|
63
|
+
reading: {
|
|
64
|
+
buffer: message.data,
|
|
65
|
+
currentOffset: 0
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
component.upsertFromBinary(entity, bb);
|
|
69
|
+
component.clearDirty();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (buffer.size()) {
|
|
73
|
+
transport.send(buffer.toBinary());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function send(dirtyMap) {
|
|
77
|
+
const buffer = (0, ByteBuffer_1.createByteBuffer)();
|
|
78
|
+
for (const [entity, componentsId] of dirtyMap) {
|
|
79
|
+
if (entity_utils_1.default.isStaticEntity(entity) && !crdtEntities.has(entity)) {
|
|
80
|
+
crdtEntities.set(entity, true);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
crdtEntities.set(entity, true);
|
|
84
|
+
for (const componentId of componentsId) {
|
|
85
|
+
const component = engine.getComponent(componentId);
|
|
86
|
+
const key = utils_1.default.getKey(entity, componentId);
|
|
87
|
+
const event = crdtClient.createEvent(key, component.toBinary(entity).toBinary());
|
|
88
|
+
componentOperation_1.PutComponentOperation.write(entity, event.timestamp, component, buffer);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (buffer.size()) {
|
|
92
|
+
transport.send(buffer.toBinary());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
send,
|
|
97
|
+
processMessages
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
exports.crdtSceneSystem = crdtSceneSystem;
|
|
101
|
+
// const { Sync } = engine.baseComponents
|
|
102
|
+
// for (const [entity] of engine.groupOf(Dirty)) {
|
|
103
|
+
// const components = engine.getEntityComponents(entity)
|
|
104
|
+
// for (const p of )
|
|
105
|
+
// }
|
|
106
|
+
// for (const [entity] of engine.mutableGroupOf(Sync)) {
|
|
107
|
+
// for (const component of engine.getEntityComponents(entity)) {
|
|
108
|
+
// // If its a new entity, we should send all the components.
|
|
109
|
+
// // Otherwise, we send only the updates (dirty)
|
|
110
|
+
// if (!crdtEntities.has(entity) || component.isDirty(entity)) {
|
|
111
|
+
// const event = crdtClient.createEvent(
|
|
112
|
+
// getKey(entity, component._id),
|
|
113
|
+
// component.toBinary(entity)
|
|
114
|
+
// )
|
|
115
|
+
// void crdtClient.sendMessage(event)
|
|
116
|
+
// return
|
|
117
|
+
// }
|
|
118
|
+
// }
|
|
119
|
+
// crdtEntities.add(entity)
|
|
120
|
+
// }
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/systems/crdt/index.ts"],"names":[],"mappings":";;;;;;AAAA,oCAAiD;AAIjD,6EAAmD;AACnD,+DAAiE;AACjE,oFAAmF;AACnF,kFAAyD;AACzD,2CAA6C;AAC7C,oDAA+B;AAE/B;;;;GAIG;AACH,SAAgB,eAAe,CAAC,MAAiB;IAC/C,MAAM,UAAU,GAAG,IAAA,mBAAY,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A;gBAClD,MAAM,GAAG,GAAG,eAAS,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;gBACjD,MAAM,KAAK,GAAG,UAAU,CAAC,WAAW,CAClC,GAAG,EACH,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CACtC,CAAA;gBACD,0CAAqB,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;aACxE;SACF;QAED,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE;YACjB,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;SAClC;IACH,CAAC;IAED,OAAO;QACL,IAAI;QACJ,eAAe;KAChB,CAAA;AACH,CAAC;AA7FD,0CA6FC;AAED,yCAAyC;AACzC,kDAAkD;AAClD,0DAA0D;AAC1D,sBAAsB;AACtB,IAAI;AAEJ,wDAAwD;AACxD,kEAAkE;AAClE,iEAAiE;AACjE,qDAAqD;AACrD,oEAAoE;AACpE,8CAA8C;AAC9C,yCAAyC;AACzC,qCAAqC;AACrC,UAAU;AACV,2CAA2C;AAC3C,eAAe;AACf,QAAQ;AACR,MAAM;AACN,6BAA6B;AAC7B,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/systems/crdt/transport.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,IAAI,aAE3C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransport = void 0;
|
|
4
|
+
function createTransport(_type) {
|
|
5
|
+
return new WebSocket('ws://localhost:8000');
|
|
6
|
+
}
|
|
7
|
+
exports.createTransport = createTransport;
|
|
8
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/systems/crdt/transport.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,KAAY;IAC1C,OAAO,IAAI,SAAS,CAAC,qBAAqB,CAAC,CAAA;AAC7C,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentDefinition } from '../../engine/component';
|
|
2
|
+
import { Entity } from '../../engine/entity';
|
|
3
|
+
export declare namespace CrdtUtils {
|
|
4
|
+
type ComponentID = ComponentDefinition['_id'];
|
|
5
|
+
function parseKey(key: string): [Entity, ComponentID];
|
|
6
|
+
function getKey(entity: Entity, componentId: ComponentID): string;
|
|
7
|
+
enum SynchronizedEntityType {
|
|
8
|
+
ALL = 0,
|
|
9
|
+
NETWORKED = 1,
|
|
10
|
+
RENDERER = 2
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export default CrdtUtils;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/systems/crdt/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,yBAAiB,SAAS,CAAC;IACzB,KAAY,WAAW,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAEpD,SAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAM3D;IAED,SAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM,CAEvE;IAED,KAAY,sBAAsB;QAEhC,GAAG,IAAA;QAEH,SAAS,IAAA;QAET,QAAQ,IAAA;KACT;CACF;AACD,eAAe,SAAS,CAAA"}
|