@dcl/ecs 7.21.1-22918726402.commit-ee210ee → 7.21.1-23252789519.commit-9f806e1
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/index.d.ts +0 -5
- package/dist/components/index.js +2 -5
- package/dist/components/manual/Transform.d.ts +13 -9
- package/dist/components/manual/Transform.js +11 -3
- package/dist/components/types.d.ts +0 -1
- package/dist/engine/component.d.ts +1 -52
- package/dist/engine/grow-only-value-set-component-definition.js +2 -45
- package/dist/engine/lww-element-set-component-definition.d.ts +1 -3
- package/dist/engine/lww-element-set-component-definition.js +12 -64
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/runtime/helpers/index.d.ts +1 -0
- package/dist/runtime/helpers/index.js +1 -0
- package/dist/runtime/helpers/tree.d.ts +6 -0
- package/dist/runtime/helpers/tree.js +2 -2
- package/dist/runtime/helpers/vectors.d.ts +1 -0
- package/dist/runtime/helpers/vectors.js +36 -0
- package/dist/runtime/initialization/index.d.ts +7 -0
- package/dist/runtime/initialization/index.js +6 -0
- package/dist/serialization/crdt/index.d.ts +0 -1
- package/dist/serialization/crdt/index.js +0 -1
- package/dist/serialization/crdt/network/utils.d.ts +9 -0
- package/dist/serialization/crdt/network/utils.js +60 -0
- package/dist/serialization/crdt/types.d.ts +3 -25
- package/dist/serialization/crdt/types.js +1 -3
- package/dist/systems/crdt/index.d.ts +1 -0
- package/dist/systems/crdt/index.js +146 -55
- package/dist/systems/physics-force.d.ts +1 -0
- package/dist/systems/physics-force.js +140 -0
- package/dist/systems/physics-impulse.d.ts +12 -0
- package/dist/systems/physics-impulse.js +85 -0
- package/dist/systems/physics.d.ts +77 -0
- package/dist/systems/physics.js +18 -0
- package/dist-cjs/components/index.d.ts +0 -5
- package/dist-cjs/components/index.js +3 -7
- package/dist-cjs/components/manual/Transform.d.ts +13 -9
- package/dist-cjs/components/manual/Transform.js +34 -3
- package/dist-cjs/components/types.d.ts +0 -1
- package/dist-cjs/engine/component.d.ts +1 -52
- package/dist-cjs/engine/grow-only-value-set-component-definition.js +1 -44
- package/dist-cjs/engine/lww-element-set-component-definition.d.ts +1 -3
- package/dist-cjs/engine/lww-element-set-component-definition.js +13 -67
- package/dist-cjs/index.d.ts +2 -2
- package/dist-cjs/index.js +2 -2
- package/dist-cjs/runtime/helpers/index.d.ts +1 -0
- package/dist-cjs/runtime/helpers/index.js +1 -0
- package/dist-cjs/runtime/helpers/tree.d.ts +6 -0
- package/dist-cjs/runtime/helpers/tree.js +3 -2
- package/dist-cjs/runtime/helpers/vectors.d.ts +1 -0
- package/dist-cjs/runtime/helpers/vectors.js +39 -0
- package/dist-cjs/runtime/initialization/index.d.ts +7 -0
- package/dist-cjs/runtime/initialization/index.js +7 -1
- package/dist-cjs/serialization/crdt/index.d.ts +0 -1
- package/dist-cjs/serialization/crdt/index.js +0 -1
- package/dist-cjs/serialization/crdt/network/utils.d.ts +9 -0
- package/dist-cjs/serialization/crdt/network/utils.js +67 -0
- package/dist-cjs/serialization/crdt/types.d.ts +3 -25
- package/dist-cjs/serialization/crdt/types.js +1 -3
- package/dist-cjs/systems/crdt/index.d.ts +1 -0
- package/dist-cjs/systems/crdt/index.js +169 -55
- package/dist-cjs/systems/physics-force.d.ts +1 -0
- package/dist-cjs/systems/physics-force.js +167 -0
- package/dist-cjs/systems/physics-impulse.d.ts +12 -0
- package/dist-cjs/systems/physics-impulse.js +112 -0
- package/dist-cjs/systems/physics.d.ts +77 -0
- package/dist-cjs/systems/physics.js +23 -0
- package/package.json +3 -2
- package/dist/components/manual/CreatedBy.d.ts +0 -9
- package/dist/components/manual/CreatedBy.js +0 -8
- package/dist/serialization/crdt/authoritativePutComponent.d.ts +0 -15
- package/dist/serialization/crdt/authoritativePutComponent.js +0 -47
- package/dist-cjs/components/manual/CreatedBy.d.ts +0 -9
- package/dist-cjs/components/manual/CreatedBy.js +0 -10
- package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +0 -15
- package/dist-cjs/serialization/crdt/authoritativePutComponent.js +0 -50
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vector3 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Lightweight Vector3 math utilities for internal use.
|
|
6
|
+
* Mirrors the subset of @dcl/ecs-math Vector3 API used by the physics helpers.
|
|
7
|
+
*
|
|
8
|
+
* TEMPORARY WORKAROUND: @dcl/ecs-math ships ESM-only, which breaks the dist-cjs build.
|
|
9
|
+
* The proper fix is to add a CJS build to @dcl/ecs-math upstream, then replace this
|
|
10
|
+
* file with `import { Vector3 } from '@dcl/ecs-math'`.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
exports.Vector3 = {
|
|
15
|
+
add(a, b) {
|
|
16
|
+
return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
|
|
17
|
+
},
|
|
18
|
+
subtract(a, b) {
|
|
19
|
+
return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
|
|
20
|
+
},
|
|
21
|
+
scale(v, s) {
|
|
22
|
+
return { x: v.x * s, y: v.y * s, z: v.z * s };
|
|
23
|
+
},
|
|
24
|
+
length(v) {
|
|
25
|
+
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
|
26
|
+
},
|
|
27
|
+
normalize(v) {
|
|
28
|
+
const len = exports.Vector3.length(v);
|
|
29
|
+
if (len === 0)
|
|
30
|
+
return { x: 0, y: 0, z: 0 };
|
|
31
|
+
return { x: v.x / len, y: v.y / len, z: v.z / len };
|
|
32
|
+
},
|
|
33
|
+
equals(a, b) {
|
|
34
|
+
return a.x === b.x && a.y === b.y && a.z === b.z;
|
|
35
|
+
},
|
|
36
|
+
equalsToFloats(v, x, y, z) {
|
|
37
|
+
return v.x === x && v.y === y && v.z === z;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -12,6 +12,7 @@ import { AssetLoadLoadingStateSystem } from '../../systems/assetLoad';
|
|
|
12
12
|
import { TweenSystem } from '../../systems/tween';
|
|
13
13
|
import { TriggerAreaEventsSystem } from '../../systems/triggerArea';
|
|
14
14
|
import { createTimers, Timers } from '../helpers/timers';
|
|
15
|
+
import { PhysicsSystem } from '../../systems/physics';
|
|
15
16
|
/**
|
|
16
17
|
* @public
|
|
17
18
|
* The engine is the part of the scene that sits in the middle and manages all of the other parts.
|
|
@@ -77,6 +78,12 @@ export { TriggerAreaEventsSystem };
|
|
|
77
78
|
*/
|
|
78
79
|
export declare const timers: Timers;
|
|
79
80
|
export { Timers, createTimers };
|
|
81
|
+
/**
|
|
82
|
+
* @public
|
|
83
|
+
* Physics helpers for applying impulses and forces to the player.
|
|
84
|
+
*/
|
|
85
|
+
export declare const Physics: PhysicsSystem;
|
|
86
|
+
export { PhysicsSystem };
|
|
80
87
|
/**
|
|
81
88
|
* @public
|
|
82
89
|
* Runs an async function
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* init and it'll be changing.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.executeTask = exports.createTimers = exports.timers = exports.triggerAreaEventsSystem = exports.tweenSystem = exports.assetLoadLoadingStateSystem = exports.videoEventsSystem = exports.raycastSystem = exports.pointerEventsSystem = exports.inputSystem = exports.engine = void 0;
|
|
7
|
+
exports.executeTask = exports.Physics = exports.createTimers = exports.timers = exports.triggerAreaEventsSystem = exports.tweenSystem = exports.assetLoadLoadingStateSystem = exports.videoEventsSystem = exports.raycastSystem = exports.pointerEventsSystem = exports.inputSystem = exports.engine = void 0;
|
|
8
8
|
const engine_1 = require("../../engine");
|
|
9
9
|
const async_task_1 = require("../../systems/async-task");
|
|
10
10
|
const events_1 = require("../../systems/events");
|
|
@@ -18,6 +18,7 @@ const triggerArea_1 = require("../../systems/triggerArea");
|
|
|
18
18
|
const timers_1 = require("../helpers/timers");
|
|
19
19
|
Object.defineProperty(exports, "createTimers", { enumerable: true, get: function () { return timers_1.createTimers; } });
|
|
20
20
|
const globals_1 = require("../globals");
|
|
21
|
+
const physics_1 = require("../../systems/physics");
|
|
21
22
|
/**
|
|
22
23
|
* @public
|
|
23
24
|
* The engine is the part of the scene that sits in the middle and manages all of the other parts.
|
|
@@ -80,6 +81,11 @@ exports.timers = (0, timers_1.createTimers)(exports.engine);
|
|
|
80
81
|
(0, globals_1.setGlobalPolyfill)('clearTimeout', exports.timers.clearTimeout);
|
|
81
82
|
(0, globals_1.setGlobalPolyfill)('setInterval', exports.timers.setInterval);
|
|
82
83
|
(0, globals_1.setGlobalPolyfill)('clearInterval', exports.timers.clearInterval);
|
|
84
|
+
/**
|
|
85
|
+
* @public
|
|
86
|
+
* Physics helpers for applying impulses and forces to the player.
|
|
87
|
+
*/
|
|
88
|
+
exports.Physics = (0, physics_1.createPhysicsSystem)(exports.engine);
|
|
83
89
|
/**
|
|
84
90
|
* Adds pointer event collider system only in DEV env
|
|
85
91
|
*/
|
|
@@ -23,4 +23,3 @@ __exportStar(require("./network/deleteComponentNetwork"), exports);
|
|
|
23
23
|
__exportStar(require("./network/deleteEntityNetwork"), exports);
|
|
24
24
|
__exportStar(require("./types"), exports);
|
|
25
25
|
__exportStar(require("./crdtMessageProtocol"), exports);
|
|
26
|
-
__exportStar(require("./authoritativePutComponent"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Entity } from '../../../engine';
|
|
2
|
+
import { ReceiveMessage, TransformType } from '../../../runtime/types';
|
|
3
|
+
import { ReceiveNetworkMessage } from '../../../systems/crdt/types';
|
|
4
|
+
import { ByteBuffer } from '../../ByteBuffer';
|
|
5
|
+
import { INetowrkEntityType } from '../../../components/types';
|
|
6
|
+
export declare function isNetworkMessage(message: ReceiveMessage): message is ReceiveNetworkMessage;
|
|
7
|
+
export declare function networkMessageToLocal(message: ReceiveNetworkMessage, localEntityId: Entity, buffer: ByteBuffer, destinationBuffer: ByteBuffer): void;
|
|
8
|
+
export declare function localMessageToNetwork(message: ReceiveMessage, network: INetowrkEntityType, buffer: ByteBuffer, destinationBuffer: ByteBuffer): void;
|
|
9
|
+
export declare function fixTransformParent(message: ReceiveMessage, transformValue?: TransformType, parent?: Entity): Uint8Array;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixTransformParent = exports.localMessageToNetwork = exports.networkMessageToLocal = exports.isNetworkMessage = void 0;
|
|
4
|
+
const ByteBuffer_1 = require("../../ByteBuffer");
|
|
5
|
+
const putComponent_1 = require("../putComponent");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const deleteComponent_1 = require("../deleteComponent");
|
|
8
|
+
const deleteEntity_1 = require("../deleteEntity");
|
|
9
|
+
const putComponentNetwork_1 = require("./putComponentNetwork");
|
|
10
|
+
const deleteComponentNetwork_1 = require("./deleteComponentNetwork");
|
|
11
|
+
const deleteEntityNetwork_1 = require("./deleteEntityNetwork");
|
|
12
|
+
const Transform_1 = require("../../../components/manual/Transform");
|
|
13
|
+
/* istanbul ignore next */
|
|
14
|
+
function isNetworkMessage(message) {
|
|
15
|
+
return [
|
|
16
|
+
types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK,
|
|
17
|
+
types_1.CrdtMessageType.DELETE_ENTITY_NETWORK,
|
|
18
|
+
types_1.CrdtMessageType.PUT_COMPONENT_NETWORK
|
|
19
|
+
].includes(message.type);
|
|
20
|
+
}
|
|
21
|
+
exports.isNetworkMessage = isNetworkMessage;
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
function networkMessageToLocal(message, localEntityId, buffer, destinationBuffer) {
|
|
24
|
+
const offset = buffer.currentWriteOffset();
|
|
25
|
+
if (message.type === types_1.CrdtMessageType.PUT_COMPONENT_NETWORK) {
|
|
26
|
+
putComponent_1.PutComponentOperation.write(localEntityId, message.timestamp, message.componentId, message.data, buffer);
|
|
27
|
+
}
|
|
28
|
+
else if (message.type === types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK) {
|
|
29
|
+
deleteComponent_1.DeleteComponent.write(localEntityId, message.componentId, message.timestamp, buffer);
|
|
30
|
+
}
|
|
31
|
+
else if (message.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
32
|
+
deleteEntity_1.DeleteEntity.write(localEntityId, buffer);
|
|
33
|
+
}
|
|
34
|
+
destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
|
|
35
|
+
}
|
|
36
|
+
exports.networkMessageToLocal = networkMessageToLocal;
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
function localMessageToNetwork(message, network, buffer, destinationBuffer) {
|
|
39
|
+
const offset = buffer.currentWriteOffset();
|
|
40
|
+
if (message.type === types_1.CrdtMessageType.PUT_COMPONENT) {
|
|
41
|
+
putComponentNetwork_1.PutNetworkComponentOperation.write(network.entityId, message.timestamp, message.componentId, network.networkId, message.data, buffer);
|
|
42
|
+
}
|
|
43
|
+
else if (message.type === types_1.CrdtMessageType.DELETE_COMPONENT) {
|
|
44
|
+
deleteComponentNetwork_1.DeleteComponentNetwork.write(network.entityId, message.componentId, message.timestamp, network.networkId, buffer);
|
|
45
|
+
}
|
|
46
|
+
else if (message.type === types_1.CrdtMessageType.DELETE_ENTITY) {
|
|
47
|
+
deleteEntityNetwork_1.DeleteEntityNetwork.write(network.entityId, network.networkId, buffer);
|
|
48
|
+
}
|
|
49
|
+
destinationBuffer.writeBuffer(buffer.buffer().subarray(offset, buffer.currentWriteOffset()), false);
|
|
50
|
+
}
|
|
51
|
+
exports.localMessageToNetwork = localMessageToNetwork;
|
|
52
|
+
const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
function fixTransformParent(message, transformValue, parent) {
|
|
55
|
+
buffer.resetBuffer();
|
|
56
|
+
let transform = transformValue;
|
|
57
|
+
if (!transform && 'data' in message) {
|
|
58
|
+
transform = Transform_1.TransformSchema.deserialize(new ByteBuffer_1.ReadWriteByteBuffer(message.data));
|
|
59
|
+
}
|
|
60
|
+
if (!transform)
|
|
61
|
+
throw new Error('Invalid parent transform');
|
|
62
|
+
// Generate new transform raw data with the parent
|
|
63
|
+
const newTransform = { ...transform, parent };
|
|
64
|
+
Transform_1.TransformSchema.serialize(newTransform, buffer);
|
|
65
|
+
return buffer.toBinary();
|
|
66
|
+
}
|
|
67
|
+
exports.fixTransformParent = fixTransformParent;
|
|
@@ -11,8 +11,7 @@ export declare enum CrdtMessageType {
|
|
|
11
11
|
PUT_COMPONENT_NETWORK = 5,
|
|
12
12
|
DELETE_COMPONENT_NETWORK = 6,
|
|
13
13
|
DELETE_ENTITY_NETWORK = 7,
|
|
14
|
-
|
|
15
|
-
MAX_MESSAGE_TYPE = 9
|
|
14
|
+
MAX_MESSAGE_TYPE = 8
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* Min length = 8 bytes
|
|
@@ -49,23 +48,6 @@ export type PutNetworkComponentMessageBody = Omit<PutComponentMessageBody, 'type
|
|
|
49
48
|
type: CrdtMessageType.PUT_COMPONENT_NETWORK;
|
|
50
49
|
networkId: number;
|
|
51
50
|
};
|
|
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
|
-
};
|
|
69
51
|
/**
|
|
70
52
|
* Min. length = header (8 bytes) + 16 bytes = 24 bytes
|
|
71
53
|
*
|
|
@@ -132,10 +114,6 @@ export type AppendValueMessage = CrdtMessageHeader & AppendValueMessageBody;
|
|
|
132
114
|
* @public
|
|
133
115
|
*/
|
|
134
116
|
export type PutComponentMessage = CrdtMessageHeader & PutComponentMessageBody;
|
|
135
|
-
/**
|
|
136
|
-
* @public
|
|
137
|
-
*/
|
|
138
|
-
export type AuthoritativePutComponentMessage = CrdtMessageHeader & AuthoritativePutComponentMessageBody;
|
|
139
117
|
/**
|
|
140
118
|
* @public
|
|
141
119
|
*/
|
|
@@ -159,7 +137,7 @@ export type DeleteEntityNetworkMessage = CrdtMessageHeader & DeleteEntityNetwork
|
|
|
159
137
|
/**
|
|
160
138
|
* @public
|
|
161
139
|
*/
|
|
162
|
-
export type CrdtMessage = PutComponentMessage |
|
|
140
|
+
export type CrdtMessage = PutComponentMessage | DeleteComponentMessage | AppendValueMessage | DeleteEntityMessage | PutNetworkComponentMessage | DeleteComponentNetworkMessage | DeleteEntityNetworkMessage;
|
|
163
141
|
/**
|
|
164
142
|
* @public
|
|
165
143
|
*/
|
|
@@ -167,7 +145,7 @@ export type CrdtNetworkMessageBody = PutNetworkComponentMessageBody | DeleteComp
|
|
|
167
145
|
/**
|
|
168
146
|
* @public
|
|
169
147
|
*/
|
|
170
|
-
export type CrdtMessageBody = PutComponentMessageBody |
|
|
148
|
+
export type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody | CrdtNetworkMessageBody;
|
|
171
149
|
export declare enum ProcessMessageResultType {
|
|
172
150
|
/**
|
|
173
151
|
* Typical message and new state set.
|
|
@@ -16,9 +16,7 @@ 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
|
-
|
|
20
|
-
CrdtMessageType[CrdtMessageType["AUTHORITATIVE_PUT_COMPONENT"] = 8] = "AUTHORITATIVE_PUT_COMPONENT";
|
|
21
|
-
CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 9] = "MAX_MESSAGE_TYPE";
|
|
19
|
+
CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 8] = "MAX_MESSAGE_TYPE";
|
|
22
20
|
})(CrdtMessageType = exports.CrdtMessageType || (exports.CrdtMessageType = {}));
|
|
23
21
|
/**
|
|
24
22
|
* @public
|
|
@@ -1,20 +1,50 @@
|
|
|
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.crdtSceneSystem = void 0;
|
|
26
|
+
exports.crdtSceneSystem = exports.LIVEKIT_MAX_SIZE = void 0;
|
|
4
27
|
const entity_1 = require("../../engine/entity");
|
|
5
28
|
const ByteBuffer_1 = require("../../serialization/ByteBuffer");
|
|
6
29
|
const crdt_1 = require("../../serialization/crdt");
|
|
7
30
|
const deleteComponent_1 = require("../../serialization/crdt/deleteComponent");
|
|
8
31
|
const deleteEntity_1 = require("../../serialization/crdt/deleteEntity");
|
|
9
32
|
const putComponent_1 = require("../../serialization/crdt/putComponent");
|
|
10
|
-
const authoritativePutComponent_1 = require("../../serialization/crdt/authoritativePutComponent");
|
|
11
33
|
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;
|
|
12
39
|
/**
|
|
13
40
|
* @internal
|
|
14
41
|
*/
|
|
15
42
|
function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
16
43
|
const transports = [];
|
|
17
|
-
//
|
|
44
|
+
// Components that we used on this system
|
|
45
|
+
const NetworkEntity = (0, components_1.NetworkEntity)(engine);
|
|
46
|
+
const NetworkParent = (0, components_1.NetworkParent)(engine);
|
|
47
|
+
const Transform = (0, components_1.Transform)(engine);
|
|
18
48
|
// Messages that we received at transport.onMessage waiting to be processed
|
|
19
49
|
const receivedMessages = [];
|
|
20
50
|
// Messages already processed by the engine but that we need to broadcast to other transports.
|
|
@@ -39,20 +69,27 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
39
69
|
if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT) {
|
|
40
70
|
message = deleteComponent_1.DeleteComponent.read(buffer);
|
|
41
71
|
}
|
|
72
|
+
else if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK) {
|
|
73
|
+
message = crdt_1.DeleteComponentNetwork.read(buffer);
|
|
74
|
+
}
|
|
42
75
|
else if (header.type === types_1.CrdtMessageType.PUT_COMPONENT) {
|
|
43
76
|
message = putComponent_1.PutComponentOperation.read(buffer);
|
|
44
77
|
}
|
|
45
|
-
else if (header.type === types_1.CrdtMessageType.
|
|
46
|
-
message =
|
|
78
|
+
else if (header.type === types_1.CrdtMessageType.PUT_COMPONENT_NETWORK) {
|
|
79
|
+
message = putComponentNetwork_1.PutNetworkComponentOperation.read(buffer);
|
|
47
80
|
}
|
|
48
81
|
else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY) {
|
|
49
82
|
message = deleteEntity_1.DeleteEntity.read(buffer);
|
|
50
83
|
}
|
|
84
|
+
else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
85
|
+
message = crdt_1.DeleteEntityNetwork.read(buffer);
|
|
86
|
+
}
|
|
51
87
|
else if (header.type === types_1.CrdtMessageType.APPEND_VALUE) {
|
|
52
88
|
message = crdt_1.AppendValueOperation.read(buffer);
|
|
89
|
+
// Unknown message, we skip it
|
|
53
90
|
}
|
|
54
91
|
else {
|
|
55
|
-
//
|
|
92
|
+
// consume the message
|
|
56
93
|
buffer.incrementReadOffset(header.length);
|
|
57
94
|
}
|
|
58
95
|
if (message) {
|
|
@@ -73,6 +110,22 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
73
110
|
const messagesToProcess = value.splice(0, value.length);
|
|
74
111
|
return messagesToProcess;
|
|
75
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Find the local entityId associated to the network component message.
|
|
115
|
+
* It's a mapping Network -> to Local
|
|
116
|
+
* If it's not a network message, return the entityId received by the message
|
|
117
|
+
*/
|
|
118
|
+
function findNetworkId(msg) {
|
|
119
|
+
const hasNetworkId = 'networkId' in msg;
|
|
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 };
|
|
128
|
+
}
|
|
76
129
|
/**
|
|
77
130
|
* This fn will be called on every tick.
|
|
78
131
|
* Process all the messages queue received by the transport
|
|
@@ -81,52 +134,46 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
81
134
|
const messagesToProcess = getMessages(receivedMessages);
|
|
82
135
|
const entitiesShouldBeCleaned = [];
|
|
83
136
|
for (const msg of messagesToProcess) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
137
|
+
let { entityId, network } = findNetworkId(msg);
|
|
138
|
+
// We receive a new Entity. Create the localEntity and map it to the NetworkEntity component
|
|
139
|
+
if (networkUtils.isNetworkMessage(msg) && !network) {
|
|
140
|
+
entityId = engine.addEntity();
|
|
141
|
+
network = { entityId: msg.entityId, networkId: msg.networkId };
|
|
142
|
+
NetworkEntity.createOrReplace(entityId, network);
|
|
143
|
+
}
|
|
144
|
+
if (msg.type === types_1.CrdtMessageType.DELETE_ENTITY || msg.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
145
|
+
entitiesShouldBeCleaned.push(entityId);
|
|
87
146
|
broadcastMessages.push(msg);
|
|
88
147
|
}
|
|
89
148
|
else {
|
|
90
|
-
const entityState = engine.entityContainer.getEntityState(
|
|
91
|
-
// Skip updates from removed
|
|
149
|
+
const entityState = engine.entityContainer.getEntityState(entityId);
|
|
150
|
+
// Skip updates from removed entityes
|
|
92
151
|
if (entityState === entity_1.EntityState.Removed)
|
|
93
152
|
continue;
|
|
94
|
-
// Entities with unknown
|
|
153
|
+
// Entities with unknown entities should update its entity state
|
|
95
154
|
if (entityState === entity_1.EntityState.Unknown) {
|
|
96
|
-
engine.entityContainer.updateUsedEntity(
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
? component.__forceUpdateFromCrdt(msg)
|
|
107
|
-
: component.updateFromCrdt(msg);
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
console.error('[receiveMessages] ERROR processing message', msg, e);
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const result = tryUpdate();
|
|
115
|
-
if (!result)
|
|
116
|
-
continue;
|
|
117
|
-
const [conflictMessage, value] = result;
|
|
118
|
-
if (!conflictMessage) {
|
|
119
|
-
// Add message to broadcast queue when no conflict
|
|
120
|
-
broadcastMessages.push(msg);
|
|
121
|
-
onProcessEntityComponentChange && onProcessEntityComponentChange(msg.entityId, msg.type, component, value);
|
|
122
|
-
}
|
|
155
|
+
engine.entityContainer.updateUsedEntity(entityId);
|
|
156
|
+
}
|
|
157
|
+
const component = engine.getComponentOrNull(msg.componentId);
|
|
158
|
+
/* istanbul ignore else */
|
|
159
|
+
if (component) {
|
|
160
|
+
if (msg.type === types_1.CrdtMessageType.PUT_COMPONENT &&
|
|
161
|
+
component.componentId === Transform.componentId &&
|
|
162
|
+
NetworkEntity.has(entityId) &&
|
|
163
|
+
NetworkParent.has(entityId)) {
|
|
164
|
+
msg.data = networkUtils.fixTransformParent(msg);
|
|
123
165
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
166
|
+
const [conflictMessage, value] = component.updateFromCrdt({ ...msg, entityId });
|
|
167
|
+
if (!conflictMessage) {
|
|
168
|
+
// Add message to transport queue to be processed by others transports
|
|
127
169
|
broadcastMessages.push(msg);
|
|
170
|
+
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, msg.type, component, value);
|
|
128
171
|
}
|
|
129
172
|
}
|
|
173
|
+
else {
|
|
174
|
+
// TODO: test this line, it is fundammental to make the editor work
|
|
175
|
+
broadcastMessages.push(msg);
|
|
176
|
+
}
|
|
130
177
|
}
|
|
131
178
|
}
|
|
132
179
|
// the last stage of the syncrhonization is to delete the entities
|
|
@@ -140,17 +187,16 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
140
187
|
}
|
|
141
188
|
}
|
|
142
189
|
/**
|
|
143
|
-
*
|
|
190
|
+
* Iterates the dirty map and generates crdt messages to be send
|
|
144
191
|
*/
|
|
145
192
|
async function sendMessages(entitiesDeletedThisTick) {
|
|
146
|
-
//
|
|
193
|
+
// CRDT Messages will be the merge between the recieved transport messages and the new crdt messages
|
|
147
194
|
const crdtMessages = getMessages(broadcastMessages);
|
|
148
195
|
const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
|
|
149
|
-
// Generate CRDT messages from component updates
|
|
150
196
|
for (const component of engine.componentsIter()) {
|
|
151
197
|
for (const message of component.getCrdtUpdates()) {
|
|
152
198
|
const offset = buffer.currentWriteOffset();
|
|
153
|
-
//
|
|
199
|
+
// Avoid creating messages if there is no transport that will handle it
|
|
154
200
|
if (transports.some((t) => t.filter(message))) {
|
|
155
201
|
if (message.type === types_1.CrdtMessageType.PUT_COMPONENT) {
|
|
156
202
|
putComponent_1.PutComponentOperation.write(message.entityId, message.timestamp, message.componentId, message.data, buffer);
|
|
@@ -174,7 +220,7 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
174
220
|
}
|
|
175
221
|
}
|
|
176
222
|
}
|
|
177
|
-
//
|
|
223
|
+
// After all updates, I execute the DeletedEntity messages
|
|
178
224
|
for (const entityId of entitiesDeletedThisTick) {
|
|
179
225
|
const offset = buffer.currentWriteOffset();
|
|
180
226
|
deleteEntity_1.DeleteEntity.write(entityId, buffer);
|
|
@@ -185,19 +231,87 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
|
|
|
185
231
|
});
|
|
186
232
|
onProcessEntityComponentChange && onProcessEntityComponentChange(entityId, types_1.CrdtMessageType.DELETE_ENTITY);
|
|
187
233
|
}
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
234
|
+
// Send CRDT messages to transports
|
|
235
|
+
const transportBuffer = new ByteBuffer_1.ReadWriteByteBuffer();
|
|
236
|
+
for (const index in transports) {
|
|
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
|
|
191
246
|
for (const message of crdtMessages) {
|
|
247
|
+
// Check if adding this message would exceed the size limit
|
|
248
|
+
const currentBufferSize = transportBuffer.toBinary().byteLength;
|
|
249
|
+
const messageSize = message.messageBuffer.byteLength;
|
|
250
|
+
if (isNetworkTransport && (currentBufferSize + messageSize) / 1024 > exports.LIVEKIT_MAX_SIZE) {
|
|
251
|
+
// If the current buffer has content, save it as a chunk
|
|
252
|
+
if (currentBufferSize > 0) {
|
|
253
|
+
__NetworkMessagesBuffer.push(transportBuffer.toCopiedBinary());
|
|
254
|
+
transportBuffer.resetBuffer();
|
|
255
|
+
}
|
|
256
|
+
// If the message itself is larger than the limit, we need to handle it specially
|
|
257
|
+
// For now, we'll skip it to prevent infinite loops
|
|
258
|
+
if (messageSize / 1024 > exports.LIVEKIT_MAX_SIZE) {
|
|
259
|
+
console.error(`Message too large (${messageSize} bytes), skipping message for entity ${message.entityId}`);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
192
263
|
// Avoid echo messages
|
|
193
|
-
if (message.transportId ===
|
|
264
|
+
if (message.transportId === transportIndex)
|
|
265
|
+
continue;
|
|
266
|
+
// Redundant message for the transport
|
|
267
|
+
if (!transport.filter(message))
|
|
268
|
+
continue;
|
|
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);
|
|
194
282
|
continue;
|
|
195
|
-
// Check if transport wants this message
|
|
196
|
-
if (transport.filter(message)) {
|
|
197
|
-
transportBuffer.writeBuffer(message.messageBuffer, false);
|
|
198
283
|
}
|
|
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());
|
|
199
312
|
}
|
|
200
|
-
|
|
313
|
+
const message = isNetworkTransport ? __NetworkMessagesBuffer : transportBuffer.toBinary();
|
|
314
|
+
await transport.send(message);
|
|
201
315
|
}
|
|
202
316
|
}
|
|
203
317
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|