@esengine/ecs-framework 2.1.27 → 2.1.28

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @esengine/ecs-framework v2.1.27
2
+ * @esengine/ecs-framework v2.1.28
3
3
  * TypeScript definitions
4
4
  */
5
5
  /**
@@ -1119,6 +1119,106 @@ declare abstract class Component implements IComponent {
1119
1119
  update(): void;
1120
1120
  }
1121
1121
 
1122
+ /**
1123
+ * BigInt兼容性抽象层
1124
+ *
1125
+ * 为不支持BigInt的环境提供兼容实现,确保ECS框架在所有平台上都能正常运行。
1126
+ * 自动检测运行时环境的BigInt支持情况,并提供统一的接口。
1127
+ *
1128
+ * @example
1129
+ * ```typescript
1130
+ * // 创建兼容的BigInt值
1131
+ * const value = BigIntFactory.create(123);
1132
+ *
1133
+ * // 位运算
1134
+ * const result = value.or(BigIntFactory.create(456));
1135
+ *
1136
+ * // 检查兼容性
1137
+ * console.log(BigIntFactory.isNativeSupported()); // true/false
1138
+ * ```
1139
+ */
1140
+ /**
1141
+ * BigInt兼容接口
1142
+ *
1143
+ * 定义了BigInt的基本操作接口,支持原生BigInt和兼容实现的统一调用。
1144
+ */
1145
+ interface IBigIntLike {
1146
+ /**
1147
+ * 获取数值表示
1148
+ * @returns 数值
1149
+ */
1150
+ valueOf(): number;
1151
+ /**
1152
+ * 转换为字符串
1153
+ * @param radix 进制,支持2、10、16
1154
+ * @returns 字符串表示
1155
+ */
1156
+ toString(radix?: number): string;
1157
+ /**
1158
+ * 位运算:与
1159
+ * @param other 另一个BigInt值
1160
+ * @returns 运算结果
1161
+ */
1162
+ and(other: IBigIntLike): IBigIntLike;
1163
+ /**
1164
+ * 位运算:或
1165
+ * @param other 另一个BigInt值
1166
+ * @returns 运算结果
1167
+ */
1168
+ or(other: IBigIntLike): IBigIntLike;
1169
+ /**
1170
+ * 位运算:异或
1171
+ * @param other 另一个BigInt值
1172
+ * @returns 运算结果
1173
+ */
1174
+ xor(other: IBigIntLike): IBigIntLike;
1175
+ /**
1176
+ * 位运算:非
1177
+ * @param maxBits 最大位数限制
1178
+ * @returns 运算结果
1179
+ */
1180
+ not(maxBits?: number): IBigIntLike;
1181
+ /**
1182
+ * 左移位运算
1183
+ * @param bits 移位数
1184
+ * @returns 运算结果
1185
+ */
1186
+ shiftLeft(bits: number): IBigIntLike;
1187
+ /**
1188
+ * 右移位运算
1189
+ * @param bits 移位数
1190
+ * @returns 运算结果
1191
+ */
1192
+ shiftRight(bits: number): IBigIntLike;
1193
+ /**
1194
+ * 相等比较
1195
+ * @param other 另一个BigInt值
1196
+ * @returns 是否相等
1197
+ */
1198
+ equals(other: IBigIntLike): boolean;
1199
+ /**
1200
+ * 检查是否为零
1201
+ * @returns 是否为零
1202
+ */
1203
+ isZero(): boolean;
1204
+ /**
1205
+ * 创建副本
1206
+ * @returns 新的实例
1207
+ */
1208
+ clone(): IBigIntLike;
1209
+ }
1210
+ /**
1211
+ * 环境信息接口
1212
+ */
1213
+ interface EnvironmentInfo {
1214
+ /** 是否支持BigInt */
1215
+ supportsBigInt: boolean;
1216
+ /** 运行环境 */
1217
+ environment: string;
1218
+ /** JavaScript引擎 */
1219
+ jsEngine: string;
1220
+ }
1221
+
1122
1222
  /**
1123
1223
  * 组件类型定义
1124
1224
  */
