@dcl/ecs 7.3.31 → 7.3.32
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 +10 -0
- package/dist/components/index.js +12 -0
- package/dist/components/manual/NetworkEntity.d.ts +12 -0
- package/dist/components/manual/NetworkEntity.js +9 -0
- package/dist/components/manual/NetworkParent.d.ts +12 -0
- package/dist/components/manual/NetworkParent.js +9 -0
- package/dist/components/types.d.ts +2 -0
- package/dist/engine/index.js +8 -21
- package/dist/engine/lww-element-set-component-definition.js +5 -2
- package/dist/engine/types.d.ts +0 -12
- package/dist/index.d.ts +11 -1
- package/dist/index.js +10 -0
- package/dist/runtime/helpers/tree.d.ts +1 -1
- package/dist/runtime/helpers/tree.js +25 -2
- package/dist/serialization/crdt/index.d.ts +3 -0
- package/dist/serialization/crdt/index.js +3 -0
- package/dist/serialization/crdt/message.js +12 -0
- package/dist/serialization/crdt/network/deleteComponentNetwork.d.ts +14 -0
- package/dist/serialization/crdt/network/deleteComponentNetwork.js +43 -0
- package/dist/serialization/crdt/network/deleteEntityNetwork.d.ts +11 -0
- package/dist/serialization/crdt/network/deleteEntityNetwork.js +33 -0
- package/dist/serialization/crdt/network/putComponentNetwork.d.ts +15 -0
- package/dist/serialization/crdt/network/putComponentNetwork.js +49 -0
- package/dist/serialization/crdt/network/utils.d.ts +9 -0
- package/dist/serialization/crdt/network/utils.js +62 -0
- package/dist/serialization/crdt/types.d.ts +48 -3
- package/dist/serialization/crdt/types.js +5 -1
- package/dist/systems/crdt/index.js +111 -69
- package/dist/systems/crdt/types.d.ts +9 -1
- package/dist-cjs/components/index.d.ts +10 -0
- package/dist-cjs/components/index.js +15 -1
- package/dist-cjs/components/manual/NetworkEntity.d.ts +12 -0
- package/dist-cjs/components/manual/NetworkEntity.js +11 -0
- package/dist-cjs/components/manual/NetworkParent.d.ts +12 -0
- package/dist-cjs/components/manual/NetworkParent.js +11 -0
- package/dist-cjs/components/types.d.ts +2 -0
- package/dist-cjs/engine/index.js +8 -21
- package/dist-cjs/engine/lww-element-set-component-definition.js +5 -2
- package/dist-cjs/engine/types.d.ts +0 -12
- package/dist-cjs/index.d.ts +11 -1
- package/dist-cjs/index.js +11 -1
- package/dist-cjs/runtime/helpers/tree.d.ts +1 -1
- package/dist-cjs/runtime/helpers/tree.js +25 -2
- package/dist-cjs/serialization/crdt/index.d.ts +3 -0
- package/dist-cjs/serialization/crdt/index.js +3 -0
- package/dist-cjs/serialization/crdt/message.js +12 -0
- package/dist-cjs/serialization/crdt/network/deleteComponentNetwork.d.ts +14 -0
- package/dist-cjs/serialization/crdt/network/deleteComponentNetwork.js +46 -0
- package/dist-cjs/serialization/crdt/network/deleteEntityNetwork.d.ts +11 -0
- package/dist-cjs/serialization/crdt/network/deleteEntityNetwork.js +36 -0
- package/dist-cjs/serialization/crdt/network/putComponentNetwork.d.ts +15 -0
- package/dist-cjs/serialization/crdt/network/putComponentNetwork.js +52 -0
- package/dist-cjs/serialization/crdt/network/utils.d.ts +9 -0
- package/dist-cjs/serialization/crdt/network/utils.js +69 -0
- package/dist-cjs/serialization/crdt/types.d.ts +48 -3
- package/dist-cjs/serialization/crdt/types.js +5 -1
- package/dist-cjs/systems/crdt/index.js +133 -68
- package/dist-cjs/systems/crdt/types.d.ts +9 -1
- package/package.json +2 -2
package/dist-cjs/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export * from './systems/videoEvents';
|
|
|
10
10
|
export * from './systems/async-task';
|
|
11
11
|
export * from './engine/entity';
|
|
12
12
|
export * from './components/types';
|
|
13
|
-
import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended } from './components/types';
|
|
13
|
+
import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent } from './components/types';
|
|
14
14
|
import { NameComponent } from './components/manual/Name';
|
|
15
15
|
export declare const Transform: TransformComponentExtended;
|
|
16
16
|
export declare const Animator: AnimatorComponentDefinitionExtended;
|
|
@@ -25,6 +25,16 @@ export declare const Tween: TweenComponentDefinitionExtended;
|
|
|
25
25
|
* Can be modified in the future since it's still in research
|
|
26
26
|
*/
|
|
27
27
|
export declare const SyncComponents: ISyncComponents;
|
|
28
|
+
/**
|
|
29
|
+
* @alpha
|
|
30
|
+
* Tag a entity to be syncronized through comms
|
|
31
|
+
*/
|
|
32
|
+
export declare const NetworkEntity: INetowrkEntity;
|
|
33
|
+
/**
|
|
34
|
+
* @alpha
|
|
35
|
+
* Tag a entity to be syncronized through comms
|
|
36
|
+
*/
|
|
37
|
+
export declare const NetworkParent: INetowrkParent;
|
|
28
38
|
export * from './components/generated/global.gen';
|
|
29
39
|
export * from './components/generated/types.gen';
|
|
30
40
|
export * from './serialization/crdt';
|
package/dist-cjs/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.SyncComponents = exports.Tween = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
|
|
29
|
+
exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tween = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
|
|
30
30
|
// The order of the following imports matters. Please do not auto-sort
|
|
31
31
|
__exportStar(require("./engine"), exports);
|
|
32
32
|
__exportStar(require("./schemas"), exports);
|
|
@@ -59,6 +59,16 @@ exports.Tween = components.Tween(initialization_1.engine);
|
|
|
59
59
|
* Can be modified in the future since it's still in research
|
|
60
60
|
*/
|
|
61
61
|
exports.SyncComponents = components.SyncComponents(initialization_1.engine);
|
|
62
|
+
/**
|
|
63
|
+
* @alpha
|
|
64
|
+
* Tag a entity to be syncronized through comms
|
|
65
|
+
*/
|
|
66
|
+
exports.NetworkEntity = components.NetworkEntity(initialization_1.engine);
|
|
67
|
+
/**
|
|
68
|
+
* @alpha
|
|
69
|
+
* Tag a entity to be syncronized through comms
|
|
70
|
+
*/
|
|
71
|
+
exports.NetworkParent = components.NetworkParent(initialization_1.engine);
|
|
62
72
|
// export components for global engine
|
|
63
73
|
__exportStar(require("./components/generated/global.gen"), exports);
|
|
64
74
|
__exportStar(require("./components/generated/types.gen"), exports);
|
|
@@ -29,4 +29,4 @@ export declare function getComponentEntityTree<T>(engine: Pick<IEngine, 'getEnti
|
|
|
29
29
|
* @param firstEntity - the root entity of the tree
|
|
30
30
|
* @public
|
|
31
31
|
*/
|
|
32
|
-
export declare function removeEntityWithChildren(engine: Pick<IEngine, 'getEntitiesWith' | 'defineComponentFromSchema' | 'removeEntity'>, entity: Entity): void;
|
|
32
|
+
export declare function removeEntityWithChildren(engine: Pick<IEngine, 'getEntitiesWith' | 'defineComponentFromSchema' | 'removeEntity' | 'defineComponent'>, entity: Entity): void;
|
|
@@ -62,6 +62,24 @@ function getComponentEntityTree(engine, entity, component) {
|
|
|
62
62
|
return genEntityTree(entity, entities);
|
|
63
63
|
}
|
|
64
64
|
exports.getComponentEntityTree = getComponentEntityTree;
|
|
65
|
+
// I swear by all the gods that this is being tested on test/sdk/network/sync-engines.spec.ts
|
|
66
|
+
/* istanbul ignore next */
|
|
67
|
+
function removeNetworkEntityChildrens(engine, parent) {
|
|
68
|
+
const NetworkParent = components.NetworkParent(engine);
|
|
69
|
+
const NetworkEntity = components.NetworkEntity(engine);
|
|
70
|
+
// Remove parent
|
|
71
|
+
engine.removeEntity(parent);
|
|
72
|
+
// Remove childs
|
|
73
|
+
const network = NetworkEntity.getOrNull(parent);
|
|
74
|
+
if (network) {
|
|
75
|
+
for (const [entity, parent] of engine.getEntitiesWith(NetworkParent)) {
|
|
76
|
+
if (parent.entityId === network.entityId && parent.networkId === network.networkId) {
|
|
77
|
+
removeNetworkEntityChildrens(engine, entity);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
65
83
|
/**
|
|
66
84
|
* Remove all components of each entity in the tree made with Transform parenting
|
|
67
85
|
* @param engine - the engine running the entities
|
|
@@ -70,8 +88,13 @@ exports.getComponentEntityTree = getComponentEntityTree;
|
|
|
70
88
|
*/
|
|
71
89
|
function removeEntityWithChildren(engine, entity) {
|
|
72
90
|
const Transform = components.Transform(engine);
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
const NetworkEntity = components.NetworkEntity(engine);
|
|
92
|
+
/* istanbul ignore if */
|
|
93
|
+
if (NetworkEntity.has(entity)) {
|
|
94
|
+
return removeNetworkEntityChildrens(engine, entity);
|
|
95
|
+
}
|
|
96
|
+
for (const ent of getComponentEntityTree(engine, entity, Transform)) {
|
|
97
|
+
engine.removeEntity(ent);
|
|
75
98
|
}
|
|
76
99
|
}
|
|
77
100
|
exports.removeEntityWithChildren = removeEntityWithChildren;
|
|
@@ -2,5 +2,8 @@ export * from './deleteComponent';
|
|
|
2
2
|
export * from './appendValue';
|
|
3
3
|
export * from './deleteEntity';
|
|
4
4
|
export * from './putComponent';
|
|
5
|
+
export * from './network/putComponentNetwork';
|
|
6
|
+
export * from './network/deleteComponentNetwork';
|
|
7
|
+
export * from './network/deleteEntityNetwork';
|
|
5
8
|
export * from './types';
|
|
6
9
|
export * from './crdtMessageProtocol';
|
|
@@ -18,5 +18,8 @@ __exportStar(require("./deleteComponent"), exports);
|
|
|
18
18
|
__exportStar(require("./appendValue"), exports);
|
|
19
19
|
__exportStar(require("./deleteEntity"), exports);
|
|
20
20
|
__exportStar(require("./putComponent"), exports);
|
|
21
|
+
__exportStar(require("./network/putComponentNetwork"), exports);
|
|
22
|
+
__exportStar(require("./network/deleteComponentNetwork"), exports);
|
|
23
|
+
__exportStar(require("./network/deleteEntityNetwork"), exports);
|
|
21
24
|
__exportStar(require("./types"), exports);
|
|
22
25
|
__exportStar(require("./crdtMessageProtocol"), exports);
|
|
@@ -7,6 +7,9 @@ const putComponent_1 = require("./putComponent");
|
|
|
7
7
|
const deleteComponent_1 = require("./deleteComponent");
|
|
8
8
|
const deleteEntity_1 = require("./deleteEntity");
|
|
9
9
|
const appendValue_1 = require("./appendValue");
|
|
10
|
+
const putComponentNetwork_1 = require("./network/putComponentNetwork");
|
|
11
|
+
const deleteComponentNetwork_1 = require("./network/deleteComponentNetwork");
|
|
12
|
+
const deleteEntityNetwork_1 = require("./network/deleteEntityNetwork");
|
|
10
13
|
function readMessage(buf) {
|
|
11
14
|
const header = crdtMessageProtocol_1.CrdtMessageProtocol.getHeader(buf);
|
|
12
15
|
if (!header)
|
|
@@ -14,15 +17,24 @@ function readMessage(buf) {
|
|
|
14
17
|
if (header.type === types_1.CrdtMessageType.PUT_COMPONENT) {
|
|
15
18
|
return putComponent_1.PutComponentOperation.read(buf);
|
|
16
19
|
}
|
|
20
|
+
else if (header.type === types_1.CrdtMessageType.PUT_COMPONENT_NETWORK) {
|
|
21
|
+
return putComponentNetwork_1.PutNetworkComponentOperation.read(buf);
|
|
22
|
+
}
|
|
17
23
|
else if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT) {
|
|
18
24
|
return deleteComponent_1.DeleteComponent.read(buf);
|
|
19
25
|
}
|
|
26
|
+
else if (header.type === types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK) {
|
|
27
|
+
return deleteComponentNetwork_1.DeleteComponentNetwork.read(buf);
|
|
28
|
+
}
|
|
20
29
|
else if (header.type === types_1.CrdtMessageType.APPEND_VALUE) {
|
|
21
30
|
return appendValue_1.AppendValueOperation.read(buf);
|
|
22
31
|
}
|
|
23
32
|
else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY) {
|
|
24
33
|
return deleteEntity_1.DeleteEntity.read(buf);
|
|
25
34
|
}
|
|
35
|
+
else if (header.type === types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
36
|
+
return deleteEntityNetwork_1.DeleteEntityNetwork.read(buf);
|
|
37
|
+
}
|
|
26
38
|
return null;
|
|
27
39
|
}
|
|
28
40
|
exports.readMessage = readMessage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Entity } from '../../../engine/entity';
|
|
2
|
+
import { ByteBuffer } from '../../ByteBuffer';
|
|
3
|
+
import { DeleteComponentNetworkMessage } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace DeleteComponentNetwork {
|
|
8
|
+
const MESSAGE_HEADER_LENGTH = 16;
|
|
9
|
+
/**
|
|
10
|
+
* Write DeleteComponent message
|
|
11
|
+
*/
|
|
12
|
+
function write(entity: Entity, componentId: number, timestamp: number, networkId: number, buf: ByteBuffer): void;
|
|
13
|
+
function read(buf: ByteBuffer): DeleteComponentNetworkMessage | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteComponentNetwork = void 0;
|
|
4
|
+
const crdtMessageProtocol_1 = require("../crdtMessageProtocol");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
var DeleteComponentNetwork;
|
|
10
|
+
(function (DeleteComponentNetwork) {
|
|
11
|
+
DeleteComponentNetwork.MESSAGE_HEADER_LENGTH = 16;
|
|
12
|
+
/**
|
|
13
|
+
* Write DeleteComponent message
|
|
14
|
+
*/
|
|
15
|
+
function write(entity, componentId, timestamp, networkId, buf) {
|
|
16
|
+
// reserve the beginning
|
|
17
|
+
const messageLength = types_1.CRDT_MESSAGE_HEADER_LENGTH + DeleteComponentNetwork.MESSAGE_HEADER_LENGTH;
|
|
18
|
+
const startMessageOffset = buf.incrementWriteOffset(messageLength);
|
|
19
|
+
// Write CrdtMessage header
|
|
20
|
+
buf.setUint32(startMessageOffset, messageLength);
|
|
21
|
+
buf.setUint32(startMessageOffset + 4, types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK);
|
|
22
|
+
// Write ComponentOperation header
|
|
23
|
+
buf.setUint32(startMessageOffset + 8, entity);
|
|
24
|
+
buf.setUint32(startMessageOffset + 12, componentId);
|
|
25
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
26
|
+
buf.setUint32(startMessageOffset + 20, networkId);
|
|
27
|
+
}
|
|
28
|
+
DeleteComponentNetwork.write = write;
|
|
29
|
+
function read(buf) {
|
|
30
|
+
const header = crdtMessageProtocol_1.CrdtMessageProtocol.readHeader(buf);
|
|
31
|
+
if (!header) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (header.type !== types_1.CrdtMessageType.DELETE_COMPONENT_NETWORK) {
|
|
35
|
+
throw new Error('DeleteComponentOperation tried to read another message type.');
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
...header,
|
|
39
|
+
entityId: buf.readUint32(),
|
|
40
|
+
componentId: buf.readUint32(),
|
|
41
|
+
timestamp: buf.readUint32(),
|
|
42
|
+
networkId: buf.readUint32()
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
DeleteComponentNetwork.read = read;
|
|
46
|
+
})(DeleteComponentNetwork = exports.DeleteComponentNetwork || (exports.DeleteComponentNetwork = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Entity } from '../../../engine/entity';
|
|
2
|
+
import { ByteBuffer } from '../../ByteBuffer';
|
|
3
|
+
import { DeleteEntityNetworkMessage } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace DeleteEntityNetwork {
|
|
8
|
+
const MESSAGE_HEADER_LENGTH = 8;
|
|
9
|
+
function write(entity: Entity, networkId: number, buf: ByteBuffer): void;
|
|
10
|
+
function read(buf: ByteBuffer): DeleteEntityNetworkMessage | null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteEntityNetwork = void 0;
|
|
4
|
+
const crdtMessageProtocol_1 = require("../crdtMessageProtocol");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
var DeleteEntityNetwork;
|
|
10
|
+
(function (DeleteEntityNetwork) {
|
|
11
|
+
DeleteEntityNetwork.MESSAGE_HEADER_LENGTH = 8;
|
|
12
|
+
function write(entity, networkId, buf) {
|
|
13
|
+
// Write CrdtMessage header
|
|
14
|
+
buf.writeUint32(types_1.CRDT_MESSAGE_HEADER_LENGTH + 4);
|
|
15
|
+
buf.writeUint32(types_1.CrdtMessageType.DELETE_ENTITY_NETWORK);
|
|
16
|
+
// body
|
|
17
|
+
buf.writeUint32(entity);
|
|
18
|
+
buf.writeUint32(networkId);
|
|
19
|
+
}
|
|
20
|
+
DeleteEntityNetwork.write = write;
|
|
21
|
+
function read(buf) {
|
|
22
|
+
const header = crdtMessageProtocol_1.CrdtMessageProtocol.readHeader(buf);
|
|
23
|
+
if (!header) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (header.type !== types_1.CrdtMessageType.DELETE_ENTITY_NETWORK) {
|
|
27
|
+
throw new Error('DeleteEntityNetwork tried to read another message type.');
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...header,
|
|
31
|
+
entityId: buf.readUint32(),
|
|
32
|
+
networkId: buf.readUint32()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
DeleteEntityNetwork.read = read;
|
|
36
|
+
})(DeleteEntityNetwork = exports.DeleteEntityNetwork || (exports.DeleteEntityNetwork = {}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Entity } from '../../../engine/entity';
|
|
2
|
+
import { ByteBuffer } from '../../ByteBuffer';
|
|
3
|
+
import { PutNetworkComponentMessage } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace PutNetworkComponentOperation {
|
|
8
|
+
const MESSAGE_HEADER_LENGTH = 20;
|
|
9
|
+
/**
|
|
10
|
+
* Call this function for an optimal writing data passing the ByteBuffer
|
|
11
|
+
* already allocated
|
|
12
|
+
*/
|
|
13
|
+
function write(entity: Entity, timestamp: number, componentId: number, networkId: number, data: Uint8Array, buf: ByteBuffer): void;
|
|
14
|
+
function read(buf: ByteBuffer): PutNetworkComponentMessage | null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PutNetworkComponentOperation = void 0;
|
|
4
|
+
const crdtMessageProtocol_1 = require("../crdtMessageProtocol");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
var PutNetworkComponentOperation;
|
|
10
|
+
(function (PutNetworkComponentOperation) {
|
|
11
|
+
PutNetworkComponentOperation.MESSAGE_HEADER_LENGTH = 20;
|
|
12
|
+
/**
|
|
13
|
+
* Call this function for an optimal writing data passing the ByteBuffer
|
|
14
|
+
* already allocated
|
|
15
|
+
*/
|
|
16
|
+
function write(entity, timestamp, componentId, networkId, data, buf) {
|
|
17
|
+
// reserve the beginning
|
|
18
|
+
const startMessageOffset = buf.incrementWriteOffset(types_1.CRDT_MESSAGE_HEADER_LENGTH + PutNetworkComponentOperation.MESSAGE_HEADER_LENGTH);
|
|
19
|
+
// write body
|
|
20
|
+
buf.writeBuffer(data, false);
|
|
21
|
+
const messageLength = buf.currentWriteOffset() - startMessageOffset;
|
|
22
|
+
// Write CrdtMessage header
|
|
23
|
+
buf.setUint32(startMessageOffset, messageLength);
|
|
24
|
+
buf.setUint32(startMessageOffset + 4, types_1.CrdtMessageType.PUT_COMPONENT_NETWORK);
|
|
25
|
+
// Write ComponentOperation header
|
|
26
|
+
buf.setUint32(startMessageOffset + 8, entity);
|
|
27
|
+
buf.setUint32(startMessageOffset + 12, componentId);
|
|
28
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
29
|
+
buf.setUint32(startMessageOffset + 20, networkId);
|
|
30
|
+
const dataLength = messageLength - PutNetworkComponentOperation.MESSAGE_HEADER_LENGTH - types_1.CRDT_MESSAGE_HEADER_LENGTH;
|
|
31
|
+
buf.setUint32(startMessageOffset + 24, dataLength);
|
|
32
|
+
}
|
|
33
|
+
PutNetworkComponentOperation.write = write;
|
|
34
|
+
function read(buf) {
|
|
35
|
+
const header = crdtMessageProtocol_1.CrdtMessageProtocol.readHeader(buf);
|
|
36
|
+
if (!header) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (header.type !== types_1.CrdtMessageType.PUT_COMPONENT_NETWORK) {
|
|
40
|
+
throw new Error('PutComponentNetworkOperation tried to read another message type.');
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...header,
|
|
44
|
+
entityId: buf.readUint32(),
|
|
45
|
+
componentId: buf.readUint32(),
|
|
46
|
+
timestamp: buf.readUint32(),
|
|
47
|
+
networkId: buf.readUint32(),
|
|
48
|
+
data: buf.readBuffer()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
PutNetworkComponentOperation.read = read;
|
|
52
|
+
})(PutNetworkComponentOperation = exports.PutNetworkComponentOperation || (exports.PutNetworkComponentOperation = {}));
|
|
@@ -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,69 @@
|
|
|
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
|
+
/* istanbul ignore next */
|
|
53
|
+
function fixTransformParent(message, transformValue, parent) {
|
|
54
|
+
let transform = transformValue;
|
|
55
|
+
const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
|
|
56
|
+
if (!transform && 'data' in message) {
|
|
57
|
+
buffer.writeBuffer(message.data);
|
|
58
|
+
transform = Transform_1.TransformSchema.deserialize(buffer);
|
|
59
|
+
buffer.resetBuffer();
|
|
60
|
+
}
|
|
61
|
+
if (!transform)
|
|
62
|
+
throw new Error('Invalid parent transform');
|
|
63
|
+
// Generate new transform raw data with the parent
|
|
64
|
+
const newTransform = { ...transform, parent };
|
|
65
|
+
buffer.resetBuffer();
|
|
66
|
+
Transform_1.TransformSchema.serialize(newTransform, buffer);
|
|
67
|
+
return buffer.toBinary();
|
|
68
|
+
}
|
|
69
|
+
exports.fixTransformParent = fixTransformParent;
|
|
@@ -8,7 +8,10 @@ export declare enum CrdtMessageType {
|
|
|
8
8
|
DELETE_COMPONENT = 2,
|
|
9
9
|
DELETE_ENTITY = 3,
|
|
10
10
|
APPEND_VALUE = 4,
|
|
11
|
-
|
|
11
|
+
PUT_COMPONENT_NETWORK = 5,
|
|
12
|
+
DELETE_COMPONENT_NETWORK = 6,
|
|
13
|
+
DELETE_ENTITY_NETWORK = 7,
|
|
14
|
+
MAX_MESSAGE_TYPE = 8
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
17
|
* Min length = 8 bytes
|
|
@@ -41,6 +44,10 @@ export type PutComponentMessageBody = {
|
|
|
41
44
|
timestamp: number;
|
|
42
45
|
data: Uint8Array;
|
|
43
46
|
};
|
|
47
|
+
export type PutNetworkComponentMessageBody = Omit<PutComponentMessageBody, 'type'> & {
|
|
48
|
+
type: CrdtMessageType.PUT_COMPONENT_NETWORK;
|
|
49
|
+
networkId: number;
|
|
50
|
+
};
|
|
44
51
|
/**
|
|
45
52
|
* Min. length = header (8 bytes) + 16 bytes = 24 bytes
|
|
46
53
|
*
|
|
@@ -69,6 +76,20 @@ export type DeleteComponentMessageBody = {
|
|
|
69
76
|
componentId: number;
|
|
70
77
|
timestamp: number;
|
|
71
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* @param entity - Uint32 number of the entity
|
|
81
|
+
* @param componentId - Uint32 number of id
|
|
82
|
+
* @param timestamp - Uint32 Lamport timestamp
|
|
83
|
+
* @param networkId - Uint32 user network id
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export type DeleteComponentNetworkMessageBody = {
|
|
87
|
+
type: CrdtMessageType.DELETE_COMPONENT_NETWORK;
|
|
88
|
+
entityId: Entity;
|
|
89
|
+
componentId: number;
|
|
90
|
+
timestamp: number;
|
|
91
|
+
networkId: number;
|
|
92
|
+
};
|
|
72
93
|
/**
|
|
73
94
|
* @param entity - uint32 number of the entity
|
|
74
95
|
* @public
|
|
@@ -77,6 +98,14 @@ export type DeleteEntityMessageBody = {
|
|
|
77
98
|
type: CrdtMessageType.DELETE_ENTITY;
|
|
78
99
|
entityId: Entity;
|
|
79
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
export type DeleteEntityNetworkMessageBody = {
|
|
105
|
+
type: CrdtMessageType.DELETE_ENTITY_NETWORK;
|
|
106
|
+
entityId: Entity;
|
|
107
|
+
networkId: number;
|
|
108
|
+
};
|
|
80
109
|
/**
|
|
81
110
|
* @public
|
|
82
111
|
*/
|
|
@@ -85,10 +114,18 @@ export type AppendValueMessage = CrdtMessageHeader & AppendValueMessageBody;
|
|
|
85
114
|
* @public
|
|
86
115
|
*/
|
|
87
116
|
export type PutComponentMessage = CrdtMessageHeader & PutComponentMessageBody;
|
|
117
|
+
/**
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
export type PutNetworkComponentMessage = CrdtMessageHeader & PutNetworkComponentMessageBody;
|
|
88
121
|
/**
|
|
89
122
|
* @public
|
|
90
123
|
*/
|
|
91
124
|
export type DeleteComponentMessage = CrdtMessageHeader & DeleteComponentMessageBody;
|
|
125
|
+
/**
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export type DeleteComponentNetworkMessage = CrdtMessageHeader & DeleteComponentNetworkMessageBody;
|
|
92
129
|
/**
|
|
93
130
|
* @public
|
|
94
131
|
*/
|
|
@@ -96,11 +133,19 @@ export type DeleteEntityMessage = CrdtMessageHeader & DeleteEntityMessageBody;
|
|
|
96
133
|
/**
|
|
97
134
|
* @public
|
|
98
135
|
*/
|
|
99
|
-
export type
|
|
136
|
+
export type DeleteEntityNetworkMessage = CrdtMessageHeader & DeleteEntityNetworkMessageBody;
|
|
137
|
+
/**
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
export type CrdtMessage = PutComponentMessage | DeleteComponentMessage | AppendValueMessage | DeleteEntityMessage | PutNetworkComponentMessage | DeleteComponentNetworkMessage | DeleteEntityNetworkMessage;
|
|
141
|
+
/**
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
export type CrdtNetworkMessageBody = PutNetworkComponentMessageBody | DeleteComponentNetworkMessageBody | DeleteEntityNetworkMessageBody;
|
|
100
145
|
/**
|
|
101
146
|
* @public
|
|
102
147
|
*/
|
|
103
|
-
export type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody;
|
|
148
|
+
export type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody | CrdtNetworkMessageBody;
|
|
104
149
|
export declare enum ProcessMessageResultType {
|
|
105
150
|
/**
|
|
106
151
|
* Typical message and new state set.
|
|
@@ -12,7 +12,11 @@ var CrdtMessageType;
|
|
|
12
12
|
CrdtMessageType[CrdtMessageType["DELETE_COMPONENT"] = 2] = "DELETE_COMPONENT";
|
|
13
13
|
CrdtMessageType[CrdtMessageType["DELETE_ENTITY"] = 3] = "DELETE_ENTITY";
|
|
14
14
|
CrdtMessageType[CrdtMessageType["APPEND_VALUE"] = 4] = "APPEND_VALUE";
|
|
15
|
-
|
|
15
|
+
// Network operations
|
|
16
|
+
CrdtMessageType[CrdtMessageType["PUT_COMPONENT_NETWORK"] = 5] = "PUT_COMPONENT_NETWORK";
|
|
17
|
+
CrdtMessageType[CrdtMessageType["DELETE_COMPONENT_NETWORK"] = 6] = "DELETE_COMPONENT_NETWORK";
|
|
18
|
+
CrdtMessageType[CrdtMessageType["DELETE_ENTITY_NETWORK"] = 7] = "DELETE_ENTITY_NETWORK";
|
|
19
|
+
CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 8] = "MAX_MESSAGE_TYPE";
|
|
16
20
|
})(CrdtMessageType = exports.CrdtMessageType || (exports.CrdtMessageType = {}));
|
|
17
21
|
/**
|
|
18
22
|
* @public
|