@esengine/ecs-framework 2.3.0 → 2.3.2

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 (490) hide show
  1. package/index.cjs +2 -0
  2. package/index.cjs.map +1 -0
  3. package/index.d.ts +13466 -0
  4. package/index.es5.js +4 -0
  5. package/index.es5.js.map +1 -0
  6. package/index.mjs +2 -0
  7. package/index.mjs.map +1 -0
  8. package/index.umd.js +4 -0
  9. package/index.umd.js.map +1 -0
  10. package/package.json +47 -84
  11. package/bin/Core/DI/Decorators.d.ts +0 -206
  12. package/bin/Core/DI/Decorators.d.ts.map +0 -1
  13. package/bin/Core/DI/Decorators.js +0 -253
  14. package/bin/Core/DI/Decorators.js.map +0 -1
  15. package/bin/Core/DI/index.d.ts +0 -8
  16. package/bin/Core/DI/index.d.ts.map +0 -1
  17. package/bin/Core/DI/index.js +0 -7
  18. package/bin/Core/DI/index.js.map +0 -1
  19. package/bin/Core/Plugin.d.ts +0 -112
  20. package/bin/Core/Plugin.d.ts.map +0 -1
  21. package/bin/Core/Plugin.js +0 -19
  22. package/bin/Core/Plugin.js.map +0 -1
  23. package/bin/Core/PluginManager.d.ts +0 -118
  24. package/bin/Core/PluginManager.d.ts.map +0 -1
  25. package/bin/Core/PluginManager.js +0 -229
  26. package/bin/Core/PluginManager.js.map +0 -1
  27. package/bin/Core/ServiceContainer.d.ts +0 -221
  28. package/bin/Core/ServiceContainer.d.ts.map +0 -1
  29. package/bin/Core/ServiceContainer.js +0 -352
  30. package/bin/Core/ServiceContainer.js.map +0 -1
  31. package/bin/Core.d.ts +0 -379
  32. package/bin/Core.d.ts.map +0 -1
  33. package/bin/Core.js +0 -553
  34. package/bin/Core.js.map +0 -1
  35. package/bin/ECS/Component.d.ts +0 -104
  36. package/bin/ECS/Component.d.ts.map +0 -1
  37. package/bin/ECS/Component.js +0 -105
  38. package/bin/ECS/Component.js.map +0 -1
  39. package/bin/ECS/Components/HierarchyComponent.d.ts +0 -46
  40. package/bin/ECS/Components/HierarchyComponent.d.ts.map +0 -1
  41. package/bin/ECS/Components/HierarchyComponent.js +0 -65
  42. package/bin/ECS/Components/HierarchyComponent.js.map +0 -1
  43. package/bin/ECS/Components/index.d.ts +0 -2
  44. package/bin/ECS/Components/index.d.ts.map +0 -1
  45. package/bin/ECS/Components/index.js +0 -2
  46. package/bin/ECS/Components/index.js.map +0 -1
  47. package/bin/ECS/Core/ArchetypeSystem.d.ts +0 -103
  48. package/bin/ECS/Core/ArchetypeSystem.d.ts.map +0 -1
  49. package/bin/ECS/Core/ArchetypeSystem.js +0 -244
  50. package/bin/ECS/Core/ArchetypeSystem.js.map +0 -1
  51. package/bin/ECS/Core/CommandBuffer.d.ts +0 -154
  52. package/bin/ECS/Core/CommandBuffer.d.ts.map +0 -1
  53. package/bin/ECS/Core/CommandBuffer.js +0 -244
  54. package/bin/ECS/Core/CommandBuffer.js.map +0 -1
  55. package/bin/ECS/Core/ComponentPool.d.ts +0 -139
  56. package/bin/ECS/Core/ComponentPool.d.ts.map +0 -1
  57. package/bin/ECS/Core/ComponentPool.js +0 -276
  58. package/bin/ECS/Core/ComponentPool.js.map +0 -1
  59. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts +0 -127
  60. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts.map +0 -1
  61. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js +0 -235
  62. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js.map +0 -1
  63. package/bin/ECS/Core/ComponentStorage.d.ts +0 -185
  64. package/bin/ECS/Core/ComponentStorage.d.ts.map +0 -1
  65. package/bin/ECS/Core/ComponentStorage.js +0 -321
  66. package/bin/ECS/Core/ComponentStorage.js.map +0 -1
  67. package/bin/ECS/Core/EntityLifecyclePolicy.d.ts +0 -26
  68. package/bin/ECS/Core/EntityLifecyclePolicy.d.ts.map +0 -1
  69. package/bin/ECS/Core/EntityLifecyclePolicy.js +0 -2
  70. package/bin/ECS/Core/EntityLifecyclePolicy.js.map +0 -1
  71. package/bin/ECS/Core/EventBus.d.ts +0 -210
  72. package/bin/ECS/Core/EventBus.d.ts.map +0 -1
  73. package/bin/ECS/Core/EventBus.js +0 -370
  74. package/bin/ECS/Core/EventBus.js.map +0 -1
  75. package/bin/ECS/Core/EventSystem.d.ts +0 -225
  76. package/bin/ECS/Core/EventSystem.d.ts.map +0 -1
  77. package/bin/ECS/Core/EventSystem.js +0 -448
  78. package/bin/ECS/Core/EventSystem.js.map +0 -1
  79. package/bin/ECS/Core/Events/index.d.ts +0 -3
  80. package/bin/ECS/Core/Events/index.d.ts.map +0 -1
  81. package/bin/ECS/Core/Events/index.js +0 -3
  82. package/bin/ECS/Core/Events/index.js.map +0 -1
  83. package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts +0 -35
  84. package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts.map +0 -1
  85. package/bin/ECS/Core/FluentAPI/ComponentBuilder.js +0 -48
  86. package/bin/ECS/Core/FluentAPI/ComponentBuilder.js.map +0 -1
  87. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts +0 -135
  88. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts.map +0 -1
  89. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js +0 -166
  90. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js.map +0 -1
  91. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts +0 -58
  92. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts.map +0 -1
  93. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js +0 -85
  94. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js.map +0 -1
  95. package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts +0 -110
  96. package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts.map +0 -1
  97. package/bin/ECS/Core/FluentAPI/EntityBuilder.js +0 -181
  98. package/bin/ECS/Core/FluentAPI/EntityBuilder.js.map +0 -1
  99. package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts +0 -53
  100. package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts.map +0 -1
  101. package/bin/ECS/Core/FluentAPI/SceneBuilder.js +0 -79
  102. package/bin/ECS/Core/FluentAPI/SceneBuilder.js.map +0 -1
  103. package/bin/ECS/Core/FluentAPI/index.d.ts +0 -6
  104. package/bin/ECS/Core/FluentAPI/index.d.ts.map +0 -1
  105. package/bin/ECS/Core/FluentAPI/index.js +0 -6
  106. package/bin/ECS/Core/FluentAPI/index.js.map +0 -1
  107. package/bin/ECS/Core/FluentAPI.d.ts +0 -2
  108. package/bin/ECS/Core/FluentAPI.d.ts.map +0 -1
  109. package/bin/ECS/Core/FluentAPI.js +0 -3
  110. package/bin/ECS/Core/FluentAPI.js.map +0 -1
  111. package/bin/ECS/Core/Query/TypedQuery.d.ts +0 -214
  112. package/bin/ECS/Core/Query/TypedQuery.d.ts.map +0 -1
  113. package/bin/ECS/Core/Query/TypedQuery.js +0 -294
  114. package/bin/ECS/Core/Query/TypedQuery.js.map +0 -1
  115. package/bin/ECS/Core/Query/index.d.ts +0 -3
  116. package/bin/ECS/Core/Query/index.d.ts.map +0 -1
  117. package/bin/ECS/Core/Query/index.js +0 -3
  118. package/bin/ECS/Core/Query/index.js.map +0 -1
  119. package/bin/ECS/Core/QuerySystem.d.ts +0 -458
  120. package/bin/ECS/Core/QuerySystem.d.ts.map +0 -1
  121. package/bin/ECS/Core/QuerySystem.js +0 -1069
  122. package/bin/ECS/Core/QuerySystem.js.map +0 -1
  123. package/bin/ECS/Core/QueryTypes.d.ts +0 -34
  124. package/bin/ECS/Core/QueryTypes.d.ts.map +0 -1
  125. package/bin/ECS/Core/QueryTypes.js +0 -13
  126. package/bin/ECS/Core/QueryTypes.js.map +0 -1
  127. package/bin/ECS/Core/ReactiveQuery.d.ts +0 -211
  128. package/bin/ECS/Core/ReactiveQuery.d.ts.map +0 -1
  129. package/bin/ECS/Core/ReactiveQuery.js +0 -401
  130. package/bin/ECS/Core/ReactiveQuery.js.map +0 -1
  131. package/bin/ECS/Core/ReferenceTracker.d.ts +0 -111
  132. package/bin/ECS/Core/ReferenceTracker.d.ts.map +0 -1
  133. package/bin/ECS/Core/ReferenceTracker.js +0 -254
  134. package/bin/ECS/Core/ReferenceTracker.js.map +0 -1
  135. package/bin/ECS/Core/SoASerializer.d.ts +0 -28
  136. package/bin/ECS/Core/SoASerializer.d.ts.map +0 -1
  137. package/bin/ECS/Core/SoASerializer.js +0 -85
  138. package/bin/ECS/Core/SoASerializer.js.map +0 -1
  139. package/bin/ECS/Core/SoAStorage.d.ts +0 -129
  140. package/bin/ECS/Core/SoAStorage.d.ts.map +0 -1
  141. package/bin/ECS/Core/SoAStorage.js +0 -685
  142. package/bin/ECS/Core/SoAStorage.js.map +0 -1
  143. package/bin/ECS/Core/SoATypeRegistry.d.ts +0 -50
  144. package/bin/ECS/Core/SoATypeRegistry.d.ts.map +0 -1
  145. package/bin/ECS/Core/SoATypeRegistry.js +0 -135
  146. package/bin/ECS/Core/SoATypeRegistry.js.map +0 -1
  147. package/bin/ECS/Core/Storage/index.d.ts +0 -4
  148. package/bin/ECS/Core/Storage/index.d.ts.map +0 -1
  149. package/bin/ECS/Core/Storage/index.js +0 -4
  150. package/bin/ECS/Core/Storage/index.js.map +0 -1
  151. package/bin/ECS/Core/StorageDecorators.d.ts +0 -20
  152. package/bin/ECS/Core/StorageDecorators.d.ts.map +0 -1
  153. package/bin/ECS/Core/StorageDecorators.js +0 -27
  154. package/bin/ECS/Core/StorageDecorators.js.map +0 -1
  155. package/bin/ECS/CoreEvents.d.ts +0 -131
  156. package/bin/ECS/CoreEvents.d.ts.map +0 -1
  157. package/bin/ECS/CoreEvents.js +0 -163
  158. package/bin/ECS/CoreEvents.js.map +0 -1
  159. package/bin/ECS/Decorators/EntityRefDecorator.d.ts +0 -46
  160. package/bin/ECS/Decorators/EntityRefDecorator.d.ts.map +0 -1
  161. package/bin/ECS/Decorators/EntityRefDecorator.js +0 -118
  162. package/bin/ECS/Decorators/EntityRefDecorator.js.map +0 -1
  163. package/bin/ECS/Decorators/PropertyDecorator.d.ts +0 -168
  164. package/bin/ECS/Decorators/PropertyDecorator.d.ts.map +0 -1
  165. package/bin/ECS/Decorators/PropertyDecorator.js +0 -40
  166. package/bin/ECS/Decorators/PropertyDecorator.js.map +0 -1
  167. package/bin/ECS/Decorators/TypeDecorators.d.ts +0 -124
  168. package/bin/ECS/Decorators/TypeDecorators.d.ts.map +0 -1
  169. package/bin/ECS/Decorators/TypeDecorators.js +0 -151
  170. package/bin/ECS/Decorators/TypeDecorators.js.map +0 -1
  171. package/bin/ECS/Decorators/index.d.ts +0 -7
  172. package/bin/ECS/Decorators/index.d.ts.map +0 -1
  173. package/bin/ECS/Decorators/index.js +0 -4
  174. package/bin/ECS/Decorators/index.js.map +0 -1
  175. package/bin/ECS/Entity.d.ts +0 -415
  176. package/bin/ECS/Entity.d.ts.map +0 -1
  177. package/bin/ECS/Entity.js +0 -683
  178. package/bin/ECS/Entity.js.map +0 -1
  179. package/bin/ECS/EntityTags.d.ts +0 -71
  180. package/bin/ECS/EntityTags.d.ts.map +0 -1
  181. package/bin/ECS/EntityTags.js +0 -82
  182. package/bin/ECS/EntityTags.js.map +0 -1
  183. package/bin/ECS/IScene.d.ts +0 -308
  184. package/bin/ECS/IScene.d.ts.map +0 -1
  185. package/bin/ECS/IScene.js +0 -2
  186. package/bin/ECS/IScene.js.map +0 -1
  187. package/bin/ECS/Scene.d.ts +0 -799
  188. package/bin/ECS/Scene.d.ts.map +0 -1
  189. package/bin/ECS/Scene.js +0 -1203
  190. package/bin/ECS/Scene.js.map +0 -1
  191. package/bin/ECS/SceneManager.d.ts +0 -197
  192. package/bin/ECS/SceneManager.d.ts.map +0 -1
  193. package/bin/ECS/SceneManager.js +0 -264
  194. package/bin/ECS/SceneManager.js.map +0 -1
  195. package/bin/ECS/Serialization/ComponentSerializer.d.ts +0 -106
  196. package/bin/ECS/Serialization/ComponentSerializer.d.ts.map +0 -1
  197. package/bin/ECS/Serialization/ComponentSerializer.js +0 -251
  198. package/bin/ECS/Serialization/ComponentSerializer.js.map +0 -1
  199. package/bin/ECS/Serialization/EntitySerializer.d.ts +0 -111
  200. package/bin/ECS/Serialization/EntitySerializer.d.ts.map +0 -1
  201. package/bin/ECS/Serialization/EntitySerializer.js +0 -155
  202. package/bin/ECS/Serialization/EntitySerializer.js.map +0 -1
  203. package/bin/ECS/Serialization/IncrementalSerializer.d.ts +0 -259
  204. package/bin/ECS/Serialization/IncrementalSerializer.d.ts.map +0 -1
  205. package/bin/ECS/Serialization/IncrementalSerializer.js +0 -500
  206. package/bin/ECS/Serialization/IncrementalSerializer.js.map +0 -1
  207. package/bin/ECS/Serialization/SceneSerializer.d.ts +0 -213
  208. package/bin/ECS/Serialization/SceneSerializer.d.ts.map +0 -1
  209. package/bin/ECS/Serialization/SceneSerializer.js +0 -387
  210. package/bin/ECS/Serialization/SceneSerializer.js.map +0 -1
  211. package/bin/ECS/Serialization/SerializationDecorators.d.ts +0 -136
  212. package/bin/ECS/Serialization/SerializationDecorators.d.ts.map +0 -1
  213. package/bin/ECS/Serialization/SerializationDecorators.js +0 -216
  214. package/bin/ECS/Serialization/SerializationDecorators.js.map +0 -1
  215. package/bin/ECS/Serialization/VersionMigration.d.ts +0 -156
  216. package/bin/ECS/Serialization/VersionMigration.d.ts.map +0 -1
  217. package/bin/ECS/Serialization/VersionMigration.js +0 -279
  218. package/bin/ECS/Serialization/VersionMigration.js.map +0 -1
  219. package/bin/ECS/Serialization/index.d.ts +0 -18
  220. package/bin/ECS/Serialization/index.d.ts.map +0 -1
  221. package/bin/ECS/Serialization/index.js +0 -18
  222. package/bin/ECS/Serialization/index.js.map +0 -1
  223. package/bin/ECS/Systems/EntityCache.d.ts +0 -114
  224. package/bin/ECS/Systems/EntityCache.d.ts.map +0 -1
  225. package/bin/ECS/Systems/EntityCache.js +0 -145
  226. package/bin/ECS/Systems/EntityCache.js.map +0 -1
  227. package/bin/ECS/Systems/EntitySystem.d.ts +0 -591
  228. package/bin/ECS/Systems/EntitySystem.d.ts.map +0 -1
  229. package/bin/ECS/Systems/EntitySystem.js +0 -1102
  230. package/bin/ECS/Systems/EntitySystem.js.map +0 -1
  231. package/bin/ECS/Systems/HierarchySystem.d.ts +0 -155
  232. package/bin/ECS/Systems/HierarchySystem.d.ts.map +0 -1
  233. package/bin/ECS/Systems/HierarchySystem.js +0 -498
  234. package/bin/ECS/Systems/HierarchySystem.js.map +0 -1
  235. package/bin/ECS/Systems/IntervalSystem.d.ts +0 -33
  236. package/bin/ECS/Systems/IntervalSystem.d.ts.map +0 -1
  237. package/bin/ECS/Systems/IntervalSystem.js +0 -50
  238. package/bin/ECS/Systems/IntervalSystem.js.map +0 -1
  239. package/bin/ECS/Systems/PassiveSystem.d.ts +0 -17
  240. package/bin/ECS/Systems/PassiveSystem.d.ts.map +0 -1
  241. package/bin/ECS/Systems/PassiveSystem.js +0 -19
  242. package/bin/ECS/Systems/PassiveSystem.js.map +0 -1
  243. package/bin/ECS/Systems/ProcessingSystem.d.ts +0 -21
  244. package/bin/ECS/Systems/ProcessingSystem.d.ts.map +0 -1
  245. package/bin/ECS/Systems/ProcessingSystem.js +0 -20
  246. package/bin/ECS/Systems/ProcessingSystem.js.map +0 -1
  247. package/bin/ECS/Systems/WorkerEntitySystem.d.ts +0 -313
  248. package/bin/ECS/Systems/WorkerEntitySystem.d.ts.map +0 -1
  249. package/bin/ECS/Systems/WorkerEntitySystem.js +0 -792
  250. package/bin/ECS/Systems/WorkerEntitySystem.js.map +0 -1
  251. package/bin/ECS/Systems/index.d.ts +0 -8
  252. package/bin/ECS/Systems/index.d.ts.map +0 -1
  253. package/bin/ECS/Systems/index.js +0 -8
  254. package/bin/ECS/Systems/index.js.map +0 -1
  255. package/bin/ECS/TypedEntity.d.ts +0 -192
  256. package/bin/ECS/TypedEntity.d.ts.map +0 -1
  257. package/bin/ECS/TypedEntity.js +0 -254
  258. package/bin/ECS/TypedEntity.js.map +0 -1
  259. package/bin/ECS/Utils/BigIntCompatibility.d.ts +0 -151
  260. package/bin/ECS/Utils/BigIntCompatibility.d.ts.map +0 -1
  261. package/bin/ECS/Utils/BigIntCompatibility.js +0 -476
  262. package/bin/ECS/Utils/BigIntCompatibility.js.map +0 -1
  263. package/bin/ECS/Utils/BitMaskHashMap.d.ts +0 -28
  264. package/bin/ECS/Utils/BitMaskHashMap.d.ts.map +0 -1
  265. package/bin/ECS/Utils/BitMaskHashMap.js +0 -127
  266. package/bin/ECS/Utils/BitMaskHashMap.js.map +0 -1
  267. package/bin/ECS/Utils/Bits.d.ts +0 -154
  268. package/bin/ECS/Utils/Bits.d.ts.map +0 -1
  269. package/bin/ECS/Utils/Bits.js +0 -331
  270. package/bin/ECS/Utils/Bits.js.map +0 -1
  271. package/bin/ECS/Utils/ComponentSparseSet.d.ts +0 -143
  272. package/bin/ECS/Utils/ComponentSparseSet.d.ts.map +0 -1
  273. package/bin/ECS/Utils/ComponentSparseSet.js +0 -347
  274. package/bin/ECS/Utils/ComponentSparseSet.js.map +0 -1
  275. package/bin/ECS/Utils/EntityList.d.ts +0 -115
  276. package/bin/ECS/Utils/EntityList.d.ts.map +0 -1
  277. package/bin/ECS/Utils/EntityList.js +0 -258
  278. package/bin/ECS/Utils/EntityList.js.map +0 -1
  279. package/bin/ECS/Utils/EntityProcessorList.d.ts +0 -56
  280. package/bin/ECS/Utils/EntityProcessorList.d.ts.map +0 -1
  281. package/bin/ECS/Utils/EntityProcessorList.js +0 -113
  282. package/bin/ECS/Utils/EntityProcessorList.js.map +0 -1
  283. package/bin/ECS/Utils/IdentifierPool.d.ts +0 -203
  284. package/bin/ECS/Utils/IdentifierPool.d.ts.map +0 -1
  285. package/bin/ECS/Utils/IdentifierPool.js +0 -325
  286. package/bin/ECS/Utils/IdentifierPool.js.map +0 -1
  287. package/bin/ECS/Utils/Matcher.d.ts +0 -171
  288. package/bin/ECS/Utils/Matcher.d.ts.map +0 -1
  289. package/bin/ECS/Utils/Matcher.js +0 -293
  290. package/bin/ECS/Utils/Matcher.js.map +0 -1
  291. package/bin/ECS/Utils/SparseSet.d.ts +0 -170
  292. package/bin/ECS/Utils/SparseSet.d.ts.map +0 -1
  293. package/bin/ECS/Utils/SparseSet.js +0 -280
  294. package/bin/ECS/Utils/SparseSet.js.map +0 -1
  295. package/bin/ECS/Utils/index.d.ts +0 -9
  296. package/bin/ECS/Utils/index.d.ts.map +0 -1
  297. package/bin/ECS/Utils/index.js +0 -10
  298. package/bin/ECS/Utils/index.js.map +0 -1
  299. package/bin/ECS/World.d.ts +0 -238
  300. package/bin/ECS/World.d.ts.map +0 -1
  301. package/bin/ECS/World.js +0 -416
  302. package/bin/ECS/World.js.map +0 -1
  303. package/bin/ECS/WorldManager.d.ts +0 -224
  304. package/bin/ECS/WorldManager.d.ts.map +0 -1
  305. package/bin/ECS/WorldManager.js +0 -365
  306. package/bin/ECS/WorldManager.js.map +0 -1
  307. package/bin/ECS/index.d.ts +0 -26
  308. package/bin/ECS/index.d.ts.map +0 -1
  309. package/bin/ECS/index.js +0 -21
  310. package/bin/ECS/index.js.map +0 -1
  311. package/bin/Platform/IPlatformAdapter.d.ts +0 -169
  312. package/bin/Platform/IPlatformAdapter.d.ts.map +0 -1
  313. package/bin/Platform/IPlatformAdapter.js +0 -2
  314. package/bin/Platform/IPlatformAdapter.js.map +0 -1
  315. package/bin/Platform/PlatformDetector.d.ts +0 -56
  316. package/bin/Platform/PlatformDetector.d.ts.map +0 -1
  317. package/bin/Platform/PlatformDetector.js +0 -247
  318. package/bin/Platform/PlatformDetector.js.map +0 -1
  319. package/bin/Platform/PlatformManager.d.ts +0 -50
  320. package/bin/Platform/PlatformManager.d.ts.map +0 -1
  321. package/bin/Platform/PlatformManager.js +0 -114
  322. package/bin/Platform/PlatformManager.js.map +0 -1
  323. package/bin/Platform/index.d.ts +0 -19
  324. package/bin/Platform/index.d.ts.map +0 -1
  325. package/bin/Platform/index.js +0 -29
  326. package/bin/Platform/index.js.map +0 -1
  327. package/bin/Plugins/DebugPlugin.d.ts +0 -156
  328. package/bin/Plugins/DebugPlugin.d.ts.map +0 -1
  329. package/bin/Plugins/DebugPlugin.js +0 -248
  330. package/bin/Plugins/DebugPlugin.js.map +0 -1
  331. package/bin/Plugins/index.d.ts +0 -2
  332. package/bin/Plugins/index.d.ts.map +0 -1
  333. package/bin/Plugins/index.js +0 -2
  334. package/bin/Plugins/index.js.map +0 -1
  335. package/bin/Types/IUpdatable.d.ts +0 -18
  336. package/bin/Types/IUpdatable.d.ts.map +0 -1
  337. package/bin/Types/IUpdatable.js +0 -7
  338. package/bin/Types/IUpdatable.js.map +0 -1
  339. package/bin/Types/TypeHelpers.d.ts +0 -238
  340. package/bin/Types/TypeHelpers.d.ts.map +0 -1
  341. package/bin/Types/TypeHelpers.js +0 -19
  342. package/bin/Types/TypeHelpers.js.map +0 -1
  343. package/bin/Types/index.d.ts +0 -466
  344. package/bin/Types/index.d.ts.map +0 -1
  345. package/bin/Types/index.js +0 -7
  346. package/bin/Types/index.js.map +0 -1
  347. package/bin/Utils/BinarySerializer.d.ts +0 -23
  348. package/bin/Utils/BinarySerializer.d.ts.map +0 -1
  349. package/bin/Utils/BinarySerializer.js +0 -100
  350. package/bin/Utils/BinarySerializer.js.map +0 -1
  351. package/bin/Utils/Debug/AdvancedProfilerCollector.d.ts +0 -153
  352. package/bin/Utils/Debug/AdvancedProfilerCollector.d.ts.map +0 -1
  353. package/bin/Utils/Debug/AdvancedProfilerCollector.js +0 -406
  354. package/bin/Utils/Debug/AdvancedProfilerCollector.js.map +0 -1
  355. package/bin/Utils/Debug/ComponentDataCollector.d.ts +0 -32
  356. package/bin/Utils/Debug/ComponentDataCollector.d.ts.map +0 -1
  357. package/bin/Utils/Debug/ComponentDataCollector.js +0 -250
  358. package/bin/Utils/Debug/ComponentDataCollector.js.map +0 -1
  359. package/bin/Utils/Debug/DebugConfigService.d.ts +0 -16
  360. package/bin/Utils/Debug/DebugConfigService.d.ts.map +0 -1
  361. package/bin/Utils/Debug/DebugConfigService.js +0 -42
  362. package/bin/Utils/Debug/DebugConfigService.js.map +0 -1
  363. package/bin/Utils/Debug/DebugManager.d.ts +0 -131
  364. package/bin/Utils/Debug/DebugManager.d.ts.map +0 -1
  365. package/bin/Utils/Debug/DebugManager.js +0 -848
  366. package/bin/Utils/Debug/DebugManager.js.map +0 -1
  367. package/bin/Utils/Debug/EntityDataCollector.d.ts +0 -115
  368. package/bin/Utils/Debug/EntityDataCollector.d.ts.map +0 -1
  369. package/bin/Utils/Debug/EntityDataCollector.js +0 -870
  370. package/bin/Utils/Debug/EntityDataCollector.js.map +0 -1
  371. package/bin/Utils/Debug/PerformanceDataCollector.d.ts +0 -31
  372. package/bin/Utils/Debug/PerformanceDataCollector.d.ts.map +0 -1
  373. package/bin/Utils/Debug/PerformanceDataCollector.js +0 -203
  374. package/bin/Utils/Debug/PerformanceDataCollector.js.map +0 -1
  375. package/bin/Utils/Debug/SceneDataCollector.d.ts +0 -18
  376. package/bin/Utils/Debug/SceneDataCollector.d.ts.map +0 -1
  377. package/bin/Utils/Debug/SceneDataCollector.js +0 -43
  378. package/bin/Utils/Debug/SceneDataCollector.js.map +0 -1
  379. package/bin/Utils/Debug/SystemDataCollector.d.ts +0 -14
  380. package/bin/Utils/Debug/SystemDataCollector.d.ts.map +0 -1
  381. package/bin/Utils/Debug/SystemDataCollector.js +0 -60
  382. package/bin/Utils/Debug/SystemDataCollector.js.map +0 -1
  383. package/bin/Utils/Debug/WebSocketManager.d.ts +0 -54
  384. package/bin/Utils/Debug/WebSocketManager.d.ts.map +0 -1
  385. package/bin/Utils/Debug/WebSocketManager.js +0 -141
  386. package/bin/Utils/Debug/WebSocketManager.js.map +0 -1
  387. package/bin/Utils/Debug/index.d.ts +0 -11
  388. package/bin/Utils/Debug/index.d.ts.map +0 -1
  389. package/bin/Utils/Debug/index.js +0 -10
  390. package/bin/Utils/Debug/index.js.map +0 -1
  391. package/bin/Utils/Emitter.d.ts +0 -61
  392. package/bin/Utils/Emitter.d.ts.map +0 -1
  393. package/bin/Utils/Emitter.js +0 -101
  394. package/bin/Utils/Emitter.js.map +0 -1
  395. package/bin/Utils/Extensions/NumberExtension.d.ts +0 -13
  396. package/bin/Utils/Extensions/NumberExtension.d.ts.map +0 -1
  397. package/bin/Utils/Extensions/NumberExtension.js +0 -17
  398. package/bin/Utils/Extensions/NumberExtension.js.map +0 -1
  399. package/bin/Utils/Extensions/TypeUtils.d.ts +0 -13
  400. package/bin/Utils/Extensions/TypeUtils.d.ts.map +0 -1
  401. package/bin/Utils/Extensions/TypeUtils.js +0 -15
  402. package/bin/Utils/Extensions/TypeUtils.js.map +0 -1
  403. package/bin/Utils/Extensions/index.d.ts +0 -3
  404. package/bin/Utils/Extensions/index.d.ts.map +0 -1
  405. package/bin/Utils/Extensions/index.js +0 -4
  406. package/bin/Utils/Extensions/index.js.map +0 -1
  407. package/bin/Utils/GlobalManager.d.ts +0 -29
  408. package/bin/Utils/GlobalManager.d.ts.map +0 -1
  409. package/bin/Utils/GlobalManager.js +0 -50
  410. package/bin/Utils/GlobalManager.js.map +0 -1
  411. package/bin/Utils/Logger/ConsoleLogger.d.ts +0 -74
  412. package/bin/Utils/Logger/ConsoleLogger.d.ts.map +0 -1
  413. package/bin/Utils/Logger/ConsoleLogger.js +0 -187
  414. package/bin/Utils/Logger/ConsoleLogger.js.map +0 -1
  415. package/bin/Utils/Logger/Constants.d.ts +0 -36
  416. package/bin/Utils/Logger/Constants.d.ts.map +0 -1
  417. package/bin/Utils/Logger/Constants.js +0 -40
  418. package/bin/Utils/Logger/Constants.js.map +0 -1
  419. package/bin/Utils/Logger/LoggerManager.d.ts +0 -91
  420. package/bin/Utils/Logger/LoggerManager.d.ts.map +0 -1
  421. package/bin/Utils/Logger/LoggerManager.js +0 -167
  422. package/bin/Utils/Logger/LoggerManager.js.map +0 -1
  423. package/bin/Utils/Logger/Types.d.ts +0 -40
  424. package/bin/Utils/Logger/Types.d.ts.map +0 -1
  425. package/bin/Utils/Logger/Types.js +0 -2
  426. package/bin/Utils/Logger/Types.js.map +0 -1
  427. package/bin/Utils/Logger/index.d.ts +0 -5
  428. package/bin/Utils/Logger/index.d.ts.map +0 -1
  429. package/bin/Utils/Logger/index.js +0 -5
  430. package/bin/Utils/Logger/index.js.map +0 -1
  431. package/bin/Utils/PerformanceMonitor.d.ts +0 -196
  432. package/bin/Utils/PerformanceMonitor.d.ts.map +0 -1
  433. package/bin/Utils/PerformanceMonitor.js +0 -244
  434. package/bin/Utils/PerformanceMonitor.js.map +0 -1
  435. package/bin/Utils/Pool/IPoolable.d.ts +0 -29
  436. package/bin/Utils/Pool/IPoolable.d.ts.map +0 -1
  437. package/bin/Utils/Pool/IPoolable.js +0 -2
  438. package/bin/Utils/Pool/IPoolable.js.map +0 -1
  439. package/bin/Utils/Pool/Pool.d.ts +0 -109
  440. package/bin/Utils/Pool/Pool.d.ts.map +0 -1
  441. package/bin/Utils/Pool/Pool.js +0 -238
  442. package/bin/Utils/Pool/Pool.js.map +0 -1
  443. package/bin/Utils/Pool/PoolManager.d.ts +0 -96
  444. package/bin/Utils/Pool/PoolManager.d.ts.map +0 -1
  445. package/bin/Utils/Pool/PoolManager.js +0 -199
  446. package/bin/Utils/Pool/PoolManager.js.map +0 -1
  447. package/bin/Utils/Pool/index.d.ts +0 -4
  448. package/bin/Utils/Pool/index.d.ts.map +0 -1
  449. package/bin/Utils/Pool/index.js +0 -4
  450. package/bin/Utils/Pool/index.js.map +0 -1
  451. package/bin/Utils/Profiler/AutoProfiler.d.ts +0 -160
  452. package/bin/Utils/Profiler/AutoProfiler.d.ts.map +0 -1
  453. package/bin/Utils/Profiler/AutoProfiler.js +0 -503
  454. package/bin/Utils/Profiler/AutoProfiler.js.map +0 -1
  455. package/bin/Utils/Profiler/ProfilerSDK.d.ts +0 -175
  456. package/bin/Utils/Profiler/ProfilerSDK.d.ts.map +0 -1
  457. package/bin/Utils/Profiler/ProfilerSDK.js +0 -727
  458. package/bin/Utils/Profiler/ProfilerSDK.js.map +0 -1
  459. package/bin/Utils/Profiler/ProfilerTypes.d.ts +0 -218
  460. package/bin/Utils/Profiler/ProfilerTypes.d.ts.map +0 -1
  461. package/bin/Utils/Profiler/ProfilerTypes.js +0 -47
  462. package/bin/Utils/Profiler/ProfilerTypes.js.map +0 -1
  463. package/bin/Utils/Profiler/index.d.ts +0 -8
  464. package/bin/Utils/Profiler/index.d.ts.map +0 -1
  465. package/bin/Utils/Profiler/index.js +0 -7
  466. package/bin/Utils/Profiler/index.js.map +0 -1
  467. package/bin/Utils/Time.d.ts +0 -47
  468. package/bin/Utils/Time.d.ts.map +0 -1
  469. package/bin/Utils/Time.js +0 -64
  470. package/bin/Utils/Time.js.map +0 -1
  471. package/bin/Utils/Timers/ITimer.d.ts +0 -16
  472. package/bin/Utils/Timers/ITimer.d.ts.map +0 -1
  473. package/bin/Utils/Timers/ITimer.js +0 -2
  474. package/bin/Utils/Timers/ITimer.js.map +0 -1
  475. package/bin/Utils/Timers/Timer.d.ts +0 -30
  476. package/bin/Utils/Timers/Timer.d.ts.map +0 -1
  477. package/bin/Utils/Timers/Timer.js +0 -58
  478. package/bin/Utils/Timers/Timer.js.map +0 -1
  479. package/bin/Utils/Timers/TimerManager.d.ts +0 -26
  480. package/bin/Utils/Timers/TimerManager.d.ts.map +0 -1
  481. package/bin/Utils/Timers/TimerManager.js +0 -48
  482. package/bin/Utils/Timers/TimerManager.js.map +0 -1
  483. package/bin/Utils/index.d.ts +0 -11
  484. package/bin/Utils/index.d.ts.map +0 -1
  485. package/bin/Utils/index.js +0 -11
  486. package/bin/Utils/index.js.map +0 -1
  487. package/bin/index.d.ts +0 -29
  488. package/bin/index.d.ts.map +0 -1
  489. package/bin/index.js +0 -36
  490. package/bin/index.js.map +0 -1
@@ -1,792 +0,0 @@
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