@@ -1247,7 +1347,7 @@ declare class ComponentStorageManager {
1247
1347
  * @param entityId 实体ID
1248
1348
  * @returns 组件位掩码
1249
1349
  */
1250
- getComponentMask(entityId: number): bigint;
1350
+ getComponentMask(entityId: number): IBigIntLike;
1251
1351
  /**
1252
1352
  * 压缩所有存储器
1253
1353
  */
@@ -1707,7 +1807,7 @@ declare class Entity {
1707
1807
  *
1708
1808
  * @returns 实体的组件位掩码
1709
1809
  */
1710
- get componentMask(): bigint;
1810
+ get componentMask(): IBigIntLike;
1711
1811
  /**
1712
1812
  * 创建并添加组件
1713
1813
  *
@@ -2022,33 +2122,60 @@ declare class EntityList {
2022
2122
 
2023
2123
  /**
2024
2124
  * 高性能位操作类
2025
- * 基于BigInt实现,支持任意数量的位操作
2125
+ *
2126
+ * 基于BigInt实现,支持任意数量的位操作。
2127
+ * 自动适配运行环境,在不支持BigInt的环境中使用兼容实现。
2128
+ *
2129
+ * @example
2130
+ * ```typescript
2131
+ * const bits = new Bits();
2132
+ * bits.set(0);
2133
+ * bits.set(5);
2134
+ * console.log(bits.get(0)); // true
2135
+ * console.log(bits.get(1)); // false
2136
+ * ```
2026
2137
  */
2027
2138
  declare class Bits {
2028
2139
  private _value;
2029
- constructor(initialValue?: bigint);
2140
+ /**
2141
+ * 构造函数
2142
+ * @param initialValue 初始值,可以是IBigIntLike或数值
2143
+ */
2144
+ constructor(initialValue?: IBigIntLike | number | string);
2030
2145
  /**
2031
2146
  * 设置指定位置的位为1
2147
+ * @param index 位索引(从0开始)
2148
+ * @throws {Error} 当索引为负数时抛出错误
2032
2149
  */
2033
2150
  set(index: number): void;
2034
2151
  /**
2035
2152
  * 清除指定位置的位(设为0)
2153
+ * @param index 位索引(从0开始)
2154
+ * @throws {Error} 当索引为负数时抛出错误
2036
2155
  */
2037
2156
  clear(index: number): void;
2038
2157
  /**
2039
2158
  * 获取指定位置的位值
2159
+ * @param index 位索引(从0开始)
2160
+ * @returns 位值(true表示1,false表示0)
2040
2161
  */
2041
2162
  get(index: number): boolean;
2042
2163
  /**
2043
2164
  * 检查是否包含所有指定的位
2165
+ * @param other 另一个Bits对象
2166
+ * @returns 是否包含所有指定的位
2044
2167
  */
2045
2168
  containsAll(other: Bits): boolean;
2046
2169
  /**
2047
2170
  * 检查是否包含任意一个指定的位
2171
+ * @param other 另一个Bits对象
2172
+ * @returns 是否包含任意一个指定的位
2048
2173
  */
2049
2174
  intersects(other: Bits): boolean;
2050
2175
  /**
2051
2176
  * 检查是否不包含任何指定的位
2177
+ * @param other 另一个Bits对象
2178
+ * @returns 是否不包含任何指定的位
2052
2179
  */
2053
2180
  excludes(other: Bits): boolean;
2054
2181
  /**
@@ -2057,74 +2184,100 @@ declare class Bits {
2057
2184
  clearAll(): void;
2058
2185
  /**
2059
2186
  * 检查是否为空(没有设置任何位)
2187
+ * @returns 是否为空
2060
2188
  */
2061
2189
  isEmpty(): boolean;
2062
2190
  /**
2063
2191
  * 获取设置的位数量
2192
+ * @returns 设置为1的位数量
2064
2193
  */
2065
2194
  cardinality(): number;
2066
2195
  /**
2067
2196
  * 位运算:与
2197
+ * @param other 另一个Bits对象
2198
+ * @returns 新的Bits对象,包含与运算结果
2068
2199
  */
2069
2200
  and(other: Bits): Bits;
2070
2201
  /**
2071
2202
  * 位运算:或
2203
+ * @param other 另一个Bits对象
2204
+ * @returns 新的Bits对象,包含或运算结果
2072
2205
  */
2073
2206
  or(other: Bits): Bits;
2074
2207
  /**
2075
2208
  * 位运算:异或
2209
+ * @param other 另一个Bits对象
2210
+ * @returns 新的Bits对象,包含异或运算结果
2076
2211
  */
2077
2212
  xor(other: Bits): Bits;
2078
2213
  /**
2079
2214
  * 位运算:非
2215
+ * @param maxBits 最大位数限制,默认64位
2216
+ * @returns 新的Bits对象,包含非运算结果
2080
2217
  */
2081
2218
  not(maxBits?: number): Bits;
2082
2219
  /**
2083
2220
  * 复制另一个Bits对象
2221
+ * @param other 要复制的Bits对象
2084
2222
  */
2085
2223
  copyFrom(other: Bits): void;
2086
2224
  /**
2087
2225
  * 创建当前Bits的副本
2226
+ * @returns 新的Bits对象副本
2088
2227
  */
2089
2228
  clone(): Bits;
2090
2229
  /**
2091
- * 获取原始BigInt值
2230
+ * 获取原始值
2231
+ * @returns 原始的IBigIntLike值
2092
2232
  */
2093
- getValue(): bigint;
2233
+ getValue(): IBigIntLike;
2094
2234
  /**
2095
- * 设置原始BigInt值
2235
+ * 设置原始值
2236
+ * @param value 新的值,可以是IBigIntLike或数值
2096
2237
  */
2097
- setValue(value: bigint): void;
2238
+ setValue(value: IBigIntLike | number | string): void;
2098
2239
  /**
2099
2240
  * 获取调试信息
2241
+ * @returns 返回显示设置位索引的字符串
2100
2242
  */
2101
2243
  toString(): string;
2102
2244
  /**
2103
2245
  * 获取二进制表示
2246
+ * @param maxBits 最大位数,默认64位
2247
+ * @returns 二进制字符串表示
2104
2248
  */
2105
2249
  toBinaryString(maxBits?: number): string;
2106
2250
  /**
2107
2251
  * 获取十六进制表示
2252
+ * @returns 十六进制字符串表示
2108
2253
  */
2109
2254
  toHexString(): string;
2110
2255
  /**
2111
2256
  * 从二进制字符串创建Bits
2257
+ * @param binaryString 二进制字符串
2258
+ * @returns 新的Bits对象
2112
2259
  */
2113
2260
  static fromBinaryString(binaryString: string): Bits;
2114
2261
  /**
2115
2262
  * 从十六进制字符串创建Bits
2263
+ * @param hexString 十六进制字符串
2264
+ * @returns 新的Bits对象
2116
2265
  */
2117
2266
  static fromHexString(hexString: string): Bits;
2118
2267
  /**
2119
2268
  * 比较两个Bits对象是否相等
2269
+ * @param other 另一个Bits对象
2270
+ * @returns 是否相等
2120
2271
  */
2121
2272
  equals(other: Bits): boolean;
2122
2273
  /**
2123
2274
  * 获取最高位的索引
2275
+ * @returns 最高位的索引,如果为空则返回-1
2124
2276
  */
2125
2277
  getHighestBitIndex(): number;
2126
2278
  /**
2127
2279
  * 获取最低位的索引
2280
+ * @returns 最低位的索引,如果为空则返回-1
2128
2281
  */
2129
2282
  getLowestBitIndex(): number;
2130
2283
  }
@@ -4510,6 +4663,10 @@ declare class Core {
4510
4663
  * Core配置
4511
4664
  */
4512
4665
  private _config;
4666
+ /**
4667
+ * 兼容性信息
4668
+ */
4669
+ private _environmentInfo;
4513
4670
  /**
4514
4671
  * 创建核心实例
4515
4672
  *
@@ -4633,6 +4790,18 @@ declare class Core {
4633
4790
  * @returns 调试状态
4634
4791
  */
4635
4792
  static get isDebugEnabled(): boolean;
4793
+ /**
4794
+ * 获取环境兼容性信息
4795
+ *
4796
+ * @returns 环境兼容性信息
4797
+ */
4798
+ static getEnvironmentInfo(): EnvironmentInfo | null;
4799
+ /**
4800
+ * 检查BigInt是否支持
4801
+ *
4802
+ * @returns 是否支持BigInt
4803
+ */
4804
+ static get supportsBigInt(): boolean;
4636
4805
  /**
4637
4806
  * 场景切换回调
4638
4807
  *
@@ -4645,6 +4814,12 @@ declare class Core {
4645
4814
  * 执行核心系统的初始化逻辑。
4646
4815
  */
4647
4816
  protected initialize(): void;
4817
+ /**
4818
+ * 记录兼容性信息
4819
+ *
4820
+ * 在控制台输出当前环境的兼容性信息和建议。
4821
+ */
4822
+ private logCompatibilityInfo;
4648
4823
  /**
4649
4824
  * 内部更新方法
4650
4825
  *
@@ -5600,6 +5775,8 @@ declare class IndexUpdateBatcher {
5600
5775
 
5601
5776
  /**
5602
5777
  * 位掩码优化器,用于预计算和缓存常用的组件掩码
5778
+ *
5779
+ * 使用BigInt兼容层确保在所有平台上的正常运行。
5603
5780
  */
5604
5781
  declare class BitMaskOptimizer {
5605
5782
  private static instance;
@@ -5618,32 +5795,51 @@ declare class BitMaskOptimizer {
5618
5795
  getComponentTypeId(componentName: string): number | undefined;
5619
5796
  /**
5620
5797
  * 创建单个组件的掩码
5798
+ * @param componentName 组件名称
5799
+ * @returns 组件掩码
5621
5800
  */
5622
- createSingleComponentMask(componentName: string): bigint;
5801
+ createSingleComponentMask(componentName: string): IBigIntLike;
5623
5802
  /**
5624
5803
  * 创建多个组件的组合掩码
5804
+ * @param componentNames 组件名称数组
5805
+ * @returns 组合掩码
5625
5806
  */
5626
- createCombinedMask(componentNames: string[]): bigint;
5807
+ createCombinedMask(componentNames: string[]): IBigIntLike;
5627
5808
  /**
5628
5809
  * 检查掩码是否包含指定组件
5810
+ * @param mask 要检查的掩码
5811
+ * @param componentName 组件名称
5812
+ * @returns 是否包含指定组件
5629
5813
  */
5630
- maskContainsComponent(mask: bigint, componentName: string): boolean;
5814
+ maskContainsComponent(mask: IBigIntLike, componentName: string): boolean;
5631
5815
  /**
5632
5816
  * 检查掩码是否包含所有指定组件
5817
+ * @param mask 要检查的掩码
5818
+ * @param componentNames 组件名称数组
5819
+ * @returns 是否包含所有指定组件
5633
5820
  */
5634
- maskContainsAllComponents(mask: bigint, componentNames: string[]): boolean;
5821
+ maskContainsAllComponents(mask: IBigIntLike, componentNames: string[]): boolean;
5635
5822
  /**
5636
5823
  * 检查掩码是否包含任一指定组件
5824
+ * @param mask 要检查的掩码
5825
+ * @param componentNames 组件名称数组
5826
+ * @returns 是否包含任一指定组件
5637
5827
  */
5638
- maskContainsAnyComponent(mask: bigint, componentNames: string[]): boolean;
5828
+ maskContainsAnyComponent(mask: IBigIntLike, componentNames: string[]): boolean;
5639
5829
  /**
5640
5830
  * 添加组件到掩码
5831
+ * @param mask 原始掩码
5832
+ * @param componentName 要添加的组件名称
5833
+ * @returns 新的掩码
5641
5834
  */
5642
- addComponentToMask(mask: bigint, componentName: string): bigint;
5835
+ addComponentToMask(mask: IBigIntLike, componentName: string): IBigIntLike;
5643
5836
  /**
5644
5837
  * 从掩码中移除组件
5838
+ * @param mask 原始掩码
5839
+ * @param componentName 要移除的组件名称
5840
+ * @returns 新的掩码
5645
5841
  */
5646
- removeComponentFromMask(mask: bigint, componentName: string): bigint;
5842
+ removeComponentFromMask(mask: IBigIntLike, componentName: string): IBigIntLike;
5647
5843
  /**
5648
5844
  * 预计算常用掩码组合
5649
5845
  */
@@ -5666,11 +5862,11 @@ declare class BitMaskOptimizer {
5666
5862
  /**
5667
5863
  * 将掩码转换为组件名称数组
5668
5864
  */
5669
- maskToComponentNames(mask: bigint): string[];
5865
+ maskToComponentNames(mask: IBigIntLike): string[];
5670
5866
  /**
5671
5867
  * 获取掩码中组件的数量
5672
5868
  */
5673
- getComponentCount(mask: bigint): number;
5869
+ getComponentCount(mask: IBigIntLike): number;
5674
5870
  }
5675
5871
 
5676
5872
  /**