@dcl/playground-assets 7.0.6-4137912823.commit-aa69b28 → 7.0.6-4153633895.commit-4aad233

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/alpha.d.ts CHANGED
@@ -1043,6 +1043,14 @@ export declare interface ComponentDefinition<T> {
1043
1043
  * @param entity - Entity to delete the component from
1044
1044
  */
1045
1045
  deleteFrom(entity: Entity): T | null;
1046
+ /**
1047
+ * @public
1048
+ * Marks the entity as deleted and signals it cannot be used ever again. It must
1049
+ * clear the component internal state, produces a synchronization message to remove
1050
+ * the component from the entity.
1051
+ * @param entity - Entity to delete the component from
1052
+ */
1053
+ entityDeleted(entity: Entity, markAsDirty: boolean): void;
1046
1054
  /**
1047
1055
  * Get the mutable component of the entity, throw an error if the entity doesn't have the component.
1048
1056
  * - Internal comment: This method adds the &lt;entity,component&gt; to the list to be reviewed next frame
@@ -1055,7 +1063,20 @@ export declare interface ComponentDefinition<T> {
1055
1063
  * @param entity - Entity to get the component from
1056
1064
  */
1057
1065
  getMutableOrNull(entity: Entity): T | null;
1058
- writeToByteBuffer(entity: Entity, buffer: ByteBuffer): void;
1066
+ /**
1067
+ * This function receives a CRDT update and returns a touple with a "conflict
1068
+ * resoluton" message, in case of the sender being updated or null in case of noop/accepted
1069
+ * change. The second element of the touple is the modified/changed/deleted value.
1070
+ * @public
1071
+ */
1072
+ updateFromCrdt(body: CrdtMessageBody): [null | PutComponentMessageBody | DeleteComponentMessageBody, T | null];
1073
+ /**
1074
+ * This function returns an iterable with all the CRDT updates that need to be
1075
+ * broadcasted to other actors in the system. After returning, this function
1076
+ * clears the internal dirty state. Updates are produced only once.
1077
+ * @public
1078
+ */
1079
+ getCrdtUpdates(): Iterable<CrdtMessageBody>;
1059
1080
  }
1060
1081
 
1061
1082
  export declare type ComponentGetter<T extends ComponentDefinition<any>> = (engine: Pick<IEngine, 'defineComponentFromSchema'>) => T;
@@ -1067,11 +1088,33 @@ export declare type ComponentSchema<T extends [ComponentDefinition<any>, ...Comp
1067
1088
  [K in keyof T]: T[K] extends ComponentDefinition<any> ? ReturnType<T[K]['getMutable']> : never;
1068
1089
  };
1069
1090
 
1091
+ /**
1092
+ * @public
1093
+ */
1094
+ export declare const CRDT_MESSAGE_HEADER_LENGTH = 8;
1095
+
1096
+ /**
1097
+ * @public
1098
+ */
1099
+ export declare type CrdtMessage = PutComponentMessage | DeleteComponentMessage | DeleteEntityMessage;
1100
+
1070
1101
  /**
1071
1102
  * @public
1072
1103
  */
1073
1104
  export declare type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody;
1074
1105
 
1106
+ /**
1107
+ * Min length = 8 bytes
1108
+ * All message length including
1109
+ * @param length - uint32 the length of all message (including the header)
1110
+ * @param type - define the function which handles the data
1111
+ * @public
1112
+ */
1113
+ export declare type CrdtMessageHeader = {
1114
+ length: uint32;
1115
+ type: uint32;
1116
+ };
1117
+
1075
1118
  /**
1076
1119
  * @public
1077
1120
  */
@@ -1088,6 +1131,10 @@ export declare function createEthereumProvider(): {
1088
1131
  sendAsync(message: RPCSendableMessage, callback: (error: Error | null, result?: any) => void): void;
1089
1132
  };
1090
1133
 
