@esengine/ecs-framework 2.2.20 → 2.3.0

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.
Files changed (491) hide show
  1. package/bin/Core/DI/Decorators.d.ts +206 -0
  2. package/bin/Core/DI/Decorators.d.ts.map +1 -0
  3. package/bin/Core/DI/Decorators.js +253 -0
  4. package/bin/Core/DI/Decorators.js.map +1 -0
  5. package/bin/Core/DI/index.d.ts +8 -0
  6. package/bin/Core/DI/index.d.ts.map +1 -0
  7. package/bin/Core/DI/index.js +7 -0
  8. package/bin/Core/DI/index.js.map +1 -0
  9. package/bin/Core/Plugin.d.ts +112 -0
  10. package/bin/Core/Plugin.d.ts.map +1 -0
  11. package/bin/Core/Plugin.js +19 -0
  12. package/bin/Core/Plugin.js.map +1 -0
  13. package/bin/Core/PluginManager.d.ts +118 -0
  14. package/bin/Core/PluginManager.d.ts.map +1 -0
  15. package/bin/Core/PluginManager.js +229 -0
  16. package/bin/Core/PluginManager.js.map +1 -0
  17. package/bin/Core/ServiceContainer.d.ts +221 -0
  18. package/bin/Core/ServiceContainer.d.ts.map +1 -0
  19. package/bin/Core/ServiceContainer.js +352 -0
  20. package/bin/Core/ServiceContainer.js.map +1 -0
  21. package/bin/Core.d.ts +379 -0
  22. package/bin/Core.d.ts.map +1 -0
  23. package/bin/Core.js +553 -0
  24. package/bin/Core.js.map +1 -0
  25. package/bin/ECS/Component.d.ts +104 -0
  26. package/bin/ECS/Component.d.ts.map +1 -0
  27. package/bin/ECS/Component.js +105 -0
  28. package/bin/ECS/Component.js.map +1 -0
  29. package/bin/ECS/Components/HierarchyComponent.d.ts +46 -0
  30. package/bin/ECS/Components/HierarchyComponent.d.ts.map +1 -0
  31. package/bin/ECS/Components/HierarchyComponent.js +65 -0
  32. package/bin/ECS/Components/HierarchyComponent.js.map +1 -0
  33. package/bin/ECS/Components/index.d.ts +2 -0
  34. package/bin/ECS/Components/index.d.ts.map +1 -0
  35. package/bin/ECS/Components/index.js +2 -0
  36. package/bin/ECS/Components/index.js.map +1 -0
  37. package/bin/ECS/Core/ArchetypeSystem.d.ts +103 -0
  38. package/bin/ECS/Core/ArchetypeSystem.d.ts.map +1 -0
  39. package/bin/ECS/Core/ArchetypeSystem.js +244 -0
  40. package/bin/ECS/Core/ArchetypeSystem.js.map +1 -0
  41. package/bin/ECS/Core/CommandBuffer.d.ts +154 -0
  42. package/bin/ECS/Core/CommandBuffer.d.ts.map +1 -0
  43. package/bin/ECS/Core/CommandBuffer.js +244 -0
  44. package/bin/ECS/Core/CommandBuffer.js.map +1 -0
  45. package/bin/ECS/Core/ComponentPool.d.ts +139 -0
  46. package/bin/ECS/Core/ComponentPool.d.ts.map +1 -0
  47. package/bin/ECS/Core/ComponentPool.js +276 -0
  48. package/bin/ECS/Core/ComponentPool.js.map +1 -0
  49. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts +127 -0
  50. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts.map +1 -0
  51. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js +235 -0
  52. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js.map +1 -0
  53. package/bin/ECS/Core/ComponentStorage.d.ts +185 -0
  54. package/bin/ECS/Core/ComponentStorage.d.ts.map +1 -0
  55. package/bin/ECS/Core/ComponentStorage.js +321 -0
  56. package/bin/ECS/Core/ComponentStorage.js.map +1 -0
  57. package/bin/ECS/Core/EntityLifecyclePolicy.d.ts +26 -0
  58. package/bin/ECS/Core/EntityLifecyclePolicy.d.ts.map +1 -0
  59. package/bin/ECS/Core/EntityLifecyclePolicy.js +2 -0
  60. package/bin/ECS/Core/EntityLifecyclePolicy.js.map +1 -0
  61. package/bin/ECS/Core/EventBus.d.ts +210 -0
  62. package/bin/ECS/Core/EventBus.d.ts.map +1 -0
  63. package/bin/ECS/Core/EventBus.js +370 -0
  64. package/bin/ECS/Core/EventBus.js.map +1 -0
  65. package/bin/ECS/Core/EventSystem.d.ts +225 -0
  66. package/bin/ECS/Core/EventSystem.d.ts.map +1 -0
  67. package/bin/ECS/Core/EventSystem.js +448 -0
  68. package/bin/ECS/Core/EventSystem.js.map +1 -0
  69. package/bin/ECS/Core/Events/index.d.ts +3 -0
  70. package/bin/ECS/Core/Events/index.d.ts.map +1 -0
  71. package/bin/ECS/Core/Events/index.js +3 -0
  72. package/bin/ECS/Core/Events/index.js.map +1 -0
  73. package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts +35 -0
  74. package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts.map +1 -0
  75. package/bin/ECS/Core/FluentAPI/ComponentBuilder.js +48 -0
  76. package/bin/ECS/Core/FluentAPI/ComponentBuilder.js.map +1 -0
  77. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts +135 -0
  78. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts.map +1 -0
  79. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js +166 -0
  80. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js.map +1 -0
  81. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts +58 -0
  82. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts.map +1 -0
  83. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js +85 -0
  84. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js.map +1 -0
  85. package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts +110 -0
  86. package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts.map +1 -0
  87. package/bin/ECS/Core/FluentAPI/EntityBuilder.js +181 -0
  88. package/bin/ECS/Core/FluentAPI/EntityBuilder.js.map +1 -0
  89. package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts +53 -0
  90. package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts.map +1 -0
  91. package/bin/ECS/Core/FluentAPI/SceneBuilder.js +79 -0
  92. package/bin/ECS/Core/FluentAPI/SceneBuilder.js.map +1 -0
  93. package/bin/ECS/Core/FluentAPI/index.d.ts +6 -0
  94. package/bin/ECS/Core/FluentAPI/index.d.ts.map +1 -0
  95. package/bin/ECS/Core/FluentAPI/index.js +6 -0
  96. package/bin/ECS/Core/FluentAPI/index.js.map +1 -0
  97. package/bin/ECS/Core/FluentAPI.d.ts +2 -0
  98. package/bin/ECS/Core/FluentAPI.d.ts.map +1 -0
  99. package/bin/ECS/Core/FluentAPI.js +3 -0
  100. package/bin/ECS/Core/FluentAPI.js.map +1 -0
  101. package/bin/ECS/Core/Query/TypedQuery.d.ts +214 -0
  102. package/bin/ECS/Core/Query/TypedQuery.d.ts.map +1 -0
  103. package/bin/ECS/Core/Query/TypedQuery.js +294 -0
  104. package/bin/ECS/Core/Query/TypedQuery.js.map +1 -0
  105. package/bin/ECS/Core/Query/index.d.ts +3 -0
  106. package/bin/ECS/Core/Query/index.d.ts.map +1 -0
  107. package/bin/ECS/Core/Query/index.js +3 -0
  108. package/bin/ECS/Core/Query/index.js.map +1 -0
  109. package/bin/ECS/Core/QuerySystem.d.ts +458 -0
  110. package/bin/ECS/Core/QuerySystem.d.ts.map +1 -0
  111. package/bin/ECS/Core/QuerySystem.js +1069 -0
  112. package/bin/ECS/Core/QuerySystem.js.map +1 -0
  113. package/bin/ECS/Core/QueryTypes.d.ts +34 -0
  114. package/bin/ECS/Core/QueryTypes.d.ts.map +1 -0
  115. package/bin/ECS/Core/QueryTypes.js +13 -0
  116. package/bin/ECS/Core/QueryTypes.js.map +1 -0
  117. package/bin/ECS/Core/ReactiveQuery.d.ts +211 -0
  118. package/bin/ECS/Core/ReactiveQuery.d.ts.map +1 -0
  119. package/bin/ECS/Core/ReactiveQuery.js +401 -0
  120. package/bin/ECS/Core/ReactiveQuery.js.map +1 -0
  121. package/bin/ECS/Core/ReferenceTracker.d.ts +111 -0
  122. package/bin/ECS/Core/ReferenceTracker.d.ts.map +1 -0
  123. package/bin/ECS/Core/ReferenceTracker.js +254 -0
  124. package/bin/ECS/Core/ReferenceTracker.js.map +1 -0
  125. package/bin/ECS/Core/SoASerializer.d.ts +28 -0
  126. package/bin/ECS/Core/SoASerializer.d.ts.map +1 -0
  127. package/bin/ECS/Core/SoASerializer.js +85 -0
  128. package/bin/ECS/Core/SoASerializer.js.map +1 -0
  129. package/bin/ECS/Core/SoAStorage.d.ts +129 -0
  130. package/bin/ECS/Core/SoAStorage.d.ts.map +1 -0
  131. package/bin/ECS/Core/SoAStorage.js +685 -0
  132. package/bin/ECS/Core/SoAStorage.js.map +1 -0
  133. package/bin/ECS/Core/SoATypeRegistry.d.ts +50 -0
  134. package/bin/ECS/Core/SoATypeRegistry.d.ts.map +1 -0
  135. package/bin/ECS/Core/SoATypeRegistry.js +135 -0
  136. package/bin/ECS/Core/SoATypeRegistry.js.map +1 -0
  137. package/bin/ECS/Core/Storage/index.d.ts +4 -0
  138. package/bin/ECS/Core/Storage/index.d.ts.map +1 -0
  139. package/bin/ECS/Core/Storage/index.js +4 -0
  140. package/bin/ECS/Core/Storage/index.js.map +1 -0
  141. package/bin/ECS/Core/StorageDecorators.d.ts +20 -0
  142. package/bin/ECS/Core/StorageDecorators.d.ts.map +1 -0
  143. package/bin/ECS/Core/StorageDecorators.js +27 -0
  144. package/bin/ECS/Core/StorageDecorators.js.map +1 -0
  145. package/bin/ECS/CoreEvents.d.ts +131 -0
  146. package/bin/ECS/CoreEvents.d.ts.map +1 -0
  147. package/bin/ECS/CoreEvents.js +163 -0
  148. package/bin/ECS/CoreEvents.js.map +1 -0
  149. package/bin/ECS/Decorators/EntityRefDecorator.d.ts +46 -0
  150. package/bin/ECS/Decorators/EntityRefDecorator.d.ts.map +1 -0
  151. package/bin/ECS/Decorators/EntityRefDecorator.js +118 -0
  152. package/bin/ECS/Decorators/EntityRefDecorator.js.map +1 -0
  153. package/bin/ECS/Decorators/PropertyDecorator.d.ts +168 -0
  154. package/bin/ECS/Decorators/PropertyDecorator.d.ts.map +1 -0
  155. package/bin/ECS/Decorators/PropertyDecorator.js +40 -0
  156. package/bin/ECS/Decorators/PropertyDecorator.js.map +1 -0
  157. package/bin/ECS/Decorators/TypeDecorators.d.ts +124 -0
  158. package/bin/ECS/Decorators/TypeDecorators.d.ts.map +1 -0
  159. package/bin/ECS/Decorators/TypeDecorators.js +151 -0
  160. package/bin/ECS/Decorators/TypeDecorators.js.map +1 -0
  161. package/bin/ECS/Decorators/index.d.ts +7 -0
  162. package/bin/ECS/Decorators/index.d.ts.map +1 -0
  163. package/bin/ECS/Decorators/index.js +4 -0
  164. package/bin/ECS/Decorators/index.js.map +1 -0
  165. package/bin/ECS/Entity.d.ts +415 -0
  166. package/bin/ECS/Entity.d.ts.map +1 -0
  167. package/bin/ECS/Entity.js +683 -0
  168. package/bin/ECS/Entity.js.map +1 -0
  169. package/bin/ECS/EntityTags.d.ts +71 -0
  170. package/bin/ECS/EntityTags.d.ts.map +1 -0
  171. package/bin/ECS/EntityTags.js +82 -0
  172. package/bin/ECS/EntityTags.js.map +1 -0
  173. package/bin/ECS/IScene.d.ts +308 -0
  174. package/bin/ECS/IScene.d.ts.map +1 -0
  175. package/bin/ECS/IScene.js +2 -0
  176. package/bin/ECS/IScene.js.map +1 -0
  177. package/bin/ECS/Scene.d.ts +799 -0
  178. package/bin/ECS/Scene.d.ts.map +1 -0
  179. package/bin/ECS/Scene.js +1203 -0
  180. package/bin/ECS/Scene.js.map +1 -0
  181. package/bin/ECS/SceneManager.d.ts +197 -0
  182. package/bin/ECS/SceneManager.d.ts.map +1 -0
  183. package/bin/ECS/SceneManager.js +264 -0
  184. package/bin/ECS/SceneManager.js.map +1 -0
  185. package/bin/ECS/Serialization/ComponentSerializer.d.ts +106 -0
  186. package/bin/ECS/Serialization/ComponentSerializer.d.ts.map +1 -0
  187. package/bin/ECS/Serialization/ComponentSerializer.js +251 -0
  188. package/bin/ECS/Serialization/ComponentSerializer.js.map +1 -0
  189. package/bin/ECS/Serialization/EntitySerializer.d.ts +111 -0
  190. package/bin/ECS/Serialization/EntitySerializer.d.ts.map +1 -0
  191. package/bin/ECS/Serialization/EntitySerializer.js +155 -0
  192. package/bin/ECS/Serialization/EntitySerializer.js.map +1 -0
  193. package/bin/ECS/Serialization/IncrementalSerializer.d.ts +259 -0
  194. package/bin/ECS/Serialization/IncrementalSerializer.d.ts.map +1 -0
  195. package/bin/ECS/Serialization/IncrementalSerializer.js +500 -0
  196. package/bin/ECS/Serialization/IncrementalSerializer.js.map +1 -0
  197. package/bin/ECS/Serialization/SceneSerializer.d.ts +213 -0
  198. package/bin/ECS/Serialization/SceneSerializer.d.ts.map +1 -0
  199. package/bin/ECS/Serialization/SceneSerializer.js +387 -0
  200. package/bin/ECS/Serialization/SceneSerializer.js.map +1 -0
  201. package/bin/ECS/Serialization/SerializationDecorators.d.ts +136 -0
  202. package/bin/ECS/Serialization/SerializationDecorators.d.ts.map +1 -0
  203. package/bin/ECS/Serialization/SerializationDecorators.js +216 -0
  204. package/bin/ECS/Serialization/SerializationDecorators.js.map +1 -0
  205. package/bin/ECS/Serialization/VersionMigration.d.ts +156 -0
  206. package/bin/ECS/Serialization/VersionMigration.d.ts.map +1 -0
  207. package/bin/ECS/Serialization/VersionMigration.js +279 -0
  208. package/bin/ECS/Serialization/VersionMigration.js.map +1 -0
  209. package/bin/ECS/Serialization/index.d.ts +18 -0
  210. package/bin/ECS/Serialization/index.d.ts.map +1 -0
  211. package/bin/ECS/Serialization/index.js +18 -0
  212. package/bin/ECS/Serialization/index.js.map +1 -0
  213. package/bin/ECS/Systems/EntityCache.d.ts +114 -0
  214. package/bin/ECS/Systems/EntityCache.d.ts.map +1 -0
  215. package/bin/ECS/Systems/EntityCache.js +145 -0
  216. package/bin/ECS/Systems/EntityCache.js.map +1 -0
  217. package/bin/ECS/Systems/EntitySystem.d.ts +591 -0
  218. package/bin/ECS/Systems/EntitySystem.d.ts.map +1 -0
  219. package/bin/ECS/Systems/EntitySystem.js +1102 -0
  220. package/bin/ECS/Systems/EntitySystem.js.map +1 -0
  221. package/bin/ECS/Systems/HierarchySystem.d.ts +155 -0
  222. package/bin/ECS/Systems/HierarchySystem.d.ts.map +1 -0
  223. package/bin/ECS/Systems/HierarchySystem.js +498 -0
  224. package/bin/ECS/Systems/HierarchySystem.js.map +1 -0
  225. package/bin/ECS/Systems/IntervalSystem.d.ts +33 -0
  226. package/bin/ECS/Systems/IntervalSystem.d.ts.map +1 -0
  227. package/bin/ECS/Systems/IntervalSystem.js +50 -0
  228. package/bin/ECS/Systems/IntervalSystem.js.map +1 -0
  229. package/bin/ECS/Systems/PassiveSystem.d.ts +17 -0
  230. package/bin/ECS/Systems/PassiveSystem.d.ts.map +1 -0
  231. package/bin/ECS/Systems/PassiveSystem.js +19 -0
  232. package/bin/ECS/Systems/PassiveSystem.js.map +1 -0
  233. package/bin/ECS/Systems/ProcessingSystem.d.ts +21 -0
  234. package/bin/ECS/Systems/ProcessingSystem.d.ts.map +1 -0
  235. package/bin/ECS/Systems/ProcessingSystem.js +20 -0
  236. package/bin/ECS/Systems/ProcessingSystem.js.map +1 -0
  237. package/bin/ECS/Systems/WorkerEntitySystem.d.ts +313 -0
  238. package/bin/ECS/Systems/WorkerEntitySystem.d.ts.map +1 -0
  239. package/bin/ECS/Systems/WorkerEntitySystem.js +792 -0
  240. package/bin/ECS/Systems/WorkerEntitySystem.js.map +1 -0
  241. package/bin/ECS/Systems/index.d.ts +8 -0
  242. package/bin/ECS/Systems/index.d.ts.map +1 -0
  243. package/bin/ECS/Systems/index.js +8 -0
  244. package/bin/ECS/Systems/index.js.map +1 -0
  245. package/bin/ECS/TypedEntity.d.ts +192 -0
  246. package/bin/ECS/TypedEntity.d.ts.map +1 -0
  247. package/bin/ECS/TypedEntity.js +254 -0
  248. package/bin/ECS/TypedEntity.js.map +1 -0
  249. package/bin/ECS/Utils/BigIntCompatibility.d.ts +151 -0
  250. package/bin/ECS/Utils/BigIntCompatibility.d.ts.map +1 -0
  251. package/bin/ECS/Utils/BigIntCompatibility.js +476 -0
  252. package/bin/ECS/Utils/BigIntCompatibility.js.map +1 -0
  253. package/bin/ECS/Utils/BitMaskHashMap.d.ts +28 -0
  254. package/bin/ECS/Utils/BitMaskHashMap.d.ts.map +1 -0
  255. package/bin/ECS/Utils/BitMaskHashMap.js +127 -0
  256. package/bin/ECS/Utils/BitMaskHashMap.js.map +1 -0
  257. package/bin/ECS/Utils/Bits.d.ts +154 -0
  258. package/bin/ECS/Utils/Bits.d.ts.map +1 -0
  259. package/bin/ECS/Utils/Bits.js +331 -0
  260. package/bin/ECS/Utils/Bits.js.map +1 -0
  261. package/bin/ECS/Utils/ComponentSparseSet.d.ts +143 -0
  262. package/bin/ECS/Utils/ComponentSparseSet.d.ts.map +1 -0
  263. package/bin/ECS/Utils/ComponentSparseSet.js +347 -0
  264. package/bin/ECS/Utils/ComponentSparseSet.js.map +1 -0
  265. package/bin/ECS/Utils/EntityList.d.ts +115 -0
  266. package/bin/ECS/Utils/EntityList.d.ts.map +1 -0
  267. package/bin/ECS/Utils/EntityList.js +258 -0
  268. package/bin/ECS/Utils/EntityList.js.map +1 -0
  269. package/bin/ECS/Utils/EntityProcessorList.d.ts +56 -0
  270. package/bin/ECS/Utils/EntityProcessorList.d.ts.map +1 -0
  271. package/bin/ECS/Utils/EntityProcessorList.js +113 -0
  272. package/bin/ECS/Utils/EntityProcessorList.js.map +1 -0
  273. package/bin/ECS/Utils/IdentifierPool.d.ts +203 -0
  274. package/bin/ECS/Utils/IdentifierPool.d.ts.map +1 -0
  275. package/bin/ECS/Utils/IdentifierPool.js +325 -0
  276. package/bin/ECS/Utils/IdentifierPool.js.map +1 -0
  277. package/bin/ECS/Utils/Matcher.d.ts +171 -0
  278. package/bin/ECS/Utils/Matcher.d.ts.map +1 -0
  279. package/bin/ECS/Utils/Matcher.js +293 -0
  280. package/bin/ECS/Utils/Matcher.js.map +1 -0
  281. package/bin/ECS/Utils/SparseSet.d.ts +170 -0
  282. package/bin/ECS/Utils/SparseSet.d.ts.map +1 -0
  283. package/bin/ECS/Utils/SparseSet.js +280 -0
  284. package/bin/ECS/Utils/SparseSet.js.map +1 -0
  285. package/bin/ECS/Utils/index.d.ts +9 -0
  286. package/bin/ECS/Utils/index.d.ts.map +1 -0
  287. package/bin/ECS/Utils/index.js +10 -0
  288. package/bin/ECS/Utils/index.js.map +1 -0
  289. package/bin/ECS/World.d.ts +238 -0
  290. package/bin/ECS/World.d.ts.map +1 -0
  291. package/bin/ECS/World.js +416 -0
  292. package/bin/ECS/World.js.map +1 -0
  293. package/bin/ECS/WorldManager.d.ts +224 -0
  294. package/bin/ECS/WorldManager.d.ts.map +1 -0
  295. package/bin/ECS/WorldManager.js +365 -0
  296. package/bin/ECS/WorldManager.js.map +1 -0
  297. package/bin/ECS/index.d.ts +26 -0
  298. package/bin/ECS/index.d.ts.map +1 -0
  299. package/bin/ECS/index.js +21 -0
  300. package/bin/ECS/index.js.map +1 -0
  301. package/bin/Platform/IPlatformAdapter.d.ts +169 -0
  302. package/bin/Platform/IPlatformAdapter.d.ts.map +1 -0
  303. package/bin/Platform/IPlatformAdapter.js +2 -0
  304. package/bin/Platform/IPlatformAdapter.js.map +1 -0
  305. package/bin/Platform/PlatformDetector.d.ts +56 -0
  306. package/bin/Platform/PlatformDetector.d.ts.map +1 -0
  307. package/bin/Platform/PlatformDetector.js +247 -0
  308. package/bin/Platform/PlatformDetector.js.map +1 -0
  309. package/bin/Platform/PlatformManager.d.ts +50 -0
  310. package/bin/Platform/PlatformManager.d.ts.map +1 -0
  311. package/bin/Platform/PlatformManager.js +114 -0
  312. package/bin/Platform/PlatformManager.js.map +1 -0
  313. package/bin/Platform/index.d.ts +19 -0
  314. package/bin/Platform/index.d.ts.map +1 -0
  315. package/bin/Platform/index.js +29 -0
  316. package/bin/Platform/index.js.map +1 -0
  317. package/bin/Plugins/DebugPlugin.d.ts +156 -0
  318. package/bin/Plugins/DebugPlugin.d.ts.map +1 -0
  319. package/bin/Plugins/DebugPlugin.js +248 -0
  320. package/bin/Plugins/DebugPlugin.js.map +1 -0
  321. package/bin/Plugins/index.d.ts +2 -0
  322. package/bin/Plugins/index.d.ts.map +1 -0
  323. package/bin/Plugins/index.js +2 -0
  324. package/bin/Plugins/index.js.map +1 -0
  325. package/bin/Types/IUpdatable.d.ts +18 -0
  326. package/bin/Types/IUpdatable.d.ts.map +1 -0
  327. package/bin/Types/IUpdatable.js +7 -0
  328. package/bin/Types/IUpdatable.js.map +1 -0
  329. package/bin/Types/TypeHelpers.d.ts +238 -0
  330. package/bin/Types/TypeHelpers.d.ts.map +1 -0
  331. package/bin/Types/TypeHelpers.js +19 -0
  332. package/bin/Types/TypeHelpers.js.map +1 -0
  333. package/bin/Types/index.d.ts +466 -0
  334. package/bin/Types/index.d.ts.map +1 -0
  335. package/bin/Types/index.js +7 -0
  336. package/bin/Types/index.js.map +1 -0
  337. package/bin/Utils/BinarySerializer.d.ts +23 -0
  338. package/bin/Utils/BinarySerializer.d.ts.map +1 -0
  339. package/bin/Utils/BinarySerializer.js +100 -0
  340. package/bin/Utils/BinarySerializer.js.map +1 -0
  341. package/bin/Utils/Debug/AdvancedProfilerCollector.d.ts +153 -0
  342. package/bin/Utils/Debug/AdvancedProfilerCollector.d.ts.map +1 -0
  343. package/bin/Utils/Debug/AdvancedProfilerCollector.js +406 -0
  344. package/bin/Utils/Debug/AdvancedProfilerCollector.js.map +1 -0
  345. package/bin/Utils/Debug/ComponentDataCollector.d.ts +32 -0
  346. package/bin/Utils/Debug/ComponentDataCollector.d.ts.map +1 -0
  347. package/bin/Utils/Debug/ComponentDataCollector.js +250 -0
  348. package/bin/Utils/Debug/ComponentDataCollector.js.map +1 -0
  349. package/bin/Utils/Debug/DebugConfigService.d.ts +16 -0
  350. package/bin/Utils/Debug/DebugConfigService.d.ts.map +1 -0
  351. package/bin/Utils/Debug/DebugConfigService.js +42 -0
  352. package/bin/Utils/Debug/DebugConfigService.js.map +1 -0
  353. package/bin/Utils/Debug/DebugManager.d.ts +131 -0
  354. package/bin/Utils/Debug/DebugManager.d.ts.map +1 -0
  355. package/bin/Utils/Debug/DebugManager.js +848 -0
  356. package/bin/Utils/Debug/DebugManager.js.map +1 -0
  357. package/bin/Utils/Debug/EntityDataCollector.d.ts +115 -0
  358. package/bin/Utils/Debug/EntityDataCollector.d.ts.map +1 -0
  359. package/bin/Utils/Debug/EntityDataCollector.js +870 -0
  360. package/bin/Utils/Debug/EntityDataCollector.js.map +1 -0
  361. package/bin/Utils/Debug/PerformanceDataCollector.d.ts +31 -0
  362. package/bin/Utils/Debug/PerformanceDataCollector.d.ts.map +1 -0
  363. package/bin/Utils/Debug/PerformanceDataCollector.js +203 -0
  364. package/bin/Utils/Debug/PerformanceDataCollector.js.map +1 -0
  365. package/bin/Utils/Debug/SceneDataCollector.d.ts +18 -0
  366. package/bin/Utils/Debug/SceneDataCollector.d.ts.map +1 -0
  367. package/bin/Utils/Debug/SceneDataCollector.js +43 -0
  368. package/bin/Utils/Debug/SceneDataCollector.js.map +1 -0
  369. package/bin/Utils/Debug/SystemDataCollector.d.ts +14 -0
  370. package/bin/Utils/Debug/SystemDataCollector.d.ts.map +1 -0
  371. package/bin/Utils/Debug/SystemDataCollector.js +60 -0
  372. package/bin/Utils/Debug/SystemDataCollector.js.map +1 -0
  373. package/bin/Utils/Debug/WebSocketManager.d.ts +54 -0
  374. package/bin/Utils/Debug/WebSocketManager.d.ts.map +1 -0
  375. package/bin/Utils/Debug/WebSocketManager.js +141 -0
  376. package/bin/Utils/Debug/WebSocketManager.js.map +1 -0
  377. package/bin/Utils/Debug/index.d.ts +11 -0
  378. package/bin/Utils/Debug/index.d.ts.map +1 -0
  379. package/bin/Utils/Debug/index.js +10 -0
  380. package/bin/Utils/Debug/index.js.map +1 -0
  381. package/bin/Utils/Emitter.d.ts +61 -0
  382. package/bin/Utils/Emitter.d.ts.map +1 -0
  383. package/bin/Utils/Emitter.js +101 -0
  384. package/bin/Utils/Emitter.js.map +1 -0
  385. package/bin/Utils/Extensions/NumberExtension.d.ts +13 -0
  386. package/bin/Utils/Extensions/NumberExtension.d.ts.map +1 -0
  387. package/bin/Utils/Extensions/NumberExtension.js +17 -0
  388. package/bin/Utils/Extensions/NumberExtension.js.map +1 -0
  389. package/bin/Utils/Extensions/TypeUtils.d.ts +13 -0
  390. package/bin/Utils/Extensions/TypeUtils.d.ts.map +1 -0
  391. package/bin/Utils/Extensions/TypeUtils.js +15 -0
  392. package/bin/Utils/Extensions/TypeUtils.js.map +1 -0
  393. package/bin/Utils/Extensions/index.d.ts +3 -0
  394. package/bin/Utils/Extensions/index.d.ts.map +1 -0
  395. package/bin/Utils/Extensions/index.js +4 -0
  396. package/bin/Utils/Extensions/index.js.map +1 -0
  397. package/bin/Utils/GlobalManager.d.ts +29 -0
  398. package/bin/Utils/GlobalManager.d.ts.map +1 -0
  399. package/bin/Utils/GlobalManager.js +50 -0
  400. package/bin/Utils/GlobalManager.js.map +1 -0
  401. package/bin/Utils/Logger/ConsoleLogger.d.ts +74 -0
  402. package/bin/Utils/Logger/ConsoleLogger.d.ts.map +1 -0
  403. package/bin/Utils/Logger/ConsoleLogger.js +187 -0
  404. package/bin/Utils/Logger/ConsoleLogger.js.map +1 -0
  405. package/bin/Utils/Logger/Constants.d.ts +36 -0
  406. package/bin/Utils/Logger/Constants.d.ts.map +1 -0
  407. package/bin/Utils/Logger/Constants.js +40 -0
  408. package/bin/Utils/Logger/Constants.js.map +1 -0
  409. package/bin/Utils/Logger/LoggerManager.d.ts +91 -0
  410. package/bin/Utils/Logger/LoggerManager.d.ts.map +1 -0
  411. package/bin/Utils/Logger/LoggerManager.js +167 -0
  412. package/bin/Utils/Logger/LoggerManager.js.map +1 -0
  413. package/bin/Utils/Logger/Types.d.ts +40 -0
  414. package/bin/Utils/Logger/Types.d.ts.map +1 -0
  415. package/bin/Utils/Logger/Types.js +2 -0
  416. package/bin/Utils/Logger/Types.js.map +1 -0
  417. package/bin/Utils/Logger/index.d.ts +5 -0
  418. package/bin/Utils/Logger/index.d.ts.map +1 -0
  419. package/bin/Utils/Logger/index.js +5 -0
  420. package/bin/Utils/Logger/index.js.map +1 -0
  421. package/bin/Utils/PerformanceMonitor.d.ts +196 -0
  422. package/bin/Utils/PerformanceMonitor.d.ts.map +1 -0
  423. package/bin/Utils/PerformanceMonitor.js +244 -0
  424. package/bin/Utils/PerformanceMonitor.js.map +1 -0
  425. package/bin/Utils/Pool/IPoolable.d.ts +29 -0
  426. package/bin/Utils/Pool/IPoolable.d.ts.map +1 -0
  427. package/bin/Utils/Pool/IPoolable.js +2 -0
  428. package/bin/Utils/Pool/IPoolable.js.map +1 -0
  429. package/bin/Utils/Pool/Pool.d.ts +109 -0
  430. package/bin/Utils/Pool/Pool.d.ts.map +1 -0
  431. package/bin/Utils/Pool/Pool.js +238 -0
  432. package/bin/Utils/Pool/Pool.js.map +1 -0
  433. package/bin/Utils/Pool/PoolManager.d.ts +96 -0
  434. package/bin/Utils/Pool/PoolManager.d.ts.map +1 -0
  435. package/bin/Utils/Pool/PoolManager.js +199 -0
  436. package/bin/Utils/Pool/PoolManager.js.map +1 -0
  437. package/bin/Utils/Pool/index.d.ts +4 -0
  438. package/bin/Utils/Pool/index.d.ts.map +1 -0
  439. package/bin/Utils/Pool/index.js +4 -0
  440. package/bin/Utils/Pool/index.js.map +1 -0
  441. package/bin/Utils/Profiler/AutoProfiler.d.ts +160 -0
  442. package/bin/Utils/Profiler/AutoProfiler.d.ts.map +1 -0
  443. package/bin/Utils/Profiler/AutoProfiler.js +503 -0
  444. package/bin/Utils/Profiler/AutoProfiler.js.map +1 -0
  445. package/bin/Utils/Profiler/ProfilerSDK.d.ts +175 -0
  446. package/bin/Utils/Profiler/ProfilerSDK.d.ts.map +1 -0
  447. package/bin/Utils/Profiler/ProfilerSDK.js +727 -0
  448. package/bin/Utils/Profiler/ProfilerSDK.js.map +1 -0
  449. package/bin/Utils/Profiler/ProfilerTypes.d.ts +218 -0
  450. package/bin/Utils/Profiler/ProfilerTypes.d.ts.map +1 -0
  451. package/bin/Utils/Profiler/ProfilerTypes.js +47 -0
  452. package/bin/Utils/Profiler/ProfilerTypes.js.map +1 -0
  453. package/bin/Utils/Profiler/index.d.ts +8 -0
  454. package/bin/Utils/Profiler/index.d.ts.map +1 -0
  455. package/bin/Utils/Profiler/index.js +7 -0
  456. package/bin/Utils/Profiler/index.js.map +1 -0
  457. package/bin/Utils/Time.d.ts +47 -0
  458. package/bin/Utils/Time.d.ts.map +1 -0
  459. package/bin/Utils/Time.js +64 -0
  460. package/bin/Utils/Time.js.map +1 -0
  461. package/bin/Utils/Timers/ITimer.d.ts +16 -0
  462. package/bin/Utils/Timers/ITimer.d.ts.map +1 -0
  463. package/bin/Utils/Timers/ITimer.js +2 -0
  464. package/bin/Utils/Timers/ITimer.js.map +1 -0
  465. package/bin/Utils/Timers/Timer.d.ts +30 -0
  466. package/bin/Utils/Timers/Timer.d.ts.map +1 -0
  467. package/bin/Utils/Timers/Timer.js +58 -0
  468. package/bin/Utils/Timers/Timer.js.map +1 -0
  469. package/bin/Utils/Timers/TimerManager.d.ts +26 -0
  470. package/bin/Utils/Timers/TimerManager.d.ts.map +1 -0
  471. package/bin/Utils/Timers/TimerManager.js +48 -0
  472. package/bin/Utils/Timers/TimerManager.js.map +1 -0
  473. package/bin/Utils/index.d.ts +11 -0
  474. package/bin/Utils/index.d.ts.map +1 -0
  475. package/bin/Utils/index.js +11 -0
  476. package/bin/Utils/index.js.map +1 -0
  477. package/bin/index.d.ts +29 -0
  478. package/bin/index.d.ts.map +1 -0
  479. package/bin/index.js +36 -0
  480. package/bin/index.js.map +1 -0
  481. package/package.json +84 -47
  482. package/LICENSE +0 -21
  483. package/index.cjs +0 -2
  484. package/index.cjs.map +0 -1
  485. package/index.d.ts +0 -13021
  486. package/index.es5.js +0 -4
  487. package/index.es5.js.map +0 -1
  488. package/index.mjs +0 -2
  489. package/index.mjs.map +0 -1
  490. package/index.umd.js +0 -4
  491. package/index.umd.js.map +0 -1
