@dcl/ecs 7.0.6-3830539086.commit-6152fbd → 7.0.6-3832097301.commit-4e46b20
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/engine/component.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReadWriteByteBuffer } from '../serialization/ByteBuffer';
|
|
2
2
|
import { deepReadonly } from './readonly';
|
|
3
3
|
export function defineComponent(componentId, spec
|
|
4
4
|
// meta: { syncFlags }
|
|
@@ -92,7 +92,7 @@ export function defineComponent(componentId, spec
|
|
|
92
92
|
if (!component) {
|
|
93
93
|
throw new Error(`[toBinary] Component ${componentId} for ${entity} not found`);
|
|
94
94
|
}
|
|
95
|
-
const writeBuffer =
|
|
95
|
+
const writeBuffer = new ReadWriteByteBuffer();
|
|
96
96
|
spec.serialize(component, writeBuffer);
|
|
97
97
|
return writeBuffer;
|
|
98
98
|
},
|
|
@@ -101,7 +101,7 @@ export function defineComponent(componentId, spec
|
|
|
101
101
|
if (!component) {
|
|
102
102
|
return null;
|
|
103
103
|
}
|
|
104
|
-
const writeBuffer =
|
|
104
|
+
const writeBuffer = new ReadWriteByteBuffer();
|
|
105
105
|
spec.serialize(component, writeBuffer);
|
|
106
106
|
return writeBuffer;
|
|
107
107
|
},
|
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param writing - writing option, see object specs.
|
|
3
|
-
* @param reading - reading option, see object specs.
|
|
4
|
-
* @param initialCapacity - Initial capacity of buffer to allocate, ignored if you use writing or reading options
|
|
5
|
-
*/
|
|
6
|
-
export interface CreateByteBufferOptions {
|
|
7
|
-
/**
|
|
8
|
-
* @param buffer - a buffer already allocated to read from there.
|
|
9
|
-
* @param currentOffset - set the cursor where begins to read. Default 0
|
|
10
|
-
* @param length - delimite where the valid data ends. Default: buffer.length
|
|
11
|
-
*/
|
|
12
|
-
reading?: {
|
|
13
|
-
buffer: Uint8Array;
|
|
14
|
-
length?: number;
|
|
15
|
-
currentOffset: number;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* @param buffer - a buffer already allocated to write there.
|
|
19
|
-
* @param currentOffset - set the cursor to not start writing from the begin of it. Default 0
|
|
20
|
-
*/
|
|
21
|
-
writing?: {
|
|
22
|
-
buffer: Uint8Array;
|
|
23
|
-
currentOffset?: number;
|
|
24
|
-
};
|
|
25
|
-
initialCapacity?: number;
|
|
26
|
-
}
|
|
27
1
|
/**
|
|
28
2
|
* ByteBuffer is a wrapper of DataView which also adds a read and write offset.
|
|
29
3
|
* Also in a write operation it resizes the buffer is being used if it needs.
|
|
@@ -31,7 +5,73 @@ export interface CreateByteBufferOptions {
|
|
|
31
5
|
* - Use read and write function to generate or consume data.
|
|
32
6
|
* - Use set and get only if you are sure that you're doing.
|
|
33
7
|
*/
|
|
34
|
-
export declare
|
|
8
|
+
export declare class ReadWriteByteBuffer implements ByteBuffer {
|
|
9
|
+
#private;
|
|
10
|
+
_buffer: Uint8Array;
|
|
11
|
+
view: DataView;
|
|
12
|
+
woffset: number;
|
|
13
|
+
roffset: number;
|
|
14
|
+
/**
|
|
15
|
+
* @param buffer - The initial buffer, provide a buffer if you need to set "initial capacity"
|
|
16
|
+
* @param readingOffset - Set the cursor where begins to read. Default 0
|
|
17
|
+
* @param writingOffset - Set the cursor to not start writing from the begin of it. Defaults to the buffer size
|
|
18
|
+
*/
|
|
19
|
+
constructor(buffer?: Uint8Array | undefined, readingOffset?: number | undefined, writingOffset?: number | undefined);
|
|
20
|
+
buffer(): Uint8Array;
|
|
21
|
+
bufferLength(): number;
|
|
22
|
+
resetBuffer(): void;
|
|
23
|
+
currentReadOffset(): number;
|
|
24
|
+
currentWriteOffset(): number;
|
|
25
|
+
incrementReadOffset(amount: number): number;
|
|
26
|
+
remainingBytes(): number;
|
|
27
|
+
readFloat32(): number;
|
|
28
|
+
readFloat64(): number;
|
|
29
|
+
readInt8(): number;
|
|
30
|
+
readInt16(): number;
|
|
31
|
+
readInt32(): number;
|
|
32
|
+
readInt64(): bigint;
|
|
33
|
+
readUint8(): number;
|
|
34
|
+
readUint16(): number;
|
|
35
|
+
readUint32(): number;
|
|
36
|
+
readUint64(): bigint;
|
|
37
|
+
readBuffer(): Uint8Array;
|
|
38
|
+
readUtf8String(): string;
|
|
39
|
+
incrementWriteOffset(amount: number): number;
|
|
40
|
+
toBinary(): Uint8Array;
|
|
41
|
+
toCopiedBinary(): Uint8Array;
|
|
42
|
+
writeBuffer(value: Uint8Array, writeLength?: boolean): void;
|
|
43
|
+
writeUtf8String(value: string, writeLength?: boolean): void;
|
|
44
|
+
writeFloat32(value: number): void;
|
|
45
|
+
writeFloat64(value: number): void;
|
|
46
|
+
writeInt8(value: number): void;
|
|
47
|
+
writeInt16(value: number): void;
|
|
48
|
+
writeInt32(value: number): void;
|
|
49
|
+
writeInt64(value: bigint): void;
|
|
50
|
+
writeUint8(value: number): void;
|
|
51
|
+
writeUint16(value: number): void;
|
|
52
|
+
writeUint32(value: number): void;
|
|
53
|
+
writeUint64(value: bigint): void;
|
|
54
|
+
getFloat32(offset: number): number;
|
|
55
|
+
getFloat64(offset: number): number;
|
|
56
|
+
getInt8(offset: number): number;
|
|
57
|
+
getInt16(offset: number): number;
|
|
58
|
+
getInt32(offset: number): number;
|
|
59
|
+
getInt64(offset: number): bigint;
|
|
60
|
+
getUint8(offset: number): number;
|
|
61
|
+
getUint16(offset: number): number;
|
|
62
|
+
getUint32(offset: number): number;
|
|
63
|
+
getUint64(offset: number): bigint;
|
|
64
|
+
setFloat32(offset: number, value: number): void;
|
|
65
|
+
setFloat64(offset: number, value: number): void;
|
|
66
|
+
setInt8(offset: number, value: number): void;
|
|
67
|
+
setInt16(offset: number, value: number): void;
|
|
68
|
+
setInt32(offset: number, value: number): void;
|
|
69
|
+
setInt64(offset: number, value: bigint): void;
|
|
70
|
+
setUint8(offset: number, value: number): void;
|
|
71
|
+
setUint16(offset: number, value: number): void;
|
|
72
|
+
setUint32(offset: number, value: number): void;
|
|
73
|
+
setUint64(offset: number, value: bigint): void;
|
|
74
|
+
}
|
|
35
75
|
/**
|
|
36
76
|
* @public
|
|
37
77
|
*/
|
|
@@ -89,10 +129,6 @@ export declare type ByteBuffer = {
|
|
|
89
129
|
* @returns The offset when this reserving starts.
|
|
90
130
|
*/
|
|
91
131
|
incrementWriteOffset(amount: number): number;
|
|
92
|
-
/**
|
|
93
|
-
* @returns The total number of bytes writen in the buffer.
|
|
94
|
-
*/
|
|
95
|
-
size(): number;
|
|
96
132
|
/**
|
|
97
133
|
* Take care using this function, if you modify the data after, the
|
|
98
134
|
* returned subarray will change too. If you'll modify the content of the
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _ReadWriteByteBuffer_instances, _ReadWriteByteBuffer_woAdd, _ReadWriteByteBuffer_roAdd;
|
|
1
7
|
import * as utf8 from '@protobufjs/utf8';
|
|
2
8
|
/**
|
|
3
9
|
* Take the max between currentSize and intendedSize and then plus 1024. Then,
|
|
@@ -18,240 +24,220 @@ const defaultInitialCapacity = 10240;
|
|
|
18
24
|
* - Use read and write function to generate or consume data.
|
|
19
25
|
* - Use set and get only if you are sure that you're doing.
|
|
20
26
|
*/
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
export class ReadWriteByteBuffer {
|
|
28
|
+
/**
|
|
29
|
+
* @param buffer - The initial buffer, provide a buffer if you need to set "initial capacity"
|
|
30
|
+
* @param readingOffset - Set the cursor where begins to read. Default 0
|
|
31
|
+
* @param writingOffset - Set the cursor to not start writing from the begin of it. Defaults to the buffer size
|
|
32
|
+
*/
|
|
33
|
+
constructor(buffer, readingOffset, writingOffset) {
|
|
34
|
+
_ReadWriteByteBuffer_instances.add(this);
|
|
35
|
+
this._buffer = buffer || new Uint8Array(defaultInitialCapacity);
|
|
36
|
+
this.view = new DataView(this._buffer.buffer, this._buffer.byteOffset);
|
|
37
|
+
this.woffset = writingOffset ?? (buffer ? this._buffer.length : null) ?? 0;
|
|
38
|
+
this.roffset = readingOffset ?? 0;
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
initialWOffset = options.reading.length || options.reading.buffer.length;
|
|
40
|
+
buffer() {
|
|
41
|
+
return this._buffer;
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
bufferLength() {
|
|
44
|
+
return this._buffer.length;
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
resetBuffer() {
|
|
47
|
+
this.roffset = 0;
|
|
48
|
+
this.woffset = 0;
|
|
49
|
+
}
|
|
50
|
+
currentReadOffset() {
|
|
51
|
+
return this.roffset;
|
|
52
|
+
}
|
|
53
|
+
currentWriteOffset() {
|
|
54
|
+
return this.woffset;
|
|
55
|
+
}
|
|
56
|
+
incrementReadOffset(amount) {
|
|
57
|
+
return __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, amount);
|
|
58
|
+
}
|
|
59
|
+
remainingBytes() {
|
|
60
|
+
return this.woffset - this.roffset;
|
|
61
|
+
}
|
|
62
|
+
readFloat32() {
|
|
63
|
+
return this.view.getFloat32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
64
|
+
}
|
|
65
|
+
readFloat64() {
|
|
66
|
+
return this.view.getFloat64(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 8));
|
|
67
|
+
}
|
|
68
|
+
readInt8() {
|
|
69
|
+
return this.view.getInt8(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 1));
|
|
70
|
+
}
|
|
71
|
+
readInt16() {
|
|
72
|
+
return this.view.getInt16(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 2));
|
|
73
|
+
}
|
|
74
|
+
readInt32() {
|
|
75
|
+
return this.view.getInt32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
76
|
+
}
|
|
77
|
+
readInt64() {
|
|
78
|
+
return this.view.getBigInt64(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 8));
|
|
79
|
+
}
|
|
80
|
+
readUint8() {
|
|
81
|
+
return this.view.getUint8(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 1));
|
|
82
|
+
}
|
|
83
|
+
readUint16() {
|
|
84
|
+
return this.view.getUint16(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 2));
|
|
85
|
+
}
|
|
86
|
+
readUint32() {
|
|
87
|
+
return this.view.getUint32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
88
|
+
}
|
|
89
|
+
readUint64() {
|
|
90
|
+
return this.view.getBigUint64(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 8));
|
|
91
|
+
}
|
|
92
|
+
readBuffer() {
|
|
93
|
+
const length = this.view.getUint32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
94
|
+
return this._buffer.subarray(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, length), __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 0));
|
|
95
|
+
}
|
|
96
|
+
readUtf8String() {
|
|
97
|
+
const length = this.view.getUint32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
98
|
+
return utf8.read(this._buffer, __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, length), __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 0));
|
|
99
|
+
}
|
|
100
|
+
incrementWriteOffset(amount) {
|
|
101
|
+
return __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, amount);
|
|
102
|
+
}
|
|
103
|
+
toBinary() {
|
|
104
|
+
return this._buffer.subarray(0, this.woffset);
|
|
105
|
+
}
|
|
106
|
+
toCopiedBinary() {
|
|
107
|
+
return new Uint8Array(this.toBinary());
|
|
108
|
+
}
|
|
109
|
+
writeBuffer(value, writeLength = true) {
|
|
110
|
+
if (writeLength) {
|
|
111
|
+
this.writeUint32(value.byteLength);
|
|
63
112
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
bufferLength() {
|
|
72
|
-
return buffer.length;
|
|
73
|
-
},
|
|
74
|
-
resetBuffer() {
|
|
75
|
-
roffset = 0;
|
|
76
|
-
woffset = 0;
|
|
77
|
-
},
|
|
78
|
-
currentReadOffset() {
|
|
79
|
-
return roffset;
|
|
80
|
-
},
|
|
81
|
-
currentWriteOffset() {
|
|
82
|
-
return woffset;
|
|
83
|
-
},
|
|
84
|
-
incrementReadOffset(amount) {
|
|
85
|
-
return roAdd(amount);
|
|
86
|
-
},
|
|
87
|
-
remainingBytes() {
|
|
88
|
-
return woffset - roffset;
|
|
89
|
-
},
|
|
90
|
-
readFloat32() {
|
|
91
|
-
return view.getFloat32(roAdd(4));
|
|
92
|
-
},
|
|
93
|
-
readFloat64() {
|
|
94
|
-
return view.getFloat64(roAdd(8));
|
|
95
|
-
},
|
|
96
|
-
readInt8() {
|
|
97
|
-
return view.getInt8(roAdd(1));
|
|
98
|
-
},
|
|
99
|
-
readInt16() {
|
|
100
|
-
return view.getInt16(roAdd(2));
|
|
101
|
-
},
|
|
102
|
-
readInt32() {
|
|
103
|
-
return view.getInt32(roAdd(4));
|
|
104
|
-
},
|
|
105
|
-
readInt64() {
|
|
106
|
-
return view.getBigInt64(roAdd(8));
|
|
107
|
-
},
|
|
108
|
-
readUint8() {
|
|
109
|
-
return view.getUint8(roAdd(1));
|
|
110
|
-
},
|
|
111
|
-
readUint16() {
|
|
112
|
-
return view.getUint16(roAdd(2));
|
|
113
|
-
},
|
|
114
|
-
readUint32() {
|
|
115
|
-
return view.getUint32(roAdd(4));
|
|
116
|
-
},
|
|
117
|
-
readUint64() {
|
|
118
|
-
return view.getBigUint64(roAdd(8));
|
|
119
|
-
},
|
|
120
|
-
readBuffer() {
|
|
121
|
-
const length = view.getUint32(roAdd(4));
|
|
122
|
-
return buffer.subarray(roAdd(length), roAdd(0));
|
|
123
|
-
},
|
|
124
|
-
readUtf8String() {
|
|
125
|
-
const length = view.getUint32(roAdd(4));
|
|
126
|
-
return utf8.read(buffer, roAdd(length), roAdd(0));
|
|
127
|
-
},
|
|
128
|
-
incrementWriteOffset(amount) {
|
|
129
|
-
return woAdd(amount);
|
|
130
|
-
},
|
|
131
|
-
size() {
|
|
132
|
-
return woffset;
|
|
133
|
-
},
|
|
134
|
-
toBinary() {
|
|
135
|
-
return buffer.subarray(0, woffset);
|
|
136
|
-
},
|
|
137
|
-
toCopiedBinary() {
|
|
138
|
-
return new Uint8Array(this.toBinary());
|
|
139
|
-
},
|
|
140
|
-
writeBuffer(value, writeLength = true) {
|
|
141
|
-
if (writeLength) {
|
|
142
|
-
this.writeUint32(value.byteLength);
|
|
143
|
-
}
|
|
144
|
-
const o = woAdd(value.byteLength);
|
|
145
|
-
buffer.set(value, o);
|
|
146
|
-
},
|
|
147
|
-
writeUtf8String(value, writeLength = true) {
|
|
148
|
-
const byteLength = utf8.length(value);
|
|
149
|
-
if (writeLength) {
|
|
150
|
-
this.writeUint32(byteLength);
|
|
151
|
-
}
|
|
152
|
-
const o = woAdd(byteLength);
|
|
153
|
-
utf8.write(value, buffer, o);
|
|
154
|
-
},
|
|
155
|
-
writeFloat32(value) {
|
|
156
|
-
const o = woAdd(4);
|
|
157
|
-
view.setFloat32(o, value);
|
|
158
|
-
},
|
|
159
|
-
writeFloat64(value) {
|
|
160
|
-
const o = woAdd(8);
|
|
161
|
-
view.setFloat64(o, value);
|
|
162
|
-
},
|
|
163
|
-
writeInt8(value) {
|
|
164
|
-
const o = woAdd(1);
|
|
165
|
-
view.setInt8(o, value);
|
|
166
|
-
},
|
|
167
|
-
writeInt16(value) {
|
|
168
|
-
const o = woAdd(2);
|
|
169
|
-
view.setInt16(o, value);
|
|
170
|
-
},
|
|
171
|
-
writeInt32(value) {
|
|
172
|
-
const o = woAdd(4);
|
|
173
|
-
view.setInt32(o, value);
|
|
174
|
-
},
|
|
175
|
-
writeInt64(value) {
|
|
176
|
-
const o = woAdd(8);
|
|
177
|
-
view.setBigInt64(o, value);
|
|
178
|
-
},
|
|
179
|
-
writeUint8(value) {
|
|
180
|
-
const o = woAdd(1);
|
|
181
|
-
view.setUint8(o, value);
|
|
182
|
-
},
|
|
183
|
-
writeUint16(value) {
|
|
184
|
-
const o = woAdd(2);
|
|
185
|
-
view.setUint16(o, value);
|
|
186
|
-
},
|
|
187
|
-
writeUint32(value) {
|
|
188
|
-
const o = woAdd(4);
|
|
189
|
-
view.setUint32(o, value);
|
|
190
|
-
},
|
|
191
|
-
writeUint64(value) {
|
|
192
|
-
const o = woAdd(8);
|
|
193
|
-
view.setBigUint64(o, value);
|
|
194
|
-
},
|
|
195
|
-
// Dataview Proxy
|
|
196
|
-
getFloat32(offset) {
|
|
197
|
-
return view.getFloat32(offset);
|
|
198
|
-
},
|
|
199
|
-
getFloat64(offset) {
|
|
200
|
-
return view.getFloat64(offset);
|
|
201
|
-
},
|
|
202
|
-
getInt8(offset) {
|
|
203
|
-
return view.getInt8(offset);
|
|
204
|
-
},
|
|
205
|
-
getInt16(offset) {
|
|
206
|
-
return view.getInt16(offset);
|
|
207
|
-
},
|
|
208
|
-
getInt32(offset) {
|
|
209
|
-
return view.getInt32(offset);
|
|
210
|
-
},
|
|
211
|
-
getInt64(offset) {
|
|
212
|
-
return view.getBigInt64(offset);
|
|
213
|
-
},
|
|
214
|
-
getUint8(offset) {
|
|
215
|
-
return view.getUint8(offset);
|
|
216
|
-
},
|
|
217
|
-
getUint16(offset) {
|
|
218
|
-
return view.getUint16(offset);
|
|
219
|
-
},
|
|
220
|
-
getUint32(offset) {
|
|
221
|
-
return view.getUint32(offset);
|
|
222
|
-
},
|
|
223
|
-
getUint64(offset) {
|
|
224
|
-
return view.getBigUint64(offset);
|
|
225
|
-
},
|
|
226
|
-
setFloat32(offset, value) {
|
|
227
|
-
view.setFloat32(offset, value);
|
|
228
|
-
},
|
|
229
|
-
setFloat64(offset, value) {
|
|
230
|
-
view.setFloat64(offset, value);
|
|
231
|
-
},
|
|
232
|
-
setInt8(offset, value) {
|
|
233
|
-
view.setInt8(offset, value);
|
|
234
|
-
},
|
|
235
|
-
setInt16(offset, value) {
|
|
236
|
-
view.setInt16(offset, value);
|
|
237
|
-
},
|
|
238
|
-
setInt32(offset, value) {
|
|
239
|
-
view.setInt32(offset, value);
|
|
240
|
-
},
|
|
241
|
-
setInt64(offset, value) {
|
|
242
|
-
view.setBigInt64(offset, value);
|
|
243
|
-
},
|
|
244
|
-
setUint8(offset, value) {
|
|
245
|
-
view.setUint8(offset, value);
|
|
246
|
-
},
|
|
247
|
-
setUint16(offset, value) {
|
|
248
|
-
view.setUint16(offset, value);
|
|
249
|
-
},
|
|
250
|
-
setUint32(offset, value) {
|
|
251
|
-
view.setUint32(offset, value);
|
|
252
|
-
},
|
|
253
|
-
setUint64(offset, value) {
|
|
254
|
-
view.setBigUint64(offset, value);
|
|
113
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, value.byteLength);
|
|
114
|
+
this._buffer.set(value, o);
|
|
115
|
+
}
|
|
116
|
+
writeUtf8String(value, writeLength = true) {
|
|
117
|
+
const byteLength = utf8.length(value);
|
|
118
|
+
if (writeLength) {
|
|
119
|
+
this.writeUint32(byteLength);
|
|
255
120
|
}
|
|
256
|
-
|
|
121
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, byteLength);
|
|
122
|
+
utf8.write(value, this._buffer, o);
|
|
123
|
+
}
|
|
124
|
+
writeFloat32(value) {
|
|
125
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 4);
|
|
126
|
+
this.view.setFloat32(o, value);
|
|
127
|
+
}
|
|
128
|
+
writeFloat64(value) {
|
|
129
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 8);
|
|
130
|
+
this.view.setFloat64(o, value);
|
|
131
|
+
}
|
|
132
|
+
writeInt8(value) {
|
|
133
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 1);
|
|
134
|
+
this.view.setInt8(o, value);
|
|
135
|
+
}
|
|
136
|
+
writeInt16(value) {
|
|
137
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 2);
|
|
138
|
+
this.view.setInt16(o, value);
|
|
139
|
+
}
|
|
140
|
+
writeInt32(value) {
|
|
141
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 4);
|
|
142
|
+
this.view.setInt32(o, value);
|
|
143
|
+
}
|
|
144
|
+
writeInt64(value) {
|
|
145
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 8);
|
|
146
|
+
this.view.setBigInt64(o, value);
|
|
147
|
+
}
|
|
148
|
+
writeUint8(value) {
|
|
149
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 1);
|
|
150
|
+
this.view.setUint8(o, value);
|
|
151
|
+
}
|
|
152
|
+
writeUint16(value) {
|
|
153
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 2);
|
|
154
|
+
this.view.setUint16(o, value);
|
|
155
|
+
}
|
|
156
|
+
writeUint32(value) {
|
|
157
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 4);
|
|
158
|
+
this.view.setUint32(o, value);
|
|
159
|
+
}
|
|
160
|
+
writeUint64(value) {
|
|
161
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 8);
|
|
162
|
+
this.view.setBigUint64(o, value);
|
|
163
|
+
}
|
|
164
|
+
// DataView Proxy
|
|
165
|
+
getFloat32(offset) {
|
|
166
|
+
return this.view.getFloat32(offset);
|
|
167
|
+
}
|
|
168
|
+
getFloat64(offset) {
|
|
169
|
+
return this.view.getFloat64(offset);
|
|
170
|
+
}
|
|
171
|
+
getInt8(offset) {
|
|
172
|
+
return this.view.getInt8(offset);
|
|
173
|
+
}
|
|
174
|
+
getInt16(offset) {
|
|
175
|
+
return this.view.getInt16(offset);
|
|
176
|
+
}
|
|
177
|
+
getInt32(offset) {
|
|
178
|
+
return this.view.getInt32(offset);
|
|
179
|
+
}
|
|
180
|
+
getInt64(offset) {
|
|
181
|
+
return this.view.getBigInt64(offset);
|
|
182
|
+
}
|
|
183
|
+
getUint8(offset) {
|
|
184
|
+
return this.view.getUint8(offset);
|
|
185
|
+
}
|
|
186
|
+
getUint16(offset) {
|
|
187
|
+
return this.view.getUint16(offset);
|
|
188
|
+
}
|
|
189
|
+
getUint32(offset) {
|
|
190
|
+
return this.view.getUint32(offset);
|
|
191
|
+
}
|
|
192
|
+
getUint64(offset) {
|
|
193
|
+
return this.view.getBigUint64(offset);
|
|
194
|
+
}
|
|
195
|
+
setFloat32(offset, value) {
|
|
196
|
+
this.view.setFloat32(offset, value);
|
|
197
|
+
}
|
|
198
|
+
setFloat64(offset, value) {
|
|
199
|
+
this.view.setFloat64(offset, value);
|
|
200
|
+
}
|
|
201
|
+
setInt8(offset, value) {
|
|
202
|
+
this.view.setInt8(offset, value);
|
|
203
|
+
}
|
|
204
|
+
setInt16(offset, value) {
|
|
205
|
+
this.view.setInt16(offset, value);
|
|
206
|
+
}
|
|
207
|
+
setInt32(offset, value) {
|
|
208
|
+
this.view.setInt32(offset, value);
|
|
209
|
+
}
|
|
210
|
+
setInt64(offset, value) {
|
|
211
|
+
this.view.setBigInt64(offset, value);
|
|
212
|
+
}
|
|
213
|
+
setUint8(offset, value) {
|
|
214
|
+
this.view.setUint8(offset, value);
|
|
215
|
+
}
|
|
216
|
+
setUint16(offset, value) {
|
|
217
|
+
this.view.setUint16(offset, value);
|
|
218
|
+
}
|
|
219
|
+
setUint32(offset, value) {
|
|
220
|
+
this.view.setUint32(offset, value);
|
|
221
|
+
}
|
|
222
|
+
setUint64(offset, value) {
|
|
223
|
+
this.view.setBigUint64(offset, value);
|
|
224
|
+
}
|
|
257
225
|
}
|
|
226
|
+
_ReadWriteByteBuffer_instances = new WeakSet(), _ReadWriteByteBuffer_woAdd = function _ReadWriteByteBuffer_woAdd(amount) {
|
|
227
|
+
if (this.woffset + amount > this._buffer.byteLength) {
|
|
228
|
+
const newsize = getNextSize(this._buffer.byteLength, this.woffset + amount);
|
|
229
|
+
const newBuffer = new Uint8Array(newsize);
|
|
230
|
+
newBuffer.set(this._buffer);
|
|
231
|
+
const oldOffset = this._buffer.byteOffset;
|
|
232
|
+
this._buffer = newBuffer;
|
|
233
|
+
this.view = new DataView(this._buffer.buffer, oldOffset);
|
|
234
|
+
}
|
|
235
|
+
this.woffset += amount;
|
|
236
|
+
return this.woffset - amount;
|
|
237
|
+
}, _ReadWriteByteBuffer_roAdd = function _ReadWriteByteBuffer_roAdd(amount) {
|
|
238
|
+
if (this.roffset + amount > this.woffset) {
|
|
239
|
+
throw new Error('Outside of the bounds of writen data.');
|
|
240
|
+
}
|
|
241
|
+
this.roffset += amount;
|
|
242
|
+
return this.roffset - amount;
|
|
243
|
+
};
|
|
@@ -12,7 +12,7 @@ export var PutComponentOperation;
|
|
|
12
12
|
const startMessageOffset = buf.incrementWriteOffset(CRDT_MESSAGE_HEADER_LENGTH + PutComponentOperation.MESSAGE_HEADER_LENGTH);
|
|
13
13
|
// write body
|
|
14
14
|
componentDefinition.writeToByteBuffer(entity, buf);
|
|
15
|
-
const messageLength = buf.
|
|
15
|
+
const messageLength = buf.currentWriteOffset() - startMessageOffset;
|
|
16
16
|
// Write CrdtMessage header
|
|
17
17
|
buf.setUint32(startMessageOffset, messageLength);
|
|
18
18
|
buf.setUint32(startMessageOffset + 4, CrdtMessageType.PUT_COMPONENT);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { crdtProtocol } from '@dcl/crdt';
|
|
2
2
|
import { CRDTMessageType, ProcessMessageResultType } from '@dcl/crdt/dist/types';
|
|
3
3
|
import { EntityState, EntityUtils } from '../../engine/entity';
|
|
4
|
-
import {
|
|
4
|
+
import { ReadWriteByteBuffer } from '../../serialization/ByteBuffer';
|
|
5
5
|
import CrdtMessageProtocol from '../../serialization/crdt';
|
|
6
6
|
import { DeleteComponent } from '../../serialization/crdt/deleteComponent';
|
|
7
7
|
import { DeleteEntity } from '../../serialization/crdt/deleteEntity';
|
|
@@ -32,9 +32,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
32
32
|
* @param chunkMessage A chunk of binary messages
|
|
33
33
|
*/
|
|
34
34
|
return function parseChunkMessage(chunkMessage) {
|
|
35
|
-
const buffer =
|
|
36
|
-
reading: { buffer: chunkMessage, currentOffset: 0 }
|
|
37
|
-
});
|
|
35
|
+
const buffer = new ReadWriteByteBuffer(chunkMessage);
|
|
38
36
|
let header;
|
|
39
37
|
while ((header = CrdtMessageProtocol.getHeader(buffer))) {
|
|
40
38
|
const offset = buffer.currentReadOffset();
|
|
@@ -94,10 +92,9 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
94
92
|
*/
|
|
95
93
|
async function receiveMessages() {
|
|
96
94
|
const messagesToProcess = getMessages(receivedMessages);
|
|
97
|
-
const bufferForOutdated =
|
|
95
|
+
const bufferForOutdated = new ReadWriteByteBuffer();
|
|
98
96
|
const entitiesShouldBeCleaned = [];
|
|
99
97
|
for (const msg of messagesToProcess) {
|
|
100
|
-
// TODO: emit delete entity to el onCrdtMessage
|
|
101
98
|
if (msg.type === CrdtMessageType.DELETE_ENTITY) {
|
|
102
99
|
crdtClient.processMessage({
|
|
103
100
|
type: CRDTMessageType.CRDTMT_DeleteEntity,
|
|
@@ -106,7 +103,6 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
106
103
|
entitiesShouldBeCleaned.push(msg.entityId);
|
|
107
104
|
}
|
|
108
105
|
else {
|
|
109
|
-
// TODO: emit pu/delete component to el onCrdtMessage
|
|
110
106
|
const crdtMessage = {
|
|
111
107
|
type: CRDTMessageType.CRDTMT_PutComponentData,
|
|
112
108
|
entityId: msg.entityId,
|
|
@@ -142,10 +138,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
142
138
|
component.deleteFrom(msg.entityId, false);
|
|
143
139
|
}
|
|
144
140
|
else {
|
|
145
|
-
const
|
|
146
|
-
reading: { buffer: msg.data, currentOffset: 0 }
|
|
147
|
-
};
|
|
148
|
-
const data = createByteBuffer(opts);
|
|
141
|
+
const data = new ReadWriteByteBuffer(msg.data);
|
|
149
142
|
component.upsertFromBinary(msg.entityId, data, false);
|
|
150
143
|
}
|
|
151
144
|
onProcessEntityComponentChange &&
|
|
@@ -184,7 +177,6 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
184
177
|
}
|
|
185
178
|
}
|
|
186
179
|
}
|
|
187
|
-
// TODO: emit delete entity to el onCrdtMessage
|
|
188
180
|
for (const entity of entitiesShouldBeCleaned) {
|
|
189
181
|
// If we tried to resend outdated message and the entity was deleted before, we avoid sending them.
|
|
190
182
|
for (let i = outdatedMessages.length - 1; i >= 0; i--) {
|
|
@@ -240,7 +232,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
240
232
|
// CRDT Messages will be the merge between the recieved transport messages and the new crdt messages
|
|
241
233
|
const crdtMessages = getMessages(broadcastMessages);
|
|
242
234
|
const outdatedMessagesBkp = getMessages(outdatedMessages);
|
|
243
|
-
const buffer =
|
|
235
|
+
const buffer = new ReadWriteByteBuffer();
|
|
244
236
|
for (const [component, entities] of dirtyEntities) {
|
|
245
237
|
for (const entity of entities) {
|
|
246
238
|
// Component will be always defined here since dirtyMap its an iterator of engine.componentsDefinition
|
|
@@ -289,7 +281,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
289
281
|
});
|
|
290
282
|
}
|
|
291
283
|
// Send CRDT messages to transports
|
|
292
|
-
const transportBuffer =
|
|
284
|
+
const transportBuffer = new ReadWriteByteBuffer();
|
|
293
285
|
for (const index in transports) {
|
|
294
286
|
const transportIndex = Number(index);
|
|
295
287
|
const transport = transports[transportIndex];
|
|
@@ -314,7 +306,7 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
314
306
|
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
315
307
|
}
|
|
316
308
|
}
|
|
317
|
-
const message = transportBuffer.
|
|
309
|
+
const message = transportBuffer.currentWriteOffset()
|
|
318
310
|
? transportBuffer.toBinary()
|
|
319
311
|
: new Uint8Array([]);
|
|
320
312
|
await transport.send(message);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
|
-
"version": "7.0.6-
|
|
3
|
+
"version": "7.0.6-3832097301.commit-4e46b20",
|
|
4
4
|
"description": "Decentraland ECS",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"ts-proto": "^1.112.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@dcl/crdt": "7.0.6-
|
|
30
|
+
"@dcl/crdt": "7.0.6-3832097301.commit-4e46b20",
|
|
31
31
|
"@dcl/js-runtime": "file:../js-runtime",
|
|
32
32
|
"@dcl/protocol": "^1.0.0-3808528053.commit-d66d462"
|
|
33
33
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"displayName": "ECS",
|
|
42
42
|
"tsconfig": "./tsconfig.json"
|
|
43
43
|
},
|
|
44
|
-
"commit": "
|
|
44
|
+
"commit": "4e46b208355a0a0d340a899c44f98bebb94d0c8b"
|
|
45
45
|
}
|