1134
+ export declare function createGetCrdtMessages(componentId: number, timestamps: Map<Entity, number>, dirtyIterator: Set<Entity>, schema: Pick<ISchema<any>, 'serialize'>, data: Map<Entity, unknown>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;
1135
+
1136
+ export declare function createUpdateFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: CrdtMessageBody) => [null | PutComponentMessageBody | DeleteComponentMessageBody, any];
1137
+
1091
1138
  /**
1092
1139
  * Transform parenting: cyclic dependency checker
1093
1140
  * It checks only in modified Transforms
@@ -1133,6 +1180,11 @@ export declare type DeepReadonlySet<T> = ReadonlySet<DeepReadonly<T>>;
1133
1180
  */
1134
1181
  export declare const DEG2RAD: number;
1135
1182
 
1183
+ /**
1184
+ * @public
1185
+ */
1186
+ export declare type DeleteComponentMessage = CrdtMessageHeader & DeleteComponentMessageBody;
1187
+
1136
1188
  /**
1137
1189
  * @param entity - Uint32 number of the entity
1138
1190
  * @param componentId - Uint32 number of id
@@ -1146,6 +1198,11 @@ export declare type DeleteComponentMessageBody = {
1146
1198
  timestamp: number;
1147
1199
  };
1148
1200
 
1201
+ /**
1202
+ * @public
1203
+ */
1204
+ export declare type DeleteEntityMessage = CrdtMessageHeader & DeleteEntityMessageBody;
1205
+
1149
1206
  /**
1150
1207
  * @param entity - uint32 number of the entity
1151
1208
  * @public
@@ -1703,6 +1760,8 @@ export declare type IncludeUndefined<T> = {
1703
1760
  [P in keyof T]: undefined extends T[P] ? P : never;
1704
1761
  }[keyof T];
1705
1762
 
1763
+ export declare function incrementTimestamp(entity: Entity, timestamps: Map<Entity, number>): number;
1764
+
1706
1765
  /**
1707
1766
  * @public
1708
1767
  * Input component
@@ -3721,6 +3780,56 @@ export declare type PositionType = 'absolute' | 'relative';
3721
3780
  */
3722
3781
  export declare type PositionUnit = `${number}px` | `${number}%` | number;
3723
3782
 
3783
+ export declare enum ProcessMessageResultType {
3784
+ /**
3785
+ * Typical message and new state set.
3786
+ * @state CHANGE
3787
+ * @reason Incoming message has a timestamp greater
3788
+ */
3789
+ StateUpdatedTimestamp = 1,
3790
+ /**
3791
+ * Typical message when it is considered old.
3792
+ * @state it does NOT CHANGE.
3793
+ * @reason incoming message has a timestamp lower.
3794
+ */
3795
+ StateOutdatedTimestamp = 2,
3796
+ /**
3797
+ * Weird message, same timestamp and data.
3798
+ * @state it does NOT CHANGE.
3799
+ * @reason consistent state between peers.
3800
+ */
3801
+ NoChanges = 3,
3802
+ /**
3803
+ * Less but typical message, same timestamp, resolution by data.
3804
+ * @state it does NOT CHANGE.
3805
+ * @reason incoming message has a LOWER data.
3806
+ */
3807
+ StateOutdatedData = 4,
3808
+ /**
3809
+ * Less but typical message, same timestamp, resolution by data.
3810
+ * @state CHANGE.
3811
+ * @reason incoming message has a GREATER data.
3812
+ */
3813
+ StateUpdatedData = 5,
3814
+ /**
3815
+ * Entity was previously deleted.
3816
+ * @state it does NOT CHANGE.
3817
+ * @reason The message is considered old.
3818
+ */
3819
+ EntityWasDeleted = 6,
3820
+ /**
3821
+ * Entity should be deleted.
3822
+ * @state CHANGE.
3823
+ * @reason the state is storing old entities
3824
+ */
3825
+ EntityDeleted = 7
3826
+ }
3827
+
3828
+ /**
3829
+ * @public
3830
+ */
3831
+ export declare type PutComponentMessage = CrdtMessageHeader & PutComponentMessageBody;
3832
+
3724
3833
  /**
3725
3834
  * Min. length = header (8 bytes) + 16 bytes = 24 bytes
3726
3835
  *
package/dist/beta.d.ts CHANGED
@@ -1043,6 +1043,14 @@ export declare interface ComponentDefinition<T> {
1043
1043
  * @param entity - Entity to delete the component from
1044
1044
  */
