@dcl/ecs 7.22.4 → 7.22.5-24776890516.commit-b10e9ab
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 -5
- package/dist/components/generated/pb/decentraland/common/colors.gen.d.ts +0 -15
- package/dist/components/generated/pb/decentraland/common/colors.gen.js +0 -47
- package/dist/components/generated/pb/decentraland/sdk/components/common/input_action.gen.d.ts +1 -10
- package/dist/components/generated/pb/decentraland/sdk/components/common/input_action.gen.js +0 -10
- package/dist/components/generated/pb/decentraland/sdk/components/pointer_events.gen.d.ts +1 -5
- package/dist/components/generated/pb/decentraland/sdk/components/pointer_events.gen.js +1 -20
- package/dist/components/generated/types.gen.d.ts +0 -2
- package/dist/components/generated/types.gen.js +0 -3
- package/dist/components/index.d.ts +5 -2
- package/dist/components/index.js +5 -5
- 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 -13
- package/dist/components/manual/Transform.js +3 -11
- package/dist/components/types.d.ts +1 -1
- 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 +5 -3
- package/dist/engine/lww-element-set-component-definition.js +70 -35
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -3
- package/dist/runtime/helpers/index.d.ts +0 -1
- package/dist/runtime/helpers/index.js +0 -1
- package/dist/runtime/helpers/tree.d.ts +0 -6
- package/dist/runtime/helpers/tree.js +2 -2
- package/dist/runtime/initialization/index.d.ts +0 -7
- package/dist/runtime/initialization/index.js +0 -6
- 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 +55 -146
- package/dist/systems/events.d.ts +0 -65
- package/dist/systems/events.js +8 -70
- 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 +1 -3
- package/dist-cjs/components/generated/index.gen.d.ts +0 -4
- package/dist-cjs/components/generated/index.gen.js +2 -8
- package/dist-cjs/components/generated/pb/decentraland/common/colors.gen.d.ts +0 -15
- package/dist-cjs/components/generated/pb/decentraland/common/colors.gen.js +1 -48
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/input_action.gen.d.ts +1 -10
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/input_action.gen.js +1 -11
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/pointer_events.gen.d.ts +1 -5
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/pointer_events.gen.js +1 -20
- package/dist-cjs/components/generated/types.gen.d.ts +0 -2
- package/dist-cjs/components/generated/types.gen.js +0 -5
- package/dist-cjs/components/index.d.ts +5 -2
- package/dist-cjs/components/index.js +7 -7
- 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 -13
- package/dist-cjs/components/manual/Transform.js +3 -34
- package/dist-cjs/components/types.d.ts +1 -1
- 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 +5 -3
- package/dist-cjs/engine/lww-element-set-component-definition.js +73 -36
- package/dist-cjs/index.d.ts +2 -3
- package/dist-cjs/index.js +2 -4
- package/dist-cjs/runtime/helpers/index.d.ts +0 -1
- package/dist-cjs/runtime/helpers/index.js +0 -1
- package/dist-cjs/runtime/helpers/tree.d.ts +0 -6
- package/dist-cjs/runtime/helpers/tree.js +2 -3
- package/dist-cjs/runtime/initialization/index.d.ts +0 -7
- package/dist-cjs/runtime/initialization/index.js +1 -7
- 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 +55 -169
- package/dist-cjs/systems/events.d.ts +0 -65
- package/dist-cjs/systems/events.js +8 -70
- package/package.json +2 -3
- package/dist/components/extended/ParticleSystem.d.ts +0 -24
- package/dist/components/extended/ParticleSystem.js +0 -23
- package/dist/components/generated/ParticleSystem.gen.d.ts +0 -1
- package/dist/components/generated/ParticleSystem.gen.js +0 -25
- package/dist/components/generated/pb/decentraland/common/floats.gen.d.ts +0 -16
- package/dist/components/generated/pb/decentraland/common/floats.gen.js +0 -50
- package/dist/components/generated/pb/decentraland/sdk/components/particle_system.gen.d.ts +0 -241
- package/dist/components/generated/pb/decentraland/sdk/components/particle_system.gen.js +0 -717
- package/dist/runtime/helpers/vectors.d.ts +0 -1
- package/dist/runtime/helpers/vectors.js +0 -36
- package/dist/serialization/crdt/network/utils.d.ts +0 -9
- package/dist/serialization/crdt/network/utils.js +0 -60
- package/dist/systems/physics-force.d.ts +0 -1
- package/dist/systems/physics-force.js +0 -140
- package/dist/systems/physics-impulse.d.ts +0 -12
- package/dist/systems/physics-impulse.js +0 -85
- package/dist/systems/physics.d.ts +0 -77
- package/dist/systems/physics.js +0 -18
- package/dist-cjs/components/extended/ParticleSystem.d.ts +0 -24
- package/dist-cjs/components/extended/ParticleSystem.js +0 -28
- package/dist-cjs/components/generated/ParticleSystem.gen.d.ts +0 -1
- package/dist-cjs/components/generated/ParticleSystem.gen.js +0 -28
- package/dist-cjs/components/generated/pb/decentraland/common/floats.gen.d.ts +0 -16
- package/dist-cjs/components/generated/pb/decentraland/common/floats.gen.js +0 -56
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/particle_system.gen.d.ts +0 -241
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/particle_system.gen.js +0 -723
- package/dist-cjs/runtime/helpers/vectors.d.ts +0 -1
- package/dist-cjs/runtime/helpers/vectors.js +0 -39
- package/dist-cjs/serialization/crdt/network/utils.d.ts +0 -9
- package/dist-cjs/serialization/crdt/network/utils.js +0 -67
- package/dist-cjs/systems/physics-force.d.ts +0 -1
- package/dist-cjs/systems/physics-force.js +0 -167
- package/dist-cjs/systems/physics-impulse.d.ts +0 -12
- package/dist-cjs/systems/physics-impulse.js +0 -112
- package/dist-cjs/systems/physics.d.ts +0 -77
- package/dist-cjs/systems/physics.js +0 -23
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ISchema } from '../schemas';
|
|
2
2
|
import { ByteBuffer } from '../serialization/ByteBuffer';
|
|
3
|
-
import { PutComponentMessageBody, DeleteComponentMessageBody, CrdtMessageBody } from '../serialization/crdt';
|
|
3
|
+
import { PutComponentMessageBody, DeleteComponentMessageBody, ProcessMessageResultType, CrdtMessageBody, PutNetworkComponentMessageBody, DeleteComponentNetworkMessageBody, AuthoritativePutComponentMessageBody } from '../serialization/crdt';
|
|
4
4
|
import { Entity } from './entity';
|
|
5
5
|
export declare function incrementTimestamp(entity: Entity, timestamps: Map<Entity, number>): number;
|
|
6
6
|
export declare function createDumpLwwFunctionFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (buffer: ByteBuffer, filterEntity?: ((entity: Entity) => boolean) | undefined) => void;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
7
|
+
export declare function createCrdtRuleValidator(timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (message: PutComponentMessageBody | DeleteComponentMessageBody | PutNetworkComponentMessageBody | DeleteComponentNetworkMessageBody) => ProcessMessageResultType;
|
|
8
|
+
export declare function createForceUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: AuthoritativePutComponentMessageBody) => [null, any];
|
|
9
|
+
export declare function createUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: CrdtMessageBody) => [null | PutComponentMessageBody | DeleteComponentMessageBody, any];
|
|
10
|
+
export declare function createGetCrdtMessagesForLww(componentId: number, timestamps: Map<Entity, number>, dirtyIterator: Set<Entity>, schema: Pick<ISchema<any>, 'serialize'>, data: Map<Entity, unknown>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;
|
|
@@ -30,16 +30,12 @@ export function createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, d
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
|
|
34
|
+
export function createCrdtRuleValidator(timestamps, schema, data) {
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* Returns the recieved data if the lamport number was bigger than ours.
|
|
40
|
-
* If it was an outdated message, then we return void
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
36
|
+
* Shared CRDT conflict resolution logic
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
43
39
|
function crdtRuleForCurrentState(message) {
|
|
44
40
|
const { entityId, timestamp } = message;
|
|
45
41
|
const currentTimestamp = timestamps.get(entityId);
|
|
@@ -49,7 +45,6 @@ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, l
|
|
|
49
45
|
}
|
|
50
46
|
// Outdated Message. Resend our state message through the wire.
|
|
51
47
|
if (currentTimestamp > timestamp) {
|
|
52
|
-
// console.log('2', currentTimestamp, timestamp)
|
|
53
48
|
return ProcessMessageResultType.StateOutdatedTimestamp;
|
|
54
49
|
}
|
|
55
50
|
// Deletes are idempotent
|
|
@@ -66,7 +61,6 @@ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, l
|
|
|
66
61
|
currentDataGreater = dataCompare(null, message.data);
|
|
67
62
|
}
|
|
68
63
|
// Same data, same timestamp. Weirdo echo message.
|
|
69
|
-
// console.log('3', currentDataGreater, writeBuffer.toBinary(), (message as any).data || null)
|
|
70
64
|
if (currentDataGreater === 0) {
|
|
71
65
|
return ProcessMessageResultType.NoChanges;
|
|
72
66
|
}
|
|
@@ -75,10 +69,35 @@ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, l
|
|
|
75
69
|
return ProcessMessageResultType.StateOutdatedData;
|
|
76
70
|
}
|
|
77
71
|
else {
|
|
78
|
-
//
|
|
72
|
+
// Current data is lower
|
|
79
73
|
return ProcessMessageResultType.StateUpdatedData;
|
|
80
74
|
}
|
|
81
75
|
}
|
|
76
|
+
return crdtRuleForCurrentState;
|
|
77
|
+
}
|
|
78
|
+
export function createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
|
|
79
|
+
/**
|
|
80
|
+
* Force update component state regardless of timestamp - used for server authoritative messages
|
|
81
|
+
*/
|
|
82
|
+
return (msg) => {
|
|
83
|
+
const buffer = new ReadWriteByteBuffer(msg.data);
|
|
84
|
+
const deserializedValue = schema.deserialize(buffer);
|
|
85
|
+
data.set(msg.entityId, deserializedValue);
|
|
86
|
+
timestamps.set(msg.entityId, msg.timestamp);
|
|
87
|
+
return [null, deserializedValue];
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
|
|
91
|
+
/**
|
|
92
|
+
* Process the received message only if the lamport number recieved is higher
|
|
93
|
+
* than the stored one. If its lower, we spread it to the network to correct the peer.
|
|
94
|
+
* If they are equal, the bigger raw data wins.
|
|
95
|
+
|
|
96
|
+
* Returns the recieved data if the lamport number was bigger than ours.
|
|
97
|
+
* If it was an outdated message, then we return void
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
const crdtRuleForCurrentState = createCrdtRuleValidator(timestamps, schema, data);
|
|
82
101
|
return (msg) => {
|
|
83
102
|
/* istanbul ignore next */
|
|
84
103
|
if (msg.type !== CrdtMessageType.PUT_COMPONENT &&
|
|
@@ -96,11 +115,9 @@ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, l
|
|
|
96
115
|
if (msg.type === CrdtMessageType.PUT_COMPONENT || msg.type === CrdtMessageType.PUT_COMPONENT_NETWORK) {
|
|
97
116
|
const buf = new ReadWriteByteBuffer(msg.data);
|
|
98
117
|
data.set(entity, schema.deserialize(buf));
|
|
99
|
-
lastSentData.set(entity, new Uint8Array(msg.data));
|
|
100
118
|
}
|
|
101
119
|
else {
|
|
102
120
|
data.delete(entity);
|
|
103
|
-
lastSentData.delete(entity);
|
|
104
121
|
}
|
|
105
122
|
return [null, data.get(entity)];
|
|
106
123
|
}
|
|
@@ -136,34 +153,23 @@ export function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, l
|
|
|
136
153
|
return [null, data.get(entity)];
|
|
137
154
|
};
|
|
138
155
|
}
|
|
139
|
-
export function createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data
|
|
156
|
+
export function createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data) {
|
|
140
157
|
return function* () {
|
|
141
|
-
const writeBuffer = new ReadWriteByteBuffer();
|
|
142
158
|
for (const entity of dirtyIterator) {
|
|
159
|
+
const newTimestamp = incrementTimestamp(entity, timestamps);
|
|
143
160
|
if (data.has(entity)) {
|
|
144
|
-
writeBuffer
|
|
161
|
+
const writeBuffer = new ReadWriteByteBuffer();
|
|
145
162
|
schema.serialize(data.get(entity), writeBuffer);
|
|
146
|
-
// Compare against last-sent snapshot using the zero-copy subarray view.
|
|
147
|
-
// Only allocate a copy when bytes actually differ.
|
|
148
|
-
const previousBytes = lastSentData.get(entity);
|
|
149
|
-
if (previousBytes && dataCompare(writeBuffer.toBinary(), previousBytes) === 0) {
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
const currentBytes = writeBuffer.toCopiedBinary();
|
|
153
|
-
const newTimestamp = incrementTimestamp(entity, timestamps);
|
|
154
|
-
lastSentData.set(entity, currentBytes);
|
|
155
163
|
const msg = {
|
|
156
164
|
type: CrdtMessageType.PUT_COMPONENT,
|
|
157
165
|
componentId,
|
|
158
166
|
entityId: entity,
|
|
159
|
-
data:
|
|
167
|
+
data: writeBuffer.toBinary(),
|
|
160
168
|
timestamp: newTimestamp
|
|
161
169
|
};
|
|
162
170
|
yield msg;
|
|
163
171
|
}
|
|
164
172
|
else {
|
|
165
|
-
lastSentData.delete(entity);
|
|
166
|
-
const newTimestamp = incrementTimestamp(entity, timestamps);
|
|
167
173
|
const msg = {
|
|
168
174
|
type: CrdtMessageType.DELETE_COMPONENT,
|
|
169
175
|
componentId,
|
|
@@ -183,8 +189,8 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
183
189
|
const data = new Map();
|
|
184
190
|
const dirtyIterator = new Set();
|
|
185
191
|
const timestamps = new Map();
|
|
186
|
-
const lastSentData = new Map();
|
|
187
192
|
const onChangeCallbacks = new Map();
|
|
193
|
+
const validateCallbacks = new Map();
|
|
188
194
|
return {
|
|
189
195
|
get componentId() {
|
|
190
196
|
return componentId;
|
|
@@ -205,14 +211,12 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
205
211
|
if (data.delete(entity) && markAsDirty) {
|
|
206
212
|
dirtyIterator.add(entity);
|
|
207
213
|
}
|
|
208
|
-
lastSentData.delete(entity);
|
|
209
214
|
return component || null;
|
|
210
215
|
},
|
|
211
216
|
entityDeleted(entity, markAsDirty) {
|
|
212
217
|
if (data.delete(entity) && markAsDirty) {
|
|
213
218
|
dirtyIterator.add(entity);
|
|
214
219
|
}
|
|
215
|
-
lastSentData.delete(entity);
|
|
216
220
|
},
|
|
217
221
|
getOrNull(entity) {
|
|
218
222
|
const component = data.get(entity);
|
|
@@ -239,7 +243,6 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
239
243
|
const usedValue = value === undefined ? schema.create() : schema.extend ? schema.extend(value) : value;
|
|
240
244
|
data.set(entity, usedValue);
|
|
241
245
|
dirtyIterator.add(entity);
|
|
242
|
-
lastSentData.delete(entity);
|
|
243
246
|
return usedValue;
|
|
244
247
|
},
|
|
245
248
|
getMutableOrNull(entity) {
|
|
@@ -277,9 +280,41 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
277
280
|
yield entity;
|
|
278
281
|
}
|
|
279
282
|
},
|
|
280
|
-
getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data
|
|
281
|
-
updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data
|
|
283
|
+
getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data),
|
|
284
|
+
updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data),
|
|
285
|
+
__forceUpdateFromCrdt: createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data),
|
|
286
|
+
__dry_run_updateFromCrdt: createCrdtRuleValidator(timestamps, schema, data),
|
|
282
287
|
dumpCrdtStateToBuffer: createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data),
|
|
288
|
+
validateBeforeChange(entityOrCb, cb) {
|
|
289
|
+
if (arguments.length === 1) {
|
|
290
|
+
// Second overload: just callback (global validation)
|
|
291
|
+
validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
if (cb) {
|
|
295
|
+
validateCallbacks.set(entityOrCb, cb);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
__run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
|
|
300
|
+
const cb = entity && validateCallbacks.get(entity);
|
|
301
|
+
const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
|
|
302
|
+
const currentValue = data.get(entity);
|
|
303
|
+
const value = { entity, currentValue, newValue, senderAddress, createdBy };
|
|
304
|
+
const globalResult = globalCb?.(value) ?? true;
|
|
305
|
+
const entityResult = (globalResult && cb?.(value)) ?? true;
|
|
306
|
+
return globalResult && entityResult;
|
|
307
|
+
},
|
|
308
|
+
getCrdtState(entity) {
|
|
309
|
+
const componentData = data.get(entity);
|
|
310
|
+
const timestamp = timestamps.get(entity);
|
|
311
|
+
if (componentData && timestamp !== undefined) {
|
|
312
|
+
const buffer = new ReadWriteByteBuffer();
|
|
313
|
+
schema.serialize(deepReadonly(componentData), buffer);
|
|
314
|
+
return { data: buffer.toBinary(), timestamp };
|
|
315
|
+
}
|
|
316
|
+
return null;
|
|
317
|
+
},
|
|
283
318
|
onChange(entity, cb) {
|
|
284
319
|
const cbs = onChangeCallbacks.get(entity) ?? [];
|
|
285
320
|
cbs.push(cb);
|
package/dist/index.d.ts
CHANGED
|
@@ -12,10 +12,9 @@ export * from './systems/assetLoad';
|
|
|
12
12
|
export * from './systems/async-task';
|
|
13
13
|
export * from './systems/tween';
|
|
14
14
|
export * from './systems/triggerArea';
|
|
15
|
-
export * from './systems/physics';
|
|
16
15
|
export * from './engine/entity';
|
|
17
16
|
export * from './components/types';
|
|
18
|
-
import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended,
|
|
17
|
+
import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended, ICreatedBy } from './components/types';
|
|
19
18
|
import { NameComponent } from './components/manual/Name';
|
|
20
19
|
import { TagsComponentDefinitionExtended } from './components/manual/Tags';
|
|
21
20
|
export declare const Transform: TransformComponentExtended;
|
|
@@ -32,7 +31,6 @@ export declare const VirtualCamera: VirtualCameraComponentDefinitionExtended;
|
|
|
32
31
|
export declare const InputModifier: InputModifierComponentDefinitionExtended;
|
|
33
32
|
export declare const LightSource: LightSourceComponentDefinitionExtended;
|
|
34
33
|
export declare const TriggerArea: TriggerAreaComponentDefinitionExtended;
|
|
35
|
-
export declare const ParticleSystem: ParticleSystemComponentDefinitionExtended;
|
|
36
34
|
/**
|
|
37
35
|
* @alpha
|
|
38
36
|
* This is going to be used for sync components through a server.
|
|
@@ -49,6 +47,7 @@ export declare const NetworkEntity: INetowrkEntity;
|
|
|
49
47
|
* Tag a entity to be syncronized through comms
|
|
50
48
|
*/
|
|
51
49
|
export declare const NetworkParent: INetowrkParent;
|
|
50
|
+
export declare const CreatedBy: ICreatedBy;
|
|
52
51
|
export * from './components/generated/global.gen';
|
|
53
52
|
export * from './components/generated/types.gen';
|
|
54
53
|
export * from './serialization/crdt';
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,6 @@ export * from './systems/assetLoad';
|
|
|
13
13
|
export * from './systems/async-task';
|
|
14
14
|
export * from './systems/tween';
|
|
15
15
|
export * from './systems/triggerArea';
|
|
16
|
-
export * from './systems/physics';
|
|
17
16
|
export * from './engine/entity';
|
|
18
17
|
export * from './components/types';
|
|
19
18
|
// @internal
|
|
@@ -36,8 +35,6 @@ export const VirtualCamera = /* @__PURE__*/ components.VirtualCamera(engine);
|
|
|
36
35
|
export const InputModifier = /* @__PURE__*/ components.InputModifier(engine);
|
|
37
36
|
export const LightSource = /* @__PURE__*/ components.LightSource(engine);
|
|
38
37
|
export const TriggerArea = /* @__PURE__*/ components.TriggerArea(engine);
|
|
39
|
-
export const ParticleSystem =
|
|
40
|
-
/* @__PURE__*/ components.ParticleSystem(engine);
|
|
41
38
|
/**
|
|
42
39
|
* @alpha
|
|
43
40
|
* This is going to be used for sync components through a server.
|
|
@@ -54,6 +51,7 @@ export const NetworkEntity = /* @__PURE__*/ components.NetworkEntity(engine);
|
|
|
54
51
|
* Tag a entity to be syncronized through comms
|
|
55
52
|
*/
|
|
56
53
|
export const NetworkParent = /* @__PURE__*/ components.NetworkParent(engine);
|
|
54
|
+
export const CreatedBy = /* @__PURE__*/ components.CreatedBy(engine);
|
|
57
55
|
// export components for global engine
|
|
58
56
|
export * from './components/generated/global.gen';
|
|
59
57
|
export * from './components/generated/types.gen';
|
|
@@ -2,12 +2,6 @@ import { Entity } from '../../engine/entity';
|
|
|
2
2
|
import { ComponentDefinition, IEngine } from '../../engine';
|
|
3
3
|
import { Vector3Type } from '../../schemas/custom/Vector3';
|
|
4
4
|
import { QuaternionType } from '../../schemas/custom/Quaternion';
|
|
5
|
-
/**
|
|
6
|
-
* @public
|
|
7
|
-
* Rotate a vector by a quaternion
|
|
8
|
-
* Uses the formula: v' = q * v * q^(-1), optimized version
|
|
9
|
-
*/
|
|
10
|
-
export declare function rotateVectorByQuaternion(v: Vector3Type, q: QuaternionType): Vector3Type;
|
|
11
5
|
/**
|
|
12
6
|
* Get an iterator of entities that follow a tree structure for a component
|
|
13
7
|
* @public
|
|
@@ -35,11 +35,11 @@ function multiplyQuaternions(q1, q2) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* @
|
|
38
|
+
* @internal
|
|
39
39
|
* Rotate a vector by a quaternion
|
|
40
40
|
* Uses the formula: v' = q * v * q^(-1), optimized version
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
function rotateVectorByQuaternion(v, q) {
|
|
43
43
|
// Extract quaternion components
|
|
44
44
|
const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
|
|
45
45
|
// Calculate cross product terms (q.xyz × v) * 2
|
|
@@ -12,7 +12,6 @@ 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';
|
|
16
15
|
/**
|
|
17
16
|
* @public
|
|
18
17
|
* The engine is the part of the scene that sits in the middle and manages all of the other parts.
|
|
@@ -78,12 +77,6 @@ export { TriggerAreaEventsSystem };
|
|
|
78
77
|
*/
|
|
79
78
|
export declare const timers: Timers;
|
|
80
79
|
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 };
|
|
87
80
|
/**
|
|
88
81
|
* @public
|
|
89
82
|
* Runs an async function
|
|
@@ -14,7 +14,6 @@ import { pointerEventColliderChecker } from '../../systems/pointer-event-collide
|
|
|
14
14
|
import { createTriggerAreaEventsSystem } from '../../systems/triggerArea';
|
|
15
15
|
import { createTimers } from '../helpers/timers';
|
|
16
16
|
import { setGlobalPolyfill } from '../globals';
|
|
17
|
-
import { createPhysicsSystem } from '../../systems/physics';
|
|
18
17
|
/**
|
|
19
18
|
* @public
|
|
20
19
|
* The engine is the part of the scene that sits in the middle and manages all of the other parts.
|
|
@@ -78,11 +77,6 @@ setGlobalPolyfill('setTimeout', timers.setTimeout);
|
|
|
78
77
|
setGlobalPolyfill('clearTimeout', timers.clearTimeout);
|
|
79
78
|
setGlobalPolyfill('setInterval', timers.setInterval);
|
|
80
79
|
setGlobalPolyfill('clearInterval', timers.clearInterval);
|
|
81
|
-
/**
|
|
82
|
-
* @public
|
|
83
|
-
* Physics helpers for applying impulses and forces to the player.
|
|
84
|
-
*/
|
|
85
|
-
export const Physics = /* @__PURE__ */ createPhysicsSystem(engine);
|
|
86
80
|
/**
|
|
87
81
|
* Adds pointer event collider system only in DEV env
|
|
88
82
|
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Entity } from '../../engine/entity';
|
|
2
|
+
import { ByteBuffer } from '../ByteBuffer';
|
|
3
|
+
import { AuthoritativePutComponentMessage } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace AuthoritativePutComponentOperation {
|
|
8
|
+
const MESSAGE_HEADER_LENGTH = 16;
|
|
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, data: Uint8Array, buf: ByteBuffer): void;
|
|
14
|
+
function read(buf: ByteBuffer): AuthoritativePutComponentMessage | null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
|
+
import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export var AuthoritativePutComponentOperation;
|
|
7
|
+
(function (AuthoritativePutComponentOperation) {
|
|
8
|
+
AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
|
|
9
|
+
/**
|
|
10
|
+
* Call this function for an optimal writing data passing the ByteBuffer
|
|
11
|
+
* already allocated
|
|
12
|
+
*/
|
|
13
|
+
function write(entity, timestamp, componentId, data, buf) {
|
|
14
|
+
// reserve the beginning
|
|
15
|
+
const startMessageOffset = buf.incrementWriteOffset(CRDT_MESSAGE_HEADER_LENGTH + AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH);
|
|
16
|
+
// write body
|
|
17
|
+
buf.writeBuffer(data, false);
|
|
18
|
+
const messageLength = buf.currentWriteOffset() - startMessageOffset;
|
|
19
|
+
// Write CrdtMessage header
|
|
20
|
+
buf.setUint32(startMessageOffset, messageLength);
|
|
21
|
+
buf.setUint32(startMessageOffset + 4, CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT);
|
|
22
|
+
// Write ComponentOperation header
|
|
23
|
+
buf.setUint32(startMessageOffset + 8, entity);
|
|
24
|
+
buf.setUint32(startMessageOffset + 12, componentId);
|
|
25
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
26
|
+
const newLocal = messageLength - AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
|
|
27
|
+
buf.setUint32(startMessageOffset + 20, newLocal);
|
|
28
|
+
}
|
|
29
|
+
AuthoritativePutComponentOperation.write = write;
|
|
30
|
+
function read(buf) {
|
|
31
|
+
const header = CrdtMessageProtocol.readHeader(buf);
|
|
32
|
+
if (!header) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (header.type !== CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
|
|
36
|
+
throw new Error('AuthoritativePutComponentOperation tried to read another message type.');
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
...header,
|
|
40
|
+
entityId: buf.readUint32(),
|
|
41
|
+
componentId: buf.readUint32(),
|
|
42
|
+
timestamp: buf.readUint32(),
|
|
43
|
+
data: buf.readBuffer()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
AuthoritativePutComponentOperation.read = read;
|
|
47
|
+
})(AuthoritativePutComponentOperation || (AuthoritativePutComponentOperation = {}));
|
|
@@ -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.
|
|
@@ -13,7 +13,9 @@ export var CrdtMessageType;
|
|
|
13
13
|
CrdtMessageType[CrdtMessageType["PUT_COMPONENT_NETWORK"] = 5] = "PUT_COMPONENT_NETWORK";
|
|
14
14
|
CrdtMessageType[CrdtMessageType["DELETE_COMPONENT_NETWORK"] = 6] = "DELETE_COMPONENT_NETWORK";
|
|
15
15
|
CrdtMessageType[CrdtMessageType["DELETE_ENTITY_NETWORK"] = 7] = "DELETE_ENTITY_NETWORK";
|
|
16
|
-
|
|
16
|
+
// Server authoritative operation - forces component state regardless of timestamp
|
|
17
|
+
CrdtMessageType[CrdtMessageType["AUTHORITATIVE_PUT_COMPONENT"] = 8] = "AUTHORITATIVE_PUT_COMPONENT";
|
|
18
|
+
CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 9] = "MAX_MESSAGE_TYPE";
|
|
17
19
|
})(CrdtMessageType || (CrdtMessageType = {}));
|
|
18
20
|
/**
|
|
19
21
|
* @public
|