@@ -0,0 +1,792 @@
1
+ import { EntitySystem } from './EntitySystem';
2
+ import { Time } from '../../Utils/Time';
3
+ import { PlatformManager } from '../../Platform/PlatformManager';
4
+ import { getSystemInstanceTypeName } from '../Decorators';
5
+ /**
6
+ * 支持Worker并行处理的EntitySystem基类
7
+ *
8
+ * 支持传统Worker和SharedArrayBuffer两种优化模式:
9
+ * - 传统模式:数据序列化传输,适用于复杂计算
10
+ * - SharedArrayBuffer模式:零拷贝数据共享,适用于大量简单计算
11
+ *
12
+ * 用户需要实现:
13
+ * 1. extractEntityData - 定义数据提取逻辑
14
+ * 2. workerProcess - 编写处理函数(纯函数,可序列化)
15
+ * 3. applyResult - 定义结果应用逻辑
16
+ * 4. (可选) SharedArrayBuffer相关方法
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * class PhysicsSystem extends WorkerEntitySystem<PhysicsData> {
21
+ * constructor() {
22
+ * super(Matcher.all(Transform, Velocity), {
23
+ * enableWorker: true,
24
+ * workerCount: 8, // 指定8个worker,系统会自动限制在系统最大值内
25
+ * entitiesPerWorker: 100, // 每个worker处理100个实体
26
+ * useSharedArrayBuffer: true,
27
+ * entityDataSize: 6, // x, y, vx, vy, radius, mass
28
+ * maxEntities: 10000,
29
+ * systemConfig: { gravity: 100, friction: 0.95 }
30
+ * });
31
+ * }
32
+ *
33
+ * protected getDefaultEntityDataSize(): number {
34
+ * return 6; // x, y, vx, vy, radius, mass
35
+ * }
36
+ *
37
+ * protected extractEntityData(entity: Entity): PhysicsData {
38
+ * const transform = entity.getComponent(Transform);
39
+ * const velocity = entity.getComponent(Velocity);
40
+ * const physics = entity.getComponent(PhysicsComponent);
41
+ * return {
42
+ * x: transform.x,
43
+ * y: transform.y,
44
+ * vx: velocity.x,
45
+ * vy: velocity.y,
46
+ * radius: physics.radius,
47
+ * mass: physics.mass
48
+ * };
49
+ * }
50
+ *
51
+ * protected workerProcess(entities: PhysicsData[], deltaTime: number, config: any): PhysicsData[] {
52
+ * return entities.map(entity => {
53
+ * // 应用重力
54
+ * entity.vy += config.gravity * deltaTime;
55
+ *
56
+ * // 更新位置
57
+ * entity.x += entity.vx * deltaTime;
58
+ * entity.y += entity.vy * deltaTime;
59
+ *
60
+ * // 应用摩擦力
61
+ * entity.vx *= config.friction;
62
+ * entity.vy *= config.friction;
63
+ *
64
+ * return entity;
65
+ * });
66
+ * }
67
+ *
68
+ * protected applyResult(entity: Entity, result: PhysicsData): void {
69
+ * const transform = entity.getComponent(Transform);
70
+ * const velocity = entity.getComponent(Velocity);
71
+ *
72
+ * transform.x = result.x;
73
+ * transform.y = result.y;
74
+ * velocity.x = result.vx;
75
+ * velocity.y = result.vy;
76
+ * }
77
+ *
78
+ * // SharedArrayBuffer优化支持
79
+ * protected writeEntityToBuffer(entityData: PhysicsData, offset: number): void {
80
+ * if (!this.sharedFloatArray) return;
81
+ *
82
+ * this.sharedFloatArray[offset] = entityData.x;
83
+ * this.sharedFloatArray[offset + 1] = entityData.y;
84
+ * this.sharedFloatArray[offset + 2] = entityData.vx;
85
+ * this.sharedFloatArray[offset + 3] = entityData.vy;
86
+ * this.sharedFloatArray[offset + 4] = entityData.radius;
87
+ * this.sharedFloatArray[offset + 5] = entityData.mass;
88
+ * }
89
+ *
90
+ * protected readEntityFromBuffer(offset: number): PhysicsData | null {
91
+ * if (!this.sharedFloatArray) return null;
92
+ *
93
+ * return {
94
+ * x: this.sharedFloatArray[offset],
95
+ * y: this.sharedFloatArray[offset + 1],
96
+ * vx: this.sharedFloatArray[offset + 2],
97
+ * vy: this.sharedFloatArray[offset + 3],
98
+ * radius: this.sharedFloatArray[offset + 4],
99
+ * mass: this.sharedFloatArray[offset + 5]
100
+ * };
101
+ * }
102
+ *
103
+ * protected getSharedArrayBufferProcessFunction(): SharedArrayBufferProcessFunction {
104
+ * return function(sharedFloatArray: Float32Array, startIndex: number, endIndex: number, deltaTime: number, config: any) {
105
+ * const entitySize = 6;
106
+ * for (let i = startIndex; i < endIndex; i++) {
107
+ * const offset = i * entitySize;
108
+ *
109
+ * // 读取数据
110
+ * let x = sharedFloatArray[offset];
111
+ * let y = sharedFloatArray[offset + 1];
112
+ * let vx = sharedFloatArray[offset + 2];
113
+ * let vy = sharedFloatArray[offset + 3];
114
+ * const radius = sharedFloatArray[offset + 4];
115
+ * const mass = sharedFloatArray[offset + 5];
116
+ *
117
+ * // 物理计算
118
+ * vy += config.gravity * deltaTime;
119
+ * x += vx * deltaTime;
120
+ * y += vy * deltaTime;
121
+ * vx *= config.friction;
122
+ * vy *= config.friction;
123
+ *
124
+ * // 写回数据
125
+ * sharedFloatArray[offset] = x;
126
+ * sharedFloatArray[offset + 1] = y;
127
+ * sharedFloatArray[offset + 2] = vx;
128
+ * sharedFloatArray[offset + 3] = vy;
129
+ * }
130
+ * };
131
+ * }
132
+ * }
133
+ *
134
+ * interface PhysicsData {
135
+ * x: number;
136
+ * y: number;
137
+ * vx: number;
138
+ * vy: number;
139
+ * radius: number;
140
+ * mass: number;
141
+ * }
142
+ * ```
143
+ */
144
+ export class WorkerEntitySystem extends EntitySystem {
145
+ constructor(matcher, config = {}) {
146
+ super(matcher);
147
+ this.workerPool = null;
148
+ this.isProcessing = false;
149
+ this.sharedBuffer = null;
150
+ this.sharedFloatArray = null;
151
+ this.hasLoggedSyncMode = false;
152
+ // 获取平台适配器
153
+ this.platformAdapter = PlatformManager.getInstance().getAdapter();
154
+ // 验证和调整 worker 数量,确保不超过系统最大值
155
+ const requestedWorkerCount = config.workerCount ?? this.getMaxSystemWorkerCount();
156
+ const maxSystemWorkerCount = this.getMaxSystemWorkerCount();
157
+ const validatedWorkerCount = Math.min(requestedWorkerCount, maxSystemWorkerCount);
158
+ // 如果用户请求的数量超过系统最大值,给出警告
159
+ if (requestedWorkerCount > maxSystemWorkerCount) {
160
+ this.logger.warn(`请求 ${requestedWorkerCount} 个Worker,但系统最多支持 ${maxSystemWorkerCount} 个。实际使用 ${validatedWorkerCount} 个Worker。`);
161
+ }
162
+ this.config = {
163
+ enableWorker: config.enableWorker ?? true,
164
+ workerCount: validatedWorkerCount,
165
+ systemConfig: config.systemConfig,
166
+ ...(config.entitiesPerWorker !== undefined && { entitiesPerWorker: config.entitiesPerWorker }),
167
+ useSharedArrayBuffer: config.useSharedArrayBuffer ?? this.isSharedArrayBufferSupported(),
168
+ entityDataSize: config.entityDataSize ?? this.getDefaultEntityDataSize(),
169
+ maxEntities: config.maxEntities ?? 10000
170
+ };
171
+ if (this.config.enableWorker && this.isWorkerSupported()) {
172
+ // 先初始化SharedArrayBuffer,再初始化Worker池
173
+ if (this.config.useSharedArrayBuffer) {
174
+ this.initializeSharedArrayBuffer();
175
+ }
176
+ this.initializeWorkerPool();
177
+ }
178
+ }
179
+ /**
180
+ * 检查是否支持Worker
181
+ */
182
+ isWorkerSupported() {
183
+ return this.platformAdapter.isWorkerSupported();
184
+ }
185
+ /**
186
+ * 检查是否支持SharedArrayBuffer
187
+ */
188
+ isSharedArrayBufferSupported() {
189
+ return this.platformAdapter.isSharedArrayBufferSupported();
190
+ }
191
+ /**
192
+ * 获取系统支持的最大Worker数量
193
+ */
194
+ getMaxSystemWorkerCount() {
195
+ const platformConfig = this.platformAdapter.getPlatformConfig();
196
+ return platformConfig.maxWorkerCount;
197
+ }
198
+ /**
199
+ * 初始化SharedArrayBuffer
200
+ */
201
+ initializeSharedArrayBuffer() {
202
+ try {
203
+ // 检查是否支持SharedArrayBuffer
204
+ if (!this.isSharedArrayBufferSupported()) {
205
+ this.logger.warn(`${this.systemName}: 平台不支持SharedArrayBuffer,降级到单Worker模式以保证数据处理完整性`);
206
+ this.config.useSharedArrayBuffer = false;
207
+ // 降级到单Worker模式:确保所有实体在同一个Worker中处理,维持实体间交互的完整性
208
+ this.config.workerCount = 1;
209
+ return;
210
+ }
211
+ // 使用配置的实体数据大小和最大实体数量
212
+ // 预分配缓冲区:maxEntities * entityDataSize * 4字节
213
+ const bufferSize = this.config.maxEntities * this.config.entityDataSize * 4;
214
+ this.sharedBuffer = this.platformAdapter.createSharedArrayBuffer(bufferSize);
215
+ if (this.sharedBuffer) {
216
+ this.sharedFloatArray = new Float32Array(this.sharedBuffer);
217
+ }
218
+ this.logger.info(`${this.systemName}: SharedArrayBuffer初始化成功 (${bufferSize} 字节)`);
219
+ }
220
+ catch (error) {
221
+ this.logger.warn(`${this.systemName}: SharedArrayBuffer初始化失败,降级到单Worker模式以保证数据处理完整性`, error);
222
+ this.config.useSharedArrayBuffer = false;
223
+ this.sharedBuffer = null;
224
+ this.sharedFloatArray = null;
225
+ this.config.workerCount = 1;
226
+ }
227
+ }
228
+ /**
229
+ * 初始化Worker池
230
+ */
231
+ initializeWorkerPool() {
232
+ try {
233
+ const script = this.createWorkerScript();
234
+ // 在WorkerEntitySystem中处理平台相关逻辑
235
+ const workers = [];
236
+ const platformConfig = this.platformAdapter.getPlatformConfig();
237
+ const fullScript = (platformConfig.workerScriptPrefix || '') + script;
238
+ for (let i = 0; i < this.config.workerCount; i++) {
239
+ try {
240
+ const worker = this.platformAdapter.createWorker(fullScript, {
241
+ name: `WorkerEntitySystem-${i}`
242
+ });
243
+ workers.push(worker);
244
+ }
245
+ catch (error) {
246
+ this.logger.error(`创建Worker ${i} 失败:`, error);
247
+ throw error;
248
+ }
249
+ }
250
+ this.workerPool = new PlatformWorkerPool(workers);
251
+ }
252
+ catch (error) {
253
+ this.logger.error(`${this.systemName}: Worker池初始化失败`, error);
254
+ this.config.enableWorker = false;
255
+ }
256
+ }
257
+ /**
258
+ * 创建Worker脚本
259
+ */
260
+ createWorkerScript() {
261
+ // 获取方法字符串并提取函数体
262
+ const methodStr = this.workerProcess.toString();
263
+ // 提取函数体部分(去掉方法签名)
264
+ const functionBodyMatch = methodStr.match(/\{([\s\S]*)\}/);
265
+ if (!functionBodyMatch) {
266
+ throw new Error('无法解析workerProcess方法');
267
+ }
268
+ const functionBody = functionBodyMatch[1];
269
+ const entityDataSize = this.config.entityDataSize;
270
+ // 获取SharedArrayBuffer处理函数的字符串
271
+ const sharedProcessMethod = this.getSharedArrayBufferProcessFunction?.() || null;
272
+ let sharedProcessFunctionBody = '';
273
+ if (sharedProcessMethod) {
274
+ const sharedMethodStr = sharedProcessMethod.toString();
275
+ const sharedFunctionBodyMatch = sharedMethodStr.match(/\{([\s\S]*)\}/);
276
+ if (sharedFunctionBodyMatch) {
277
+ sharedProcessFunctionBody = sharedFunctionBodyMatch[1] ?? '';
278
+ }
279
+ }
280
+ return `
281
+ // Worker脚本 - 支持SharedArrayBuffer
282
+ let sharedFloatArray = null;
283
+ const ENTITY_DATA_SIZE = ${entityDataSize};
284
+
285
+ self.onmessage = function(e) {
286
+ const { type, id, entities, deltaTime, systemConfig, startIndex, endIndex, sharedBuffer } = e.data;
287
+
288
+
289
+ try {
290
+ // 处理SharedArrayBuffer初始化
291
+ if (type === 'init' && sharedBuffer) {
292
+ sharedFloatArray = new Float32Array(sharedBuffer);
293
+ self.postMessage({ type: 'init', success: true });
294
+ return;
295
+ }
296
+
297
+ // 处理SharedArrayBuffer数据
298
+ if (type === 'shared' && sharedFloatArray) {
299
+ processSharedArrayBuffer(startIndex, endIndex, deltaTime, systemConfig);
300
+ self.postMessage({ id, result: null }); // SharedArrayBuffer不需要返回数据
301
+ return;
302
+ }
303
+
304
+ // 传统处理方式
305
+ if (entities) {
306
+ // 定义处理函数
307
+ function workerProcess(entities, deltaTime, systemConfig) {
308
+ ${functionBody}
309
+ }
310
+
311
+ // 执行处理
312
+ const result = workerProcess(entities, deltaTime, systemConfig);
313
+
314
+ // 处理Promise返回值
315
+ if (result && typeof result.then === 'function') {
316
+ result.then(finalResult => {
317
+ self.postMessage({ id, result: finalResult });
318
+ }).catch(error => {
319
+ self.postMessage({ id, error: error.message });
320
+ });
321
+ } else {
322
+ self.postMessage({ id, result });
323
+ }
324
+ }
325
+ } catch (error) {
326
+ self.postMessage({ id, error: error.message });
327
+ }
328
+ };
329
+
330
+ // SharedArrayBuffer处理函数 - 由子类定义
331
+ function processSharedArrayBuffer(startIndex, endIndex, deltaTime, systemConfig) {
332
+ if (!sharedFloatArray) return;
333
+
334
+ ${sharedProcessFunctionBody ? `
335
+ // 用户定义的处理函数
336
+ const userProcessFunction = function(sharedFloatArray, startIndex, endIndex, deltaTime, systemConfig) {
337
+ ${sharedProcessFunctionBody}
338
+ };
339
+ userProcessFunction(sharedFloatArray, startIndex, endIndex, deltaTime, systemConfig);
340
+ ` : ''}
341
+ }
342
+ `;
343
+ }
344
+ /**
345
+ * 重写process方法,支持Worker并行处理
346
+ */
347
+ process(entities) {
348
+ if (this.isProcessing)
349
+ return;
350
+ this.isProcessing = true;
351
+ try {
352
+ if (this.config.enableWorker && this.workerPool) {
353
+ // 检查SharedArrayBuffer是否真正可用
354
+ if (this.config.useSharedArrayBuffer && this.sharedFloatArray && this.isSharedArrayBufferSupported()) {
355
+ // 使用SharedArrayBuffer优化的异步处理
356
+ this.processWithSharedArrayBuffer(entities).finally(() => {
357
+ this.isProcessing = false;
358
+ });
359
+ }
360
+ else {
361
+ // 如果配置了SharedArrayBuffer但不可用,记录降级信息
362
+ if (this.config.useSharedArrayBuffer) {
363
+ this.logger.info(`${this.systemName}: 本帧降级到传统Worker模式`);
364
+ }
365
+ // 传统Worker异步处理
366
+ this.processWithWorker(entities).finally(() => {
367
+ this.isProcessing = false;
368
+ });
369
+ }
370
+ }
371
+ else {
372
+ // 同步处理(最后的fallback)
373
+ if (!this.hasLoggedSyncMode) {
374
+ this.logger.info(`${this.systemName}: Worker不可用,使用同步处理`);
375
+ this.hasLoggedSyncMode = true;
376
+ }
377
+ this.processSynchronously(entities);
378
+ this.isProcessing = false;
379
+ }
380
+ }
381
+ catch (error) {
382
+ this.isProcessing = false;
383
+ this.logger.error(`${this.systemName}: 处理失败`, error);
384
+ throw error;
385
+ }
386
+ }
387
+ /**
388
+ * 使用SharedArrayBuffer优化的Worker处理
389
+ */
390
+ async processWithSharedArrayBuffer(entities) {
391
+ if (!this.sharedFloatArray) {
392
+ throw new Error('SharedArrayBuffer not initialized');
393
+ }
394
+ // 1. 将实体数据写入SharedArrayBuffer
395
+ this.writeEntitiesToSharedBuffer(entities);
396
+ // 2. 通知Workers处理数据
397
+ const promises = this.createSharedArrayBufferTasks(entities.length);
398
+ await Promise.all(promises);
399
+ // 3. 从SharedArrayBuffer读取结果并应用
400
+ this.readResultsFromSharedBuffer(entities);
401
+ }
402
+ /**
403
+ * 使用Worker并行处理
404
+ */
405
+ async processWithWorker(entities) {
406
+ // 1. 数据提取阶段
407
+ const entityData = [];
408
+ for (let i = 0; i < entities.length; i++) {
409
+ entityData[i] = this.extractEntityData(entities[i]);
410
+ }
411
+ // 2. 分批处理
412
+ const batches = this.createBatches(entityData);
413
+ const deltaTime = Time.deltaTime;
414
+ // 3. Worker执行阶段
415
+ const promises = batches.map((batch) => this.workerPool.execute({
416
+ entities: batch,
417
+ deltaTime,
418
+ systemConfig: this.config.systemConfig
419
+ }));
420
+ const results = await Promise.all(promises);
421
+ // 4. 结果应用阶段
422
+ let entityIndex = 0;
423
+ for (const batchResult of results) {
424
+ for (const result of batchResult) {
425
+ if (entityIndex < entities.length) {
426
+ const entity = entities[entityIndex];
427
+ // 只对有效实体应用结果
428
+ if (entity && result) {
429
+ this.applyResult(entity, result);
430
+ }
431
+ }
432
+ entityIndex++;
433
+ }
434
+ }
435
+ }
436
+ /**
437
+ * 同步处理(fallback)
438
+ */
439
+ processSynchronously(entities) {
440
+ // 1. 数据提取阶段
441
+ const entityData = entities.map((entity) => this.extractEntityData(entity));
442
+ // 2. 主线程处理阶段
443
+ const deltaTime = Time.deltaTime;
444
+ const results = this.workerProcess(entityData, deltaTime, this.config.systemConfig);
445
+ // 3. 结果应用阶段
446
+ // 处理Promise返回值
447
+ if (results && typeof results.then === 'function') {
448
+ results.then((finalResults) => {
449
+ entities.forEach((entity, index) => {
450
+ this.applyResult(entity, finalResults[index]);
451
+ });
452
+ });
453
+ }
454
+ else {
455
+ entities.forEach((entity, index) => {
456
+ this.applyResult(entity, results[index]);
457
+ });
458
+ }
459
+ }
460
+ /**
461
+ * 创建数据批次 - 支持用户指定每个Worker的实体数量
462
+ */
463
+ createBatches(data) {
464
+ const workerCount = this.config.workerCount;
465
+ const batches = [];
466
+ // 如果用户指定了每个Worker处理的实体数量
467
+ if (this.config.entitiesPerWorker) {
468
+ const entitiesPerWorker = this.config.entitiesPerWorker;
469
+ for (let i = 0; i < data.length; i += entitiesPerWorker) {
470
+ const endIndex = Math.min(i + entitiesPerWorker, data.length);
471
+ batches.push(data.slice(i, endIndex));
472
+ }
473
+ // 限制批次数量不超过Worker数量
474
+ if (batches.length > workerCount) {
475
+ this.logger.warn(`${this.systemName}: 创建了 ${batches.length} 个批次,但只有 ${workerCount} 个Worker。某些Worker将依次处理多个批次。`);
476
+ }
477
+ }
478
+ else {
479
+ // 默认行为:按Worker数量平均分配
480
+ const batchSize = Math.ceil(data.length / workerCount);
481
+ for (let i = 0; i < workerCount; i++) {
482
+ const startIndex = i * batchSize;
483
+ const endIndex = Math.min(startIndex + batchSize, data.length);
484
+ if (startIndex < data.length) {
485
+ batches.push(data.slice(startIndex, endIndex));
486
+ }
487
+ }
488
+ }
489
+ return batches;
490
+ }
491
+ /**
492
+ * 将实体数据写入SharedArrayBuffer
493
+ */
494
+ writeEntitiesToSharedBuffer(entities) {
495
+ if (!this.sharedFloatArray)
496
+ return;
497
+ for (let i = 0; i < entities.length && i < this.config.maxEntities; i++) {
498
+ const entity = entities[i];
499
+ const data = this.extractEntityData(entity);
500
+ const offset = i * this.config.entityDataSize; // 使用配置的数据大小
501
+ // 使用子类提供的数据提取方法,然后转换为标准格式
502
+ this.writeEntityToBuffer(data, offset);
503
+ }
504
+ }
505
+ /**
506
+ * 创建SharedArrayBuffer任务 - 支持用户指定每个Worker的实体数量
507
+ */
508
+ createSharedArrayBufferTasks(entityCount) {
509
+ const promises = [];
510
+ // 如果用户指定了每个Worker处理的实体数量
511
+ if (this.config.entitiesPerWorker) {
512
+ const entitiesPerWorker = this.config.entitiesPerWorker;
513
+ const tasksNeeded = Math.ceil(entityCount / entitiesPerWorker);
514
+ const availableWorkers = this.config.workerCount;
515
+ // 如果任务数超过Worker数量,警告用户
516
+ if (tasksNeeded > availableWorkers) {
517
+ this.logger.warn(`${this.systemName}: 需要 ${tasksNeeded} 个任务处理 ${entityCount} 个实体(每任务 ${entitiesPerWorker} 个),但只有 ${availableWorkers} 个Worker。某些Worker将依次处理多个任务。`);
518
+ }
519
+ for (let i = 0; i < entityCount; i += entitiesPerWorker) {
520
+ const startIndex = i;
521
+ const endIndex = Math.min(i + entitiesPerWorker, entityCount);
522
+ const promise = this.workerPool.executeSharedBuffer({
523
+ startIndex,
524
+ endIndex,
525
+ deltaTime: Time.deltaTime,
526
+ systemConfig: this.config.systemConfig
527
+ });
528
+ promises.push(promise);
529
+ }
530
+ }
531
+ else {
532
+ // 默认行为:按Worker数量平均分配
533
+ const entitiesPerWorker = Math.ceil(entityCount / this.config.workerCount);
534
+ for (let i = 0; i < this.config.workerCount; i++) {
535
+ const startIndex = i * entitiesPerWorker;
536
+ const endIndex = Math.min(startIndex + entitiesPerWorker, entityCount);
537
+ if (startIndex < entityCount) {
538
+ const promise = this.workerPool.executeSharedBuffer({
539
+ startIndex,
540
+ endIndex,
541
+ deltaTime: Time.deltaTime,
542
+ systemConfig: this.config.systemConfig
543
+ });
544
+ promises.push(promise);
545
+ }
546
+ }
547
+ }
548
+ return promises;
549
+ }
550
+ /**
551
+ * 从SharedArrayBuffer读取结果并应用
552
+ */
553
+ readResultsFromSharedBuffer(entities) {
554
+ if (!this.sharedFloatArray)
555
+ return;
556
+ for (let i = 0; i < entities.length && i < this.config.maxEntities; i++) {
557
+ const entity = entities[i];
558
+ const offset = i * this.config.entityDataSize; // 使用配置的数据大小
559
+ // 从SharedArrayBuffer读取数据
560
+ const result = this.readEntityFromBuffer(offset);
561
+ if (result) {
562
+ this.applyResult(entity, result);
563
+ }
564
+ }
565
+ }
566
+ /**
567
+ * 更新Worker配置
568
+ */
569
+ updateConfig(newConfig) {
570
+ const oldConfig = { ...this.config };
571
+ // 如果更新了workerCount,需要验证并调整
572
+ if (newConfig.workerCount !== undefined) {
573
+ const maxSystemWorkerCount = this.getMaxSystemWorkerCount();
574
+ const validatedWorkerCount = Math.min(newConfig.workerCount, maxSystemWorkerCount);
575
+ if (newConfig.workerCount > maxSystemWorkerCount) {
576
+ this.logger.warn(`请求 ${newConfig.workerCount} 个Worker,但系统最多支持 ${maxSystemWorkerCount} 个。实际使用 ${validatedWorkerCount} 个Worker。`);
577
+ }
578
+ newConfig.workerCount = validatedWorkerCount;
579
+ }
580
+ Object.assign(this.config, newConfig);
581
+ // 如果 SharedArrayBuffer 设置发生变化,需要重新初始化
582
+ if (oldConfig.useSharedArrayBuffer !== this.config.useSharedArrayBuffer) {
583
+ this.reinitializeWorkerSystem();
584
+ return;
585
+ }
586
+ // 如果 Worker 数量发生变化,需要重新创建 Worker 池
587
+ if (oldConfig.workerCount !== this.config.workerCount) {
588
+ this.reinitializeWorkerPool();
589
+ return;
590
+ }
591
+ // 如果禁用Worker,清理Worker池
592
+ if (!this.config.enableWorker && this.workerPool) {
593
+ this.workerPool.destroy();
594
+ this.workerPool = null;
595
+ }
596
+ // 如果启用Worker但池不存在,重新创建
597
+ if (this.config.enableWorker && !this.workerPool && this.isWorkerSupported()) {
598
+ this.initializeWorkerPool();
599
+ }
600
+ }
601
+ /**
602
+ * 重新初始化整个 Worker 系统(包括 SharedArrayBuffer)
603
+ */
604
+ reinitializeWorkerSystem() {
605
+ // 清理现有资源
606
+ if (this.workerPool) {
607
+ this.workerPool.destroy();
608
+ this.workerPool = null;
609
+ }
610
+ this.sharedBuffer = null;
611
+ this.sharedFloatArray = null;
612
+ // 如果禁用 SharedArrayBuffer,降级到单 Worker 模式
613
+ if (!this.config.useSharedArrayBuffer) {
614
+ this.config.workerCount = 1;
615
+ }
616
+ // 重新初始化
617
+ if (this.config.enableWorker && this.isWorkerSupported()) {
618
+ if (this.config.useSharedArrayBuffer) {
619
+ this.initializeSharedArrayBuffer();
620
+ }
621
+ this.initializeWorkerPool();
622
+ }
623
+ }
624
+ /**
625
+ * 重新初始化 Worker 池(保持 SharedArrayBuffer)
626
+ */
627
+ reinitializeWorkerPool() {
628
+ if (this.workerPool) {
629
+ this.workerPool.destroy();
630
+ this.workerPool = null;
631
+ }
632
+ if (this.config.enableWorker && this.isWorkerSupported()) {
633
+ this.initializeWorkerPool();
634
+ }
635
+ }
636
+ /**
637
+ * 获取系统性能信息
638
+ */
639
+ getWorkerInfo() {
640
+ let currentMode = 'sync';
641
+ if (this.config.enableWorker && this.workerPool) {
642
+ if (this.config.useSharedArrayBuffer && this.sharedFloatArray && this.isSharedArrayBufferSupported()) {
643
+ currentMode = 'shared-buffer';
644
+ }
645
+ else {
646
+ currentMode = 'worker';
647
+ }
648
+ }
649
+ return {
650
+ enabled: this.config.enableWorker,
651
+ workerCount: this.config.workerCount,
652
+ ...(this.config.entitiesPerWorker !== undefined && { entitiesPerWorker: this.config.entitiesPerWorker }),
653
+ maxSystemWorkerCount: this.getMaxSystemWorkerCount(),
654
+ isProcessing: this.isProcessing,
655
+ sharedArrayBufferSupported: this.isSharedArrayBufferSupported(),
656
+ sharedArrayBufferEnabled: this.config.useSharedArrayBuffer,
657
+ currentMode
658
+ };
659
+ }
660
+ /**
661
+ * 销毁系统时清理Worker池
662
+ */
663
+ onDestroy() {
664
+ super.onDestroy();
665
+ if (this.workerPool) {
666
+ this.workerPool.destroy();
667
+ this.workerPool = null;
668
+ }
669
+ }
670
+ getLoggerName() {
671
+ return getSystemInstanceTypeName(this);
672
+ }
673
+ }
674
+ /**
675
+ * 平台适配的Worker池管理器
676
+ */
677
+ class PlatformWorkerPool {
678
+ constructor(workers) {
679
+ this.workers = [];
680
+ this.taskQueue = [];
681
+ this.busyWorkers = new Set();
682
+ this.taskCounter = 0;
683
+ this.workers = workers;
684
+ // 为每个Worker设置消息处理器
685
+ for (let i = 0; i < workers.length; i++) {
686
+ const worker = workers[i];
687
+ if (!worker)
688
+ continue;
689
+ // 设置消息处理器
690
+ worker.onMessage((event) => this.handleWorkerMessage(i, event.data));
691
+ worker.onError((error) => this.handleWorkerError(i, error));
692
+ }
693
+ }
694
+ /**
695
+ * 执行SharedArrayBuffer任务
696
+ */
697
+ executeSharedBuffer(data) {
698
+ return new Promise((resolve, reject) => {
699
+ const task = {
700
+ id: `shared-task-${++this.taskCounter}`,
701
+ data: { ...data, type: 'shared' },
702
+ resolve: () => resolve(), // SharedArrayBuffer不需要返回数据
703
+ reject
704
+ };
705
+ this.taskQueue.push(task);
706
+ this.processQueue();
707
+ });
708
+ }
709
+ /**
710
+ * 执行任务
711
+ */
712
+ execute(data) {
713
+ return new Promise((resolve, reject) => {
714
+ const task = {
715
+ id: `task-${++this.taskCounter}`,
716
+ data,
717
+ resolve: (result) => {
718
+ resolve(result);
719
+ },
720
+ reject
721
+ };
722
+ this.taskQueue.push(task);
723
+ this.processQueue();
724
+ });
725
+ }
726
+ /**
727
+ * 处理任务队列
728
+ */
729
+ processQueue() {
730
+ if (this.taskQueue.length === 0)
731
+ return;
732
+ // 找到空闲的Worker
733
+ for (let i = 0; i < this.workers.length; i++) {
734
+ if (!this.busyWorkers.has(i) && this.taskQueue.length > 0) {
735
+ const task = this.taskQueue.shift();
736
+ this.busyWorkers.add(i);
737
+ const worker = this.workers[i];
738
+ worker.postMessage({
739
+ id: task.id,
740
+ ...task.data
741
+ });
742
+ // 存储任务信息以便后续处理
743
+ worker._currentTask = task;
744
+ }
745
+ }
746
+ }
747
+ /**
748
+ * 处理Worker消息
749
+ */
750
+ handleWorkerMessage(workerIndex, data) {
751
+ const worker = this.workers[workerIndex];
752
+ const task = worker._currentTask;
753
+ if (!task)
754
+ return;
755
+ this.busyWorkers.delete(workerIndex);
756
+ worker._currentTask = null;
757
+ if (data.error) {
758
+ task.reject(new Error(data.error));
759
+ }
760
+ else {
761
+ task.resolve(data.result);
762
+ }
763
+ // 处理下一个任务
764
+ this.processQueue();
765
+ }
766
+ /**
767
+ * 处理Worker错误
768
+ */
769
+ handleWorkerError(workerIndex, error) {
770
+ const worker = this.workers[workerIndex];
771
+ const task = worker._currentTask;
772
+ if (task) {
773
+ this.busyWorkers.delete(workerIndex);
774
+ worker._currentTask = null;
775
+ task.reject(new Error(error.message));
776
+ }
777
+ // 处理下一个任务
778
+ this.processQueue();
779
+ }
780
+ /**
781
+ * 销毁Worker池
782
+ */
783
+ destroy() {
784
+ for (const worker of this.workers) {
785
+ worker.terminate();
786
+ }
787
+ this.workers.length = 0;
788
+ this.taskQueue.length = 0;
789
+ this.busyWorkers.clear();
790
+ }
791
+ }
792
+ //# sourceMappingURL=WorkerEntitySystem.js.map