@dcl/playground-assets 7.0.6-4177592674.commit-39cdc99 → 7.0.6-4180146485.commit-9a7dde9
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 +222 -142
- package/dist/beta.d.ts +222 -142
- package/dist/index.bundled.d.ts +222 -142
- package/dist/index.js +321 -142
- 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 +3 -3
- package/dist/playground-assets.d.ts +222 -142
- package/etc/playground-assets.api.json +2259 -1941
- package/etc/playground-assets.api.md +122 -87
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -11080,40 +11080,6 @@
|
|
|
11080
11080
|
|
|
11081
11081
|
/* eslint-disable */
|
|
11082
11082
|
function createBasePBPointerEventsResult() {
|
|
11083
|
-
return { commands: [] };
|
|
11084
|
-
}
|
|
11085
|
-
/**
|
|
11086
|
-
* @public
|
|
11087
|
-
*/
|
|
11088
|
-
/**
|
|
11089
|
-
* @internal
|
|
11090
|
-
*/
|
|
11091
|
-
const PBPointerEventsResult = {
|
|
11092
|
-
encode(message, writer = _m0.Writer.create()) {
|
|
11093
|
-
for (const v of message.commands) {
|
|
11094
|
-
PBPointerEventsResult_PointerCommand.encode(v, writer.uint32(10).fork()).ldelim();
|
|
11095
|
-
}
|
|
11096
|
-
return writer;
|
|
11097
|
-
},
|
|
11098
|
-
decode(input, length) {
|
|
11099
|
-
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
11100
|
-
let end = length === undefined ? reader.len : reader.pos + length;
|
|
11101
|
-
const message = createBasePBPointerEventsResult();
|
|
11102
|
-
while (reader.pos < end) {
|
|
11103
|
-
const tag = reader.uint32();
|
|
11104
|
-
switch (tag >>> 3) {
|
|
11105
|
-
case 1:
|
|
11106
|
-
message.commands.push(PBPointerEventsResult_PointerCommand.decode(reader, reader.uint32()));
|
|
11107
|
-
break;
|
|
11108
|
-
default:
|
|
11109
|
-
reader.skipType(tag & 7);
|
|
11110
|
-
break;
|
|
11111
|
-
}
|
|
11112
|
-
}
|
|
11113
|
-
return message;
|
|
11114
|
-
},
|
|
11115
|
-
};
|
|
11116
|
-
function createBasePBPointerEventsResult_PointerCommand() {
|
|
11117
11083
|
return { button: 0, hit: undefined, state: 0, timestamp: 0, analog: undefined };
|
|
11118
11084
|
}
|
|
11119
11085
|
/**
|
|
@@ -11122,7 +11088,7 @@
|
|
|
11122
11088
|
/**
|
|
11123
11089
|
* @internal
|
|
11124
11090
|
*/
|
|
11125
|
-
const
|
|
11091
|
+
const PBPointerEventsResult = {
|
|
11126
11092
|
encode(message, writer = _m0.Writer.create()) {
|
|
11127
11093
|
if (message.button !== 0) {
|
|
11128
11094
|
writer.uint32(8).int32(message.button);
|
|
@@ -11144,7 +11110,7 @@
|
|
|
11144
11110
|
decode(input, length) {
|
|
11145
11111
|
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
11146
11112
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
11147
|
-
const message =
|
|
11113
|
+
const message = createBasePBPointerEventsResult();
|
|
11148
11114
|
while (reader.pos < end) {
|
|
11149
11115
|
const tag = reader.uint32();
|
|
11150
11116
|
switch (tag >>> 3) {
|
|
@@ -12775,7 +12741,10 @@
|
|
|
12775
12741
|
/** @public */ const MeshRenderer$2 = engine => engine.defineComponentFromSchema("core::MeshRenderer", MeshRendererSchema);
|
|
12776
12742
|
/** @public */ const NftShape$1 = engine => engine.defineComponentFromSchema("core::NftShape", NftShapeSchema);
|
|
12777
12743
|
/** @public */ const PointerEvents$1 = engine => engine.defineComponentFromSchema("core::PointerEvents", PointerEventsSchema);
|
|
12778
|
-
/** @public */ const PointerEventsResult$1 = engine => engine.
|
|
12744
|
+
/** @public */ const PointerEventsResult$1 = (engine) => engine.defineValueSetComponentFromSchema("core::PointerEventsResult", PointerEventsResultSchema, {
|
|
12745
|
+
timestampFunction: (t) => t.timestamp,
|
|
12746
|
+
maxElements: 100
|
|
12747
|
+
});
|
|
12779
12748
|
/** @public */ const PointerLock$1 = engine => engine.defineComponentFromSchema("core::PointerLock", PointerLockSchema);
|
|
12780
12749
|
/** @public */ const Raycast$1 = engine => engine.defineComponentFromSchema("core::Raycast", RaycastSchema);
|
|
12781
12750
|
/** @public */ const RaycastResult$1 = engine => engine.defineComponentFromSchema("core::RaycastResult", RaycastResultSchema);
|
|
@@ -13098,7 +13067,6 @@
|
|
|
13098
13067
|
PBNftShape: PBNftShape,
|
|
13099
13068
|
PBPointerEvents: PBPointerEvents,
|
|
13100
13069
|
PBPointerEventsResult: PBPointerEventsResult,
|
|
13101
|
-
PBPointerEventsResult_PointerCommand: PBPointerEventsResult_PointerCommand,
|
|
13102
13070
|
PBPointerEvents_Entry: PBPointerEvents_Entry,
|
|
13103
13071
|
PBPointerEvents_Info: PBPointerEvents_Info,
|
|
13104
13072
|
PBPointerLock: PBPointerLock,
|
|
@@ -13239,8 +13207,13 @@
|
|
|
13239
13207
|
return ((unsignedCRC32(bytes) + MAX_STATIC_COMPONENT) & 4294967295) >>> 0;
|
|
13240
13208
|
}
|
|
13241
13209
|
|
|
13210
|
+
/* istanbul ignore file */
|
|
13211
|
+
const __DEV__ = (typeof DEBUG === 'boolean' && DEBUG) ||
|
|
13212
|
+
(typeof process === 'object' &&
|
|
13213
|
+
(process.env?.NODE_ENV !== 'production' || process.env?.NODE_ENV === 'development')) ||
|
|
13214
|
+
false;
|
|
13242
13215
|
function checkNotThenable(t, error) {
|
|
13243
|
-
if (
|
|
13216
|
+
if (__DEV__) {
|
|
13244
13217
|
if (t && typeof t === 'object' && typeof t.then === 'function') {
|
|
13245
13218
|
throw new Error(error);
|
|
13246
13219
|
}
|
|
@@ -14144,7 +14117,8 @@
|
|
|
14144
14117
|
CrdtMessageType[CrdtMessageType["PUT_COMPONENT"] = 1] = "PUT_COMPONENT";
|
|
14145
14118
|
CrdtMessageType[CrdtMessageType["DELETE_COMPONENT"] = 2] = "DELETE_COMPONENT";
|
|
14146
14119
|
CrdtMessageType[CrdtMessageType["DELETE_ENTITY"] = 3] = "DELETE_ENTITY";
|
|
14147
|
-
CrdtMessageType[CrdtMessageType["
|
|
14120
|
+
CrdtMessageType[CrdtMessageType["APPEND_VALUE"] = 4] = "APPEND_VALUE";
|
|
14121
|
+
CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 5] = "MAX_MESSAGE_TYPE";
|
|
14148
14122
|
})(exports.CrdtMessageType || (exports.CrdtMessageType = {}));
|
|
14149
14123
|
/**
|
|
14150
14124
|
* @public
|
|
@@ -14317,6 +14291,54 @@
|
|
|
14317
14291
|
DeleteComponent.read = read;
|
|
14318
14292
|
})(exports.DeleteComponent || (exports.DeleteComponent = {}));
|
|
14319
14293
|
|
|
14294
|
+
/**
|
|
14295
|
+
* @internal
|
|
14296
|
+
*/
|
|
14297
|
+
exports.AppendValueOperation = void 0;
|
|
14298
|
+
(function (AppendValueOperation) {
|
|
14299
|
+
AppendValueOperation.MESSAGE_HEADER_LENGTH = 16;
|
|
14300
|
+
/**
|
|
14301
|
+
* Call this function for an optimal writing data passing the ByteBuffer
|
|
14302
|
+
* already allocated
|
|
14303
|
+
*/
|
|
14304
|
+
function write(entity, timestamp, componentId, data, buf) {
|
|
14305
|
+
// reserve the beginning
|
|
14306
|
+
const startMessageOffset = buf.incrementWriteOffset(CRDT_MESSAGE_HEADER_LENGTH + AppendValueOperation.MESSAGE_HEADER_LENGTH);
|
|
14307
|
+
// write body
|
|
14308
|
+
buf.writeBuffer(data, false);
|
|
14309
|
+
const messageLength = buf.currentWriteOffset() - startMessageOffset;
|
|
14310
|
+
// Write CrdtMessage header
|
|
14311
|
+
buf.setUint32(startMessageOffset, messageLength);
|
|
14312
|
+
buf.setUint32(startMessageOffset + 4, exports.CrdtMessageType.APPEND_VALUE);
|
|
14313
|
+
// Write ComponentOperation header
|
|
14314
|
+
buf.setUint32(startMessageOffset + 8, entity);
|
|
14315
|
+
buf.setUint32(startMessageOffset + 12, componentId);
|
|
14316
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
14317
|
+
const newLocal = messageLength - AppendValueOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
|
|
14318
|
+
buf.setUint32(startMessageOffset + 20, newLocal);
|
|
14319
|
+
}
|
|
14320
|
+
AppendValueOperation.write = write;
|
|
14321
|
+
function read(buf) {
|
|
14322
|
+
const header = exports.CrdtMessageProtocol.readHeader(buf);
|
|
14323
|
+
/* istanbul ignore if */
|
|
14324
|
+
if (!header) {
|
|
14325
|
+
return null;
|
|
14326
|
+
}
|
|
14327
|
+
/* istanbul ignore if */
|
|
14328
|
+
if (header.type !== exports.CrdtMessageType.APPEND_VALUE) {
|
|
14329
|
+
throw new Error('AppendValueOperation tried to read another message type.');
|
|
14330
|
+
}
|
|
14331
|
+
return {
|
|
14332
|
+
...header,
|
|
14333
|
+
entityId: buf.readUint32(),
|
|
14334
|
+
componentId: buf.readUint32(),
|
|
14335
|
+
timestamp: buf.readUint32(),
|
|
14336
|
+
data: buf.readBuffer()
|
|
14337
|
+
};
|
|
14338
|
+
}
|
|
14339
|
+
AppendValueOperation.read = read;
|
|
14340
|
+
})(exports.AppendValueOperation || (exports.AppendValueOperation = {}));
|
|
14341
|
+
|
|
14320
14342
|
/**
|
|
14321
14343
|
* @internal
|
|
14322
14344
|
*/
|
|
@@ -14423,7 +14445,6 @@
|
|
|
14423
14445
|
if (header.type === exports.CrdtMessageType.DELETE_COMPONENT) {
|
|
14424
14446
|
const message = exports.DeleteComponent.read(buffer);
|
|
14425
14447
|
receivedMessages.push({
|
|
14426
|
-
...header,
|
|
14427
14448
|
...message,
|
|
14428
14449
|
transportId,
|
|
14429
14450
|
messageBuffer: buffer.buffer().subarray(offset, buffer.currentReadOffset())
|
|
@@ -14432,7 +14453,6 @@
|
|
|
14432
14453
|
else if (header.type === exports.CrdtMessageType.PUT_COMPONENT) {
|
|
14433
14454
|
const message = exports.PutComponentOperation.read(buffer);
|
|
14434
14455
|
receivedMessages.push({
|
|
14435
|
-
...header,
|
|
14436
14456
|
...message,
|
|
14437
14457
|
transportId,
|
|
14438
14458
|
messageBuffer: buffer.buffer().subarray(offset, buffer.currentReadOffset())
|
|
@@ -14441,7 +14461,14 @@
|
|
|
14441
14461
|
else if (header.type === exports.CrdtMessageType.DELETE_ENTITY) {
|
|
14442
14462
|
const message = exports.DeleteEntity.read(buffer);
|
|
14443
14463
|
receivedMessages.push({
|
|
14444
|
-
...
|
|
14464
|
+
...message,
|
|
14465
|
+
transportId,
|
|
14466
|
+
messageBuffer: buffer.buffer().subarray(offset, buffer.currentReadOffset())
|
|
14467
|
+
});
|
|
14468
|
+
}
|
|
14469
|
+
else if (header.type === exports.CrdtMessageType.APPEND_VALUE) {
|
|
14470
|
+
const message = exports.AppendValueOperation.read(buffer);
|
|
14471
|
+
receivedMessages.push({
|
|
14445
14472
|
...message,
|
|
14446
14473
|
transportId,
|
|
14447
14474
|
messageBuffer: buffer.buffer().subarray(offset, buffer.currentReadOffset())
|
|
@@ -14487,13 +14514,13 @@
|
|
|
14487
14514
|
}
|
|
14488
14515
|
const component = engine.getComponentOrNull(msg.componentId);
|
|
14489
14516
|
if (component) {
|
|
14490
|
-
const [conflictMessage] = component.updateFromCrdt(msg);
|
|
14517
|
+
const [conflictMessage, value] = component.updateFromCrdt(msg);
|
|
14491
14518
|
if (conflictMessage) {
|
|
14492
14519
|
const offset = bufferForOutdated.currentWriteOffset();
|
|
14493
14520
|
if (conflictMessage.type === exports.CrdtMessageType.PUT_COMPONENT) {
|
|
14494
14521
|
exports.PutComponentOperation.write(msg.entityId, conflictMessage.timestamp, conflictMessage.componentId, conflictMessage.data, bufferForOutdated);
|
|
14495
14522
|
}
|
|
14496
|
-
else {
|
|
14523
|
+
else if (conflictMessage.type === exports.CrdtMessageType.DELETE_COMPONENT) {
|
|
14497
14524
|
exports.DeleteComponent.write(msg.entityId, component.componentId, conflictMessage.timestamp, bufferForOutdated);
|
|
14498
14525
|
}
|
|
14499
14526
|
outdatedMessages.push({
|
|
@@ -14504,7 +14531,7 @@
|
|
|
14504
14531
|
else {
|
|
14505
14532
|
// Add message to transport queue to be processed by others transports
|
|
14506
14533
|
broadcastMessages.push(msg);
|
|
14507
|
-
onProcessEntityComponentChange && onProcessEntityComponentChange(msg.entityId, msg.type, component);
|
|
14534
|
+
onProcessEntityComponentChange && onProcessEntityComponentChange(msg.entityId, msg.type, component, value);
|
|
14508
14535
|
}
|
|
14509
14536
|
}
|
|
14510
14537
|
}
|
|
@@ -14543,11 +14570,19 @@
|
|
|
14543
14570
|
else if (message.type === exports.CrdtMessageType.DELETE_COMPONENT) {
|
|
14544
14571
|
exports.DeleteComponent.write(message.entityId, component.componentId, message.timestamp, buffer);
|
|
14545
14572
|
}
|
|
14573
|
+
else if (message.type === exports.CrdtMessageType.APPEND_VALUE) {
|
|
14574
|
+
exports.AppendValueOperation.write(message.entityId, message.timestamp, message.componentId, message.data, buffer);
|
|
14575
|
+
}
|
|
14546
14576
|
crdtMessages.push({
|
|
14547
14577
|
...message,
|
|
14548
14578
|
messageBuffer: buffer.buffer().subarray(offset, buffer.currentWriteOffset())
|
|
14549
14579
|
});
|
|
14550
|
-
|
|
14580
|
+
if (onProcessEntityComponentChange) {
|
|
14581
|
+
const rawValue = message.type === exports.CrdtMessageType.PUT_COMPONENT || message.type === exports.CrdtMessageType.APPEND_VALUE
|
|
14582
|
+
? component.get(message.entityId)
|
|
14583
|
+
: undefined;
|
|
14584
|
+
onProcessEntityComponentChange(message.entityId, message.type, component, rawValue);
|
|
14585
|
+
}
|
|
14551
14586
|
}
|
|
14552
14587
|
}
|
|
14553
14588
|
}
|
|
@@ -14658,7 +14693,7 @@
|
|
|
14658
14693
|
timestamps.set(entity, newTimestamp);
|
|
14659
14694
|
return newTimestamp;
|
|
14660
14695
|
}
|
|
14661
|
-
function
|
|
14696
|
+
function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
|
|
14662
14697
|
/**
|
|
14663
14698
|
* Process the received message only if the lamport number recieved is higher
|
|
14664
14699
|
* than the stored one. If its lower, we spread it to the network to correct the peer.
|
|
@@ -14759,7 +14794,7 @@
|
|
|
14759
14794
|
return [null, data.get(entity)];
|
|
14760
14795
|
};
|
|
14761
14796
|
}
|
|
14762
|
-
function
|
|
14797
|
+
function createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data) {
|
|
14763
14798
|
return function* () {
|
|
14764
14799
|
for (const entity of dirtyIterator) {
|
|
14765
14800
|
const newTimestamp = incrementTimestamp(entity, timestamps);
|
|
@@ -14802,12 +14837,11 @@
|
|
|
14802
14837
|
get componentName() {
|
|
14803
14838
|
return componentName;
|
|
14804
14839
|
},
|
|
14805
|
-
|
|
14806
|
-
|
|
14807
|
-
|
|
14808
|
-
isDirty(entity) {
|
|
14809
|
-
return dirtyIterator.has(entity);
|
|
14840
|
+
get componentType() {
|
|
14841
|
+
// a getter is used here to prevent accidental changes
|
|
14842
|
+
return 0 /* ComponentType.LastWriteWinElementSet */;
|
|
14810
14843
|
},
|
|
14844
|
+
schema,
|
|
14811
14845
|
has(entity) {
|
|
14812
14846
|
return data.has(entity);
|
|
14813
14847
|
},
|
|
@@ -14875,20 +14909,8 @@
|
|
|
14875
14909
|
yield entity;
|
|
14876
14910
|
}
|
|
14877
14911
|
},
|
|
14878
|
-
getCrdtUpdates:
|
|
14879
|
-
|
|
14880
|
-
const component = data.get(entity);
|
|
14881
|
-
if (!component) {
|
|
14882
|
-
throw new Error(`[toBinary] Component ${componentName} for ${entity} not found`);
|
|
14883
|
-
}
|
|
14884
|
-
const writeBuffer = new ReadWriteByteBuffer();
|
|
14885
|
-
schema.serialize(component, writeBuffer);
|
|
14886
|
-
return writeBuffer;
|
|
14887
|
-
},
|
|
14888
|
-
updateFromCrdt: createUpdateFromCrdt(componentId, timestamps, schema, data),
|
|
14889
|
-
deserialize(buffer) {
|
|
14890
|
-
return schema.deserialize(buffer);
|
|
14891
|
-
}
|
|
14912
|
+
getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data),
|
|
14913
|
+
updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data)
|
|
14892
14914
|
};
|
|
14893
14915
|
}
|
|
14894
14916
|
|
|
@@ -14937,6 +14959,135 @@
|
|
|
14937
14959
|
};
|
|
14938
14960
|
}
|
|
14939
14961
|
|
|
14962
|
+
const emptyReadonlySet = freezeSet(new Set());
|
|
14963
|
+
function frozenError() {
|
|
14964
|
+
throw new Error('The set is frozen');
|
|
14965
|
+
}
|
|
14966
|
+
function freezeSet(set) {
|
|
14967
|
+
set.add = frozenError;
|
|
14968
|
+
set.clear = frozenError;
|
|
14969
|
+
return set;
|
|
14970
|
+
}
|
|
14971
|
+
function sortByTimestamp(a, b) {
|
|
14972
|
+
return a.timestamp > b.timestamp ? 1 : -1;
|
|
14973
|
+
}
|
|
14974
|
+
/**
|
|
14975
|
+
* @internal
|
|
14976
|
+
*/
|
|
14977
|
+
function createValueSetComponentDefinitionFromSchema(componentName, componentId, schema, options) {
|
|
14978
|
+
const data = new Map();
|
|
14979
|
+
const dirtyIterator = new Set();
|
|
14980
|
+
const queuedCommands = [];
|
|
14981
|
+
// only sort the array if the latest (N) element has a timestamp <= N-1
|
|
14982
|
+
function shouldSort(row) {
|
|
14983
|
+
const len = row.raw.length;
|
|
14984
|
+
if (len > 1 && row.raw[len - 1].timestamp <= row.raw[len - 2].timestamp) {
|
|
14985
|
+
return true;
|
|
14986
|
+
}
|
|
14987
|
+
return false;
|
|
14988
|
+
}
|
|
14989
|
+
function gotUpdated(entity) {
|
|
14990
|
+
const row = data.get(entity);
|
|
14991
|
+
/* istanbul ignore else */
|
|
14992
|
+
if (row) {
|
|
14993
|
+
if (shouldSort(row)) {
|
|
14994
|
+
row.raw.sort(sortByTimestamp);
|
|
14995
|
+
}
|
|
14996
|
+
while (row.raw.length > options.maxElements) {
|
|
14997
|
+
row.raw.shift();
|
|
14998
|
+
}
|
|
14999
|
+
const frozenSet = freezeSet(new Set(row?.raw.map(($) => $.value)));
|
|
15000
|
+
row.frozenSet = frozenSet;
|
|
15001
|
+
return frozenSet;
|
|
15002
|
+
}
|
|
15003
|
+
else {
|
|
15004
|
+
/* istanbul ignore next */
|
|
15005
|
+
return emptyReadonlySet;
|
|
15006
|
+
}
|
|
15007
|
+
}
|
|
15008
|
+
function append(entity, value) {
|
|
15009
|
+
let row = data.get(entity);
|
|
15010
|
+
if (!row) {
|
|
15011
|
+
row = { raw: [], frozenSet: emptyReadonlySet };
|
|
15012
|
+
data.set(entity, row);
|
|
15013
|
+
}
|
|
15014
|
+
const usedValue = schema.extend ? schema.extend(value) : value;
|
|
15015
|
+
const timestamp = options.timestampFunction(usedValue);
|
|
15016
|
+
if (__DEV__) {
|
|
15017
|
+
// only freeze the objects in dev mode to warn the developers because
|
|
15018
|
+
// it is an expensive operation
|
|
15019
|
+
Object.freeze(usedValue);
|
|
15020
|
+
}
|
|
15021
|
+
row.raw.push({ value: usedValue, timestamp });
|
|
15022
|
+
return { set: gotUpdated(entity), value: usedValue };
|
|
15023
|
+
}
|
|
15024
|
+
const ret = {
|
|
15025
|
+
get componentId() {
|
|
15026
|
+
return componentId;
|
|
15027
|
+
},
|
|
15028
|
+
get componentName() {
|
|
15029
|
+
return componentName;
|
|
15030
|
+
},
|
|
15031
|
+
get componentType() {
|
|
15032
|
+
// a getter is used here to prevent accidental changes
|
|
15033
|
+
return 1 /* ComponentType.GrowOnlyValueSet */;
|
|
15034
|
+
},
|
|
15035
|
+
schema,
|
|
15036
|
+
has(entity) {
|
|
15037
|
+
return data.has(entity);
|
|
15038
|
+
},
|
|
15039
|
+
entityDeleted(entity) {
|
|
15040
|
+
data.delete(entity);
|
|
15041
|
+
},
|
|
15042
|
+
get(entity) {
|
|
15043
|
+
const values = data.get(entity);
|
|
15044
|
+
if (values) {
|
|
15045
|
+
return values.frozenSet;
|
|
15046
|
+
}
|
|
15047
|
+
else {
|
|
15048
|
+
return emptyReadonlySet;
|
|
15049
|
+
}
|
|
15050
|
+
},
|
|
15051
|
+
addValue(entity, rawValue) {
|
|
15052
|
+
const { set, value } = append(entity, rawValue);
|
|
15053
|
+
dirtyIterator.add(entity);
|
|
15054
|
+
const buf = new ReadWriteByteBuffer();
|
|
15055
|
+
schema.serialize(value, buf);
|
|
15056
|
+
queuedCommands.push({
|
|
15057
|
+
componentId,
|
|
15058
|
+
data: buf.toBinary(),
|
|
15059
|
+
entityId: entity,
|
|
15060
|
+
timestamp: 0,
|
|
15061
|
+
type: exports.CrdtMessageType.APPEND_VALUE
|
|
15062
|
+
});
|
|
15063
|
+
return set;
|
|
15064
|
+
},
|
|
15065
|
+
*iterator() {
|
|
15066
|
+
for (const [entity, component] of data) {
|
|
15067
|
+
yield [entity, component.frozenSet];
|
|
15068
|
+
}
|
|
15069
|
+
},
|
|
15070
|
+
*dirtyIterator() {
|
|
15071
|
+
for (const entity of dirtyIterator) {
|
|
15072
|
+
yield entity;
|
|
15073
|
+
}
|
|
15074
|
+
},
|
|
15075
|
+
getCrdtUpdates() {
|
|
15076
|
+
// return a copy of the commands, and then clear the local copy
|
|
15077
|
+
dirtyIterator.clear();
|
|
15078
|
+
return queuedCommands.splice(0, queuedCommands.length);
|
|
15079
|
+
},
|
|
15080
|
+
updateFromCrdt(_body) {
|
|
15081
|
+
if (_body.type === exports.CrdtMessageType.APPEND_VALUE) {
|
|
15082
|
+
const buf = new ReadWriteByteBuffer(_body.data);
|
|
15083
|
+
append(_body.entityId, schema.deserialize(buf));
|
|
15084
|
+
}
|
|
15085
|
+
return [null, undefined];
|
|
15086
|
+
}
|
|
15087
|
+
};
|
|
15088
|
+
return ret;
|
|
15089
|
+
}
|
|
15090
|
+
|
|
14940
15091
|
const InputCommands = [
|
|
14941
15092
|
0 /* InputAction.IA_POINTER */,
|
|
14942
15093
|
1 /* InputAction.IA_PRIMARY */,
|
|
@@ -14952,69 +15103,71 @@
|
|
|
14952
15103
|
12 /* InputAction.IA_ACTION_5 */,
|
|
14953
15104
|
13 /* InputAction.IA_ACTION_6 */
|
|
14954
15105
|
];
|
|
14955
|
-
const
|
|
14956
|
-
timestampLastUpdate: exports.Schemas.Number,
|
|
14957
|
-
currentTimestamp: exports.Schemas.Number,
|
|
14958
|
-
buttonState: exports.Schemas.Array(exports.Schemas.Map({
|
|
14959
|
-
value: exports.Schemas.Boolean,
|
|
14960
|
-
ts: exports.Schemas.Number
|
|
14961
|
-
}))
|
|
14962
|
-
};
|
|
14963
|
-
const TimestampUpdateSystemPriority = 1 << 20;
|
|
14964
|
-
const ButtonStateUpdateSystemPriority = 0;
|
|
15106
|
+
const InputStateUpdateSystemPriority = 1 << 20;
|
|
14965
15107
|
/**
|
|
14966
15108
|
* @internal
|
|
14967
15109
|
*/
|
|
14968
15110
|
function createInputSystem(engine) {
|
|
14969
15111
|
const PointerEventsResult = PointerEventsResult$1(engine);
|
|
14970
|
-
const
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
}
|
|
14982
|
-
}
|
|
14983
|
-
function* commandIterator() {
|
|
14984
|
-
for (const [, value] of engine.getEntitiesWith(PointerEventsResult)) {
|
|
14985
|
-
yield* value.commands;
|
|
15112
|
+
const globalState = {
|
|
15113
|
+
previousFrameMaxTimestamp: 0,
|
|
15114
|
+
currentFrameMaxTimestamp: 0,
|
|
15115
|
+
buttonState: new Map()
|
|
15116
|
+
};
|
|
15117
|
+
function findLastAction(pointerEventType, inputAction, entity) {
|
|
15118
|
+
const ascendingTimestampIterator = PointerEventsResult.get(entity);
|
|
15119
|
+
for (const command of Array.from(ascendingTimestampIterator).reverse()) {
|
|
15120
|
+
if (command.button === inputAction && command.state === pointerEventType) {
|
|
15121
|
+
return command;
|
|
15122
|
+
}
|
|
14986
15123
|
}
|
|
14987
15124
|
}
|
|
14988
|
-
function
|
|
14989
|
-
|
|
14990
|
-
for (const command of
|
|
14991
|
-
if (command.button === inputAction
|
|
14992
|
-
command
|
|
14993
|
-
(!entity || (command.hit && entity === command.hit.entityId))) {
|
|
14994
|
-
if (!commandToReturn || command.timestamp >= commandToReturn.timestamp)
|
|
14995
|
-
commandToReturn = command;
|
|
15125
|
+
function* findCommandsByActionDescending(inputAction, entity) {
|
|
15126
|
+
const ascendingTimestampIterator = PointerEventsResult.get(entity);
|
|
15127
|
+
for (const command of Array.from(ascendingTimestampIterator).reverse()) {
|
|
15128
|
+
if (command.button === inputAction) {
|
|
15129
|
+
yield command;
|
|
14996
15130
|
}
|
|
14997
15131
|
}
|
|
14998
|
-
return commandToReturn;
|
|
14999
15132
|
}
|
|
15000
15133
|
function buttonStateUpdateSystem() {
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
for (const
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15134
|
+
// first store the previous' frame timestamp
|
|
15135
|
+
let maxTimestamp = globalState.currentFrameMaxTimestamp;
|
|
15136
|
+
globalState.previousFrameMaxTimestamp = maxTimestamp;
|
|
15137
|
+
// then iterate over all new commands
|
|
15138
|
+
for (const [, commands] of engine.getEntitiesWith(PointerEventsResult)) {
|
|
15139
|
+
// TODO: adapt the gset component to have a cached "reversed" option by default
|
|
15140
|
+
const arrayCommands = Array.from(commands);
|
|
15141
|
+
for (let i = arrayCommands.length - 1; i >= 0; i--) {
|
|
15142
|
+
const command = arrayCommands[i];
|
|
15143
|
+
if (command.timestamp > maxTimestamp) {
|
|
15144
|
+
maxTimestamp = command.timestamp;
|
|
15009
15145
|
}
|
|
15010
|
-
|
|
15011
|
-
|
|
15146
|
+
if (command.state === 0 /* PointerEventType.PET_UP */ || command.state === 1 /* PointerEventType.PET_DOWN */) {
|
|
15147
|
+
const prevCommand = globalState.buttonState.get(command.button);
|
|
15148
|
+
if (!prevCommand || command.timestamp > prevCommand.timestamp) {
|
|
15149
|
+
globalState.buttonState.set(command.button, command);
|
|
15150
|
+
}
|
|
15151
|
+
else {
|
|
15152
|
+
// since we are iterating a descending array, we can early finish the
|
|
15153
|
+
// loop
|
|
15154
|
+
break;
|
|
15155
|
+
}
|
|
15012
15156
|
}
|
|
15013
15157
|
}
|
|
15014
15158
|
}
|
|
15159
|
+
// update current frame's max timestamp
|
|
15160
|
+
globalState.currentFrameMaxTimestamp = maxTimestamp;
|
|
15161
|
+
}
|
|
15162
|
+
engine.addSystem(buttonStateUpdateSystem, InputStateUpdateSystemPriority, '@dcl/ecs#inputSystem');
|
|
15163
|
+
function timestampIsCurrentFrame(timestamp) {
|
|
15164
|
+
if (timestamp > globalState.previousFrameMaxTimestamp && timestamp <= globalState.currentFrameMaxTimestamp) {
|
|
15165
|
+
return true;
|
|
15166
|
+
}
|
|
15167
|
+
else {
|
|
15168
|
+
return false;
|
|
15169
|
+
}
|
|
15015
15170
|
}
|
|
15016
|
-
engine.addSystem(buttonStateUpdateSystem, ButtonStateUpdateSystemPriority, '@dcl/ecs#buttonStateUpdateSystem');
|
|
15017
|
-
engine.addSystem(timestampUpdateSystem, TimestampUpdateSystemPriority, '@dcl/ecs#timestampUpdateSystem');
|
|
15018
15171
|
function getClick(inputAction, entity) {
|
|
15019
15172
|
if (inputAction !== 3 /* InputAction.IA_ANY */) {
|
|
15020
15173
|
return findClick(inputAction, entity);
|
|
@@ -15027,18 +15180,27 @@
|
|
|
15027
15180
|
return null;
|
|
15028
15181
|
}
|
|
15029
15182
|
function findClick(inputAction, entity) {
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
// We search the last UP command sorted by timestamp
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15183
|
+
let down = null;
|
|
15184
|
+
let up = null;
|
|
15185
|
+
// We search the last UP & DOWN command sorted by timestamp descending
|
|
15186
|
+
for (const it of findCommandsByActionDescending(inputAction, entity)) {
|
|
15187
|
+
if (!up) {
|
|
15188
|
+
if (it.state === 0 /* PointerEventType.PET_UP */) {
|
|
15189
|
+
up = it;
|
|
15190
|
+
continue;
|
|
15191
|
+
}
|
|
15192
|
+
}
|
|
15193
|
+
else if (!down) {
|
|
15194
|
+
if (it.state === 1 /* PointerEventType.PET_DOWN */) {
|
|
15195
|
+
down = it;
|
|
15196
|
+
break;
|
|
15197
|
+
}
|
|
15198
|
+
}
|
|
15199
|
+
}
|
|
15200
|
+
if (!up || !down)
|
|
15037
15201
|
return null;
|
|
15038
|
-
const state = InternalInputStateComponent.get(engine.RootEntity);
|
|
15039
15202
|
// If the DOWN command has happen before the UP commands, it means that that a clicked has happen
|
|
15040
|
-
if (down.timestamp < up.timestamp && up.timestamp
|
|
15041
|
-
InternalInputStateComponent.getMutable(engine.RootEntity).currentTimestamp = Math.max(up.timestamp, state.currentTimestamp);
|
|
15203
|
+
if (down.timestamp < up.timestamp && timestampIsCurrentFrame(up.timestamp)) {
|
|
15042
15204
|
return { up, down };
|
|
15043
15205
|
}
|
|
15044
15206
|
return null;
|
|
@@ -15059,38 +15221,45 @@
|
|
|
15059
15221
|
const command = findLastAction(pointerEventType, inputAction, entity);
|
|
15060
15222
|
if (!command)
|
|
15061
15223
|
return null;
|
|
15062
|
-
|
|
15063
|
-
if (command.timestamp > state.timestampLastUpdate) {
|
|
15064
|
-
InternalInputStateComponent.getMutable(engine.RootEntity).currentTimestamp = Math.max(command.timestamp, state.currentTimestamp);
|
|
15224
|
+
if (timestampIsCurrentFrame(command.timestamp)) {
|
|
15065
15225
|
return command;
|
|
15066
15226
|
}
|
|
15067
15227
|
else {
|
|
15068
15228
|
return null;
|
|
15069
15229
|
}
|
|
15070
15230
|
}
|
|
15231
|
+
// returns true if there was a DOWN (in any past frame), and then an UP in the last frame
|
|
15071
15232
|
function isClicked(inputAction, entity) {
|
|
15072
15233
|
return getClick(inputAction, entity) !== null;
|
|
15073
15234
|
}
|
|
15235
|
+
// returns true if the provided last action was triggered in the last frame
|
|
15074
15236
|
function isTriggered(inputAction, pointerEventType, entity) {
|
|
15075
|
-
|
|
15237
|
+
const command = findLastAction(pointerEventType, inputAction, entity);
|
|
15238
|
+
return (command && timestampIsCurrentFrame(command.timestamp)) || false;
|
|
15076
15239
|
}
|
|
15240
|
+
// returns the global state of the input. This global state is updated from the system
|
|
15077
15241
|
function isPressed(inputAction) {
|
|
15078
|
-
return
|
|
15242
|
+
return globalState.buttonState.get(inputAction)?.state === 1 /* PointerEventType.PET_DOWN */;
|
|
15079
15243
|
}
|
|
15080
15244
|
return {
|
|
15081
|
-
// @public
|
|
15082
15245
|
isPressed,
|
|
15083
|
-
// @internal
|
|
15084
15246
|
getClick,
|
|
15085
|
-
// @public
|
|
15086
15247
|
getInputCommand,
|
|
15087
|
-
// @internal
|
|
15088
15248
|
isClicked,
|
|
15089
|
-
// @public
|
|
15090
15249
|
isTriggered
|
|
15091
15250
|
};
|
|
15092
15251
|
}
|
|
15093
15252
|
|
|
15253
|
+
/**
|
|
15254
|
+
* Component types are used to pick the wire protocol and the conflict resolution algorithm
|
|
15255
|
+
* @public
|
|
15256
|
+
*/
|
|
15257
|
+
exports.ComponentType = void 0;
|
|
15258
|
+
(function (ComponentType) {
|
|
15259
|
+
ComponentType[ComponentType["LastWriteWinElementSet"] = 0] = "LastWriteWinElementSet";
|
|
15260
|
+
ComponentType[ComponentType["GrowOnlyValueSet"] = 1] = "GrowOnlyValueSet";
|
|
15261
|
+
})(exports.ComponentType || (exports.ComponentType = {}));
|
|
15262
|
+
|
|
15094
15263
|
function preEngine() {
|
|
15095
15264
|
const entityContainer = EntityContainer();
|
|
15096
15265
|
const componentsDefinition = new Map();
|
|
@@ -15146,6 +15315,20 @@
|
|
|
15146
15315
|
componentsDefinition.set(componentId, newComponent);
|
|
15147
15316
|
return newComponent;
|
|
15148
15317
|
}
|
|
15318
|
+
function defineValueSetComponentFromSchema(componentName, schema, options) {
|
|
15319
|
+
/* istanbul ignore next */
|
|
15320
|
+
if (sealed)
|
|
15321
|
+
throw new Error('Engine is already sealed. No components can be added at this stage');
|
|
15322
|
+
const componentId = componentNumberFromName(componentName);
|
|
15323
|
+
const prev = componentsDefinition.get(componentId);
|
|
15324
|
+
if (prev) {
|
|
15325
|
+
// TODO: assert spec === prev.spec
|
|
15326
|
+
return prev;
|
|
15327
|
+
}
|
|
15328
|
+
const newComponent = createValueSetComponentDefinitionFromSchema(componentName, componentId, schema, options);
|
|
15329
|
+
componentsDefinition.set(componentId, newComponent);
|
|
15330
|
+
return newComponent;
|
|
15331
|
+
}
|
|
15149
15332
|
function defineComponent(componentName, mapSpec, constructorDefault) {
|
|
15150
15333
|
if (sealed)
|
|
15151
15334
|
throw new Error('Engine is already sealed. No components can be added at this stage');
|
|
@@ -15241,6 +15424,7 @@
|
|
|
15241
15424
|
removeSystem,
|
|
15242
15425
|
defineComponent,
|
|
15243
15426
|
defineComponentFromSchema,
|
|
15427
|
+
defineValueSetComponentFromSchema,
|
|
15244
15428
|
getEntitiesWith,
|
|
15245
15429
|
getComponent,
|
|
15246
15430
|
getComponentOrNull,
|
|
@@ -15276,6 +15460,7 @@
|
|
|
15276
15460
|
removeSystem: partialEngine.removeSystem,
|
|
15277
15461
|
defineComponent: partialEngine.defineComponent,
|
|
15278
15462
|
defineComponentFromSchema: partialEngine.defineComponentFromSchema,
|
|
15463
|
+
defineValueSetComponentFromSchema: partialEngine.defineValueSetComponentFromSchema,
|
|
15279
15464
|
registerComponentDefinition: partialEngine.registerComponentDefinition,
|
|
15280
15465
|
getEntitiesWith: partialEngine.getEntitiesWith,
|
|
15281
15466
|
getComponent: partialEngine.getComponent,
|
|
@@ -42180,8 +42365,7 @@
|
|
|
42180
42365
|
}
|
|
42181
42366
|
},
|
|
42182
42367
|
filter(message) {
|
|
42183
|
-
if (
|
|
42184
|
-
message.componentId > MAX_STATIC_COMPONENT) {
|
|
42368
|
+
if (message.componentId > MAX_STATIC_COMPONENT) {
|
|
42185
42369
|
return false;
|
|
42186
42370
|
}
|
|
42187
42371
|
return !!message;
|
|
@@ -42268,7 +42452,6 @@
|
|
|
42268
42452
|
exports.PBNftShape = PBNftShape;
|
|
42269
42453
|
exports.PBPointerEvents = PBPointerEvents;
|
|
42270
42454
|
exports.PBPointerEventsResult = PBPointerEventsResult;
|
|
42271
|
-
exports.PBPointerEventsResult_PointerCommand = PBPointerEventsResult_PointerCommand;
|
|
42272
42455
|
exports.PBPointerEvents_Entry = PBPointerEvents_Entry;
|
|
42273
42456
|
exports.PBPointerEvents_Info = PBPointerEvents_Info;
|
|
42274
42457
|
exports.PBPointerLock = PBPointerLock;
|
|
@@ -42312,19 +42495,15 @@
|
|
|
42312
42495
|
exports.VideoTexture = VideoTexture;
|
|
42313
42496
|
exports.VisibilityComponent = VisibilityComponent;
|
|
42314
42497
|
exports.components = index;
|
|
42315
|
-
exports.createComponentDefinitionFromSchema = createComponentDefinitionFromSchema;
|
|
42316
42498
|
exports.createEthereumProvider = createEthereumProvider;
|
|
42317
|
-
exports.createGetCrdtMessages = createGetCrdtMessages;
|
|
42318
42499
|
exports.createInputSystem = createInputSystem;
|
|
42319
42500
|
exports.createPointerEventSystem = createPointerEventSystem;
|
|
42320
42501
|
exports.createReactBasedUiSystem = createReactBasedUiSystem;
|
|
42321
42502
|
exports.createTaskSystem = createTaskSystem;
|
|
42322
|
-
exports.createUpdateFromCrdt = createUpdateFromCrdt;
|
|
42323
42503
|
exports.cyclicParentingChecker = cyclicParentingChecker;
|
|
42324
42504
|
exports.deepReadonly = deepReadonly;
|
|
42325
42505
|
exports.engine = engine;
|
|
42326
42506
|
exports.executeTask = executeTask;
|
|
42327
|
-
exports.incrementTimestamp = incrementTimestamp;
|
|
42328
42507
|
exports.inputSystem = inputSystem;
|
|
42329
42508
|
exports.isListener = isListener;
|
|
42330
42509
|
exports.onCommsMessage = onCommsMessage;
|