@dcl/ecs 7.0.6-4087883663.commit-054d424 → 7.0.6-4106696113.commit-cda3cfd
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/engine/input.js +21 -23
- package/dist/serialization/crdt/crdtMessageProtocol.d.ts +1 -0
- package/dist/serialization/crdt/crdtMessageProtocol.js +68 -0
- package/dist/serialization/crdt/deleteComponent.js +4 -10
- package/dist/serialization/crdt/deleteEntity.js +2 -2
- package/dist/serialization/crdt/index.d.ts +3 -2
- package/dist/serialization/crdt/index.js +3 -70
- package/dist/serialization/crdt/message.js +4 -1
- package/dist/serialization/crdt/putComponent.js +5 -5
- package/dist/serialization/crdt/types.d.ts +7 -4
- package/package.json +3 -3
package/dist/engine/input.js
CHANGED
|
@@ -43,12 +43,29 @@ export function createInputSystem(engine) {
|
|
|
43
43
|
InternalInputStateComponent.getMutable(engine.RootEntity).timestampLastUpdate = state.currentTimestamp;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
function* commandIterator() {
|
|
47
|
+
for (const [, value] of engine.getEntitiesWith(PointerEventsResult)) {
|
|
48
|
+
yield* value.commands;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function findLastAction(pointerEventType, inputAction, entity) {
|
|
52
|
+
let commandToReturn = undefined;
|
|
53
|
+
for (const command of commandIterator()) {
|
|
54
|
+
if (command.button === inputAction &&
|
|
55
|
+
command.state === pointerEventType &&
|
|
56
|
+
(!entity || (command.hit && entity === command.hit.entityId))) {
|
|
57
|
+
if (!commandToReturn || command.timestamp >= commandToReturn.timestamp)
|
|
58
|
+
commandToReturn = command;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return commandToReturn;
|
|
62
|
+
}
|
|
46
63
|
function buttonStateUpdateSystem() {
|
|
47
64
|
const component = PointerEventsResult.getOrNull(engine.RootEntity);
|
|
48
65
|
if (!component)
|
|
49
66
|
return;
|
|
50
67
|
const state = InternalInputStateComponent.getMutable(engine.RootEntity);
|
|
51
|
-
for (const command of
|
|
68
|
+
for (const command of commandIterator()) {
|
|
52
69
|
if (command.timestamp > state.buttonState[command.button].ts) {
|
|
53
70
|
if (command.state === 1 /* PointerEventType.PET_DOWN */) {
|
|
54
71
|
state.buttonState[command.button].value = true;
|
|
@@ -73,16 +90,12 @@ export function createInputSystem(engine) {
|
|
|
73
90
|
return null;
|
|
74
91
|
}
|
|
75
92
|
function findClick(inputAction, entity) {
|
|
76
|
-
const component = PointerEventsResult.getOrNull(engine.RootEntity);
|
|
77
|
-
if (!component)
|
|
78
|
-
return null;
|
|
79
|
-
const commands = component.commands;
|
|
80
93
|
// We search the last DOWN command sorted by timestamp
|
|
81
|
-
const down = findLastAction(
|
|
94
|
+
const down = findLastAction(1 /* PointerEventType.PET_DOWN */, inputAction, entity);
|
|
82
95
|
// We search the last UP command sorted by timestamp
|
|
83
96
|
if (!down)
|
|
84
97
|
return null;
|
|
85
|
-
const up = findLastAction(
|
|
98
|
+
const up = findLastAction(0 /* PointerEventType.PET_UP */, inputAction, entity);
|
|
86
99
|
if (!up)
|
|
87
100
|
return null;
|
|
88
101
|
const state = InternalInputStateComponent.get(engine.RootEntity);
|
|
@@ -105,11 +118,8 @@ export function createInputSystem(engine) {
|
|
|
105
118
|
return null;
|
|
106
119
|
}
|
|
107
120
|
function findInputCommand(inputAction, pointerEventType, entity) {
|
|
108
|
-
const component = PointerEventsResult.getOrNull(engine.RootEntity);
|
|
109
|
-
if (!component)
|
|
110
|
-
return null;
|
|
111
121
|
// We search the last pointer Event command sorted by timestamp
|
|
112
|
-
const command = findLastAction(
|
|
122
|
+
const command = findLastAction(pointerEventType, inputAction, entity);
|
|
113
123
|
if (!command)
|
|
114
124
|
return null;
|
|
115
125
|
const state = InternalInputStateComponent.get(engine.RootEntity);
|
|
@@ -143,15 +153,3 @@ export function createInputSystem(engine) {
|
|
|
143
153
|
isTriggered
|
|
144
154
|
};
|
|
145
155
|
}
|
|
146
|
-
function findLastAction(commands, pointerEventType, inputAction, entity) {
|
|
147
|
-
let commandToReturn = undefined;
|
|
148
|
-
for (const command of commands) {
|
|
149
|
-
if (command.button === inputAction &&
|
|
150
|
-
command.state === pointerEventType &&
|
|
151
|
-
(!entity || (command.hit && entity === command.hit.entityId))) {
|
|
152
|
-
if (!commandToReturn || command.timestamp >= commandToReturn.timestamp)
|
|
153
|
-
commandToReturn = command;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return commandToReturn;
|
|
157
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export var CrdtMessageProtocol;
|
|
6
|
+
(function (CrdtMessageProtocol) {
|
|
7
|
+
/**
|
|
8
|
+
* Validate if the message incoming is completed
|
|
9
|
+
* @param buf - ByteBuffer
|
|
10
|
+
*/
|
|
11
|
+
function validate(buf) {
|
|
12
|
+
const rem = buf.remainingBytes();
|
|
13
|
+
if (rem < CRDT_MESSAGE_HEADER_LENGTH) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const messageLength = buf.getUint32(buf.currentReadOffset());
|
|
17
|
+
if (rem < messageLength) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
CrdtMessageProtocol.validate = validate;
|
|
23
|
+
/**
|
|
24
|
+
* Get the current header, consuming the bytes involved.
|
|
25
|
+
* @param buf - ByteBuffer
|
|
26
|
+
* @returns header or null if there is no validated message
|
|
27
|
+
*/
|
|
28
|
+
function readHeader(buf) {
|
|
29
|
+
if (!validate(buf)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
length: buf.readUint32(),
|
|
34
|
+
type: buf.readUint32()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
CrdtMessageProtocol.readHeader = readHeader;
|
|
38
|
+
/**
|
|
39
|
+
* Get the current header, without consuming the bytes involved.
|
|
40
|
+
* @param buf - ByteBuffer
|
|
41
|
+
* @returns header or null if there is no validated message
|
|
42
|
+
*/
|
|
43
|
+
function getHeader(buf) {
|
|
44
|
+
if (!validate(buf)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const currentOffset = buf.currentReadOffset();
|
|
48
|
+
return {
|
|
49
|
+
length: buf.getUint32(currentOffset),
|
|
50
|
+
type: buf.getUint32(currentOffset + 4)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
CrdtMessageProtocol.getHeader = getHeader;
|
|
54
|
+
/**
|
|
55
|
+
* Consume the incoming message without processing it.
|
|
56
|
+
* @param buf - ByteBuffer
|
|
57
|
+
* @returns true in case of success or false if there is no valid message.
|
|
58
|
+
*/
|
|
59
|
+
function consumeMessage(buf) {
|
|
60
|
+
const header = getHeader(buf);
|
|
61
|
+
if (!header) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
buf.incrementReadOffset(header.length);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
CrdtMessageProtocol.consumeMessage = consumeMessage;
|
|
68
|
+
})(CrdtMessageProtocol || (CrdtMessageProtocol = {}));
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { CrdtMessageProtocol } from '
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export var DeleteComponent;
|
|
7
7
|
(function (DeleteComponent) {
|
|
8
|
-
|
|
9
|
-
DeleteComponent.MESSAGE_HEADER_LENGTH = 20;
|
|
8
|
+
DeleteComponent.MESSAGE_HEADER_LENGTH = 12;
|
|
10
9
|
/**
|
|
11
10
|
* Write DeleteComponent message
|
|
12
11
|
*/
|
|
@@ -20,10 +19,7 @@ export var DeleteComponent;
|
|
|
20
19
|
// Write ComponentOperation header
|
|
21
20
|
buf.setUint32(startMessageOffset + 8, entity);
|
|
22
21
|
buf.setUint32(startMessageOffset + 12, componentId);
|
|
23
|
-
|
|
24
|
-
buf.setUint64(startMessageOffset + 16, BigInt(timestamp));
|
|
25
|
-
// TODO: remove buffer length (-4 bytes)
|
|
26
|
-
buf.setUint32(startMessageOffset + 24, 0);
|
|
22
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
27
23
|
}
|
|
28
24
|
DeleteComponent.write = write;
|
|
29
25
|
function read(buf) {
|
|
@@ -38,10 +34,8 @@ export var DeleteComponent;
|
|
|
38
34
|
...header,
|
|
39
35
|
entityId: buf.readUint32(),
|
|
40
36
|
componentId: buf.readUint32(),
|
|
41
|
-
timestamp:
|
|
37
|
+
timestamp: buf.readUint32()
|
|
42
38
|
};
|
|
43
|
-
// TODO: remove buffer length
|
|
44
|
-
buf.incrementReadOffset(4);
|
|
45
39
|
return msg;
|
|
46
40
|
}
|
|
47
41
|
DeleteComponent.read = read;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CrdtMessageProtocol } from '
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
@@ -20,7 +20,7 @@ export var DeleteEntity;
|
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
22
|
if (header.type !== CrdtMessageType.DELETE_ENTITY) {
|
|
23
|
-
throw new Error('
|
|
23
|
+
throw new Error('DeleteEntity tried to read another message type.');
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
26
|
...header,
|
|
@@ -1,72 +1,5 @@
|
|
|
1
|
-
import { CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
2
|
-
export * from './types';
|
|
3
1
|
export * from './deleteComponent';
|
|
4
|
-
export * from './putComponent';
|
|
5
2
|
export * from './deleteEntity';
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
export var CrdtMessageProtocol;
|
|
10
|
-
(function (CrdtMessageProtocol) {
|
|
11
|
-
/**
|
|
12
|
-
* Validate if the message incoming is completed
|
|
13
|
-
* @param buf - ByteBuffer
|
|
14
|
-
*/
|
|
15
|
-
function validate(buf) {
|
|
16
|
-
const rem = buf.remainingBytes();
|
|
17
|
-
if (rem < CRDT_MESSAGE_HEADER_LENGTH) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const messageLength = buf.getUint32(buf.currentReadOffset());
|
|
21
|
-
if (rem < messageLength) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
CrdtMessageProtocol.validate = validate;
|
|
27
|
-
/**
|
|
28
|
-
* Get the current header, consuming the bytes involved.
|
|
29
|
-
* @param buf - ByteBuffer
|
|
30
|
-
* @returns header or null if there is no validated message
|
|
31
|
-
*/
|
|
32
|
-
function readHeader(buf) {
|
|
33
|
-
if (!validate(buf)) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
length: buf.readUint32(),
|
|
38
|
-
type: buf.readUint32()
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
CrdtMessageProtocol.readHeader = readHeader;
|
|
42
|
-
/**
|
|
43
|
-
* Get the current header, without consuming the bytes involved.
|
|
44
|
-
* @param buf - ByteBuffer
|
|
45
|
-
* @returns header or null if there is no validated message
|
|
46
|
-
*/
|
|
47
|
-
function getHeader(buf) {
|
|
48
|
-
if (!validate(buf)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
const currentOffset = buf.currentReadOffset();
|
|
52
|
-
return {
|
|
53
|
-
length: buf.getUint32(currentOffset),
|
|
54
|
-
type: buf.getUint32(currentOffset + 4)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
CrdtMessageProtocol.getHeader = getHeader;
|
|
58
|
-
/**
|
|
59
|
-
* Consume the incoming message without processing it.
|
|
60
|
-
* @param buf - ByteBuffer
|
|
61
|
-
* @returns true in case of success or false if there is no valid message.
|
|
62
|
-
*/
|
|
63
|
-
function consumeMessage(buf) {
|
|
64
|
-
const header = getHeader(buf);
|
|
65
|
-
if (!header) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
buf.incrementReadOffset(header.length);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
CrdtMessageProtocol.consumeMessage = consumeMessage;
|
|
72
|
-
})(CrdtMessageProtocol || (CrdtMessageProtocol = {}));
|
|
3
|
+
export * from './putComponent';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './crdtMessageProtocol';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { CrdtMessageProtocol
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType } from './types';
|
|
3
|
+
import { PutComponentOperation } from './putComponent';
|
|
4
|
+
import { DeleteComponent } from './deleteComponent';
|
|
5
|
+
import { DeleteEntity } from './deleteEntity';
|
|
3
6
|
export function readMessage(buf) {
|
|
4
7
|
const header = CrdtMessageProtocol.getHeader(buf);
|
|
5
8
|
if (!header)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CrdtMessageProtocol } from '
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export var PutComponentOperation;
|
|
7
7
|
(function (PutComponentOperation) {
|
|
8
|
-
PutComponentOperation.MESSAGE_HEADER_LENGTH =
|
|
8
|
+
PutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
|
|
9
9
|
/**
|
|
10
10
|
* Call this function for an optimal writing data passing the ByteBuffer
|
|
11
11
|
* already allocated
|
|
@@ -22,9 +22,9 @@ export var PutComponentOperation;
|
|
|
22
22
|
// Write ComponentOperation header
|
|
23
23
|
buf.setUint32(startMessageOffset + 8, entity);
|
|
24
24
|
buf.setUint32(startMessageOffset + 12, componentDefinition.componentId);
|
|
25
|
-
buf.
|
|
25
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
26
26
|
const newLocal = messageLength - PutComponentOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
|
|
27
|
-
buf.setUint32(startMessageOffset +
|
|
27
|
+
buf.setUint32(startMessageOffset + 20, newLocal);
|
|
28
28
|
}
|
|
29
29
|
PutComponentOperation.write = write;
|
|
30
30
|
function read(buf) {
|
|
@@ -39,7 +39,7 @@ export var PutComponentOperation;
|
|
|
39
39
|
...header,
|
|
40
40
|
entityId: buf.readUint32(),
|
|
41
41
|
componentId: buf.readUint32(),
|
|
42
|
-
timestamp:
|
|
42
|
+
timestamp: buf.readUint32(),
|
|
43
43
|
data: buf.readBuffer()
|
|
44
44
|
};
|
|
45
45
|
}
|
|
@@ -10,11 +10,11 @@ export declare enum CrdtMessageType {
|
|
|
10
10
|
MAX_MESSAGE_TYPE = 4
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Min. length = header (8 bytes) +
|
|
13
|
+
* Min. length = header (8 bytes) + 16 bytes = 24 bytes
|
|
14
14
|
*
|
|
15
|
-
* @param entity -
|
|
16
|
-
* @param componentId -
|
|
17
|
-
* @param timestamp -
|
|
15
|
+
* @param entity - Uint32 number of the entity
|
|
16
|
+
* @param componentId - Uint32 number of id
|
|
17
|
+
* @param timestamp - Uint32 Lamport timestamp
|
|
18
18
|
* @param data - Uint8[] data of component => length(4 bytes) + block of bytes[0..length-1]
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
@@ -26,6 +26,9 @@ export type PutComponentMessageBody = {
|
|
|
26
26
|
data: Uint8Array;
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
|
+
* @param entity - Uint32 number of the entity
|
|
30
|
+
* @param componentId - Uint32 number of id
|
|
31
|
+
* @param timestamp - Uint32 Lamport timestamp
|
|
29
32
|
* @public
|
|
30
33
|
*/
|
|
31
34
|
export type DeleteComponentMessageBody = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
|
-
"version": "7.0.6-
|
|
3
|
+
"version": "7.0.6-4106696113.commit-cda3cfd",
|
|
4
4
|
"description": "Decentraland ECS",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"ts-proto": "^1.112.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@dcl/crdt": "7.0.6-
|
|
30
|
+
"@dcl/crdt": "7.0.6-4106696113.commit-cda3cfd",
|
|
31
31
|
"@dcl/js-runtime": "file:../js-runtime",
|
|
32
32
|
"@dcl/protocol": "1.0.0-4085628047.commit-0f6384e"
|
|
33
33
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"displayName": "ECS",
|
|
42
42
|
"tsconfig": "./tsconfig.json"
|
|
43
43
|
},
|
|
44
|
-
"commit": "
|
|
44
|
+
"commit": "cda3cfd5ce0ddeb287ff28c1e4f1ad3329c017c0"
|
|
45
45
|
}
|