1045
1045
  deleteFrom(entity: Entity): T | null;
1046
+ /**
1047
+ * @public
1048
+ * Marks the entity as deleted and signals it cannot be used ever again. It must
1049
+ * clear the component internal state, produces a synchronization message to remove
1050
+ * the component from the entity.
1051
+ * @param entity - Entity to delete the component from
1052
+ */
1053
+ entityDeleted(entity: Entity, markAsDirty: boolean): void;
1046
1054
  /**
1047
1055
  * Get the mutable component of the entity, throw an error if the entity doesn't have the component.
1048
1056
  * - Internal comment: This method adds the &lt;entity,component&gt; to the list to be reviewed next frame
@@ -1055,7 +1063,20 @@ export declare interface ComponentDefinition<T> {
1055
1063
  * @param entity - Entity to get the component from
1056
1064
  */
1057
1065
  getMutableOrNull(entity: Entity): T | null;
1058
- writeToByteBuffer(entity: Entity, buffer: ByteBuffer): void;
1066
+ /**
1067
+ * This function receives a CRDT update and returns a touple with a "conflict
1068
+ * resoluton" message, in case of the sender being updated or null in case of noop/accepted
1069
+ * change. The second element of the touple is the modified/changed/deleted value.
1070
+ * @public
1071
+ */
1072
+ updateFromCrdt(body: CrdtMessageBody): [null | PutComponentMessageBody | DeleteComponentMessageBody, T | null];
1073
+ /**
1074
+ * This function returns an iterable with all the CRDT updates that need to be
1075
+ * broadcasted to other actors in the system. After returning, this function
1076
+ * clears the internal dirty state. Updates are produced only once.
1077
+ * @public
1078
+ */
1079
+ getCrdtUpdates(): Iterable<CrdtMessageBody>;
1059
1080
  }
1060
1081
 
1061
1082
  export declare type ComponentGetter<T extends ComponentDefinition<any>> = (engine: Pick<IEngine, 'defineComponentFromSchema'>) => T;
@@ -1067,11 +1088,33 @@ export declare type ComponentSchema<T extends [ComponentDefinition<any>, ...Comp
1067
1088
  [K in keyof T]: T[K] extends ComponentDefinition<any> ? ReturnType<T[K]['getMutable']> : never;
1068
1089
  };
1069
1090
 
1091
+ /**
1092
+ * @public
1093
+ */
1094
+ export declare const CRDT_MESSAGE_HEADER_LENGTH = 8;
1095
+
1096
+ /**
1097
+ * @public
1098
+ */
1099
+ export declare type CrdtMessage = PutComponentMessage | DeleteComponentMessage | DeleteEntityMessage;
1100
+
1070
1101
  /**
1071
1102
  * @public
1072
1103
  */
1073
1104
  export declare type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody;
1074
1105
 
1106
+ /**
1107
+ * Min length = 8 bytes
1108
+ * All message length including
1109
+ * @param length - uint32 the length of all message (including the header)
1110
+ * @param type - define the function which handles the data
1111
+ * @public
1112
+ */
1113
+ export declare type CrdtMessageHeader = {
1114
+ length: uint32;
1115
+ type: uint32;
1116
+ };
1117
+
1075
1118
  /**
1076
1119
  * @public
1077
1120
  */
@@ -1088,6 +1131,10 @@ export declare function createEthereumProvider(): {
1088
1131
  sendAsync(message: RPCSendableMessage, callback: (error: Error | null, result?: any) => void): void;
1089
1132
  };
1090
1133
 
