@dcl/ecs 7.29.1-36591934525.commit-48aa9b5 → 7.29.1-36625469671.commit-2d5ffac
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/components/generated/component-names.gen.js +0 -1
- package/dist/components/generated/global.gen.d.ts +0 -2
- package/dist/components/generated/global.gen.js +0 -1
- package/dist/components/generated/index.gen.d.ts +0 -4
- package/dist/components/generated/index.gen.js +0 -7
- package/dist/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.d.ts +2 -4
- package/dist/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.js +1 -3
- package/dist/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.d.ts +3 -8
- package/dist/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.js +1 -10
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -2
- package/dist/components/manual/CreatedBy.d.ts +9 -0
- package/dist/components/manual/CreatedBy.js +8 -0
- package/dist/components/manual/Transform.d.ts +9 -0
- package/dist/components/manual/Transform.js +3 -3
- package/dist/components/types.d.ts +1 -0
- package/dist/engine/component.d.ts +52 -1
- package/dist/engine/grow-only-value-set-component-definition.js +45 -2
- package/dist/engine/lww-element-set-component-definition.d.ts +3 -1
- package/dist/engine/lww-element-set-component-definition.js +68 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/serialization/crdt/authoritativePutComponent.d.ts +15 -0
- package/dist/serialization/crdt/authoritativePutComponent.js +47 -0
- package/dist/serialization/crdt/index.d.ts +1 -0
- package/dist/serialization/crdt/index.js +1 -0
- package/dist/serialization/crdt/types.d.ts +25 -3
- package/dist/serialization/crdt/types.js +3 -1
- package/dist/systems/crdt/index.d.ts +0 -1
- package/dist/systems/crdt/index.js +76 -143
- package/dist/systems/crdt/types.d.ts +10 -0
- package/dist-cjs/components/generated/component-names.gen.js +0 -1
- package/dist-cjs/components/generated/global.gen.d.ts +0 -2
- package/dist-cjs/components/generated/global.gen.js +2 -3
- package/dist-cjs/components/generated/index.gen.d.ts +0 -4
- package/dist-cjs/components/generated/index.gen.js +2 -10
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.d.ts +2 -4
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.js +1 -3
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.d.ts +3 -8
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.js +1 -10
- package/dist-cjs/components/index.d.ts +5 -0
- package/dist-cjs/components/index.js +7 -3
- package/dist-cjs/components/manual/CreatedBy.d.ts +9 -0
- package/dist-cjs/components/manual/CreatedBy.js +10 -0
- package/dist-cjs/components/manual/Transform.d.ts +9 -0
- package/dist-cjs/components/manual/Transform.js +3 -3
- package/dist-cjs/components/types.d.ts +1 -0
- package/dist-cjs/engine/component.d.ts +52 -1
- package/dist-cjs/engine/grow-only-value-set-component-definition.js +44 -1
- package/dist-cjs/engine/lww-element-set-component-definition.d.ts +3 -1
- package/dist-cjs/engine/lww-element-set-component-definition.js +71 -14
- package/dist-cjs/index.d.ts +2 -1
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +15 -0
- package/dist-cjs/serialization/crdt/authoritativePutComponent.js +50 -0
- package/dist-cjs/serialization/crdt/index.d.ts +1 -0
- package/dist-cjs/serialization/crdt/index.js +1 -0
- package/dist-cjs/serialization/crdt/types.d.ts +25 -3
- package/dist-cjs/serialization/crdt/types.js +3 -1
- package/dist-cjs/systems/crdt/index.d.ts +0 -1
- package/dist-cjs/systems/crdt/index.js +76 -166
- package/dist-cjs/systems/crdt/types.d.ts +10 -0
- package/package.json +2 -2
- package/dist/components/generated/ExplorerItemPurchaseResult.gen.d.ts +0 -1
- package/dist/components/generated/ExplorerItemPurchaseResult.gen.js +0 -25
- package/dist/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.d.ts +0 -68
- package/dist/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.js +0 -184
- package/dist/serialization/crdt/network/utils.d.ts +0 -9
- package/dist/serialization/crdt/network/utils.js +0 -60
- package/dist-cjs/components/generated/ExplorerItemPurchaseResult.gen.d.ts +0 -1
- package/dist-cjs/components/generated/ExplorerItemPurchaseResult.gen.js +0 -28
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.d.ts +0 -68
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.js +0 -190
- package/dist-cjs/serialization/crdt/network/utils.d.ts +0 -9
- package/dist-cjs/serialization/crdt/network/utils.js +0 -67
|
@@ -11,7 +11,8 @@ export declare enum CrdtMessageType {
|
|
|
11
11
|
PUT_COMPONENT_NETWORK = 5,
|
|
12
12
|
DELETE_COMPONENT_NETWORK = 6,
|
|
13
13
|
DELETE_ENTITY_NETWORK = 7,
|
|
14
|
-
|
|
14
|
+
AUTHORITATIVE_PUT_COMPONENT = 8,
|
|
15
|
+
MAX_MESSAGE_TYPE = 9
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Min length = 8 bytes
|
|
@@ -48,6 +49,23 @@ export type PutNetworkComponentMessageBody = Omit<PutComponentMessageBody, 'type
|
|
|
48
49
|
type: CrdtMessageType.PUT_COMPONENT_NETWORK;
|
|
49
50
|
networkId: number;
|
|
50
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Server authoritative message - identical to PutComponentMessageBody but with forced processing
|
|
54
|
+
* Min. length = header (8 bytes) + 16 bytes = 24 bytes
|
|
55
|
+
*
|
|
56
|
+
* @param entity - Uint32 number of the entity
|
|
57
|
+
* @param componentId - Uint32 number of id
|
|
58
|
+
* @param timestamp - Uint32 Lamport timestamp (server's authoritative timestamp)
|
|
59
|
+
* @param data - Uint8[] data of component => length(4 bytes) + block of bytes[0..length-1]
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export type AuthoritativePutComponentMessageBody = {
|
|
63
|
+
type: CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT;
|
|
64
|
+
entityId: Entity;
|
|
65
|
+
componentId: number;
|
|
66
|
+
timestamp: number;
|
|
67
|
+
data: Uint8Array;
|
|
68
|
+
};
|
|
51
69
|
/**
|
|
52
70
|
* Min. length = header (8 bytes) + 16 bytes = 24 bytes
|
|
53
71
|
*
|
|
@@ -114,6 +132,10 @@ export type AppendValueMessage = CrdtMessageHeader & AppendValueMessageBody;
|
|
|
114
132
|
* @public
|
|
115
133
|
*/
|
|
116
134
|
export type PutComponentMessage = CrdtMessageHeader & PutComponentMessageBody;
|
|
135
|
+
/**
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export type AuthoritativePutComponentMessage = CrdtMessageHeader & AuthoritativePutComponentMessageBody;
|
|
117
139
|
/**
|
|
118
140
|
* @public
|
|
119
141
|
*/
|
|
@@ -137,7 +159,7 @@ export type DeleteEntityNetworkMessage = CrdtMessageHeader & DeleteEntityNetwork
|
|
|
137
159
|
/**
|
|
138
160
|
* @public
|
|
139
161
|
*/
|
|
140
|
-
export type CrdtMessage = PutComponentMessage | DeleteComponentMessage | AppendValueMessage | DeleteEntityMessage | PutNetworkComponentMessage | DeleteComponentNetworkMessage | DeleteEntityNetworkMessage;
|
|
162
|
+
export type CrdtMessage = PutComponentMessage | AuthoritativePutComponentMessage | DeleteComponentMessage | AppendValueMessage | DeleteEntityMessage | PutNetworkComponentMessage | DeleteComponentNetworkMessage | DeleteEntityNetworkMessage;
|
|
141
163
|
/**
|
|
142
164
|
* @public
|
|
143
165
|
*/
|
|
@@ -145,7 +167,7 @@ export type CrdtNetworkMessageBody = PutNetworkComponentMessageBody | DeleteComp
|
|
|
145
167
|
/**
|
|
146
168
|
* @public
|
|
147
169
|
*/
|
|
148
|
-
export type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody | CrdtNetworkMessageBody;
|
|
170
|
+
export type CrdtMessageBody = PutComponentMessageBody | AuthoritativePutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody | CrdtNetworkMessageBody;
|
|
149
171
|
export declare enum ProcessMessageResultType {
|
|
150
172
|
/**
|
|
151
173
|
* Typical message and new state set.
|
|
@@ -16,7 +16,9 @@ var CrdtMessageType;
|
|
|
16
16
|
CrdtMessageType[CrdtMessageType["PUT_COMPONENT_NETWORK"] = 5] = "PUT_COMPONENT_NETWORK";
|
|
17
17
|
CrdtMessageType[CrdtMessageType["DELETE_COMPONENT_NETWORK"] = 6] = "DELETE_COMPONENT_NETWORK";
|
|
18
18
|
CrdtMessageType[CrdtMessageType["DELETE_ENTITY_NETWORK"] = 7] = "DELETE_ENTITY_NETWORK";
|
|
19
|
-
|
|
19
|
+
// Server authoritative operation - forces component state regardless of timestamp
|
|
20
|
+
CrdtMessageType[CrdtMessageType["AUTHORITATIVE_PUT_COMPONENT"] = 8] = "AUTHORITATIVE_PUT_COMPONENT";
|
|
21
|
+
CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 9] = "MAX_MESSAGE_TYPE";
|
|
20
22
|
})(CrdtMessageType = exports.CrdtMessageType || (exports.CrdtMessageType = {}));
|
|
21
23
|
/**
|
|
22
24
|
* @public
|
|
@@ -1,50 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.crdtSceneSystem =
|
|
3
|
+
exports.crdtSceneSystem = void 0;
|
|
27
4
|
const entity_1 = require("../../engine/entity");
|
|
28
5
|
const ByteBuffer_1 = require("../../serialization/ByteBuffer");
|
|
29
6
|
const crdt_1 = require("../../serialization/crdt");
|
|
30
7
|
const deleteComponent_1 = require("../../serialization/crdt/deleteComponent");
|
|
31
8
|
const deleteEntity_1 = require("../../serialization/crdt/deleteEntity");
|
|
32
9
|
const putComponent_1 = require("../../serialization/crdt/putComponent");
|
|
10
|
+
const authoritativePutComponent_1 = require("../../serialization/crdt/authoritativePutComponent");
|
|
33
11
|
const types_1 = require("../../serialization/crdt/types");
|
|
34
|
-
const putComponentNetwork_1 = require("../../serialization/crdt/network/putComponentNetwork");
|
|
35
|
-
const components_1 = require("../../components");
|
|
36
|
-
const networkUtils = __importStar(require("../../serialization/crdt/network/utils"));
|
|
37
|
-
// NetworkMessages can only have a MAX_SIZE of 12kb. So we need to send it in chunks.
|
|
38
|
-
exports.LIVEKIT_MAX_SIZE = 12;
|
|
39
12
|
/**
|
|
40
13
|
* @internal
|
|
41
14
|
*/
|
|
42
15
|
function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
43
16
|
const transports = [];
|
|
44
|
-
//
|
|
45
|
-
const NetworkEntity = (0, components_1.NetworkEntity)(engine);
|
|
46
|
-
const NetworkParent = (0, components_1.NetworkParent)(engine);
|
|
47
|
-
const Transform = (0, components_1.Transform)(engine);
|
|
17
|
+
// No network components needed - pure CRDT processing only
|
|
48
18
|
// Messages that we received at transport.onMessage waiting to be processed
|
|
49
19
|
const receivedMessages = [];
|
|
50
20
|
// Messages already processed by the engine but that we need to broadcast to other transports.
|
|
@@ -69,27 +39,20 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
69
39
|
if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT) {
|
|
70
40
|
message = deleteComponent_1.DeleteComponent.read(buffer);
|
|
71
41
|
}
|
|
72
|
-
else if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK) {
|
|
73
|
-
message = crdt_1.DeleteComponentNetwork.read(buffer);
|
|
74
|
-
}
|
|
75
42
|
else if (header.type === types_1.CrdtMessageType.PUT_COMPONENT) {
|
|
76
43
|
message = putComponent_1.PutComponentOperation.read(buffer);
|
|
77
44
|
}
|
|
78
|
-
else if (header.type === types_1.CrdtMessageType.
|
|
79
|
-
message =
|
|
45
|
+
else if (header.type === types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
|
|
46
|
+
message = authoritativePutComponent_1.AuthoritativePutComponentOperation.read(buffer);
|
|
80
47
|
}
|
|
81
48
|
else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY) {
|
|
82
49
|
message = deleteEntity_1.DeleteEntity.read(buffer);
|
|
83
50
|
}
|
|
84
|
-
else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
85
|
-
message = crdt_1.DeleteEntityNetwork.read(buffer);
|
|
86
|
-
}
|
|
87
51
|
else if (header.type === types_1.CrdtMessageType.APPEND_VALUE) {
|
|
88
52
|
message = crdt_1.AppendValueOperation.read(buffer);
|
|
89
|
-
// Unknown message, we skip it
|
|
90
53
|
}
|
|
91
54
|
else {
|
|
92
|
-
//
|
|
55
|
+
// Unknown message, we skip it (including NETWORK messages)
|
|
93
56
|
buffer.incrementReadOffset(header.length);
|
|
94
57
|
}
|
|
95
58
|
if (message) {
|
|
@@ -111,20 +74,12 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
111
74
|
return messagesToProcess;
|
|
112
75
|
}
|
|
113
76
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
77
|
+
* Reserved-range entities (root/player/camera + avatars, entity number <
|
|
78
|
+
* RESERVED_STATIC_ENTITIES) are host-owned: only a transport flagged with
|
|
79
|
+
* `allowReservedEntities` (the host/renderer) may mutate or delete them.
|
|
117
80
|
*/
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
if (hasNetworkId) {
|
|
121
|
-
for (const [entityId, network] of engine.getEntitiesWith(NetworkEntity)) {
|
|
122
|
-
if (network.networkId === msg.networkId && network.entityId === msg.entityId) {
|
|
123
|
-
return { entityId, network };
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return { entityId: msg.entityId };
|
|
81
|
+
function isTrustedForReservedEntities(transportId) {
|
|
82
|
+
return transportId !== undefined && !!transports[transportId]?.allowReservedEntities;
|
|
128
83
|
}
|
|
129
84
|
/**
|
|
130
85
|
* This fn will be called on every tick.
|
|
@@ -134,46 +89,68 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
134
89
|
const messagesToProcess = getMessages(receivedMessages);
|
|
135
90
|
const entitiesShouldBeCleaned = [];
|
|
136
91
|
for (const msg of messagesToProcess) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
92
|
+
// Simple CRDT processing - no network logic
|
|
93
|
+
if (msg.type === types_1.CrdtMessageType.DELETE_ENTITY) {
|
|
94
|
+
// Reject an inbound DELETE_ENTITY on a reserved entity from an untrusted
|
|
95
|
+
// transport (a comms peer, or a scene-added transport). The allocator half
|
|
96
|
+
// is already guarded (engine.removeEntity is a no-op on this range); this
|
|
97
|
+
// closes the receive-side half.
|
|
98
|
+
const isReserved = engine.entityContainer.getEntityState(msg.entityId) === entity_1.EntityState.Reserved;
|
|
99
|
+
if (isReserved && !isTrustedForReservedEntities(msg.transportId)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
entitiesShouldBeCleaned.push(msg.entityId);
|
|
146
103
|
broadcastMessages.push(msg);
|
|
147
104
|
}
|
|
148
105
|
else {
|
|
149
|
-
const entityState = engine.entityContainer.getEntityState(entityId);
|
|
150
|
-
// Skip updates from removed
|
|
106
|
+
const entityState = engine.entityContainer.getEntityState(msg.entityId);
|
|
107
|
+
// Skip updates from removed entities
|
|
151
108
|
if (entityState === entity_1.EntityState.Removed)
|
|
152
109
|
continue;
|
|
153
|
-
//
|
|
110
|
+
// Reject component operations (PUT/DELETE/APPEND, including AUTHORITATIVE_PUT
|
|
111
|
+
// which bypasses timestamps entirely) on reserved entities from untrusted
|
|
112
|
+
// transports. Dropping before updateFromCrdt keeps local LWW timestamps
|
|
113
|
+
// unpoisoned by forged high timestamps, and also prevents the
|
|
114
|
+
// unknown-component rebroadcast below from relaying forged reserved-entity
|
|
115
|
+
// data to other transports (including the renderer).
|
|
116
|
+
if (entityState === entity_1.EntityState.Reserved && !isTrustedForReservedEntities(msg.transportId))
|
|
117
|
+
continue;
|
|
118
|
+
// Entities with unknown state should update its entity state
|
|
154
119
|
if (entityState === entity_1.EntityState.Unknown) {
|
|
155
|
-
engine.entityContainer.updateUsedEntity(entityId);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
120
|
+
engine.entityContainer.updateUsedEntity(msg.entityId);
|
|
121
|
+
}
|
|
122
|
+
// Only process component-related messages (not DELETE_ENTITY)
|
|
123
|
+
if ('componentId' in msg) {
|
|
124
|
+
const component = engine.getComponentOrNull(msg.componentId);
|
|
125
|
+
if (component) {
|
|
126
|
+
// Handle authoritative messages differently - they force the state regardless of timestamp
|
|
127
|
+
const tryUpdate = () => {
|
|
128
|
+
try {
|
|
129
|
+
return msg.type === types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT
|
|
130
|
+
? component.__forceUpdateFromCrdt(msg)
|
|
131
|
+
: component.updateFromCrdt(msg);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
console.error('[receiveMessages] ERROR processing message', msg, e);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const result = tryUpdate();
|
|
139
|
+
if (!result)
|
|
140
|
+
continue;
|
|
141
|
+
const [conflictMessage, value] = result;
|
|
142
|
+
if (!conflictMessage) {
|
|
143
|
+
// Add message to broadcast queue when no conflict
|
|
144
|
+
broadcastMessages.push(msg);
|
|
145
|
+
onProcessEntityComponentChange && onProcessEntityComponentChange(msg.entityId, msg.type, component, value);
|
|
146
|
+
}
|
|
165
147
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
148
|
+
else {
|
|
149
|
+
// Component not found - still broadcast for editor compatibility
|
|
150
|
+
/* istanbul ignore next */
|
|
169
151
|
broadcastMessages.push(msg);
|
|
170
|
-
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, msg.type, component, value);
|
|
171
152
|
}
|
|
172
153
|
}
|
|
173
|
-
else {
|
|
174
|
-
// TODO: test this line, it is fundammental to make the editor work
|
|
175
|
-
broadcastMessages.push(msg);
|
|
176
|
-
}
|
|
177
154
|
}
|
|
178
155
|
}
|
|
179
156
|
// the last stage of the syncrhonization is to delete the entities
|
|
@@ -187,16 +164,17 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
187
164
|
}
|
|
188
165
|
}
|
|
189
166
|
/**
|
|
190
|
-
*
|
|
167
|
+
* Simple CRDT message broadcasting - no network-specific logic
|
|
191
168
|
*/
|
|
192
169
|
async function sendMessages(entitiesDeletedThisTick) {
|
|
193
|
-
//
|
|
170
|
+
// Get messages from broadcast queue and component updates
|
|
194
171
|
const crdtMessages = getMessages(broadcastMessages);
|
|
195
172
|
const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
|
|
173
|
+
// Generate CRDT messages from component updates
|
|
196
174
|
for (const component of engine.componentsIter()) {
|
|
197
175
|
for (const message of component.getCrdtUpdates()) {
|
|
198
176
|
const offset = buffer.currentWriteOffset();
|
|
199
|
-
//
|
|
177
|
+
// Only create messages if there's a transport that will handle it
|
|
200
178
|
if (transports.some((t) => t.filter(message))) {
|
|
201
179
|
if (message.type === types_1.CrdtMessageType.PUT_COMPONENT) {
|
|
202
180
|
putComponent_1.PutComponentOperation.write(message.entityId, message.timestamp, message.componentId, message.data, buffer);
|
|
@@ -220,7 +198,7 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
220
198
|
}
|
|
221
199
|
}
|
|
222
200
|
}
|
|
223
|
-
//
|
|
201
|
+
// Handle deleted entities
|
|
224
202
|
for (const entityId of entitiesDeletedThisTick) {
|
|
225
203
|
const offset = buffer.currentWriteOffset();
|
|
226
204
|
deleteEntity_1.DeleteEntity.write(entityId, buffer);
|
|
@@ -231,87 +209,19 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
231
209
|
});
|
|
232
210
|
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, types_1.CrdtMessageType.DELETE_ENTITY);
|
|
233
211
|
}
|
|
234
|
-
//
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
const __NetworkMessagesBuffer = [];
|
|
238
|
-
const transportIndex = Number(index);
|
|
239
|
-
const transport = transports[transportIndex];
|
|
240
|
-
const isRendererTransport = transport.type === 'renderer';
|
|
241
|
-
const isNetworkTransport = transport.type === 'network';
|
|
242
|
-
// Reset Buffer for each Transport
|
|
243
|
-
transportBuffer.resetBuffer();
|
|
244
|
-
const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
|
|
245
|
-
// Then we send all the new crdtMessages that the transport needs to process
|
|
212
|
+
// Simple transport broadcasting - no network-specific transforms
|
|
213
|
+
for (const transport of transports) {
|
|
214
|
+
const transportBuffer = new ByteBuffer_1.ReadWriteByteBuffer();
|
|
246
215
|
for (const message of crdtMessages) {
|
|
247
216
|
// Avoid echo messages
|
|
248
|
-
if (message.transportId ===
|
|
249
|
-
continue;
|
|
250
|
-
// Redundant message for the transport
|
|
251
|
-
if (!transport.filter(message))
|
|
252
|
-
continue;
|
|
253
|
-
// Check if adding this message would exceed the size limit
|
|
254
|
-
const currentBufferSize = transportBuffer.toBinary().byteLength;
|
|
255
|
-
const messageSize = message.messageBuffer.byteLength;
|
|
256
|
-
if (isNetworkTransport && (currentBufferSize + messageSize) / 1024 > exports.LIVEKIT_MAX_SIZE) {
|
|
257
|
-
// If the current buffer has content, save it as a chunk
|
|
258
|
-
if (currentBufferSize > 0) {
|
|
259
|
-
__NetworkMessagesBuffer.push(transportBuffer.toCopiedBinary());
|
|
260
|
-
transportBuffer.resetBuffer();
|
|
261
|
-
}
|
|
262
|
-
// If the message itself is larger than the limit, we need to handle it specially
|
|
263
|
-
// For now, we'll skip it to prevent infinite loops
|
|
264
|
-
if (messageSize / 1024 > exports.LIVEKIT_MAX_SIZE) {
|
|
265
|
-
console.error(`Message too large (${messageSize} bytes), skipping message for entity ${message.entityId}`);
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
const { entityId } = findNetworkId(message);
|
|
270
|
-
const transformNeedsFix = 'componentId' in message &&
|
|
271
|
-
message.componentId === Transform.componentId &&
|
|
272
|
-
Transform.has(entityId) &&
|
|
273
|
-
NetworkParent.has(entityId) &&
|
|
274
|
-
NetworkEntity.has(entityId);
|
|
275
|
-
// If there was a LOCAL change in the transform. Add the parent to that transform
|
|
276
|
-
if (isRendererTransport && message.type === types_1.CrdtMessageType.PUT_COMPONENT && transformNeedsFix) {
|
|
277
|
-
const parent = findNetworkId(NetworkParent.get(entityId));
|
|
278
|
-
const transformData = networkUtils.fixTransformParent(message, Transform.get(entityId), parent.entityId);
|
|
279
|
-
const offset = buffer.currentWriteOffset();
|
|
280
|
-
putComponent_1.PutComponentOperation.write(entityId, message.timestamp, message.componentId, transformData, buffer);
|
|
281
|
-
transportBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
|
|
217
|
+
if (message.transportId === transports.indexOf(transport))
|
|
282
218
|
continue;
|
|
219
|
+
// Check if transport wants this message
|
|
220
|
+
if (transport.filter(message)) {
|
|
221
|
+
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
283
222
|
}
|
|
284
|
-
if (isRendererTransport && networkUtils.isNetworkMessage(message)) {
|
|
285
|
-
// If it's the renderer transport and its a NetworkMessage, we need to fix the entityId field and convert it to a known Message.
|
|
286
|
-
// PUT_NETWORK_COMPONENT -> PUT_COMPONENT
|
|
287
|
-
let transformData = 'data' in message ? message.data : new Uint8Array();
|
|
288
|
-
if (transformNeedsFix) {
|
|
289
|
-
const parent = findNetworkId(NetworkParent.get(entityId));
|
|
290
|
-
transformData = networkUtils.fixTransformParent(message, Transform.get(entityId), parent.entityId);
|
|
291
|
-
}
|
|
292
|
-
networkUtils.networkMessageToLocal({ ...message, data: transformData }, entityId, buffer, transportBuffer);
|
|
293
|
-
// Iterate the next message
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
// If its a network transport and its a PUT_COMPONENT that has a NetworkEntity component, we need to send this message
|
|
297
|
-
// through comms with the EntityID and NetworkID from ther NetworkEntity so everyone can recieve this message and map to their custom entityID.
|
|
298
|
-
if (isNetworkTransport && !networkUtils.isNetworkMessage(message)) {
|
|
299
|
-
const networkData = NetworkEntity.getOrNull(message.entityId);
|
|
300
|
-
// If it has networkData convert the message to PUT_NETWORK_COMPONENT.
|
|
301
|
-
if (networkData) {
|
|
302
|
-
networkUtils.localMessageToNetwork(message, networkData, buffer, transportBuffer);
|
|
303
|
-
// Iterate the next message
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// Common message
|
|
308
|
-
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
309
|
-
}
|
|
310
|
-
if (isNetworkTransport && transportBuffer.currentWriteOffset()) {
|
|
311
|
-
__NetworkMessagesBuffer.push(transportBuffer.toBinary());
|
|
312
223
|
}
|
|
313
|
-
|
|
314
|
-
await transport.send(message);
|
|
224
|
+
await transport.send(transportBuffer.toBinary());
|
|
315
225
|
}
|
|
316
226
|
}
|
|
317
227
|
/**
|
|
@@ -29,4 +29,14 @@ export type Transport = {
|
|
|
29
29
|
onmessage?(message: Uint8Array): void;
|
|
30
30
|
filter(message: Omit<TransportMessage, 'messageBuffer'>): boolean;
|
|
31
31
|
type?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Whether this transport is allowed to mutate reserved-range entities
|
|
34
|
+
* (root/player/camera + avatars, entity number below `RESERVED_STATIC_ENTITIES`).
|
|
35
|
+
* Only the trusted host/renderer transport sets this. An inbound DELETE_ENTITY
|
|
36
|
+
* or component operation (PUT_COMPONENT, DELETE_COMPONENT, APPEND_VALUE,
|
|
37
|
+
* AUTHORITATIVE_PUT_COMPONENT) on a reserved entity from a transport without
|
|
38
|
+
* this flag (a comms peer, or any scene-added transport) is rejected — see
|
|
39
|
+
* `receiveMessages`.
|
|
40
|
+
*/
|
|
41
|
+
allowReservedEntities?: boolean;
|
|
32
42
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
3
|
"description": "Decentraland ECS",
|
|
4
|
-
"version": "7.29.1-
|
|
4
|
+
"version": "7.29.1-36625469671.commit-2d5ffac",
|
|
5
5
|
"author": "DCL",
|
|
6
6
|
"bugs": "https://github.com/decentraland/ecs/issues",
|
|
7
7
|
"files": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"dependencies": {},
|
|
35
35
|
"types": "./dist/index.d.ts",
|
|
36
36
|
"typings": "./dist/index.d.ts",
|
|
37
|
-
"commit": "
|
|
37
|
+
"commit": "2d5ffaca13b81a16cd09d797bc95b052151a89df"
|
|
38
38
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { PBExplorerItemPurchaseResult } from './pb/decentraland/sdk/components/explorer_item_purchase_result.gen';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export const ExplorerItemPurchaseResultSchema = {
|
|
6
|
-
COMPONENT_ID: 1222,
|
|
7
|
-
serialize(value, builder) {
|
|
8
|
-
const writer = PBExplorerItemPurchaseResult.encode(value);
|
|
9
|
-
const buffer = new Uint8Array(writer.finish(), 0, writer.len);
|
|
10
|
-
builder.writeBuffer(buffer, false);
|
|
11
|
-
},
|
|
12
|
-
deserialize(reader) {
|
|
13
|
-
return PBExplorerItemPurchaseResult.decode(reader.buffer(), reader.remainingBytes());
|
|
14
|
-
},
|
|
15
|
-
create() {
|
|
16
|
-
// TODO: this is a hack.
|
|
17
|
-
return PBExplorerItemPurchaseResult.decode(new Uint8Array());
|
|
18
|
-
},
|
|
19
|
-
jsonSchema: {
|
|
20
|
-
type: "object",
|
|
21
|
-
properties: {},
|
|
22
|
-
serializationType: "protocol-buffer",
|
|
23
|
-
protocolBuffer: "PBExplorerItemPurchaseResult"
|
|
24
|
-
}
|
|
25
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import _m0 from "protobufjs/minimal";
|
|
2
|
-
/**
|
|
3
|
-
* Grow-only value set appended to the scene root entity.
|
|
4
|
-
* Reports the outcome of an EU_ITEM_PURCHASE flow triggered via OpenExplorerUi.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface PBExplorerItemPurchaseResult {
|
|
10
|
-
urn: string;
|
|
11
|
-
/** The scene tick when the event occurred */
|
|
12
|
-
timestamp: number;
|
|
13
|
-
/** The OpenExplorerUiRequest.request_id that caused this event; 0 when the request carried none */
|
|
14
|
-
requestId: number;
|
|
15
|
-
status?: {
|
|
16
|
-
$case: "purchased";
|
|
17
|
-
purchased: PBExplorerItemPurchaseResult_Purchased;
|
|
18
|
-
} | {
|
|
19
|
-
$case: "dismissed";
|
|
20
|
-
dismissed: PBExplorerItemPurchaseResult_Dismissed;
|
|
21
|
-
} | {
|
|
22
|
-
$case: "failed";
|
|
23
|
-
failed: PBExplorerItemPurchaseResult_Failed;
|
|
24
|
-
} | undefined;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
export interface PBExplorerItemPurchaseResult_Purchased {
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
export interface PBExplorerItemPurchaseResult_Dismissed {
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export interface PBExplorerItemPurchaseResult_Failed {
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
export declare namespace PBExplorerItemPurchaseResult {
|
|
45
|
-
function encode(message: PBExplorerItemPurchaseResult, writer?: _m0.Writer): _m0.Writer;
|
|
46
|
-
function decode(input: _m0.Reader | Uint8Array, length?: number): PBExplorerItemPurchaseResult;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
export declare namespace PBExplorerItemPurchaseResult_Purchased {
|
|
52
|
-
function encode(_: PBExplorerItemPurchaseResult_Purchased, writer?: _m0.Writer): _m0.Writer;
|
|
53
|
-
function decode(input: _m0.Reader | Uint8Array, length?: number): PBExplorerItemPurchaseResult_Purchased;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
export declare namespace PBExplorerItemPurchaseResult_Dismissed {
|
|
59
|
-
function encode(_: PBExplorerItemPurchaseResult_Dismissed, writer?: _m0.Writer): _m0.Writer;
|
|
60
|
-
function decode(input: _m0.Reader | Uint8Array, length?: number): PBExplorerItemPurchaseResult_Dismissed;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
export declare namespace PBExplorerItemPurchaseResult_Failed {
|
|
66
|
-
function encode(_: PBExplorerItemPurchaseResult_Failed, writer?: _m0.Writer): _m0.Writer;
|
|
67
|
-
function decode(input: _m0.Reader | Uint8Array, length?: number): PBExplorerItemPurchaseResult_Failed;
|
|
68
|
-
}
|