@dcl/playground-assets 7.0.6-3824930139.commit-9bd6c05 → 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/alpha.d.ts +162 -46
- package/dist/beta.d.ts +162 -46
- package/dist/index.bundled.d.ts +162 -46
- package/dist/index.js +995 -532
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/playground/sdk/dcl-sdk.package.json +2 -2
- package/dist/playground-assets.d.ts +162 -46
- package/etc/playground-assets.api.json +1608 -431
- package/etc/playground-assets.api.md +166 -46
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -13130,6 +13130,80 @@
|
|
|
13130
13130
|
|
|
13131
13131
|
var dist = {};
|
|
13132
13132
|
|
|
13133
|
+
var gset = {};
|
|
13134
|
+
|
|
13135
|
+
var hasRequiredGset;
|
|
13136
|
+
|
|
13137
|
+
function requireGset () {
|
|
13138
|
+
if (hasRequiredGset) return gset;
|
|
13139
|
+
hasRequiredGset = 1;
|
|
13140
|
+
Object.defineProperty(gset, "__esModule", { value: true });
|
|
13141
|
+
gset.createGSet = void 0;
|
|
13142
|
+
/**
|
|
13143
|
+
*
|
|
13144
|
+
* @returns a new GSet
|
|
13145
|
+
*/
|
|
13146
|
+
function createGSet() {
|
|
13147
|
+
const lastVersion = new Map();
|
|
13148
|
+
return {
|
|
13149
|
+
/**
|
|
13150
|
+
*
|
|
13151
|
+
* @param n
|
|
13152
|
+
* @param v
|
|
13153
|
+
* @returns
|
|
13154
|
+
*/
|
|
13155
|
+
addTo(n, v) {
|
|
13156
|
+
if (v < 0) {
|
|
13157
|
+
return false;
|
|
13158
|
+
}
|
|
13159
|
+
const currentValue = lastVersion.get(n);
|
|
13160
|
+
// If the version is >=, it means the value it's already in the set
|
|
13161
|
+
if (currentValue !== undefined && currentValue >= v) {
|
|
13162
|
+
return true;
|
|
13163
|
+
}
|
|
13164
|
+
lastVersion.set(n, v);
|
|
13165
|
+
return true;
|
|
13166
|
+
},
|
|
13167
|
+
/**
|
|
13168
|
+
* @returns the set with [number, version] of each value
|
|
13169
|
+
*/
|
|
13170
|
+
get() {
|
|
13171
|
+
const arr = [];
|
|
13172
|
+
for (const [n, v] of lastVersion) {
|
|
13173
|
+
for (let i = 0; i <= v; i++) {
|
|
13174
|
+
arr.push([n, i]);
|
|
13175
|
+
}
|
|
13176
|
+
}
|
|
13177
|
+
return arr;
|
|
13178
|
+
},
|
|
13179
|
+
/**
|
|
13180
|
+
* @returns the set with [number, version] of each value
|
|
13181
|
+
*/
|
|
13182
|
+
has(n, v) {
|
|
13183
|
+
const currentValue = lastVersion.get(n);
|
|
13184
|
+
// If the version is >=, it means the value it's already in the set
|
|
13185
|
+
if (currentValue !== undefined && currentValue >= v) {
|
|
13186
|
+
return true;
|
|
13187
|
+
}
|
|
13188
|
+
return false;
|
|
13189
|
+
},
|
|
13190
|
+
/**
|
|
13191
|
+
* Warning: this function returns the reference to the internal map,
|
|
13192
|
+
* if you need to mutate some value, make a copy.
|
|
13193
|
+
* For optimization purpose the copy isn't made here.
|
|
13194
|
+
*
|
|
13195
|
+
* @returns the map of number to version
|
|
13196
|
+
*/
|
|
13197
|
+
getMap() {
|
|
13198
|
+
return lastVersion;
|
|
13199
|
+
}
|
|
13200
|
+
};
|
|
13201
|
+
}
|
|
13202
|
+
gset.createGSet = createGSet;
|
|
13203
|
+
|
|
13204
|
+
return gset;
|
|
13205
|
+
}
|
|
13206
|
+
|
|
13133
13207
|
var types = {};
|
|
13134
13208
|
|
|
13135
13209
|
var hasRequiredTypes;
|
|
@@ -13137,8 +13211,71 @@
|
|
|
13137
13211
|
function requireTypes () {
|
|
13138
13212
|
if (hasRequiredTypes) return types;
|
|
13139
13213
|
hasRequiredTypes = 1;
|
|
13140
|
-
|
|
13141
|
-
|
|
13214
|
+
(function (exports) {
|
|
13215
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13216
|
+
exports.ProcessMessageResultType = exports.CRDTMessageType = void 0;
|
|
13217
|
+
(function (CRDTMessageType) {
|
|
13218
|
+
CRDTMessageType[CRDTMessageType["CRDTMT_PutComponentData"] = 1] = "CRDTMT_PutComponentData";
|
|
13219
|
+
CRDTMessageType[CRDTMessageType["CRDTMT_DeleteEntity"] = 2] = "CRDTMT_DeleteEntity";
|
|
13220
|
+
})(exports.CRDTMessageType || (exports.CRDTMessageType = {}));
|
|
13221
|
+
(function (ProcessMessageResultType) {
|
|
13222
|
+
/**
|
|
13223
|
+
* Typical message and new state set.
|
|
13224
|
+
* @state CHANGE
|
|
13225
|
+
* @reason Incoming message has a timestamp greater
|
|
13226
|
+
*/
|
|
13227
|
+
ProcessMessageResultType[ProcessMessageResultType["StateUpdatedTimestamp"] = 1] = "StateUpdatedTimestamp";
|
|
13228
|
+
/**
|
|
13229
|
+
* Typical message when it is considered old.
|
|
13230
|
+
* @state it does NOT CHANGE.
|
|
13231
|
+
* @reason incoming message has a timestamp lower.
|
|
13232
|
+
*/
|
|
13233
|
+
ProcessMessageResultType[ProcessMessageResultType["StateOutdatedTimestamp"] = 2] = "StateOutdatedTimestamp";
|
|
13234
|
+
/**
|
|
13235
|
+
* Weird message, same timestamp and data.
|
|
13236
|
+
* @state it does NOT CHANGE.
|
|
13237
|
+
* @reason consistent state between peers.
|
|
13238
|
+
*/
|
|
13239
|
+
ProcessMessageResultType[ProcessMessageResultType["NoChanges"] = 3] = "NoChanges";
|
|
13240
|
+
/**
|
|
13241
|
+
* Less but typical message, same timestamp, resolution by data.
|
|
13242
|
+
* @state it does NOT CHANGE.
|
|
13243
|
+
* @reason incoming message has a LOWER data.
|
|
13244
|
+
*/
|
|
13245
|
+
ProcessMessageResultType[ProcessMessageResultType["StateOutdatedData"] = 4] = "StateOutdatedData";
|
|
13246
|
+
/**
|
|
13247
|
+
* Less but typical message, same timestamp, resolution by data.
|
|
13248
|
+
* @state CHANGE.
|
|
13249
|
+
* @reason incoming message has a GREATER data.
|
|
13250
|
+
*/
|
|
13251
|
+
ProcessMessageResultType[ProcessMessageResultType["StateUpdatedData"] = 5] = "StateUpdatedData";
|
|
13252
|
+
/**
|
|
13253
|
+
* Entity was previously deleted.
|
|
13254
|
+
* @state it does NOT CHANGE.
|
|
13255
|
+
* @reason The message is considered old.
|
|
13256
|
+
*/
|
|
13257
|
+
ProcessMessageResultType[ProcessMessageResultType["EntityWasDeleted"] = 6] = "EntityWasDeleted";
|
|
13258
|
+
/**
|
|
13259
|
+
* Entity should be deleted.
|
|
13260
|
+
* @state CHANGE.
|
|
13261
|
+
* @reason the state is storing old entities
|
|
13262
|
+
*/
|
|
13263
|
+
ProcessMessageResultType[ProcessMessageResultType["EntityDeleted"] = 7] = "EntityDeleted";
|
|
13264
|
+
})(exports.ProcessMessageResultType || (exports.ProcessMessageResultType = {}));
|
|
13265
|
+
// we receive LWW, v=6, we have v=5 => we receive with delay the deleteEntity(v=5)
|
|
13266
|
+
// => we should generate the deleteEntity message effects internally with deleteEntity(v=5),
|
|
13267
|
+
// but don't resend the deleteEntity
|
|
13268
|
+
// - (CRDT) addDeletedEntitySet v=5 (with crdt state cleaning) and then LWW v=6
|
|
13269
|
+
// - (engine) engine.deleteEntity v=5
|
|
13270
|
+
// we receive LWW, v=7, we have v=5 => we receive with delay the deleteEntity(v=5), deleteEntity(v=6), ..., N
|
|
13271
|
+
// => we should generate the deleteEntity message effects internally with deleteEntity(v=5),
|
|
13272
|
+
// but don't resend the deleteEntity
|
|
13273
|
+
// - (CRDT) addDeletedEntitySet v=5 (with crdt state cleaning) and then LWW v=6
|
|
13274
|
+
// - (engine) engine.deleteEntity v=5
|
|
13275
|
+
// msg delete entity: it only should be sent by deleter
|
|
13276
|
+
//
|
|
13277
|
+
|
|
13278
|
+
} (types));
|
|
13142
13279
|
return types;
|
|
13143
13280
|
}
|
|
13144
13281
|
|
|
@@ -13163,46 +13300,57 @@
|
|
|
13163
13300
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
13164
13301
|
};
|
|
13165
13302
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13166
|
-
exports.crdtProtocol = exports.stateIterator = exports.
|
|
13167
|
-
|
|
13303
|
+
exports.crdtProtocol = exports.stateIterator = exports.dataCompare = void 0;
|
|
13304
|
+
const gset_1 = requireGset();
|
|
13305
|
+
const types_1 = requireTypes();
|
|
13168
13306
|
const globalBuffer = globalThis.Buffer;
|
|
13307
|
+
__exportStar(requireTypes(), exports);
|
|
13169
13308
|
/**
|
|
13170
13309
|
* Compare raw data.
|
|
13171
13310
|
* @internal
|
|
13311
|
+
* @returns 0 if is the same data, 1 if a > b, -1 if b > a
|
|
13172
13312
|
*/
|
|
13173
|
-
function
|
|
13313
|
+
function dataCompare(a, b) {
|
|
13174
13314
|
// At reference level
|
|
13175
13315
|
if (a === b)
|
|
13176
|
-
return
|
|
13316
|
+
return 0;
|
|
13317
|
+
if (a === null && b !== null)
|
|
13318
|
+
return -1;
|
|
13319
|
+
if (a !== null && b === null)
|
|
13320
|
+
return 1;
|
|
13177
13321
|
if (a instanceof Uint8Array && b instanceof Uint8Array) {
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
if (
|
|
13183
|
-
return
|
|
13322
|
+
let res;
|
|
13323
|
+
const n = a.byteLength > b.byteLength ? b.byteLength : a.byteLength;
|
|
13324
|
+
for (let i = 0; i < n; i++) {
|
|
13325
|
+
res = a[i] - b[i];
|
|
13326
|
+
if (res !== 0) {
|
|
13327
|
+
return res > 0 ? 1 : -1;
|
|
13184
13328
|
}
|
|
13185
13329
|
}
|
|
13186
|
-
|
|
13330
|
+
res = a.byteLength - b.byteLength;
|
|
13331
|
+
return res > 0 ? 1 : res < 0 ? -1 : 0;
|
|
13187
13332
|
}
|
|
13188
13333
|
if (globalBuffer) {
|
|
13189
13334
|
/* istanbul ignore next */
|
|
13190
13335
|
if (a instanceof globalBuffer && b instanceof globalBuffer) {
|
|
13191
13336
|
/* istanbul ignore next */
|
|
13192
|
-
return a.
|
|
13337
|
+
return a.compare(b);
|
|
13193
13338
|
}
|
|
13194
13339
|
}
|
|
13195
|
-
|
|
13340
|
+
if (typeof a === 'string') {
|
|
13341
|
+
return a.localeCompare(b);
|
|
13342
|
+
}
|
|
13343
|
+
return a > b ? 1 : -1;
|
|
13196
13344
|
}
|
|
13197
|
-
exports.
|
|
13345
|
+
exports.dataCompare = dataCompare;
|
|
13198
13346
|
/**
|
|
13199
13347
|
* State iterator
|
|
13200
13348
|
* @internal
|
|
13201
13349
|
*/
|
|
13202
13350
|
function* stateIterator(state) {
|
|
13203
|
-
for (const [
|
|
13204
|
-
for (const [
|
|
13205
|
-
yield [
|
|
13351
|
+
for (const [componentId, value1] of state.components.entries()) {
|
|
13352
|
+
for (const [entityId, value2] of value1.entries()) {
|
|
13353
|
+
yield [componentId, entityId, value2];
|
|
13206
13354
|
}
|
|
13207
13355
|
}
|
|
13208
13356
|
}
|
|
@@ -13214,40 +13362,70 @@
|
|
|
13214
13362
|
* to process and store the new data in case its an update, or
|
|
13215
13363
|
* to discard and send our local value cause remote it's outdated.
|
|
13216
13364
|
*/
|
|
13217
|
-
function crdtProtocol() {
|
|
13365
|
+
function crdtProtocol(entityUtils) {
|
|
13218
13366
|
/**
|
|
13219
13367
|
* Local state where we store the latest lamport timestamp
|
|
13220
13368
|
* and the raw data value
|
|
13221
13369
|
* @internal
|
|
13222
13370
|
*/
|
|
13223
|
-
const state =
|
|
13371
|
+
const state = {
|
|
13372
|
+
components: new Map(),
|
|
13373
|
+
deletedEntities: (0, gset_1.createGSet)()
|
|
13374
|
+
};
|
|
13224
13375
|
/**
|
|
13225
13376
|
* We should call this fn in order to update the state
|
|
13226
13377
|
* @internal
|
|
13227
13378
|
*/
|
|
13228
|
-
function updateState(
|
|
13229
|
-
|
|
13230
|
-
const
|
|
13231
|
-
|
|
13232
|
-
|
|
13379
|
+
function updateState(componentId, entityId, // todo: force type entity
|
|
13380
|
+
data, remoteTimestamp) {
|
|
13381
|
+
const componentIdValue = state.components.get(componentId);
|
|
13382
|
+
const timestamp = Math.max(remoteTimestamp, componentIdValue?.get(entityId)?.timestamp || 0);
|
|
13383
|
+
if (componentIdValue) {
|
|
13384
|
+
componentIdValue.set(entityId, { timestamp, data });
|
|
13233
13385
|
}
|
|
13234
13386
|
else {
|
|
13235
|
-
const
|
|
13236
|
-
|
|
13237
|
-
state.set(
|
|
13387
|
+
const componentIdValue = new Map();
|
|
13388
|
+
componentIdValue.set(entityId, { timestamp, data });
|
|
13389
|
+
state.components.set(componentId, componentIdValue);
|
|
13238
13390
|
}
|
|
13239
13391
|
return { timestamp, data };
|
|
13240
13392
|
}
|
|
13241
13393
|
/**
|
|
13242
13394
|
* Create an event for the specified key and store the new data and
|
|
13243
|
-
* lamport timestmap incremented by one in the state.
|
|
13395
|
+
* lamport timestmap incremented by one in the state.components.
|
|
13244
13396
|
* @public
|
|
13245
13397
|
*/
|
|
13246
|
-
function
|
|
13398
|
+
function createComponentDataEvent(componentId, entityId, data) {
|
|
13247
13399
|
// Increment the timestamp
|
|
13248
|
-
const timestamp = (state.get(
|
|
13249
|
-
|
|
13250
|
-
|
|
13400
|
+
const timestamp = (state.components.get(componentId)?.get(entityId)?.timestamp || 0) + 1;
|
|
13401
|
+
const msg = {
|
|
13402
|
+
type: types_1.CRDTMessageType.CRDTMT_PutComponentData,
|
|
13403
|
+
componentId,
|
|
13404
|
+
entityId,
|
|
13405
|
+
data,
|
|
13406
|
+
timestamp
|
|
13407
|
+
};
|
|
13408
|
+
const res = processComponentDataMessage(msg);
|
|
13409
|
+
if (res === types_1.ProcessMessageResultType.StateUpdatedTimestamp) {
|
|
13410
|
+
return msg;
|
|
13411
|
+
}
|
|
13412
|
+
else {
|
|
13413
|
+
return null;
|
|
13414
|
+
}
|
|
13415
|
+
}
|
|
13416
|
+
/**
|
|
13417
|
+
* Create an event for the specified key and store the new data and
|
|
13418
|
+
* lamport timestmap incremented by one in the state.components.
|
|
13419
|
+
* @public
|
|
13420
|
+
*/
|
|
13421
|
+
function createDeleteEntityEvent(entityId) {
|
|
13422
|
+
// Increment the timestamp
|
|
13423
|
+
const message = {
|
|
13424
|
+
type: types_1.CRDTMessageType.CRDTMT_DeleteEntity,
|
|
13425
|
+
entityId
|
|
13426
|
+
};
|
|
13427
|
+
processDeleteEntityMessage(message);
|
|
13428
|
+
return message;
|
|
13251
13429
|
}
|
|
13252
13430
|
/**
|
|
13253
13431
|
* Process the received message only if the lamport number recieved is higher
|
|
@@ -13258,42 +13436,59 @@
|
|
|
13258
13436
|
* If it was an outdated message, then we return void
|
|
13259
13437
|
* @public
|
|
13260
13438
|
*/
|
|
13261
|
-
function
|
|
13262
|
-
const
|
|
13263
|
-
|
|
13264
|
-
|
|
13439
|
+
function processComponentDataMessage(message) {
|
|
13440
|
+
const [entityNumber, entityVersion] = entityUtils.fromEntityId(message.entityId);
|
|
13441
|
+
if (state.deletedEntities.has(entityNumber, entityVersion)) {
|
|
13442
|
+
return types_1.ProcessMessageResultType.EntityWasDeleted;
|
|
13443
|
+
}
|
|
13444
|
+
const { componentId, entityId, data, timestamp } = message;
|
|
13445
|
+
const current = state.components.get(componentId)?.get(entityId);
|
|
13446
|
+
// The received message is > than our current value, update our state.components.
|
|
13265
13447
|
if (!current || current.timestamp < timestamp) {
|
|
13266
|
-
updateState(
|
|
13267
|
-
return
|
|
13448
|
+
updateState(componentId, entityId, data, timestamp);
|
|
13449
|
+
return types_1.ProcessMessageResultType.StateUpdatedTimestamp;
|
|
13268
13450
|
}
|
|
13269
13451
|
// Outdated Message. Resend our state message through the wire.
|
|
13270
13452
|
if (current.timestamp > timestamp) {
|
|
13271
|
-
return
|
|
13272
|
-
key1,
|
|
13273
|
-
key2,
|
|
13274
|
-
data: current.data,
|
|
13275
|
-
timestamp: current.timestamp
|
|
13276
|
-
};
|
|
13453
|
+
return types_1.ProcessMessageResultType.StateOutdatedData;
|
|
13277
13454
|
}
|
|
13455
|
+
const currentDataGreater = dataCompare(current.data, data);
|
|
13278
13456
|
// Same data, same timestamp. Weirdo echo message.
|
|
13279
|
-
if (
|
|
13280
|
-
return
|
|
13457
|
+
if (currentDataGreater === 0) {
|
|
13458
|
+
return types_1.ProcessMessageResultType.NoChanges;
|
|
13459
|
+
// Current data is greater
|
|
13281
13460
|
}
|
|
13282
|
-
|
|
13283
|
-
|
|
13284
|
-
//
|
|
13285
|
-
return !current || current > data;
|
|
13461
|
+
else if (currentDataGreater > 0) {
|
|
13462
|
+
return types_1.ProcessMessageResultType.StateOutdatedData;
|
|
13463
|
+
// Curent data is lower
|
|
13286
13464
|
}
|
|
13287
|
-
|
|
13288
|
-
|
|
13289
|
-
|
|
13290
|
-
key2,
|
|
13291
|
-
data: current.data,
|
|
13292
|
-
timestamp: current.timestamp
|
|
13293
|
-
};
|
|
13465
|
+
else {
|
|
13466
|
+
updateState(componentId, entityId, data, timestamp);
|
|
13467
|
+
return types_1.ProcessMessageResultType.StateUpdatedData;
|
|
13294
13468
|
}
|
|
13295
|
-
|
|
13296
|
-
|
|
13469
|
+
}
|
|
13470
|
+
/*
|
|
13471
|
+
* @public
|
|
13472
|
+
*/
|
|
13473
|
+
function processMessage(message) {
|
|
13474
|
+
if (message.type === types_1.CRDTMessageType.CRDTMT_PutComponentData) {
|
|
13475
|
+
return processComponentDataMessage(message);
|
|
13476
|
+
}
|
|
13477
|
+
else if (message.type === types_1.CRDTMessageType.CRDTMT_DeleteEntity) {
|
|
13478
|
+
return processDeleteEntityMessage(message);
|
|
13479
|
+
}
|
|
13480
|
+
else {
|
|
13481
|
+
return types_1.ProcessMessageResultType.NoChanges;
|
|
13482
|
+
}
|
|
13483
|
+
}
|
|
13484
|
+
function processDeleteEntityMessage(message) {
|
|
13485
|
+
const { entityId } = message;
|
|
13486
|
+
const [entityNumber, entityVersion] = entityUtils.fromEntityId(message.entityId);
|
|
13487
|
+
state.deletedEntities.addTo(entityNumber, entityVersion);
|
|
13488
|
+
for (const [, payload] of state.components) {
|
|
13489
|
+
payload.delete(entityId);
|
|
13490
|
+
}
|
|
13491
|
+
return types_1.ProcessMessageResultType.EntityDeleted;
|
|
13297
13492
|
}
|
|
13298
13493
|
/**
|
|
13299
13494
|
* Returns the current state
|
|
@@ -13306,12 +13501,13 @@
|
|
|
13306
13501
|
* Returns the element state of a given element of the LWW-ElementSet
|
|
13307
13502
|
* @public
|
|
13308
13503
|
*/
|
|
13309
|
-
function getElementSetState(
|
|
13310
|
-
return state.get(
|
|
13504
|
+
function getElementSetState(componentId, entityId) {
|
|
13505
|
+
return state.components.get(componentId)?.get(entityId) || null;
|
|
13311
13506
|
}
|
|
13312
13507
|
return {
|
|
13313
13508
|
getElementSetState,
|
|
13314
|
-
|
|
13509
|
+
createComponentDataEvent,
|
|
13510
|
+
createDeleteEntityEvent,
|
|
13315
13511
|
processMessage,
|
|
13316
13512
|
getState
|
|
13317
13513
|
};
|
|
@@ -13324,8 +13520,179 @@
|
|
|
13324
13520
|
|
|
13325
13521
|
var distExports = requireDist();
|
|
13326
13522
|
|
|
13523
|
+
var typesExports = requireTypes();
|
|
13524
|
+
|
|
13525
|
+
var gsetExports = requireGset();
|
|
13526
|
+
|
|
13527
|
+
const MAX_U16 = 0xffff;
|
|
13528
|
+
const MASK_UPPER_16_ON_32 = 0xffff0000;
|
|
13529
|
+
const AMOUNT_VERSION_AVAILABLE = MAX_U16 + 1;
|
|
13530
|
+
// This type matches with @dcl/crdt entity type.
|
|
13531
|
+
/**
|
|
13532
|
+
* @public This first 512 entities are reserved by the renderer
|
|
13533
|
+
*/
|
|
13534
|
+
const RESERVED_STATIC_ENTITIES = 512;
|
|
13535
|
+
/**
|
|
13536
|
+
* @public
|
|
13537
|
+
*/
|
|
13538
|
+
const MAX_ENTITY_NUMBER = MAX_U16;
|
|
13539
|
+
exports.EntityUtils = void 0;
|
|
13540
|
+
(function (EntityUtils) {
|
|
13541
|
+
/**
|
|
13542
|
+
* @returns [entityNumber, entityVersion]
|
|
13543
|
+
*/
|
|
13544
|
+
function fromEntityId(entityId) {
|
|
13545
|
+
return [
|
|
13546
|
+
(entityId & MAX_U16) >>> 0,
|
|
13547
|
+
(((entityId & MASK_UPPER_16_ON_32) >> 16) & MAX_U16) >>> 0
|
|
13548
|
+
];
|
|
13549
|
+
}
|
|
13550
|
+
EntityUtils.fromEntityId = fromEntityId;
|
|
13551
|
+
/**
|
|
13552
|
+
* @returns compound number from entityNumber and entityVerison
|
|
13553
|
+
*/
|
|
13554
|
+
function toEntityId(entityNumber, entityVersion) {
|
|
13555
|
+
return (((entityNumber & MAX_U16) | ((entityVersion & MAX_U16) << 16)) >>>
|
|
13556
|
+
0);
|
|
13557
|
+
}
|
|
13558
|
+
EntityUtils.toEntityId = toEntityId;
|
|
13559
|
+
})(exports.EntityUtils || (exports.EntityUtils = {}));
|
|
13560
|
+
/**
|
|
13561
|
+
* @public
|
|
13562
|
+
*/
|
|
13563
|
+
exports.EntityState = void 0;
|
|
13564
|
+
(function (EntityState) {
|
|
13565
|
+
EntityState[EntityState["Unknown"] = 0] = "Unknown";
|
|
13566
|
+
/**
|
|
13567
|
+
* The entity was generated and added to the usedEntities set
|
|
13568
|
+
*/
|
|
13569
|
+
EntityState[EntityState["UsedEntity"] = 1] = "UsedEntity";
|
|
13570
|
+
/**
|
|
13571
|
+
* The entity was removed from current engine or remotely
|
|
13572
|
+
*/
|
|
13573
|
+
EntityState[EntityState["Removed"] = 2] = "Removed";
|
|
13574
|
+
/**
|
|
13575
|
+
* The entity is reserved number.
|
|
13576
|
+
*/
|
|
13577
|
+
EntityState[EntityState["Reserved"] = 3] = "Reserved";
|
|
13578
|
+
})(exports.EntityState || (exports.EntityState = {}));
|
|
13579
|
+
function EntityContainer() {
|
|
13580
|
+
let entityCounter = RESERVED_STATIC_ENTITIES;
|
|
13581
|
+
const usedEntities = new Set();
|
|
13582
|
+
let toRemoveEntities = [];
|
|
13583
|
+
const removedEntities = gsetExports.createGSet();
|
|
13584
|
+
function generateNewEntity() {
|
|
13585
|
+
if (entityCounter > MAX_ENTITY_NUMBER - 1) {
|
|
13586
|
+
throw new Error(`It fails trying to generate an entity out of range ${MAX_ENTITY_NUMBER}.`);
|
|
13587
|
+
}
|
|
13588
|
+
const entityNumber = entityCounter++;
|
|
13589
|
+
const entityVersion = removedEntities.getMap().has(entityNumber)
|
|
13590
|
+
? removedEntities.getMap().get(entityNumber) + 1
|
|
13591
|
+
: 0;
|
|
13592
|
+
const entity = exports.EntityUtils.toEntityId(entityNumber, entityVersion);
|
|
13593
|
+
usedEntities.add(entity);
|
|
13594
|
+
return entity;
|
|
13595
|
+
}
|
|
13596
|
+
function generateEntity() {
|
|
13597
|
+
// If all entities until `entityCounter` are being used, we need to generate another one
|
|
13598
|
+
if (usedEntities.size + RESERVED_STATIC_ENTITIES >= entityCounter) {
|
|
13599
|
+
return generateNewEntity();
|
|
13600
|
+
}
|
|
13601
|
+
for (const [number, version] of removedEntities.getMap()) {
|
|
13602
|
+
if (version < MAX_U16) {
|
|
13603
|
+
const entity = exports.EntityUtils.toEntityId(number, version + 1);
|
|
13604
|
+
// If the entity is not being used, we can re-use it
|
|
13605
|
+
// If the entity was removed in this tick, we're not counting for the usedEntities, but we have it in the toRemoveEntityArray
|
|
13606
|
+
if (!usedEntities.has(entity) && !toRemoveEntities.includes(entity)) {
|
|
13607
|
+
usedEntities.add(entity);
|
|
13608
|
+
return entity;
|
|
13609
|
+
}
|
|
13610
|
+
}
|
|
13611
|
+
}
|
|
13612
|
+
return generateNewEntity();
|
|
13613
|
+
}
|
|
13614
|
+
function removeEntity(entity) {
|
|
13615
|
+
if (entity < RESERVED_STATIC_ENTITIES)
|
|
13616
|
+
return false;
|
|
13617
|
+
if (usedEntities.has(entity)) {
|
|
13618
|
+
usedEntities.delete(entity);
|
|
13619
|
+
toRemoveEntities.push(entity);
|
|
13620
|
+
}
|
|
13621
|
+
else {
|
|
13622
|
+
updateRemovedEntity(entity);
|
|
13623
|
+
}
|
|
13624
|
+
return true;
|
|
13625
|
+
}
|
|
13626
|
+
function releaseRemovedEntities() {
|
|
13627
|
+
const arr = toRemoveEntities;
|
|
13628
|
+
toRemoveEntities = [];
|
|
13629
|
+
for (const entity of arr) {
|
|
13630
|
+
const [n, v] = exports.EntityUtils.fromEntityId(entity);
|
|
13631
|
+
removedEntities.addTo(n, v);
|
|
13632
|
+
}
|
|
13633
|
+
return arr;
|
|
13634
|
+
}
|
|
13635
|
+
function updateRemovedEntity(entity) {
|
|
13636
|
+
const [n, v] = exports.EntityUtils.fromEntityId(entity);
|
|
13637
|
+
// Update the removed entities map
|
|
13638
|
+
removedEntities.addTo(n, v);
|
|
13639
|
+
// Remove the usedEntities if exist
|
|
13640
|
+
for (let i = 0; i <= v; i++) {
|
|
13641
|
+
usedEntities.delete(exports.EntityUtils.toEntityId(n, i));
|
|
13642
|
+
}
|
|
13643
|
+
return true;
|
|
13644
|
+
}
|
|
13645
|
+
function updateUsedEntity(entity) {
|
|
13646
|
+
const [n, v] = exports.EntityUtils.fromEntityId(entity);
|
|
13647
|
+
const removedVersion = removedEntities.getMap().get(n);
|
|
13648
|
+
if (removedVersion !== undefined && removedVersion >= v) {
|
|
13649
|
+
return false;
|
|
13650
|
+
}
|
|
13651
|
+
// Update
|
|
13652
|
+
if (v > 0) {
|
|
13653
|
+
for (let i = 0; i <= v - 1; i++) {
|
|
13654
|
+
usedEntities.delete(exports.EntityUtils.toEntityId(n, i));
|
|
13655
|
+
}
|
|
13656
|
+
removedEntities.addTo(n, v - 1);
|
|
13657
|
+
}
|
|
13658
|
+
usedEntities.add(entity);
|
|
13659
|
+
return true;
|
|
13660
|
+
}
|
|
13661
|
+
function getEntityState(entity) {
|
|
13662
|
+
const [n, v] = exports.EntityUtils.fromEntityId(entity);
|
|
13663
|
+
if (n < RESERVED_STATIC_ENTITIES) {
|
|
13664
|
+
return exports.EntityState.Reserved;
|
|
13665
|
+
}
|
|
13666
|
+
if (usedEntities.has(entity)) {
|
|
13667
|
+
return exports.EntityState.UsedEntity;
|
|
13668
|
+
}
|
|
13669
|
+
const removedVersion = removedEntities.getMap().get(n);
|
|
13670
|
+
if (removedVersion !== undefined && removedVersion >= v) {
|
|
13671
|
+
return exports.EntityState.Removed;
|
|
13672
|
+
}
|
|
13673
|
+
return exports.EntityState.Unknown;
|
|
13674
|
+
}
|
|
13675
|
+
return {
|
|
13676
|
+
generateEntity,
|
|
13677
|
+
removeEntity,
|
|
13678
|
+
getExistingEntities() {
|
|
13679
|
+
return new Set(usedEntities);
|
|
13680
|
+
},
|
|
13681
|
+
getEntityState,
|
|
13682
|
+
releaseRemovedEntities,
|
|
13683
|
+
updateRemovedEntity,
|
|
13684
|
+
updateUsedEntity
|
|
13685
|
+
};
|
|
13686
|
+
}
|
|
13687
|
+
|
|
13327
13688
|
var utf8Exports = requireUtf8();
|
|
13328
13689
|
|
|
13690
|
+
var __classPrivateFieldGet = (globalThis && globalThis.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
13691
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13692
|
+
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");
|
|
13693
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13694
|
+
};
|
|
13695
|
+
var _ReadWriteByteBuffer_instances, _ReadWriteByteBuffer_woAdd, _ReadWriteByteBuffer_roAdd;
|
|
13329
13696
|
/**
|
|
13330
13697
|
* Take the max between currentSize and intendedSize and then plus 1024. Then,
|
|
13331
13698
|
* find the next nearer multiple of 1024.
|
|
@@ -13345,275 +13712,358 @@
|
|
|
13345
13712
|
* - Use read and write function to generate or consume data.
|
|
13346
13713
|
* - Use set and get only if you are sure that you're doing.
|
|
13347
13714
|
*/
|
|
13348
|
-
|
|
13349
|
-
const initialROffset = options.reading?.currentOffset || 0;
|
|
13350
|
-
let initialBuffer = null;
|
|
13351
|
-
let initialWOffset = 0;
|
|
13352
|
-
if (options.writing) {
|
|
13353
|
-
initialBuffer = options.writing.buffer;
|
|
13354
|
-
if (options.writing.currentOffset) {
|
|
13355
|
-
initialWOffset = options.writing.currentOffset;
|
|
13356
|
-
}
|
|
13357
|
-
}
|
|
13358
|
-
else if (options.reading) {
|
|
13359
|
-
initialBuffer = options.reading.buffer;
|
|
13360
|
-
initialWOffset = options.reading.length || options.reading.buffer.length;
|
|
13361
|
-
}
|
|
13362
|
-
else {
|
|
13363
|
-
initialBuffer = new Uint8Array(options.initialCapacity || defaultInitialCapacity);
|
|
13364
|
-
}
|
|
13365
|
-
let buffer = initialBuffer;
|
|
13366
|
-
let view = new DataView(buffer.buffer, buffer.byteOffset);
|
|
13367
|
-
let woffset = initialWOffset;
|
|
13368
|
-
let roffset = initialROffset;
|
|
13369
|
-
/**
|
|
13370
|
-
* Increement the write offset and resize the buffer if it needs.
|
|
13371
|
-
*/
|
|
13372
|
-
const woAdd = (amount) => {
|
|
13373
|
-
if (woffset + amount > buffer.byteLength) {
|
|
13374
|
-
const newsize = getNextSize(buffer.byteLength, woffset + amount);
|
|
13375
|
-
const newBuffer = new Uint8Array(newsize);
|
|
13376
|
-
newBuffer.set(buffer);
|
|
13377
|
-
buffer = newBuffer;
|
|
13378
|
-
view = new DataView(buffer.buffer);
|
|
13379
|
-
}
|
|
13380
|
-
woffset += amount;
|
|
13381
|
-
return woffset - amount;
|
|
13382
|
-
};
|
|
13715
|
+
class ReadWriteByteBuffer {
|
|
13383
13716
|
/**
|
|
13384
|
-
*
|
|
13385
|
-
*
|
|
13717
|
+
* @param buffer - The initial buffer, provide a buffer if you need to set "initial capacity"
|
|
13718
|
+
* @param readingOffset - Set the cursor where begins to read. Default 0
|
|
13719
|
+
* @param writingOffset - Set the cursor to not start writing from the begin of it. Defaults to the buffer size
|
|
13386
13720
|
*/
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
13721
|
+
constructor(buffer, readingOffset, writingOffset) {
|
|
13722
|
+
_ReadWriteByteBuffer_instances.add(this);
|
|
13723
|
+
this._buffer = buffer || new Uint8Array(defaultInitialCapacity);
|
|
13724
|
+
this.view = new DataView(this._buffer.buffer, this._buffer.byteOffset);
|
|
13725
|
+
this.woffset = writingOffset ?? (buffer ? this._buffer.length : null) ?? 0;
|
|
13726
|
+
this.roffset = readingOffset ?? 0;
|
|
13727
|
+
}
|
|
13728
|
+
buffer() {
|
|
13729
|
+
return this._buffer;
|
|
13730
|
+
}
|
|
13731
|
+
bufferLength() {
|
|
13732
|
+
return this._buffer.length;
|
|
13733
|
+
}
|
|
13734
|
+
resetBuffer() {
|
|
13735
|
+
this.roffset = 0;
|
|
13736
|
+
this.woffset = 0;
|
|
13737
|
+
}
|
|
13738
|
+
currentReadOffset() {
|
|
13739
|
+
return this.roffset;
|
|
13740
|
+
}
|
|
13741
|
+
currentWriteOffset() {
|
|
13742
|
+
return this.woffset;
|
|
13743
|
+
}
|
|
13744
|
+
incrementReadOffset(amount) {
|
|
13745
|
+
return __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, amount);
|
|
13746
|
+
}
|
|
13747
|
+
remainingBytes() {
|
|
13748
|
+
return this.woffset - this.roffset;
|
|
13749
|
+
}
|
|
13750
|
+
readFloat32() {
|
|
13751
|
+
return this.view.getFloat32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
13752
|
+
}
|
|
13753
|
+
readFloat64() {
|
|
13754
|
+
return this.view.getFloat64(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 8));
|
|
13755
|
+
}
|
|
13756
|
+
readInt8() {
|
|
13757
|
+
return this.view.getInt8(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 1));
|
|
13758
|
+
}
|
|
13759
|
+
readInt16() {
|
|
13760
|
+
return this.view.getInt16(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 2));
|
|
13761
|
+
}
|
|
13762
|
+
readInt32() {
|
|
13763
|
+
return this.view.getInt32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
13764
|
+
}
|
|
13765
|
+
readInt64() {
|
|
13766
|
+
return this.view.getBigInt64(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 8));
|
|
13767
|
+
}
|
|
13768
|
+
readUint8() {
|
|
13769
|
+
return this.view.getUint8(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 1));
|
|
13770
|
+
}
|
|
13771
|
+
readUint16() {
|
|
13772
|
+
return this.view.getUint16(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 2));
|
|
13773
|
+
}
|
|
13774
|
+
readUint32() {
|
|
13775
|
+
return this.view.getUint32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
13776
|
+
}
|
|
13777
|
+
readUint64() {
|
|
13778
|
+
return this.view.getBigUint64(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 8));
|
|
13779
|
+
}
|
|
13780
|
+
readBuffer() {
|
|
13781
|
+
const length = this.view.getUint32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
13782
|
+
return this._buffer.subarray(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, length), __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 0));
|
|
13783
|
+
}
|
|
13784
|
+
readUtf8String() {
|
|
13785
|
+
const length = this.view.getUint32(__classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 4));
|
|
13786
|
+
return utf8Exports.read(this._buffer, __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, length), __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_roAdd).call(this, 0));
|
|
13787
|
+
}
|
|
13788
|
+
incrementWriteOffset(amount) {
|
|
13789
|
+
return __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, amount);
|
|
13790
|
+
}
|
|
13791
|
+
toBinary() {
|
|
13792
|
+
return this._buffer.subarray(0, this.woffset);
|
|
13793
|
+
}
|
|
13794
|
+
toCopiedBinary() {
|
|
13795
|
+
return new Uint8Array(this.toBinary());
|
|
13796
|
+
}
|
|
13797
|
+
writeBuffer(value, writeLength = true) {
|
|
13798
|
+
if (writeLength) {
|
|
13799
|
+
this.writeUint32(value.byteLength);
|
|
13390
13800
|
}
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
}
|
|
13394
|
-
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
bufferLength() {
|
|
13399
|
-
return buffer.length;
|
|
13400
|
-
},
|
|
13401
|
-
resetBuffer() {
|
|
13402
|
-
roffset = 0;
|
|
13403
|
-
woffset = 0;
|
|
13404
|
-
},
|
|
13405
|
-
currentReadOffset() {
|
|
13406
|
-
return roffset;
|
|
13407
|
-
},
|
|
13408
|
-
currentWriteOffset() {
|
|
13409
|
-
return woffset;
|
|
13410
|
-
},
|
|
13411
|
-
incrementReadOffset(amount) {
|
|
13412
|
-
return roAdd(amount);
|
|
13413
|
-
},
|
|
13414
|
-
remainingBytes() {
|
|
13415
|
-
return woffset - roffset;
|
|
13416
|
-
},
|
|
13417
|
-
readFloat32() {
|
|
13418
|
-
return view.getFloat32(roAdd(4));
|
|
13419
|
-
},
|
|
13420
|
-
readFloat64() {
|
|
13421
|
-
return view.getFloat64(roAdd(8));
|
|
13422
|
-
},
|
|
13423
|
-
readInt8() {
|
|
13424
|
-
return view.getInt8(roAdd(1));
|
|
13425
|
-
},
|
|
13426
|
-
readInt16() {
|
|
13427
|
-
return view.getInt16(roAdd(2));
|
|
13428
|
-
},
|
|
13429
|
-
readInt32() {
|
|
13430
|
-
return view.getInt32(roAdd(4));
|
|
13431
|
-
},
|
|
13432
|
-
readInt64() {
|
|
13433
|
-
return view.getBigInt64(roAdd(8));
|
|
13434
|
-
},
|
|
13435
|
-
readUint8() {
|
|
13436
|
-
return view.getUint8(roAdd(1));
|
|
13437
|
-
},
|
|
13438
|
-
readUint16() {
|
|
13439
|
-
return view.getUint16(roAdd(2));
|
|
13440
|
-
},
|
|
13441
|
-
readUint32() {
|
|
13442
|
-
return view.getUint32(roAdd(4));
|
|
13443
|
-
},
|
|
13444
|
-
readUint64() {
|
|
13445
|
-
return view.getBigUint64(roAdd(8));
|
|
13446
|
-
},
|
|
13447
|
-
readBuffer() {
|
|
13448
|
-
const length = view.getUint32(roAdd(4));
|
|
13449
|
-
return buffer.subarray(roAdd(length), roAdd(0));
|
|
13450
|
-
},
|
|
13451
|
-
readUtf8String() {
|
|
13452
|
-
const length = view.getUint32(roAdd(4));
|
|
13453
|
-
return utf8Exports.read(buffer, roAdd(length), roAdd(0));
|
|
13454
|
-
},
|
|
13455
|
-
incrementWriteOffset(amount) {
|
|
13456
|
-
return woAdd(amount);
|
|
13457
|
-
},
|
|
13458
|
-
size() {
|
|
13459
|
-
return woffset;
|
|
13460
|
-
},
|
|
13461
|
-
toBinary() {
|
|
13462
|
-
return buffer.subarray(0, woffset);
|
|
13463
|
-
},
|
|
13464
|
-
toCopiedBinary() {
|
|
13465
|
-
return new Uint8Array(this.toBinary());
|
|
13466
|
-
},
|
|
13467
|
-
writeBuffer(value, writeLength = true) {
|
|
13468
|
-
if (writeLength) {
|
|
13469
|
-
this.writeUint32(value.byteLength);
|
|
13470
|
-
}
|
|
13471
|
-
const o = woAdd(value.byteLength);
|
|
13472
|
-
buffer.set(value, o);
|
|
13473
|
-
},
|
|
13474
|
-
writeUtf8String(value, writeLength = true) {
|
|
13475
|
-
const byteLength = utf8Exports.length(value);
|
|
13476
|
-
if (writeLength) {
|
|
13477
|
-
this.writeUint32(byteLength);
|
|
13478
|
-
}
|
|
13479
|
-
const o = woAdd(byteLength);
|
|
13480
|
-
utf8Exports.write(value, buffer, o);
|
|
13481
|
-
},
|
|
13482
|
-
writeFloat32(value) {
|
|
13483
|
-
const o = woAdd(4);
|
|
13484
|
-
view.setFloat32(o, value);
|
|
13485
|
-
},
|
|
13486
|
-
writeFloat64(value) {
|
|
13487
|
-
const o = woAdd(8);
|
|
13488
|
-
view.setFloat64(o, value);
|
|
13489
|
-
},
|
|
13490
|
-
writeInt8(value) {
|
|
13491
|
-
const o = woAdd(1);
|
|
13492
|
-
view.setInt8(o, value);
|
|
13493
|
-
},
|
|
13494
|
-
writeInt16(value) {
|
|
13495
|
-
const o = woAdd(2);
|
|
13496
|
-
view.setInt16(o, value);
|
|
13497
|
-
},
|
|
13498
|
-
writeInt32(value) {
|
|
13499
|
-
const o = woAdd(4);
|
|
13500
|
-
view.setInt32(o, value);
|
|
13501
|
-
},
|
|
13502
|
-
writeInt64(value) {
|
|
13503
|
-
const o = woAdd(8);
|
|
13504
|
-
view.setBigInt64(o, value);
|
|
13505
|
-
},
|
|
13506
|
-
writeUint8(value) {
|
|
13507
|
-
const o = woAdd(1);
|
|
13508
|
-
view.setUint8(o, value);
|
|
13509
|
-
},
|
|
13510
|
-
writeUint16(value) {
|
|
13511
|
-
const o = woAdd(2);
|
|
13512
|
-
view.setUint16(o, value);
|
|
13513
|
-
},
|
|
13514
|
-
writeUint32(value) {
|
|
13515
|
-
const o = woAdd(4);
|
|
13516
|
-
view.setUint32(o, value);
|
|
13517
|
-
},
|
|
13518
|
-
writeUint64(value) {
|
|
13519
|
-
const o = woAdd(8);
|
|
13520
|
-
view.setBigUint64(o, value);
|
|
13521
|
-
},
|
|
13522
|
-
// Dataview Proxy
|
|
13523
|
-
getFloat32(offset) {
|
|
13524
|
-
return view.getFloat32(offset);
|
|
13525
|
-
},
|
|
13526
|
-
getFloat64(offset) {
|
|
13527
|
-
return view.getFloat64(offset);
|
|
13528
|
-
},
|
|
13529
|
-
getInt8(offset) {
|
|
13530
|
-
return view.getInt8(offset);
|
|
13531
|
-
},
|
|
13532
|
-
getInt16(offset) {
|
|
13533
|
-
return view.getInt16(offset);
|
|
13534
|
-
},
|
|
13535
|
-
getInt32(offset) {
|
|
13536
|
-
return view.getInt32(offset);
|
|
13537
|
-
},
|
|
13538
|
-
getInt64(offset) {
|
|
13539
|
-
return view.getBigInt64(offset);
|
|
13540
|
-
},
|
|
13541
|
-
getUint8(offset) {
|
|
13542
|
-
return view.getUint8(offset);
|
|
13543
|
-
},
|
|
13544
|
-
getUint16(offset) {
|
|
13545
|
-
return view.getUint16(offset);
|
|
13546
|
-
},
|
|
13547
|
-
getUint32(offset) {
|
|
13548
|
-
return view.getUint32(offset);
|
|
13549
|
-
},
|
|
13550
|
-
getUint64(offset) {
|
|
13551
|
-
return view.getBigUint64(offset);
|
|
13552
|
-
},
|
|
13553
|
-
setFloat32(offset, value) {
|
|
13554
|
-
view.setFloat32(offset, value);
|
|
13555
|
-
},
|
|
13556
|
-
setFloat64(offset, value) {
|
|
13557
|
-
view.setFloat64(offset, value);
|
|
13558
|
-
},
|
|
13559
|
-
setInt8(offset, value) {
|
|
13560
|
-
view.setInt8(offset, value);
|
|
13561
|
-
},
|
|
13562
|
-
setInt16(offset, value) {
|
|
13563
|
-
view.setInt16(offset, value);
|
|
13564
|
-
},
|
|
13565
|
-
setInt32(offset, value) {
|
|
13566
|
-
view.setInt32(offset, value);
|
|
13567
|
-
},
|
|
13568
|
-
setInt64(offset, value) {
|
|
13569
|
-
view.setBigInt64(offset, value);
|
|
13570
|
-
},
|
|
13571
|
-
setUint8(offset, value) {
|
|
13572
|
-
view.setUint8(offset, value);
|
|
13573
|
-
},
|
|
13574
|
-
setUint16(offset, value) {
|
|
13575
|
-
view.setUint16(offset, value);
|
|
13576
|
-
},
|
|
13577
|
-
setUint32(offset, value) {
|
|
13578
|
-
view.setUint32(offset, value);
|
|
13579
|
-
},
|
|
13580
|
-
setUint64(offset, value) {
|
|
13581
|
-
view.setBigUint64(offset, value);
|
|
13801
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, value.byteLength);
|
|
13802
|
+
this._buffer.set(value, o);
|
|
13803
|
+
}
|
|
13804
|
+
writeUtf8String(value, writeLength = true) {
|
|
13805
|
+
const byteLength = utf8Exports.length(value);
|
|
13806
|
+
if (writeLength) {
|
|
13807
|
+
this.writeUint32(byteLength);
|
|
13582
13808
|
}
|
|
13583
|
-
|
|
13809
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, byteLength);
|
|
13810
|
+
utf8Exports.write(value, this._buffer, o);
|
|
13811
|
+
}
|
|
13812
|
+
writeFloat32(value) {
|
|
13813
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 4);
|
|
13814
|
+
this.view.setFloat32(o, value);
|
|
13815
|
+
}
|
|
13816
|
+
writeFloat64(value) {
|
|
13817
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 8);
|
|
13818
|
+
this.view.setFloat64(o, value);
|
|
13819
|
+
}
|
|
13820
|
+
writeInt8(value) {
|
|
13821
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 1);
|
|
13822
|
+
this.view.setInt8(o, value);
|
|
13823
|
+
}
|
|
13824
|
+
writeInt16(value) {
|
|
13825
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 2);
|
|
13826
|
+
this.view.setInt16(o, value);
|
|
13827
|
+
}
|
|
13828
|
+
writeInt32(value) {
|
|
13829
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 4);
|
|
13830
|
+
this.view.setInt32(o, value);
|
|
13831
|
+
}
|
|
13832
|
+
writeInt64(value) {
|
|
13833
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 8);
|
|
13834
|
+
this.view.setBigInt64(o, value);
|
|
13835
|
+
}
|
|
13836
|
+
writeUint8(value) {
|
|
13837
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 1);
|
|
13838
|
+
this.view.setUint8(o, value);
|
|
13839
|
+
}
|
|
13840
|
+
writeUint16(value) {
|
|
13841
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 2);
|
|
13842
|
+
this.view.setUint16(o, value);
|
|
13843
|
+
}
|
|
13844
|
+
writeUint32(value) {
|
|
13845
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 4);
|
|
13846
|
+
this.view.setUint32(o, value);
|
|
13847
|
+
}
|
|
13848
|
+
writeUint64(value) {
|
|
13849
|
+
const o = __classPrivateFieldGet(this, _ReadWriteByteBuffer_instances, "m", _ReadWriteByteBuffer_woAdd).call(this, 8);
|
|
13850
|
+
this.view.setBigUint64(o, value);
|
|
13851
|
+
}
|
|
13852
|
+
// DataView Proxy
|
|
13853
|
+
getFloat32(offset) {
|
|
13854
|
+
return this.view.getFloat32(offset);
|
|
13855
|
+
}
|
|
13856
|
+
getFloat64(offset) {
|
|
13857
|
+
return this.view.getFloat64(offset);
|
|
13858
|
+
}
|
|
13859
|
+
getInt8(offset) {
|
|
13860
|
+
return this.view.getInt8(offset);
|
|
13861
|
+
}
|
|
13862
|
+
getInt16(offset) {
|
|
13863
|
+
return this.view.getInt16(offset);
|
|
13864
|
+
}
|
|
13865
|
+
getInt32(offset) {
|
|
13866
|
+
return this.view.getInt32(offset);
|
|
13867
|
+
}
|
|
13868
|
+
getInt64(offset) {
|
|
13869
|
+
return this.view.getBigInt64(offset);
|
|
13870
|
+
}
|
|
13871
|
+
getUint8(offset) {
|
|
13872
|
+
return this.view.getUint8(offset);
|
|
13873
|
+
}
|
|
13874
|
+
getUint16(offset) {
|
|
13875
|
+
return this.view.getUint16(offset);
|
|
13876
|
+
}
|
|
13877
|
+
getUint32(offset) {
|
|
13878
|
+
return this.view.getUint32(offset);
|
|
13879
|
+
}
|
|
13880
|
+
getUint64(offset) {
|
|
13881
|
+
return this.view.getBigUint64(offset);
|
|
13882
|
+
}
|
|
13883
|
+
setFloat32(offset, value) {
|
|
13884
|
+
this.view.setFloat32(offset, value);
|
|
13885
|
+
}
|
|
13886
|
+
setFloat64(offset, value) {
|
|
13887
|
+
this.view.setFloat64(offset, value);
|
|
13888
|
+
}
|
|
13889
|
+
setInt8(offset, value) {
|
|
13890
|
+
this.view.setInt8(offset, value);
|
|
13891
|
+
}
|
|
13892
|
+
setInt16(offset, value) {
|
|
13893
|
+
this.view.setInt16(offset, value);
|
|
13894
|
+
}
|
|
13895
|
+
setInt32(offset, value) {
|
|
13896
|
+
this.view.setInt32(offset, value);
|
|
13897
|
+
}
|
|
13898
|
+
setInt64(offset, value) {
|
|
13899
|
+
this.view.setBigInt64(offset, value);
|
|
13900
|
+
}
|
|
13901
|
+
setUint8(offset, value) {
|
|
13902
|
+
this.view.setUint8(offset, value);
|
|
13903
|
+
}
|
|
13904
|
+
setUint16(offset, value) {
|
|
13905
|
+
this.view.setUint16(offset, value);
|
|
13906
|
+
}
|
|
13907
|
+
setUint32(offset, value) {
|
|
13908
|
+
this.view.setUint32(offset, value);
|
|
13909
|
+
}
|
|
13910
|
+
setUint64(offset, value) {
|
|
13911
|
+
this.view.setBigUint64(offset, value);
|
|
13912
|
+
}
|
|
13584
13913
|
}
|
|
13914
|
+
_ReadWriteByteBuffer_instances = new WeakSet(), _ReadWriteByteBuffer_woAdd = function _ReadWriteByteBuffer_woAdd(amount) {
|
|
13915
|
+
if (this.woffset + amount > this._buffer.byteLength) {
|
|
13916
|
+
const newsize = getNextSize(this._buffer.byteLength, this.woffset + amount);
|
|
13917
|
+
const newBuffer = new Uint8Array(newsize);
|
|
13918
|
+
newBuffer.set(this._buffer);
|
|
13919
|
+
const oldOffset = this._buffer.byteOffset;
|
|
13920
|
+
this._buffer = newBuffer;
|
|
13921
|
+
this.view = new DataView(this._buffer.buffer, oldOffset);
|
|
13922
|
+
}
|
|
13923
|
+
this.woffset += amount;
|
|
13924
|
+
return this.woffset - amount;
|
|
13925
|
+
}, _ReadWriteByteBuffer_roAdd = function _ReadWriteByteBuffer_roAdd(amount) {
|
|
13926
|
+
if (this.roffset + amount > this.woffset) {
|
|
13927
|
+
throw new Error('Outside of the bounds of writen data.');
|
|
13928
|
+
}
|
|
13929
|
+
this.roffset += amount;
|
|
13930
|
+
return this.roffset - amount;
|
|
13931
|
+
};
|
|
13585
13932
|
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13933
|
+
exports.CrdtMessageType = void 0;
|
|
13934
|
+
(function (CrdtMessageType) {
|
|
13935
|
+
CrdtMessageType[CrdtMessageType["RESERVED"] = 0] = "RESERVED";
|
|
13936
|
+
// Component Operation
|
|
13937
|
+
CrdtMessageType[CrdtMessageType["PUT_COMPONENT"] = 1] = "PUT_COMPONENT";
|
|
13938
|
+
CrdtMessageType[CrdtMessageType["DELETE_COMPONENT"] = 2] = "DELETE_COMPONENT";
|
|
13939
|
+
CrdtMessageType[CrdtMessageType["DELETE_ENTITY"] = 3] = "DELETE_ENTITY";
|
|
13940
|
+
CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 4] = "MAX_MESSAGE_TYPE";
|
|
13941
|
+
})(exports.CrdtMessageType || (exports.CrdtMessageType = {}));
|
|
13942
|
+
const CRDT_MESSAGE_HEADER_LENGTH = 8;
|
|
13943
|
+
|
|
13944
|
+
exports.DeleteComponent = void 0;
|
|
13945
|
+
(function (DeleteComponent) {
|
|
13946
|
+
// TODO: change timestamp to 32 bit and remove buffer length (-8 bytes)
|
|
13947
|
+
DeleteComponent.MESSAGE_HEADER_LENGTH = 20;
|
|
13948
|
+
/**
|
|
13949
|
+
* Write DeleteComponent message
|
|
13950
|
+
*/
|
|
13951
|
+
function write(entity, componentId, timestamp, buf) {
|
|
13952
|
+
// reserve the beginning
|
|
13953
|
+
const messageLength = CRDT_MESSAGE_HEADER_LENGTH + DeleteComponent.MESSAGE_HEADER_LENGTH;
|
|
13954
|
+
const startMessageOffset = buf.incrementWriteOffset(messageLength);
|
|
13955
|
+
// Write CrdtMessage header
|
|
13956
|
+
buf.setUint32(startMessageOffset, messageLength);
|
|
13957
|
+
buf.setUint32(startMessageOffset + 4, exports.CrdtMessageType.DELETE_COMPONENT);
|
|
13958
|
+
// Write ComponentOperation header
|
|
13959
|
+
buf.setUint32(startMessageOffset + 8, entity);
|
|
13960
|
+
buf.setUint32(startMessageOffset + 12, componentId);
|
|
13961
|
+
// TODO: change timestamp to 32bit (-4 bytes)
|
|
13962
|
+
buf.setUint64(startMessageOffset + 16, BigInt(timestamp));
|
|
13963
|
+
// TODO: remove buffer length (-4 bytes)
|
|
13964
|
+
buf.setUint32(startMessageOffset + 24, 0);
|
|
13965
|
+
}
|
|
13966
|
+
DeleteComponent.write = write;
|
|
13967
|
+
function read(buf) {
|
|
13968
|
+
const header = CrdtMessageProtocol.readHeader(buf);
|
|
13969
|
+
if (!header) {
|
|
13970
|
+
return null;
|
|
13971
|
+
}
|
|
13972
|
+
if (header.type !== exports.CrdtMessageType.DELETE_COMPONENT) {
|
|
13973
|
+
throw new Error('DeleteComponentOperation tried to read another message type.');
|
|
13974
|
+
}
|
|
13975
|
+
const msg = {
|
|
13976
|
+
...header,
|
|
13977
|
+
entityId: buf.readUint32(),
|
|
13978
|
+
componentId: buf.readInt32(),
|
|
13979
|
+
timestamp: Number(buf.readUint64())
|
|
13980
|
+
};
|
|
13981
|
+
// TODO: remove buffer length
|
|
13982
|
+
buf.incrementReadOffset(4);
|
|
13983
|
+
return msg;
|
|
13984
|
+
}
|
|
13985
|
+
DeleteComponent.read = read;
|
|
13986
|
+
})(exports.DeleteComponent || (exports.DeleteComponent = {}));
|
|
13987
|
+
|
|
13988
|
+
exports.PutComponentOperation = void 0;
|
|
13989
|
+
(function (PutComponentOperation) {
|
|
13990
|
+
PutComponentOperation.MESSAGE_HEADER_LENGTH = 20;
|
|
13991
|
+
/**
|
|
13992
|
+
* Call this function for an optimal writing data passing the ByteBuffer
|
|
13993
|
+
* already allocated
|
|
13994
|
+
*/
|
|
13995
|
+
function write(entity, timestamp, componentDefinition, buf) {
|
|
13996
|
+
// reserve the beginning
|
|
13997
|
+
const startMessageOffset = buf.incrementWriteOffset(CRDT_MESSAGE_HEADER_LENGTH + PutComponentOperation.MESSAGE_HEADER_LENGTH);
|
|
13998
|
+
// write body
|
|
13999
|
+
componentDefinition.writeToByteBuffer(entity, buf);
|
|
14000
|
+
const messageLength = buf.currentWriteOffset() - startMessageOffset;
|
|
14001
|
+
// Write CrdtMessage header
|
|
14002
|
+
buf.setUint32(startMessageOffset, messageLength);
|
|
14003
|
+
buf.setUint32(startMessageOffset + 4, exports.CrdtMessageType.PUT_COMPONENT);
|
|
14004
|
+
// Write ComponentOperation header
|
|
14005
|
+
buf.setUint32(startMessageOffset + 8, entity);
|
|
14006
|
+
buf.setUint32(startMessageOffset + 12, componentDefinition._id);
|
|
14007
|
+
buf.setUint64(startMessageOffset + 16, BigInt(timestamp));
|
|
14008
|
+
const newLocal = messageLength - PutComponentOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
|
|
14009
|
+
buf.setUint32(startMessageOffset + 24, newLocal);
|
|
14010
|
+
}
|
|
14011
|
+
PutComponentOperation.write = write;
|
|
14012
|
+
function read(buf) {
|
|
14013
|
+
const header = CrdtMessageProtocol.readHeader(buf);
|
|
14014
|
+
if (!header) {
|
|
14015
|
+
return null;
|
|
14016
|
+
}
|
|
14017
|
+
if (header.type !== exports.CrdtMessageType.PUT_COMPONENT) {
|
|
14018
|
+
throw new Error('PutComponentOperation tried to read another message type.');
|
|
14019
|
+
}
|
|
14020
|
+
return {
|
|
14021
|
+
...header,
|
|
14022
|
+
entityId: buf.readUint32(),
|
|
14023
|
+
componentId: buf.readInt32(),
|
|
14024
|
+
timestamp: Number(buf.readUint64()),
|
|
14025
|
+
data: buf.readBuffer()
|
|
14026
|
+
};
|
|
14027
|
+
}
|
|
14028
|
+
PutComponentOperation.read = read;
|
|
14029
|
+
})(exports.PutComponentOperation || (exports.PutComponentOperation = {}));
|
|
14030
|
+
|
|
14031
|
+
exports.DeleteEntity = void 0;
|
|
14032
|
+
(function (DeleteEntity) {
|
|
14033
|
+
DeleteEntity.MESSAGE_HEADER_LENGTH = 4;
|
|
14034
|
+
function write(entity, buf) {
|
|
14035
|
+
// Write CrdtMessage header
|
|
14036
|
+
buf.writeUint32(CRDT_MESSAGE_HEADER_LENGTH + 4);
|
|
14037
|
+
buf.writeUint32(exports.CrdtMessageType.DELETE_ENTITY);
|
|
14038
|
+
// body
|
|
14039
|
+
buf.writeUint32(entity);
|
|
14040
|
+
}
|
|
14041
|
+
DeleteEntity.write = write;
|
|
14042
|
+
function read(buf) {
|
|
14043
|
+
const header = CrdtMessageProtocol.readHeader(buf);
|
|
14044
|
+
if (!header) {
|
|
14045
|
+
return null;
|
|
14046
|
+
}
|
|
14047
|
+
if (header.type !== exports.CrdtMessageType.DELETE_ENTITY) {
|
|
14048
|
+
throw new Error('DeleteComponentOperation tried to read another message type.');
|
|
14049
|
+
}
|
|
14050
|
+
return {
|
|
14051
|
+
...header,
|
|
14052
|
+
entityId: buf.readUint32()
|
|
14053
|
+
};
|
|
14054
|
+
}
|
|
14055
|
+
DeleteEntity.read = read;
|
|
14056
|
+
})(exports.DeleteEntity || (exports.DeleteEntity = {}));
|
|
14057
|
+
|
|
14058
|
+
exports.CrdtMessageProtocol = void 0;
|
|
14059
|
+
(function (CrdtMessageProtocol) {
|
|
13610
14060
|
/**
|
|
13611
14061
|
* Validate if the message incoming is completed
|
|
13612
14062
|
* @param buf - ByteBuffer
|
|
13613
14063
|
*/
|
|
13614
14064
|
function validate(buf) {
|
|
13615
14065
|
const rem = buf.remainingBytes();
|
|
13616
|
-
if (rem <
|
|
14066
|
+
if (rem < CRDT_MESSAGE_HEADER_LENGTH) {
|
|
13617
14067
|
return false;
|
|
13618
14068
|
}
|
|
13619
14069
|
const messageLength = buf.getUint32(buf.currentReadOffset());
|
|
@@ -13622,7 +14072,12 @@
|
|
|
13622
14072
|
}
|
|
13623
14073
|
return true;
|
|
13624
14074
|
}
|
|
13625
|
-
|
|
14075
|
+
CrdtMessageProtocol.validate = validate;
|
|
14076
|
+
/**
|
|
14077
|
+
* Get the current header, consuming the bytes involved.
|
|
14078
|
+
* @param buf - ByteBuffer
|
|
14079
|
+
* @returns header or null if there is no validated message
|
|
14080
|
+
*/
|
|
13626
14081
|
function readHeader(buf) {
|
|
13627
14082
|
if (!validate(buf)) {
|
|
13628
14083
|
return null;
|
|
@@ -13632,65 +14087,47 @@
|
|
|
13632
14087
|
type: buf.readUint32()
|
|
13633
14088
|
};
|
|
13634
14089
|
}
|
|
13635
|
-
|
|
13636
|
-
function getType(component, entity) {
|
|
13637
|
-
return component.has(entity) ? Enum.PUT_COMPONENT : Enum.DELETE_COMPONENT;
|
|
13638
|
-
}
|
|
13639
|
-
WireMessage.getType = getType;
|
|
13640
|
-
})(WireMessage || (WireMessage = {}));
|
|
13641
|
-
var WireMessage$1 = WireMessage;
|
|
13642
|
-
|
|
13643
|
-
var ComponentOperation;
|
|
13644
|
-
(function (ComponentOperation) {
|
|
13645
|
-
ComponentOperation.MESSAGE_HEADER_LENGTH = 20;
|
|
14090
|
+
CrdtMessageProtocol.readHeader = readHeader;
|
|
13646
14091
|
/**
|
|
13647
|
-
*
|
|
13648
|
-
*
|
|
14092
|
+
* Get the current header, without consuming the bytes involved.
|
|
14093
|
+
* @param buf - ByteBuffer
|
|
14094
|
+
* @returns header or null if there is no validated message
|
|
13649
14095
|
*/
|
|
13650
|
-
function
|
|
13651
|
-
|
|
13652
|
-
const startMessageOffset = buf.incrementWriteOffset(WireMessage$1.HEADER_LENGTH + ComponentOperation.MESSAGE_HEADER_LENGTH);
|
|
13653
|
-
// write body
|
|
13654
|
-
if (type === WireMessage$1.Enum.PUT_COMPONENT) {
|
|
13655
|
-
componentDefinition.writeToByteBuffer(entity, buf);
|
|
13656
|
-
}
|
|
13657
|
-
const messageLength = buf.size() - startMessageOffset;
|
|
13658
|
-
// Write WireMessage header
|
|
13659
|
-
buf.setUint32(startMessageOffset, messageLength);
|
|
13660
|
-
buf.setUint32(startMessageOffset + 4, type);
|
|
13661
|
-
// Write ComponentOperation header
|
|
13662
|
-
buf.setUint32(startMessageOffset + 8, entity);
|
|
13663
|
-
buf.setUint32(startMessageOffset + 12, componentDefinition._id);
|
|
13664
|
-
buf.setUint64(startMessageOffset + 16, BigInt(timestamp));
|
|
13665
|
-
buf.setUint32(startMessageOffset + 24, messageLength - ComponentOperation.MESSAGE_HEADER_LENGTH - WireMessage$1.HEADER_LENGTH);
|
|
13666
|
-
}
|
|
13667
|
-
ComponentOperation.write = write;
|
|
13668
|
-
function read(buf) {
|
|
13669
|
-
const header = WireMessage$1.readHeader(buf);
|
|
13670
|
-
if (!header) {
|
|
14096
|
+
function getHeader(buf) {
|
|
14097
|
+
if (!validate(buf)) {
|
|
13671
14098
|
return null;
|
|
13672
14099
|
}
|
|
13673
|
-
const
|
|
13674
|
-
...header,
|
|
13675
|
-
entity: buf.readUint32(),
|
|
13676
|
-
componentId: buf.readInt32(),
|
|
13677
|
-
timestamp: Number(buf.readUint64())
|
|
13678
|
-
};
|
|
13679
|
-
if (header.type === WireMessage$1.Enum.DELETE_COMPONENT) {
|
|
13680
|
-
return common;
|
|
13681
|
-
}
|
|
14100
|
+
const currentOffset = buf.currentReadOffset();
|
|
13682
14101
|
return {
|
|
13683
|
-
|
|
13684
|
-
|
|
14102
|
+
length: buf.getUint32(currentOffset),
|
|
14103
|
+
type: buf.getUint32(currentOffset + 4)
|
|
13685
14104
|
};
|
|
13686
14105
|
}
|
|
13687
|
-
|
|
13688
|
-
|
|
14106
|
+
CrdtMessageProtocol.getHeader = getHeader;
|
|
14107
|
+
/**
|
|
14108
|
+
* Consume the incoming message without processing it.
|
|
14109
|
+
* @param buf - ByteBuffer
|
|
14110
|
+
* @returns true in case of success or false if there is no valid message.
|
|
14111
|
+
*/
|
|
14112
|
+
function consumeMessage(buf) {
|
|
14113
|
+
const header = getHeader(buf);
|
|
14114
|
+
if (!header) {
|
|
14115
|
+
return false;
|
|
14116
|
+
}
|
|
14117
|
+
buf.incrementReadOffset(header.length);
|
|
14118
|
+
return true;
|
|
14119
|
+
}
|
|
14120
|
+
CrdtMessageProtocol.consumeMessage = consumeMessage;
|
|
14121
|
+
})(exports.CrdtMessageProtocol || (exports.CrdtMessageProtocol = {}));
|
|
14122
|
+
var CrdtMessageProtocol = exports.CrdtMessageProtocol;
|
|
13689
14123
|
|
|
13690
14124
|
function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
13691
14125
|
const transports = [];
|
|
13692
14126
|
// CRDT Client
|
|
13693
|
-
const crdtClient = distExports.crdtProtocol(
|
|
14127
|
+
const crdtClient = distExports.crdtProtocol({
|
|
14128
|
+
toEntityId: exports.EntityUtils.toEntityId,
|
|
14129
|
+
fromEntityId: exports.EntityUtils.fromEntityId
|
|
14130
|
+
});
|
|
13694
14131
|
// Messages that we received at transport.onMessage waiting to be processed
|
|
13695
14132
|
const receivedMessages = [];
|
|
13696
14133
|
// Messages already processed by the engine but that we need to broadcast to other transports.
|
|
@@ -13709,24 +14146,48 @@
|
|
|
13709
14146
|
* @param chunkMessage A chunk of binary messages
|
|
13710
14147
|
*/
|
|
13711
14148
|
return function parseChunkMessage(chunkMessage) {
|
|
13712
|
-
const buffer =
|
|
13713
|
-
|
|
13714
|
-
|
|
13715
|
-
while (WireMessage$1.validate(buffer)) {
|
|
14149
|
+
const buffer = new ReadWriteByteBuffer(chunkMessage);
|
|
14150
|
+
let header;
|
|
14151
|
+
while ((header = CrdtMessageProtocol.getHeader(buffer))) {
|
|
13716
14152
|
const offset = buffer.currentReadOffset();
|
|
13717
|
-
|
|
13718
|
-
|
|
13719
|
-
|
|
13720
|
-
|
|
13721
|
-
|
|
13722
|
-
|
|
13723
|
-
|
|
13724
|
-
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
|
|
13728
|
-
|
|
13729
|
-
|
|
14153
|
+
if (header.type === exports.CrdtMessageType.DELETE_COMPONENT) {
|
|
14154
|
+
const message = exports.DeleteComponent.read(buffer);
|
|
14155
|
+
receivedMessages.push({
|
|
14156
|
+
...header,
|
|
14157
|
+
...message,
|
|
14158
|
+
transportId,
|
|
14159
|
+
messageBuffer: buffer
|
|
14160
|
+
.buffer()
|
|
14161
|
+
.subarray(offset, buffer.currentReadOffset())
|
|
14162
|
+
});
|
|
14163
|
+
}
|
|
14164
|
+
else if (header.type === exports.CrdtMessageType.PUT_COMPONENT) {
|
|
14165
|
+
const message = exports.PutComponentOperation.read(buffer);
|
|
14166
|
+
receivedMessages.push({
|
|
14167
|
+
...header,
|
|
14168
|
+
...message,
|
|
14169
|
+
transportId,
|
|
14170
|
+
messageBuffer: buffer
|
|
14171
|
+
.buffer()
|
|
14172
|
+
.subarray(offset, buffer.currentReadOffset())
|
|
14173
|
+
});
|
|
14174
|
+
}
|
|
14175
|
+
else if (header.type === exports.CrdtMessageType.DELETE_ENTITY) {
|
|
14176
|
+
const message = exports.DeleteEntity.read(buffer);
|
|
14177
|
+
receivedMessages.push({
|
|
14178
|
+
...header,
|
|
14179
|
+
...message,
|
|
14180
|
+
transportId,
|
|
14181
|
+
messageBuffer: buffer
|
|
14182
|
+
.buffer()
|
|
14183
|
+
.subarray(offset, buffer.currentReadOffset())
|
|
14184
|
+
});
|
|
14185
|
+
// Unknown message, we skip it
|
|
14186
|
+
}
|
|
14187
|
+
else {
|
|
14188
|
+
// consume the message
|
|
14189
|
+
buffer.incrementReadOffset(header.length);
|
|
14190
|
+
}
|
|
13730
14191
|
}
|
|
13731
14192
|
// TODO: do something if buffler.len>0
|
|
13732
14193
|
};
|
|
@@ -13745,56 +14206,103 @@
|
|
|
13745
14206
|
*/
|
|
13746
14207
|
async function receiveMessages() {
|
|
13747
14208
|
const messagesToProcess = getMessages(receivedMessages);
|
|
13748
|
-
const bufferForOutdated =
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
13755
|
-
timestamp: timestamp
|
|
13756
|
-
};
|
|
13757
|
-
const component = engine.getComponentOrNull(componentId);
|
|
13758
|
-
if (component?.isDirty(entity)) {
|
|
13759
|
-
crdtClient.createEvent(entity, component._id, component.toBinaryOrNull(entity)?.toBinary() || null);
|
|
13760
|
-
}
|
|
13761
|
-
const current = crdtClient.processMessage(crdtMessage);
|
|
13762
|
-
if (!component) {
|
|
13763
|
-
continue;
|
|
13764
|
-
}
|
|
13765
|
-
// CRDT outdated message. Resend this message to the transport
|
|
13766
|
-
// To do this we add this message to a queue that will be processed at the end of the update tick
|
|
13767
|
-
if (crdtMessage !== current) {
|
|
13768
|
-
const offset = bufferForOutdated.currentWriteOffset();
|
|
13769
|
-
const type = WireMessage$1.getType(component, entity);
|
|
13770
|
-
const ts = current.timestamp;
|
|
13771
|
-
ComponentOperation.write(type, entity, ts, component, bufferForOutdated);
|
|
13772
|
-
outdatedMessages.push({
|
|
13773
|
-
...message,
|
|
13774
|
-
timestamp: current.timestamp,
|
|
13775
|
-
messageBuffer: bufferForOutdated
|
|
13776
|
-
.buffer()
|
|
13777
|
-
.subarray(offset, bufferForOutdated.currentWriteOffset())
|
|
14209
|
+
const bufferForOutdated = new ReadWriteByteBuffer();
|
|
14210
|
+
const entitiesShouldBeCleaned = [];
|
|
14211
|
+
for (const msg of messagesToProcess) {
|
|
14212
|
+
if (msg.type === exports.CrdtMessageType.DELETE_ENTITY) {
|
|
14213
|
+
crdtClient.processMessage({
|
|
14214
|
+
type: typesExports.CRDTMessageType.CRDTMT_DeleteEntity,
|
|
14215
|
+
entityId: msg.entityId
|
|
13778
14216
|
});
|
|
14217
|
+
entitiesShouldBeCleaned.push(msg.entityId);
|
|
13779
14218
|
}
|
|
13780
14219
|
else {
|
|
13781
|
-
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
|
-
|
|
13785
|
-
|
|
14220
|
+
const crdtMessage = {
|
|
14221
|
+
type: typesExports.CRDTMessageType.CRDTMT_PutComponentData,
|
|
14222
|
+
entityId: msg.entityId,
|
|
14223
|
+
componentId: msg.componentId,
|
|
14224
|
+
data: msg.type === exports.CrdtMessageType.PUT_COMPONENT ? msg.data : null,
|
|
14225
|
+
timestamp: msg.timestamp
|
|
14226
|
+
};
|
|
14227
|
+
const entityState = engine.entityContainer.getEntityState(msg.entityId);
|
|
14228
|
+
// Skip updates from removed entityes
|
|
14229
|
+
if (entityState === exports.EntityState.Removed)
|
|
14230
|
+
continue;
|
|
14231
|
+
// Entities with unknown entities should update its entity state
|
|
14232
|
+
if (entityState === exports.EntityState.Unknown) {
|
|
14233
|
+
engine.entityContainer.updateUsedEntity(msg.entityId);
|
|
13786
14234
|
}
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
|
|
13792
|
-
|
|
14235
|
+
const component = engine.getComponentOrNull(msg.componentId);
|
|
14236
|
+
// The state isn't updated because the dirty was set
|
|
14237
|
+
// out of the block of systems update between `receiveMessage` and `updateState`
|
|
14238
|
+
if (component?.isDirty(msg.entityId)) {
|
|
14239
|
+
crdtClient.createComponentDataEvent(component._id, msg.entityId, component.toBinaryOrNull(msg.entityId)?.toBinary() || null);
|
|
14240
|
+
}
|
|
14241
|
+
const processResult = crdtClient.processMessage(crdtMessage);
|
|
14242
|
+
if (!component) {
|
|
14243
|
+
continue;
|
|
14244
|
+
}
|
|
14245
|
+
switch (processResult) {
|
|
14246
|
+
case typesExports.ProcessMessageResultType.StateUpdatedTimestamp:
|
|
14247
|
+
case typesExports.ProcessMessageResultType.StateUpdatedData:
|
|
14248
|
+
// Add message to transport queue to be processed by others transports
|
|
14249
|
+
broadcastMessages.push(msg);
|
|
14250
|
+
// Process CRDT Message
|
|
14251
|
+
if (msg.type === exports.CrdtMessageType.DELETE_COMPONENT) {
|
|
14252
|
+
component.deleteFrom(msg.entityId, false);
|
|
14253
|
+
}
|
|
14254
|
+
else {
|
|
14255
|
+
const data = new ReadWriteByteBuffer(msg.data);
|
|
14256
|
+
component.upsertFromBinary(msg.entityId, data, false);
|
|
14257
|
+
}
|
|
14258
|
+
onProcessEntityComponentChange &&
|
|
14259
|
+
onProcessEntityComponentChange(msg.entityId, msg.type, component);
|
|
14260
|
+
break;
|
|
14261
|
+
// CRDT outdated message. Resend this message to the transport
|
|
14262
|
+
// To do this we add this message to a queue that will be processed at the end of the update tick
|
|
14263
|
+
case typesExports.ProcessMessageResultType.StateOutdatedData:
|
|
14264
|
+
case typesExports.ProcessMessageResultType.StateOutdatedTimestamp:
|
|
14265
|
+
const current = crdtClient
|
|
14266
|
+
.getState()
|
|
14267
|
+
.components.get(msg.componentId)
|
|
14268
|
+
?.get(msg.entityId);
|
|
14269
|
+
if (current) {
|
|
14270
|
+
const offset = bufferForOutdated.currentWriteOffset();
|
|
14271
|
+
const ts = current.timestamp;
|
|
14272
|
+
if (component.has(msg.entityId)) {
|
|
14273
|
+
exports.PutComponentOperation.write(msg.entityId, ts, component, bufferForOutdated);
|
|
14274
|
+
}
|
|
14275
|
+
else {
|
|
14276
|
+
exports.DeleteComponent.write(msg.entityId, component._id, ts, bufferForOutdated);
|
|
14277
|
+
}
|
|
14278
|
+
outdatedMessages.push({
|
|
14279
|
+
...msg,
|
|
14280
|
+
messageBuffer: bufferForOutdated
|
|
14281
|
+
.buffer()
|
|
14282
|
+
.subarray(offset, bufferForOutdated.currentWriteOffset())
|
|
14283
|
+
});
|
|
14284
|
+
}
|
|
14285
|
+
break;
|
|
14286
|
+
case typesExports.ProcessMessageResultType.NoChanges:
|
|
14287
|
+
case typesExports.ProcessMessageResultType.EntityDeleted:
|
|
14288
|
+
case typesExports.ProcessMessageResultType.EntityWasDeleted:
|
|
13793
14289
|
}
|
|
13794
|
-
onProcessEntityComponentChange &&
|
|
13795
|
-
onProcessEntityComponentChange(entity, component, type);
|
|
13796
14290
|
}
|
|
13797
14291
|
}
|
|
14292
|
+
for (const entity of entitiesShouldBeCleaned) {
|
|
14293
|
+
// If we tried to resend outdated message and the entity was deleted before, we avoid sending them.
|
|
14294
|
+
for (let i = outdatedMessages.length - 1; i >= 0; i--) {
|
|
14295
|
+
if (outdatedMessages[i].entityId === entity) {
|
|
14296
|
+
outdatedMessages.splice(i, 1);
|
|
14297
|
+
}
|
|
14298
|
+
}
|
|
14299
|
+
for (const definition of engine.componentsIter()) {
|
|
14300
|
+
definition.deleteFrom(entity, false);
|
|
14301
|
+
}
|
|
14302
|
+
engine.entityContainer.updateRemovedEntity(entity);
|
|
14303
|
+
onProcessEntityComponentChange &&
|
|
14304
|
+
onProcessEntityComponentChange(entity, exports.CrdtMessageType.DELETE_ENTITY);
|
|
14305
|
+
}
|
|
13798
14306
|
}
|
|
13799
14307
|
/**
|
|
13800
14308
|
* Updates CRDT state of the current engine dirty components
|
|
@@ -13811,15 +14319,20 @@
|
|
|
13811
14319
|
entitySet = [];
|
|
13812
14320
|
dirtyMap.set(component, entitySet);
|
|
13813
14321
|
}
|
|
13814
|
-
entitySet.push(entity);
|
|
13815
14322
|
// TODO: reuse shared writer to prevent extra allocations of toBinary
|
|
13816
14323
|
const componentValue = component.toBinaryOrNull(entity)?.toBinary() ?? null;
|
|
13817
14324
|
// TODO: do not emit event if componentValue equals the value didn't change
|
|
13818
|
-
|
|
13819
|
-
|
|
13820
|
-
|
|
13821
|
-
|
|
13822
|
-
|
|
14325
|
+
// if update goes bad, the entity doesn't accept put anymore (it's added to deleted entities set)
|
|
14326
|
+
if (crdtClient.createComponentDataEvent(component._id, entity, componentValue) === null) {
|
|
14327
|
+
component.deleteFrom(entity, false);
|
|
14328
|
+
}
|
|
14329
|
+
else {
|
|
14330
|
+
entitySet.push(entity);
|
|
14331
|
+
onProcessEntityComponentChange &&
|
|
14332
|
+
onProcessEntityComponentChange(entity, componentValue === null
|
|
14333
|
+
? exports.CrdtMessageType.DELETE_COMPONENT
|
|
14334
|
+
: exports.CrdtMessageType.PUT_COMPONENT, component);
|
|
14335
|
+
}
|
|
13823
14336
|
}
|
|
13824
14337
|
}
|
|
13825
14338
|
return dirtyMap;
|
|
@@ -13827,29 +14340,36 @@
|
|
|
13827
14340
|
/**
|
|
13828
14341
|
* Iterates the dirty map and generates crdt messages to be send
|
|
13829
14342
|
*/
|
|
13830
|
-
async function sendMessages(dirtyEntities) {
|
|
14343
|
+
async function sendMessages(dirtyEntities, deletedEntities) {
|
|
13831
14344
|
// CRDT Messages will be the merge between the recieved transport messages and the new crdt messages
|
|
13832
14345
|
const crdtMessages = getMessages(broadcastMessages);
|
|
13833
14346
|
const outdatedMessagesBkp = getMessages(outdatedMessages);
|
|
13834
|
-
const buffer =
|
|
14347
|
+
const buffer = new ReadWriteByteBuffer();
|
|
13835
14348
|
for (const [component, entities] of dirtyEntities) {
|
|
13836
14349
|
for (const entity of entities) {
|
|
13837
14350
|
// Component will be always defined here since dirtyMap its an iterator of engine.componentsDefinition
|
|
13838
14351
|
const { timestamp } = crdtClient
|
|
13839
14352
|
.getState()
|
|
13840
|
-
.get(
|
|
13841
|
-
.get(
|
|
14353
|
+
.components.get(component._id)
|
|
14354
|
+
.get(entity);
|
|
13842
14355
|
const offset = buffer.currentWriteOffset();
|
|
13843
|
-
const type =
|
|
14356
|
+
const type = component.has(entity)
|
|
14357
|
+
? exports.CrdtMessageType.PUT_COMPONENT
|
|
14358
|
+
: exports.CrdtMessageType.DELETE_COMPONENT;
|
|
13844
14359
|
const transportMessage = {
|
|
13845
14360
|
type,
|
|
14361
|
+
entityId: entity,
|
|
13846
14362
|
componentId: component._id,
|
|
13847
|
-
entity,
|
|
13848
14363
|
timestamp
|
|
13849
14364
|
};
|
|
13850
14365
|
// Avoid creating messages if there is no transport that will handle it
|
|
13851
14366
|
if (transports.some((t) => t.filter(transportMessage))) {
|
|
13852
|
-
|
|
14367
|
+
if (transportMessage.type === exports.CrdtMessageType.PUT_COMPONENT) {
|
|
14368
|
+
exports.PutComponentOperation.write(entity, timestamp, component, buffer);
|
|
14369
|
+
}
|
|
14370
|
+
else {
|
|
14371
|
+
exports.DeleteComponent.write(entity, component._id, timestamp, buffer);
|
|
14372
|
+
}
|
|
13853
14373
|
crdtMessages.push({
|
|
13854
14374
|
...transportMessage,
|
|
13855
14375
|
messageBuffer: buffer
|
|
@@ -13859,8 +14379,21 @@
|
|
|
13859
14379
|
}
|
|
13860
14380
|
}
|
|
13861
14381
|
}
|
|
14382
|
+
// After all updates, I execute the DeletedEntity messages
|
|
14383
|
+
for (const entityId of deletedEntities) {
|
|
14384
|
+
crdtClient.createDeleteEntityEvent(entityId);
|
|
14385
|
+
const offset = buffer.currentWriteOffset();
|
|
14386
|
+
exports.DeleteEntity.write(entityId, buffer);
|
|
14387
|
+
crdtMessages.push({
|
|
14388
|
+
type: exports.CrdtMessageType.DELETE_ENTITY,
|
|
14389
|
+
entityId,
|
|
14390
|
+
messageBuffer: buffer
|
|
14391
|
+
.buffer()
|
|
14392
|
+
.subarray(offset, buffer.currentWriteOffset())
|
|
14393
|
+
});
|
|
14394
|
+
}
|
|
13862
14395
|
// Send CRDT messages to transports
|
|
13863
|
-
const transportBuffer =
|
|
14396
|
+
const transportBuffer = new ReadWriteByteBuffer();
|
|
13864
14397
|
for (const index in transports) {
|
|
13865
14398
|
const transportIndex = Number(index);
|
|
13866
14399
|
const transport = transports[transportIndex];
|
|
@@ -13869,8 +14402,11 @@
|
|
|
13869
14402
|
// So we can fix their crdt state
|
|
13870
14403
|
for (const message of outdatedMessagesBkp) {
|
|
13871
14404
|
if (message.transportId === transportIndex &&
|
|
14405
|
+
// TODO: This is an optimization, the state should converge anyway, whatever the message is sent.
|
|
13872
14406
|
// Avoid sending multiple messages for the same entity-componentId
|
|
13873
|
-
!crdtMessages.find((m) => m.
|
|
14407
|
+
!crdtMessages.find((m) => m.entityId === message.entityId &&
|
|
14408
|
+
// TODO: as any, with multiple type of messages, it should have many checks before the check for similar messages
|
|
14409
|
+
m.componentId &&
|
|
13874
14410
|
m.componentId === message.componentId)) {
|
|
13875
14411
|
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
13876
14412
|
}
|
|
@@ -13882,7 +14418,7 @@
|
|
|
13882
14418
|
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
13883
14419
|
}
|
|
13884
14420
|
}
|
|
13885
|
-
const message = transportBuffer.
|
|
14421
|
+
const message = transportBuffer.currentWriteOffset()
|
|
13886
14422
|
? transportBuffer.toBinary()
|
|
13887
14423
|
: new Uint8Array([]);
|
|
13888
14424
|
await transport.send(message);
|
|
@@ -14011,7 +14547,7 @@
|
|
|
14011
14547
|
if (!component) {
|
|
14012
14548
|
throw new Error(`[toBinary] Component ${componentId} for ${entity} not found`);
|
|
14013
14549
|
}
|
|
14014
|
-
const writeBuffer =
|
|
14550
|
+
const writeBuffer = new ReadWriteByteBuffer();
|
|
14015
14551
|
spec.serialize(component, writeBuffer);
|
|
14016
14552
|
return writeBuffer;
|
|
14017
14553
|
},
|
|
@@ -14020,7 +14556,7 @@
|
|
|
14020
14556
|
if (!component) {
|
|
14021
14557
|
return null;
|
|
14022
14558
|
}
|
|
14023
|
-
const writeBuffer =
|
|
14559
|
+
const writeBuffer = new ReadWriteByteBuffer();
|
|
14024
14560
|
spec.serialize(component, writeBuffer);
|
|
14025
14561
|
return writeBuffer;
|
|
14026
14562
|
},
|
|
@@ -14058,79 +14594,6 @@
|
|
|
14058
14594
|
};
|
|
14059
14595
|
}
|
|
14060
14596
|
|
|
14061
|
-
const MAX_U16 = 0xffff;
|
|
14062
|
-
const MASK_UPPER_16_ON_32 = 0xffff0000;
|
|
14063
|
-
const AMOUNT_VERSION_AVAILABLE = MAX_U16 + 1;
|
|
14064
|
-
/**
|
|
14065
|
-
* @public This first 512 entities are reserved by the renderer
|
|
14066
|
-
*/
|
|
14067
|
-
const RESERVED_STATIC_ENTITIES = 512;
|
|
14068
|
-
/**
|
|
14069
|
-
* @public
|
|
14070
|
-
*/
|
|
14071
|
-
const MAX_ENTITY_NUMBER = MAX_U16;
|
|
14072
|
-
function EntityContainer() {
|
|
14073
|
-
let entityCounter = RESERVED_STATIC_ENTITIES;
|
|
14074
|
-
const usedEntities = new Set();
|
|
14075
|
-
const removedEntities = new Map();
|
|
14076
|
-
function entityVersion(entity) {
|
|
14077
|
-
return (((entity & MASK_UPPER_16_ON_32) >> 16) & MAX_U16) >>> 0;
|
|
14078
|
-
}
|
|
14079
|
-
function entityNumber(entity) {
|
|
14080
|
-
return (entity & MAX_U16) >>> 0;
|
|
14081
|
-
}
|
|
14082
|
-
function entityId(entityNumber, entityVersion) {
|
|
14083
|
-
return (((entityNumber & MAX_U16) | ((entityVersion & MAX_U16) << 16)) >>>
|
|
14084
|
-
0);
|
|
14085
|
-
}
|
|
14086
|
-
function generateNewEntity() {
|
|
14087
|
-
if (entityCounter > MAX_ENTITY_NUMBER - 1) {
|
|
14088
|
-
throw new Error(`It fails trying to generate an entity out of range ${MAX_ENTITY_NUMBER}.`);
|
|
14089
|
-
}
|
|
14090
|
-
const entity = entityCounter++;
|
|
14091
|
-
usedEntities.add(entity);
|
|
14092
|
-
return entity;
|
|
14093
|
-
}
|
|
14094
|
-
function generateEntity() {
|
|
14095
|
-
if (usedEntities.size + RESERVED_STATIC_ENTITIES >= entityCounter) {
|
|
14096
|
-
return generateNewEntity();
|
|
14097
|
-
}
|
|
14098
|
-
for (const [number, version] of removedEntities) {
|
|
14099
|
-
if (version < MAX_U16) {
|
|
14100
|
-
const entity = entityId(number, version + 1);
|
|
14101
|
-
usedEntities.add(entity);
|
|
14102
|
-
removedEntities.delete(number);
|
|
14103
|
-
return entity;
|
|
14104
|
-
}
|
|
14105
|
-
}
|
|
14106
|
-
return generateNewEntity();
|
|
14107
|
-
}
|
|
14108
|
-
function removeEntity(entity) {
|
|
14109
|
-
const deleted = usedEntities.delete(entity);
|
|
14110
|
-
if (deleted) {
|
|
14111
|
-
removedEntities.set(entityNumber(entity), entityVersion(entity));
|
|
14112
|
-
}
|
|
14113
|
-
return deleted;
|
|
14114
|
-
}
|
|
14115
|
-
return {
|
|
14116
|
-
generateEntity() {
|
|
14117
|
-
return generateEntity();
|
|
14118
|
-
},
|
|
14119
|
-
removeEntity(entity) {
|
|
14120
|
-
return removeEntity(entity);
|
|
14121
|
-
},
|
|
14122
|
-
entityExists(entity) {
|
|
14123
|
-
return entity < RESERVED_STATIC_ENTITIES || usedEntities.has(entity);
|
|
14124
|
-
},
|
|
14125
|
-
getExistingEntities() {
|
|
14126
|
-
return new Set(usedEntities);
|
|
14127
|
-
},
|
|
14128
|
-
entityVersion,
|
|
14129
|
-
entityNumber,
|
|
14130
|
-
entityId
|
|
14131
|
-
};
|
|
14132
|
-
}
|
|
14133
|
-
|
|
14134
14597
|
const SYSTEMS_REGULAR_PRIORITY = 100e3;
|
|
14135
14598
|
function SystemContainer() {
|
|
14136
14599
|
const systems = [];
|
|
@@ -14345,9 +14808,6 @@
|
|
|
14345
14808
|
const entity = entityContainer.generateEntity();
|
|
14346
14809
|
return entity;
|
|
14347
14810
|
}
|
|
14348
|
-
function entityExists(entity) {
|
|
14349
|
-
return entityContainer.entityExists(entity);
|
|
14350
|
-
}
|
|
14351
14811
|
function removeEntity(entity) {
|
|
14352
14812
|
for (const [, component] of componentsDefinition) {
|
|
14353
14813
|
if (component.has(entity)) {
|
|
@@ -14454,8 +14914,6 @@
|
|
|
14454
14914
|
}
|
|
14455
14915
|
}
|
|
14456
14916
|
return {
|
|
14457
|
-
entityExists,
|
|
14458
|
-
componentsDefinition,
|
|
14459
14917
|
addEntity,
|
|
14460
14918
|
removeEntity,
|
|
14461
14919
|
addSystem,
|
|
@@ -14469,6 +14927,7 @@
|
|
|
14469
14927
|
removeComponentDefinition,
|
|
14470
14928
|
removeEntityWithChildren,
|
|
14471
14929
|
registerCustomComponent,
|
|
14930
|
+
entityContainer,
|
|
14472
14931
|
componentsIter
|
|
14473
14932
|
};
|
|
14474
14933
|
}
|
|
@@ -14485,8 +14944,9 @@
|
|
|
14485
14944
|
checkNotThenable(ret, `A system (${system.name || 'anonymous'}) returned a thenable. Systems cannot be async functions. Documentation: https://dcl.gg/sdk/sync-systems`);
|
|
14486
14945
|
}
|
|
14487
14946
|
const dirtyEntities = crdtSystem.updateState();
|
|
14488
|
-
|
|
14489
|
-
|
|
14947
|
+
const deletedEntites = engine.entityContainer.releaseRemovedEntities();
|
|
14948
|
+
await crdtSystem.sendMessages(dirtyEntities, deletedEntites);
|
|
14949
|
+
for (const definition of engine.componentsIter()) {
|
|
14490
14950
|
definition.clearDirty();
|
|
14491
14951
|
}
|
|
14492
14952
|
}
|
|
@@ -14508,10 +14968,10 @@
|
|
|
14508
14968
|
RootEntity: 0,
|
|
14509
14969
|
PlayerEntity: 1,
|
|
14510
14970
|
CameraEntity: 2,
|
|
14511
|
-
|
|
14971
|
+
getEntityState: engine.entityContainer.getEntityState,
|
|
14512
14972
|
addTransport: crdtSystem.addTransport,
|
|
14513
14973
|
getCrdtState: crdtSystem.getCrdt,
|
|
14514
|
-
|
|
14974
|
+
entityContainer: engine.entityContainer
|
|
14515
14975
|
};
|
|
14516
14976
|
}
|
|
14517
14977
|
|
|
@@ -14597,7 +15057,7 @@
|
|
|
14597
15057
|
// @internal
|
|
14598
15058
|
engine.addSystem(function EventSystem() {
|
|
14599
15059
|
for (const [entity, event] of eventsMap) {
|
|
14600
|
-
if (
|
|
15060
|
+
if (engine.getEntityState(entity) === exports.EntityState.Removed) {
|
|
14601
15061
|
eventsMap.delete(entity);
|
|
14602
15062
|
continue;
|
|
14603
15063
|
}
|
|
@@ -41150,7 +41610,9 @@
|
|
|
41150
41610
|
}
|
|
41151
41611
|
},
|
|
41152
41612
|
filter(message) {
|
|
41153
|
-
if (
|
|
41613
|
+
if ((message.type === exports.CrdtMessageType.PUT_COMPONENT ||
|
|
41614
|
+
message.type === exports.CrdtMessageType.DELETE_COMPONENT) &&
|
|
41615
|
+
!componentIds.includes(message.componentId)) {
|
|
41154
41616
|
return false;
|
|
41155
41617
|
}
|
|
41156
41618
|
return !!message;
|
|
@@ -41178,6 +41640,7 @@
|
|
|
41178
41640
|
exports.BorderRect = BorderRect;
|
|
41179
41641
|
exports.Button = Button;
|
|
41180
41642
|
exports.CANVAS_ROOT_ENTITY = CANVAS_ROOT_ENTITY;
|
|
41643
|
+
exports.CRDT_MESSAGE_HEADER_LENGTH = CRDT_MESSAGE_HEADER_LENGTH;
|
|
41181
41644
|
exports.CameraMode = CameraMode;
|
|
41182
41645
|
exports.CameraModeArea = CameraModeArea;
|
|
41183
41646
|
exports.DEG2RAD = DEG2RAD;
|