1134
+ export declare function createGetCrdtMessages(componentId: number, timestamps: Map<Entity, number>, dirtyIterator: Set<Entity>, schema: Pick<ISchema<any>, 'serialize'>, data: Map<Entity, unknown>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;
1135
+
1136
+ export declare function createUpdateFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: CrdtMessageBody) => [null | PutComponentMessageBody | DeleteComponentMessageBody, any];
1137
+
1091
1138
  /**
1092
1139
  * Transform parenting: cyclic dependency checker
1093
1140
  * It checks only in modified Transforms
@@ -1133,6 +1180,11 @@ export declare type DeepReadonlySet<T> = ReadonlySet<DeepReadonly<T>>;
1133
1180
  */
1134
1181
  export declare const DEG2RAD: number;
1135
1182
 
1183
+ /**
1184
+ * @public
1185
+ */
1186
+ export declare type DeleteComponentMessage = CrdtMessageHeader & DeleteComponentMessageBody;
1187
+
1136
1188
  /**
1137
1189
  * @param entity - Uint32 number of the entity
1138
1190
  * @param componentId - Uint32 number of id
@@ -1146,6 +1198,11 @@ export declare type DeleteComponentMessageBody = {
1146
1198
  timestamp: number;
1147
1199
  };
1148
1200
 
1201
+ /**
1202
+ * @public
1203
+ */
1204
+ export declare type DeleteEntityMessage = CrdtMessageHeader & DeleteEntityMessageBody;
1205
+
1149
1206
  /**
1150
1207
  * @param entity - uint32 number of the entity
1151
1208
  * @public
@@ -1699,6 +1756,8 @@ export declare type IncludeUndefined<T> = {
1699
1756
  [P in keyof T]: undefined extends T[P] ? P : never;
1700
1757
  }[keyof T];
1701
1758
 
1759
+ export declare function incrementTimestamp(entity: Entity, timestamps: Map<Entity, number>): number;
1760
+
1702
1761
  /**
1703
1762
  * @public
1704
1763
  * Input component
@@ -3717,6 +3776,56 @@ export declare type PositionType = 'absolute' | 'relative';
3717
3776
  */
3718
3777
  export declare type PositionUnit = `${number}px` | `${number}%` | number;
3719
3778
 
3779
+ export declare enum ProcessMessageResultType {
3780
+ /**
3781
+ * Typical message and new state set.
3782
+ * @state CHANGE
3783
+ * @reason Incoming message has a timestamp greater
3784
+ */
3785
+ StateUpdatedTimestamp = 1,
3786
+ /**
3787
+ * Typical message when it is considered old.
3788
+ * @state it does NOT CHANGE.
3789
+ * @reason incoming message has a timestamp lower.
3790
+ */
3791
+ StateOutdatedTimestamp = 2,
3792
+ /**
3793
+ * Weird message, same timestamp and data.
3794
+ * @state it does NOT CHANGE.
3795
+ * @reason consistent state between peers.
3796
+ */
3797
+ NoChanges = 3,
3798
+ /**
3799
+ * Less but typical message, same timestamp, resolution by data.
3800
+ * @state it does NOT CHANGE.
3801
+ * @reason incoming message has a LOWER data.
3802
+ */
3803
+ StateOutdatedData = 4,
3804
+ /**
3805
+ * Less but typical message, same timestamp, resolution by data.
3806
+ * @state CHANGE.
3807
+ * @reason incoming message has a GREATER data.
3808
+ */
3809
+ StateUpdatedData = 5,
3810
+ /**
3811
+ * Entity was previously deleted.
3812
+ * @state it does NOT CHANGE.
3813
+ * @reason The message is considered old.
3814
+ */
3815
+ EntityWasDeleted = 6,
3816
+ /**
3817
+ * Entity should be deleted.
3818
+ * @state CHANGE.
3819
+ * @reason the state is storing old entities
3820
+ */
3821
+ EntityDeleted = 7
3822
+ }
3823
+
3824
+ /**
3825
+ * @public
3826
+ */
3827
+ export declare type PutComponentMessage = CrdtMessageHeader & PutComponentMessageBody;
3828
+
3720
3829
  /**
3721
3830
  * Min. length = header (8 bytes) + 16 bytes = 24 bytes
3722
3831
  *
@@ -1043,6 +1043,14 @@ export declare interface ComponentDefinition<T> {
1043
1043
  * @param entity - Entity to delete the component from
1044
1044
  */
1045
1045
  deleteFrom(entity: Entity): T | null;
1046
+ /**
1047
+ * @public
1048
+ * Marks the entity as deleted and signals it cannot be used ever again. It must
1049
+ * clear the component internal state, produces a synchronization message to remove
1050
+ * the component from the entity.
1051
+ * @param entity - Entity to delete the component from
1052
+ */
1053
+ entityDeleted(entity: Entity, markAsDirty: boolean): void;
1046
1054
  /**
1047
1055
  * Get the mutable component of the entity, throw an error if the entity doesn't have the component.
1048
1056
  * - Internal comment: This method adds the &lt;entity,component&gt; to the list to be reviewed next frame
@@ -1055,7 +1063,20 @@ export declare interface ComponentDefinition<T> {
1055
1063
  * @param entity - Entity to get the component from
1056
1064
  */
1057
1065
  getMutableOrNull(entity: Entity): T | null;
1058
- writeToByteBuffer(entity: Entity, buffer: ByteBuffer): void;
1066
+ /**
1067
+ * This function receives a CRDT update and returns a touple with a "conflict
1068
+ * resoluton" message, in case of the sender being updated or null in case of noop/accepted
1069
+ * change. The second element of the touple is the modified/changed/deleted value.
1070
+ * @public
1071
+ */
1072
+ updateFromCrdt(body: CrdtMessageBody): [null | PutComponentMessageBody | DeleteComponentMessageBody, T | null];
1073
+ /**
1074
+ * This function returns an iterable with all the CRDT updates that need to be
1075
+ * broadcasted to other actors in the system. After returning, this function
1076
+ * clears the internal dirty state. Updates are produced only once.
1077
+ * @public
1078
+ */
1079
+ getCrdtUpdates(): Iterable<CrdtMessageBody>;
1059
1080
  }
1060
1081
 
1061
1082
  export declare type ComponentGetter<T extends ComponentDefinition<any>> = (engine: Pick<IEngine, 'defineComponentFromSchema'>) => T;
@@ -1067,11 +1088,33 @@ export declare type ComponentSchema<T extends [ComponentDefinition<any>, ...Comp
1067
1088
  [K in keyof T]: T[K] extends ComponentDefinition<any> ? ReturnType<T[K]['getMutable']> : never;
1068
1089
  };
1069
1090
 
1091
+ /**
1092
+ * @public
1093
+ */
1094
+ export declare const CRDT_MESSAGE_HEADER_LENGTH = 8;
1095
+
1096
+ /**
1097
+ * @public
1098
+ */
1099
+ export declare type CrdtMessage = PutComponentMessage | DeleteComponentMessage | DeleteEntityMessage;
1100
+
1070
1101
  /**
1071
1102
  * @public
1072
1103
  */
1073
1104
  export declare type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody;
1074
1105
 
1106
+ /**
1107
+ * Min length = 8 bytes
1108
+ * All message length including
1109
+ * @param length - uint32 the length of all message (including the header)
1110
+ * @param type - define the function which handles the data
1111
+ * @public
1112
+ */
1113
+ export declare type CrdtMessageHeader = {
1114
+ length: uint32;
1115
+ type: uint32;
1116
+ };
1117
+
1075
1118
  /**
1076
1119
  * @public
1077
1120
  */
@@ -1088,6 +1131,10 @@ export declare function createEthereumProvider(): {
1088
1131
  sendAsync(message: RPCSendableMessage, callback: (error: Error | null, result?: any) => void): void;
1089
1132
  };
1090
1133
 
1134
+ export declare function createGetCrdtMessages(componentId: number, timestamps: Map<Entity, number>, dirtyIterator: Set<Entity>, schema: Pick<ISchema<any>, 'serialize'>, data: Map<Entity, unknown>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;
1135
+
1136
+ export declare function createUpdateFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: CrdtMessageBody) => [null | PutComponentMessageBody | DeleteComponentMessageBody, any];
1137
+
1091
1138
  /**
1092
1139
  * Transform parenting: cyclic dependency checker
1093
1140
  * It checks only in modified Transforms
@@ -1133,6 +1180,11 @@ export declare type DeepReadonlySet<T> = ReadonlySet<DeepReadonly<T>>;
1133
1180
  */
1134
1181
  export declare const DEG2RAD: number;
1135
1182
 
1183
+ /**
1184
+ * @public
1185
+ */
1186
+ export declare type DeleteComponentMessage = CrdtMessageHeader & DeleteComponentMessageBody;
1187
+
1136
1188
  /**
1137
1189
  * @param entity - Uint32 number of the entity
1138
1190
  * @param componentId - Uint32 number of id
@@ -1146,6 +1198,11 @@ export declare type DeleteComponentMessageBody = {
1146
1198
  timestamp: number;
1147
1199
  };
1148
1200
 
1201
+ /**
1202
+ * @public
1203
+ */
1204
+ export declare type DeleteEntityMessage = CrdtMessageHeader & DeleteEntityMessageBody;
1205
+
1149
1206
  /**
1150
1207
  * @param entity - uint32 number of the entity
1151
1208
  * @public
@@ -1699,6 +1756,8 @@ export declare type IncludeUndefined<T> = {
1699
1756
  [P in keyof T]: undefined extends T[P] ? P : never;
1700
1757
  }[keyof T];
1701
1758
 
1759
+ export declare function incrementTimestamp(entity: Entity, timestamps: Map<Entity, number>): number;
1760
+
1702
1761
  /**
1703
1762
  * @public
1704
1763
  * Input component
@@ -3717,6 +3776,56 @@ export declare type PositionType = 'absolute' | 'relative';
3717
3776
  */
3718
3777
  export declare type PositionUnit = `${number}px` | `${number}%` | number;
3719
3778
 
3779
+ export declare enum ProcessMessageResultType {
3780
+ /**
3781
+ * Typical message and new state set.
3782
+ * @state CHANGE
3783
+ * @reason Incoming message has a timestamp greater
3784
+ */
3785
+ StateUpdatedTimestamp = 1,
3786
+ /**
3787
+ * Typical message when it is considered old.
3788
+ * @state it does NOT CHANGE.
3789
+ * @reason incoming message has a timestamp lower.
3790
+ */
3791
+ StateOutdatedTimestamp = 2,
3792
+ /**
3793
+ * Weird message, same timestamp and data.
3794
+ * @state it does NOT CHANGE.
3795
+ * @reason consistent state between peers.
3796
+ */
3797
+ NoChanges = 3,
3798
+ /**
3799
+ * Less but typical message, same timestamp, resolution by data.
3800
+ * @state it does NOT CHANGE.
3801
+ * @reason incoming message has a LOWER data.
3802
+ */
3803
+ StateOutdatedData = 4,
3804
+ /**
3805
+ * Less but typical message, same timestamp, resolution by data.
3806
+ * @state CHANGE.
3807
+ * @reason incoming message has a GREATER data.
3808
+ */
3809
+ StateUpdatedData = 5,
3810
+ /**
3811
+ * Entity was previously deleted.
3812
+ * @state it does NOT CHANGE.
3813
+ * @reason The message is considered old.
3814
+ */
3815
+ EntityWasDeleted = 6,
3816
+ /**
3817
+ * Entity should be deleted.
3818
+ * @state CHANGE.
3819
+ * @reason the state is storing old entities
3820
+ */
3821
+ EntityDeleted = 7
3822
+ }
3823
+
3824
+ /**
3825
+ * @public
3826
+ */
3827
+ export declare type PutComponentMessage = CrdtMessageHeader & PutComponentMessageBody;
3828
+
3720
3829
  /**
3721
3830
  * Min. length = header (8 bytes) + 16 bytes = 24 bytes
3722
3831
  *