@esengine/ecs-framework 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +13451 -0
- package/dist/index.es5.js +4 -0
- package/dist/index.es5.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +4 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/package.json +47 -0
- package/package.json +87 -84
- package/bin/Core/DI/Decorators.d.ts +0 -206
- package/bin/Core/DI/Decorators.d.ts.map +0 -1
- package/bin/Core/DI/Decorators.js +0 -253
- package/bin/Core/DI/Decorators.js.map +0 -1
- package/bin/Core/DI/index.d.ts +0 -8
- package/bin/Core/DI/index.d.ts.map +0 -1
- package/bin/Core/DI/index.js +0 -7
- package/bin/Core/DI/index.js.map +0 -1
- package/bin/Core/Plugin.d.ts +0 -112
- package/bin/Core/Plugin.d.ts.map +0 -1
- package/bin/Core/Plugin.js +0 -19
- package/bin/Core/Plugin.js.map +0 -1
- package/bin/Core/PluginManager.d.ts +0 -118
- package/bin/Core/PluginManager.d.ts.map +0 -1
- package/bin/Core/PluginManager.js +0 -229
- package/bin/Core/PluginManager.js.map +0 -1
- package/bin/Core/ServiceContainer.d.ts +0 -221
- package/bin/Core/ServiceContainer.d.ts.map +0 -1
- package/bin/Core/ServiceContainer.js +0 -352
- package/bin/Core/ServiceContainer.js.map +0 -1
- package/bin/Core.d.ts +0 -379
- package/bin/Core.d.ts.map +0 -1
- package/bin/Core.js +0 -553
- package/bin/Core.js.map +0 -1
- package/bin/ECS/Component.d.ts +0 -104
- package/bin/ECS/Component.d.ts.map +0 -1
- package/bin/ECS/Component.js +0 -105
- package/bin/ECS/Component.js.map +0 -1
- package/bin/ECS/Components/HierarchyComponent.d.ts +0 -46
- package/bin/ECS/Components/HierarchyComponent.d.ts.map +0 -1
- package/bin/ECS/Components/HierarchyComponent.js +0 -65
- package/bin/ECS/Components/HierarchyComponent.js.map +0 -1
- package/bin/ECS/Components/index.d.ts +0 -2
- package/bin/ECS/Components/index.d.ts.map +0 -1
- package/bin/ECS/Components/index.js +0 -2
- package/bin/ECS/Components/index.js.map +0 -1
- package/bin/ECS/Core/ArchetypeSystem.d.ts +0 -103
- package/bin/ECS/Core/ArchetypeSystem.d.ts.map +0 -1
- package/bin/ECS/Core/ArchetypeSystem.js +0 -244
- package/bin/ECS/Core/ArchetypeSystem.js.map +0 -1
- package/bin/ECS/Core/CommandBuffer.d.ts +0 -154
- package/bin/ECS/Core/CommandBuffer.d.ts.map +0 -1
- package/bin/ECS/Core/CommandBuffer.js +0 -244
- package/bin/ECS/Core/CommandBuffer.js.map +0 -1
- package/bin/ECS/Core/ComponentPool.d.ts +0 -139
- package/bin/ECS/Core/ComponentPool.d.ts.map +0 -1
- package/bin/ECS/Core/ComponentPool.js +0 -276
- package/bin/ECS/Core/ComponentPool.js.map +0 -1
- package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts +0 -127
- package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts.map +0 -1
- package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js +0 -235
- package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js.map +0 -1
- package/bin/ECS/Core/ComponentStorage.d.ts +0 -185
- package/bin/ECS/Core/ComponentStorage.d.ts.map +0 -1
- package/bin/ECS/Core/ComponentStorage.js +0 -321
- package/bin/ECS/Core/ComponentStorage.js.map +0 -1
- package/bin/ECS/Core/EntityLifecyclePolicy.d.ts +0 -26
- package/bin/ECS/Core/EntityLifecyclePolicy.d.ts.map +0 -1
- package/bin/ECS/Core/EntityLifecyclePolicy.js +0 -2
- package/bin/ECS/Core/EntityLifecyclePolicy.js.map +0 -1
- package/bin/ECS/Core/EventBus.d.ts +0 -210
- package/bin/ECS/Core/EventBus.d.ts.map +0 -1
- package/bin/ECS/Core/EventBus.js +0 -370
- package/bin/ECS/Core/EventBus.js.map +0 -1
- package/bin/ECS/Core/EventSystem.d.ts +0 -225
- package/bin/ECS/Core/EventSystem.d.ts.map +0 -1
- package/bin/ECS/Core/EventSystem.js +0 -448
- package/bin/ECS/Core/EventSystem.js.map +0 -1
- package/bin/ECS/Core/Events/index.d.ts +0 -3
- package/bin/ECS/Core/Events/index.d.ts.map +0 -1
- package/bin/ECS/Core/Events/index.js +0 -3
- package/bin/ECS/Core/Events/index.js.map +0 -1
- package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts +0 -35
- package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts.map +0 -1
- package/bin/ECS/Core/FluentAPI/ComponentBuilder.js +0 -48
- package/bin/ECS/Core/FluentAPI/ComponentBuilder.js.map +0 -1
- package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts +0 -135
- package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts.map +0 -1
- package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js +0 -166
- package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js.map +0 -1
- package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts +0 -58
- package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts.map +0 -1
- package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js +0 -85
- package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js.map +0 -1
- package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts +0 -110
- package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts.map +0 -1
- package/bin/ECS/Core/FluentAPI/EntityBuilder.js +0 -181
- package/bin/ECS/Core/FluentAPI/EntityBuilder.js.map +0 -1
- package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts +0 -53
- package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts.map +0 -1
- package/bin/ECS/Core/FluentAPI/SceneBuilder.js +0 -79
- package/bin/ECS/Core/FluentAPI/SceneBuilder.js.map +0 -1
- package/bin/ECS/Core/FluentAPI/index.d.ts +0 -6
- package/bin/ECS/Core/FluentAPI/index.d.ts.map +0 -1
- package/bin/ECS/Core/FluentAPI/index.js +0 -6
- package/bin/ECS/Core/FluentAPI/index.js.map +0 -1
- package/bin/ECS/Core/FluentAPI.d.ts +0 -2
- package/bin/ECS/Core/FluentAPI.d.ts.map +0 -1
- package/bin/ECS/Core/FluentAPI.js +0 -3
- package/bin/ECS/Core/FluentAPI.js.map +0 -1
- package/bin/ECS/Core/Query/TypedQuery.d.ts +0 -214
- package/bin/ECS/Core/Query/TypedQuery.d.ts.map +0 -1
- package/bin/ECS/Core/Query/TypedQuery.js +0 -294
- package/bin/ECS/Core/Query/TypedQuery.js.map +0 -1
- package/bin/ECS/Core/Query/index.d.ts +0 -3
- package/bin/ECS/Core/Query/index.d.ts.map +0 -1
- package/bin/ECS/Core/Query/index.js +0 -3
- package/bin/ECS/Core/Query/index.js.map +0 -1
- package/bin/ECS/Core/QuerySystem.d.ts +0 -458
- package/bin/ECS/Core/QuerySystem.d.ts.map +0 -1
- package/bin/ECS/Core/QuerySystem.js +0 -1069
- package/bin/ECS/Core/QuerySystem.js.map +0 -1
- package/bin/ECS/Core/QueryTypes.d.ts +0 -34
- package/bin/ECS/Core/QueryTypes.d.ts.map +0 -1
- package/bin/ECS/Core/QueryTypes.js +0 -13
- package/bin/ECS/Core/QueryTypes.js.map +0 -1
- package/bin/ECS/Core/ReactiveQuery.d.ts +0 -211
- package/bin/ECS/Core/ReactiveQuery.d.ts.map +0 -1
- package/bin/ECS/Core/ReactiveQuery.js +0 -401
- package/bin/ECS/Core/ReactiveQuery.js.map +0 -1
- package/bin/ECS/Core/ReferenceTracker.d.ts +0 -111
- package/bin/ECS/Core/ReferenceTracker.d.ts.map +0 -1
- package/bin/ECS/Core/ReferenceTracker.js +0 -254
- package/bin/ECS/Core/ReferenceTracker.js.map +0 -1
- package/bin/ECS/Core/SoASerializer.d.ts +0 -28
- package/bin/ECS/Core/SoASerializer.d.ts.map +0 -1
- package/bin/ECS/Core/SoASerializer.js +0 -85
- package/bin/ECS/Core/SoASerializer.js.map +0 -1
- package/bin/ECS/Core/SoAStorage.d.ts +0 -129
- package/bin/ECS/Core/SoAStorage.d.ts.map +0 -1
- package/bin/ECS/Core/SoAStorage.js +0 -685
- package/bin/ECS/Core/SoAStorage.js.map +0 -1
- package/bin/ECS/Core/SoATypeRegistry.d.ts +0 -50
- package/bin/ECS/Core/SoATypeRegistry.d.ts.map +0 -1
- package/bin/ECS/Core/SoATypeRegistry.js +0 -135
- package/bin/ECS/Core/SoATypeRegistry.js.map +0 -1
- package/bin/ECS/Core/Storage/index.d.ts +0 -4
- package/bin/ECS/Core/Storage/index.d.ts.map +0 -1
- package/bin/ECS/Core/Storage/index.js +0 -4
- package/bin/ECS/Core/Storage/index.js.map +0 -1
- package/bin/ECS/Core/StorageDecorators.d.ts +0 -20
- package/bin/ECS/Core/StorageDecorators.d.ts.map +0 -1
- package/bin/ECS/Core/StorageDecorators.js +0 -27
- package/bin/ECS/Core/StorageDecorators.js.map +0 -1
- package/bin/ECS/CoreEvents.d.ts +0 -131
- package/bin/ECS/CoreEvents.d.ts.map +0 -1
- package/bin/ECS/CoreEvents.js +0 -163
- package/bin/ECS/CoreEvents.js.map +0 -1
- package/bin/ECS/Decorators/EntityRefDecorator.d.ts +0 -46
- package/bin/ECS/Decorators/EntityRefDecorator.d.ts.map +0 -1
- package/bin/ECS/Decorators/EntityRefDecorator.js +0 -118
- package/bin/ECS/Decorators/EntityRefDecorator.js.map +0 -1
- package/bin/ECS/Decorators/PropertyDecorator.d.ts +0 -168
- package/bin/ECS/Decorators/PropertyDecorator.d.ts.map +0 -1
- package/bin/ECS/Decorators/PropertyDecorator.js +0 -40
- package/bin/ECS/Decorators/PropertyDecorator.js.map +0 -1
- package/bin/ECS/Decorators/TypeDecorators.d.ts +0 -124
- package/bin/ECS/Decorators/TypeDecorators.d.ts.map +0 -1
- package/bin/ECS/Decorators/TypeDecorators.js +0 -151
- package/bin/ECS/Decorators/TypeDecorators.js.map +0 -1
- package/bin/ECS/Decorators/index.d.ts +0 -7
- package/bin/ECS/Decorators/index.d.ts.map +0 -1
- package/bin/ECS/Decorators/index.js +0 -4
- package/bin/ECS/Decorators/index.js.map +0 -1
- package/bin/ECS/Entity.d.ts +0 -415
- package/bin/ECS/Entity.d.ts.map +0 -1
- package/bin/ECS/Entity.js +0 -683
- package/bin/ECS/Entity.js.map +0 -1
- package/bin/ECS/EntityTags.d.ts +0 -71
- package/bin/ECS/EntityTags.d.ts.map +0 -1
- package/bin/ECS/EntityTags.js +0 -82
- package/bin/ECS/EntityTags.js.map +0 -1
- package/bin/ECS/IScene.d.ts +0 -308
- package/bin/ECS/IScene.d.ts.map +0 -1
- package/bin/ECS/IScene.js +0 -2
- package/bin/ECS/IScene.js.map +0 -1
- package/bin/ECS/Scene.d.ts +0 -799
- package/bin/ECS/Scene.d.ts.map +0 -1
- package/bin/ECS/Scene.js +0 -1203
- package/bin/ECS/Scene.js.map +0 -1
- package/bin/ECS/SceneManager.d.ts +0 -197
- package/bin/ECS/SceneManager.d.ts.map +0 -1
- package/bin/ECS/SceneManager.js +0 -264
- package/bin/ECS/SceneManager.js.map +0 -1
- package/bin/ECS/Serialization/ComponentSerializer.d.ts +0 -106
- package/bin/ECS/Serialization/ComponentSerializer.d.ts.map +0 -1
- package/bin/ECS/Serialization/ComponentSerializer.js +0 -251
- package/bin/ECS/Serialization/ComponentSerializer.js.map +0 -1
- package/bin/ECS/Serialization/EntitySerializer.d.ts +0 -111
- package/bin/ECS/Serialization/EntitySerializer.d.ts.map +0 -1
- package/bin/ECS/Serialization/EntitySerializer.js +0 -155
- package/bin/ECS/Serialization/EntitySerializer.js.map +0 -1
- package/bin/ECS/Serialization/IncrementalSerializer.d.ts +0 -259
- package/bin/ECS/Serialization/IncrementalSerializer.d.ts.map +0 -1
- package/bin/ECS/Serialization/IncrementalSerializer.js +0 -500
- package/bin/ECS/Serialization/IncrementalSerializer.js.map +0 -1
- package/bin/ECS/Serialization/SceneSerializer.d.ts +0 -213
- package/bin/ECS/Serialization/SceneSerializer.d.ts.map +0 -1
- package/bin/ECS/Serialization/SceneSerializer.js +0 -387
- package/bin/ECS/Serialization/SceneSerializer.js.map +0 -1
- package/bin/ECS/Serialization/SerializationDecorators.d.ts +0 -136
- package/bin/ECS/Serialization/SerializationDecorators.d.ts.map +0 -1
- package/bin/ECS/Serialization/SerializationDecorators.js +0 -216
- package/bin/ECS/Serialization/SerializationDecorators.js.map +0 -1
- package/bin/ECS/Serialization/VersionMigration.d.ts +0 -156
- package/bin/ECS/Serialization/VersionMigration.d.ts.map +0 -1
- package/bin/ECS/Serialization/VersionMigration.js +0 -279
- package/bin/ECS/Serialization/VersionMigration.js.map +0 -1
- package/bin/ECS/Serialization/index.d.ts +0 -18
- package/bin/ECS/Serialization/index.d.ts.map +0 -1
- package/bin/ECS/Serialization/index.js +0 -18
- package/bin/ECS/Serialization/index.js.map +0 -1
- package/bin/ECS/Systems/EntityCache.d.ts +0 -114
- package/bin/ECS/Systems/EntityCache.d.ts.map +0 -1
- package/bin/ECS/Systems/EntityCache.js +0 -145
- package/bin/ECS/Systems/EntityCache.js.map +0 -1
- package/bin/ECS/Systems/EntitySystem.d.ts +0 -591
- package/bin/ECS/Systems/EntitySystem.d.ts.map +0 -1
- package/bin/ECS/Systems/EntitySystem.js +0 -1102
- package/bin/ECS/Systems/EntitySystem.js.map +0 -1
- package/bin/ECS/Systems/HierarchySystem.d.ts +0 -155
- package/bin/ECS/Systems/HierarchySystem.d.ts.map +0 -1
- package/bin/ECS/Systems/HierarchySystem.js +0 -498
- package/bin/ECS/Systems/HierarchySystem.js.map +0 -1
- package/bin/ECS/Systems/IntervalSystem.d.ts +0 -33
- package/bin/ECS/Systems/IntervalSystem.d.ts.map +0 -1
- package/bin/ECS/Systems/IntervalSystem.js +0 -50
- package/bin/ECS/Systems/IntervalSystem.js.map +0 -1
- package/bin/ECS/Systems/PassiveSystem.d.ts +0 -17
- package/bin/ECS/Systems/PassiveSystem.d.ts.map +0 -1
- package/bin/ECS/Systems/PassiveSystem.js +0 -19
- package/bin/ECS/Systems/PassiveSystem.js.map +0 -1
- package/bin/ECS/Systems/ProcessingSystem.d.ts +0 -21
- package/bin/ECS/Systems/ProcessingSystem.d.ts.map +0 -1
- package/bin/ECS/Systems/ProcessingSystem.js +0 -20
- package/bin/ECS/Systems/ProcessingSystem.js.map +0 -1
- package/bin/ECS/Systems/WorkerEntitySystem.d.ts +0 -313
- package/bin/ECS/Systems/WorkerEntitySystem.d.ts.map +0 -1
- package/bin/ECS/Systems/WorkerEntitySystem.js +0 -792
- package/bin/ECS/Systems/WorkerEntitySystem.js.map +0 -1
- package/bin/ECS/Systems/index.d.ts +0 -8
- package/bin/ECS/Systems/index.d.ts.map +0 -1
- package/bin/ECS/Systems/index.js +0 -8
- package/bin/ECS/Systems/index.js.map +0 -1
- package/bin/ECS/TypedEntity.d.ts +0 -192
- package/bin/ECS/TypedEntity.d.ts.map +0 -1
- package/bin/ECS/TypedEntity.js +0 -254
- package/bin/ECS/TypedEntity.js.map +0 -1
- package/bin/ECS/Utils/BigIntCompatibility.d.ts +0 -151
- package/bin/ECS/Utils/BigIntCompatibility.d.ts.map +0 -1
- package/bin/ECS/Utils/BigIntCompatibility.js +0 -476
- package/bin/ECS/Utils/BigIntCompatibility.js.map +0 -1
- package/bin/ECS/Utils/BitMaskHashMap.d.ts +0 -28
- package/bin/ECS/Utils/BitMaskHashMap.d.ts.map +0 -1
- package/bin/ECS/Utils/BitMaskHashMap.js +0 -127
- package/bin/ECS/Utils/BitMaskHashMap.js.map +0 -1
- package/bin/ECS/Utils/Bits.d.ts +0 -154
- package/bin/ECS/Utils/Bits.d.ts.map +0 -1
- package/bin/ECS/Utils/Bits.js +0 -331
- package/bin/ECS/Utils/Bits.js.map +0 -1
- package/bin/ECS/Utils/ComponentSparseSet.d.ts +0 -143
- package/bin/ECS/Utils/ComponentSparseSet.d.ts.map +0 -1
- package/bin/ECS/Utils/ComponentSparseSet.js +0 -347
- package/bin/ECS/Utils/ComponentSparseSet.js.map +0 -1
- package/bin/ECS/Utils/EntityList.d.ts +0 -115
- package/bin/ECS/Utils/EntityList.d.ts.map +0 -1
- package/bin/ECS/Utils/EntityList.js +0 -258
- package/bin/ECS/Utils/EntityList.js.map +0 -1
- package/bin/ECS/Utils/EntityProcessorList.d.ts +0 -56
- package/bin/ECS/Utils/EntityProcessorList.d.ts.map +0 -1
- package/bin/ECS/Utils/EntityProcessorList.js +0 -113
- package/bin/ECS/Utils/EntityProcessorList.js.map +0 -1
- package/bin/ECS/Utils/IdentifierPool.d.ts +0 -203
- package/bin/ECS/Utils/IdentifierPool.d.ts.map +0 -1
- package/bin/ECS/Utils/IdentifierPool.js +0 -325
- package/bin/ECS/Utils/IdentifierPool.js.map +0 -1
- package/bin/ECS/Utils/Matcher.d.ts +0 -171
- package/bin/ECS/Utils/Matcher.d.ts.map +0 -1
- package/bin/ECS/Utils/Matcher.js +0 -293
- package/bin/ECS/Utils/Matcher.js.map +0 -1
- package/bin/ECS/Utils/SparseSet.d.ts +0 -170
- package/bin/ECS/Utils/SparseSet.d.ts.map +0 -1
- package/bin/ECS/Utils/SparseSet.js +0 -280
- package/bin/ECS/Utils/SparseSet.js.map +0 -1
- package/bin/ECS/Utils/index.d.ts +0 -9
- package/bin/ECS/Utils/index.d.ts.map +0 -1
- package/bin/ECS/Utils/index.js +0 -10
- package/bin/ECS/Utils/index.js.map +0 -1
- package/bin/ECS/World.d.ts +0 -238
- package/bin/ECS/World.d.ts.map +0 -1
- package/bin/ECS/World.js +0 -416
- package/bin/ECS/World.js.map +0 -1
- package/bin/ECS/WorldManager.d.ts +0 -224
- package/bin/ECS/WorldManager.d.ts.map +0 -1
- package/bin/ECS/WorldManager.js +0 -365
- package/bin/ECS/WorldManager.js.map +0 -1
- package/bin/ECS/index.d.ts +0 -26
- package/bin/ECS/index.d.ts.map +0 -1
- package/bin/ECS/index.js +0 -21
- package/bin/ECS/index.js.map +0 -1
- package/bin/Platform/IPlatformAdapter.d.ts +0 -169
- package/bin/Platform/IPlatformAdapter.d.ts.map +0 -1
- package/bin/Platform/IPlatformAdapter.js +0 -2
- package/bin/Platform/IPlatformAdapter.js.map +0 -1
- package/bin/Platform/PlatformDetector.d.ts +0 -56
- package/bin/Platform/PlatformDetector.d.ts.map +0 -1
- package/bin/Platform/PlatformDetector.js +0 -247
- package/bin/Platform/PlatformDetector.js.map +0 -1
- package/bin/Platform/PlatformManager.d.ts +0 -50
- package/bin/Platform/PlatformManager.d.ts.map +0 -1
- package/bin/Platform/PlatformManager.js +0 -114
- package/bin/Platform/PlatformManager.js.map +0 -1
- package/bin/Platform/index.d.ts +0 -19
- package/bin/Platform/index.d.ts.map +0 -1
- package/bin/Platform/index.js +0 -29
- package/bin/Platform/index.js.map +0 -1
- package/bin/Plugins/DebugPlugin.d.ts +0 -156
- package/bin/Plugins/DebugPlugin.d.ts.map +0 -1
- package/bin/Plugins/DebugPlugin.js +0 -248
- package/bin/Plugins/DebugPlugin.js.map +0 -1
- package/bin/Plugins/index.d.ts +0 -2
- package/bin/Plugins/index.d.ts.map +0 -1
- package/bin/Plugins/index.js +0 -2
- package/bin/Plugins/index.js.map +0 -1
- package/bin/Types/IUpdatable.d.ts +0 -18
- package/bin/Types/IUpdatable.d.ts.map +0 -1
- package/bin/Types/IUpdatable.js +0 -7
- package/bin/Types/IUpdatable.js.map +0 -1
- package/bin/Types/TypeHelpers.d.ts +0 -238
- package/bin/Types/TypeHelpers.d.ts.map +0 -1
- package/bin/Types/TypeHelpers.js +0 -19
- package/bin/Types/TypeHelpers.js.map +0 -1
- package/bin/Types/index.d.ts +0 -466
- package/bin/Types/index.d.ts.map +0 -1
- package/bin/Types/index.js +0 -7
- package/bin/Types/index.js.map +0 -1
- package/bin/Utils/BinarySerializer.d.ts +0 -23
- package/bin/Utils/BinarySerializer.d.ts.map +0 -1
- package/bin/Utils/BinarySerializer.js +0 -100
- package/bin/Utils/BinarySerializer.js.map +0 -1
- package/bin/Utils/Debug/AdvancedProfilerCollector.d.ts +0 -153
- package/bin/Utils/Debug/AdvancedProfilerCollector.d.ts.map +0 -1
- package/bin/Utils/Debug/AdvancedProfilerCollector.js +0 -406
- package/bin/Utils/Debug/AdvancedProfilerCollector.js.map +0 -1
- package/bin/Utils/Debug/ComponentDataCollector.d.ts +0 -32
- package/bin/Utils/Debug/ComponentDataCollector.d.ts.map +0 -1
- package/bin/Utils/Debug/ComponentDataCollector.js +0 -250
- package/bin/Utils/Debug/ComponentDataCollector.js.map +0 -1
- package/bin/Utils/Debug/DebugConfigService.d.ts +0 -16
- package/bin/Utils/Debug/DebugConfigService.d.ts.map +0 -1
- package/bin/Utils/Debug/DebugConfigService.js +0 -42
- package/bin/Utils/Debug/DebugConfigService.js.map +0 -1
- package/bin/Utils/Debug/DebugManager.d.ts +0 -131
- package/bin/Utils/Debug/DebugManager.d.ts.map +0 -1
- package/bin/Utils/Debug/DebugManager.js +0 -848
- package/bin/Utils/Debug/DebugManager.js.map +0 -1
- package/bin/Utils/Debug/EntityDataCollector.d.ts +0 -115
- package/bin/Utils/Debug/EntityDataCollector.d.ts.map +0 -1
- package/bin/Utils/Debug/EntityDataCollector.js +0 -870
- package/bin/Utils/Debug/EntityDataCollector.js.map +0 -1
- package/bin/Utils/Debug/PerformanceDataCollector.d.ts +0 -31
- package/bin/Utils/Debug/PerformanceDataCollector.d.ts.map +0 -1
- package/bin/Utils/Debug/PerformanceDataCollector.js +0 -203
- package/bin/Utils/Debug/PerformanceDataCollector.js.map +0 -1
- package/bin/Utils/Debug/SceneDataCollector.d.ts +0 -18
- package/bin/Utils/Debug/SceneDataCollector.d.ts.map +0 -1
- package/bin/Utils/Debug/SceneDataCollector.js +0 -43
- package/bin/Utils/Debug/SceneDataCollector.js.map +0 -1
- package/bin/Utils/Debug/SystemDataCollector.d.ts +0 -14
- package/bin/Utils/Debug/SystemDataCollector.d.ts.map +0 -1
- package/bin/Utils/Debug/SystemDataCollector.js +0 -60
- package/bin/Utils/Debug/SystemDataCollector.js.map +0 -1
- package/bin/Utils/Debug/WebSocketManager.d.ts +0 -54
- package/bin/Utils/Debug/WebSocketManager.d.ts.map +0 -1
- package/bin/Utils/Debug/WebSocketManager.js +0 -141
- package/bin/Utils/Debug/WebSocketManager.js.map +0 -1
- package/bin/Utils/Debug/index.d.ts +0 -11
- package/bin/Utils/Debug/index.d.ts.map +0 -1
- package/bin/Utils/Debug/index.js +0 -10
- package/bin/Utils/Debug/index.js.map +0 -1
- package/bin/Utils/Emitter.d.ts +0 -61
- package/bin/Utils/Emitter.d.ts.map +0 -1
- package/bin/Utils/Emitter.js +0 -101
- package/bin/Utils/Emitter.js.map +0 -1
- package/bin/Utils/Extensions/NumberExtension.d.ts +0 -13
- package/bin/Utils/Extensions/NumberExtension.d.ts.map +0 -1
- package/bin/Utils/Extensions/NumberExtension.js +0 -17
- package/bin/Utils/Extensions/NumberExtension.js.map +0 -1
- package/bin/Utils/Extensions/TypeUtils.d.ts +0 -13
- package/bin/Utils/Extensions/TypeUtils.d.ts.map +0 -1
- package/bin/Utils/Extensions/TypeUtils.js +0 -15
- package/bin/Utils/Extensions/TypeUtils.js.map +0 -1
- package/bin/Utils/Extensions/index.d.ts +0 -3
- package/bin/Utils/Extensions/index.d.ts.map +0 -1
- package/bin/Utils/Extensions/index.js +0 -4
- package/bin/Utils/Extensions/index.js.map +0 -1
- package/bin/Utils/GlobalManager.d.ts +0 -29
- package/bin/Utils/GlobalManager.d.ts.map +0 -1
- package/bin/Utils/GlobalManager.js +0 -50
- package/bin/Utils/GlobalManager.js.map +0 -1
- package/bin/Utils/Logger/ConsoleLogger.d.ts +0 -74
- package/bin/Utils/Logger/ConsoleLogger.d.ts.map +0 -1
- package/bin/Utils/Logger/ConsoleLogger.js +0 -187
- package/bin/Utils/Logger/ConsoleLogger.js.map +0 -1
- package/bin/Utils/Logger/Constants.d.ts +0 -36
- package/bin/Utils/Logger/Constants.d.ts.map +0 -1
- package/bin/Utils/Logger/Constants.js +0 -40
- package/bin/Utils/Logger/Constants.js.map +0 -1
- package/bin/Utils/Logger/LoggerManager.d.ts +0 -91
- package/bin/Utils/Logger/LoggerManager.d.ts.map +0 -1
- package/bin/Utils/Logger/LoggerManager.js +0 -167
- package/bin/Utils/Logger/LoggerManager.js.map +0 -1
- package/bin/Utils/Logger/Types.d.ts +0 -40
- package/bin/Utils/Logger/Types.d.ts.map +0 -1
- package/bin/Utils/Logger/Types.js +0 -2
- package/bin/Utils/Logger/Types.js.map +0 -1
- package/bin/Utils/Logger/index.d.ts +0 -5
- package/bin/Utils/Logger/index.d.ts.map +0 -1
- package/bin/Utils/Logger/index.js +0 -5
- package/bin/Utils/Logger/index.js.map +0 -1
- package/bin/Utils/PerformanceMonitor.d.ts +0 -196
- package/bin/Utils/PerformanceMonitor.d.ts.map +0 -1
- package/bin/Utils/PerformanceMonitor.js +0 -244
- package/bin/Utils/PerformanceMonitor.js.map +0 -1
- package/bin/Utils/Pool/IPoolable.d.ts +0 -29
- package/bin/Utils/Pool/IPoolable.d.ts.map +0 -1
- package/bin/Utils/Pool/IPoolable.js +0 -2
- package/bin/Utils/Pool/IPoolable.js.map +0 -1
- package/bin/Utils/Pool/Pool.d.ts +0 -109
- package/bin/Utils/Pool/Pool.d.ts.map +0 -1
- package/bin/Utils/Pool/Pool.js +0 -238
- package/bin/Utils/Pool/Pool.js.map +0 -1
- package/bin/Utils/Pool/PoolManager.d.ts +0 -96
- package/bin/Utils/Pool/PoolManager.d.ts.map +0 -1
- package/bin/Utils/Pool/PoolManager.js +0 -199
- package/bin/Utils/Pool/PoolManager.js.map +0 -1
- package/bin/Utils/Pool/index.d.ts +0 -4
- package/bin/Utils/Pool/index.d.ts.map +0 -1
- package/bin/Utils/Pool/index.js +0 -4
- package/bin/Utils/Pool/index.js.map +0 -1
- package/bin/Utils/Profiler/AutoProfiler.d.ts +0 -160
- package/bin/Utils/Profiler/AutoProfiler.d.ts.map +0 -1
- package/bin/Utils/Profiler/AutoProfiler.js +0 -503
- package/bin/Utils/Profiler/AutoProfiler.js.map +0 -1
- package/bin/Utils/Profiler/ProfilerSDK.d.ts +0 -175
- package/bin/Utils/Profiler/ProfilerSDK.d.ts.map +0 -1
- package/bin/Utils/Profiler/ProfilerSDK.js +0 -727
- package/bin/Utils/Profiler/ProfilerSDK.js.map +0 -1
- package/bin/Utils/Profiler/ProfilerTypes.d.ts +0 -218
- package/bin/Utils/Profiler/ProfilerTypes.d.ts.map +0 -1
- package/bin/Utils/Profiler/ProfilerTypes.js +0 -47
- package/bin/Utils/Profiler/ProfilerTypes.js.map +0 -1
- package/bin/Utils/Profiler/index.d.ts +0 -8
- package/bin/Utils/Profiler/index.d.ts.map +0 -1
- package/bin/Utils/Profiler/index.js +0 -7
- package/bin/Utils/Profiler/index.js.map +0 -1
- package/bin/Utils/Time.d.ts +0 -47
- package/bin/Utils/Time.d.ts.map +0 -1
- package/bin/Utils/Time.js +0 -64
- package/bin/Utils/Time.js.map +0 -1
- package/bin/Utils/Timers/ITimer.d.ts +0 -16
- package/bin/Utils/Timers/ITimer.d.ts.map +0 -1
- package/bin/Utils/Timers/ITimer.js +0 -2
- package/bin/Utils/Timers/ITimer.js.map +0 -1
- package/bin/Utils/Timers/Timer.d.ts +0 -30
- package/bin/Utils/Timers/Timer.d.ts.map +0 -1
- package/bin/Utils/Timers/Timer.js +0 -58
- package/bin/Utils/Timers/Timer.js.map +0 -1
- package/bin/Utils/Timers/TimerManager.d.ts +0 -26
- package/bin/Utils/Timers/TimerManager.d.ts.map +0 -1
- package/bin/Utils/Timers/TimerManager.js +0 -48
- package/bin/Utils/Timers/TimerManager.js.map +0 -1
- package/bin/Utils/index.d.ts +0 -11
- package/bin/Utils/index.d.ts.map +0 -1
- package/bin/Utils/index.js +0 -11
- package/bin/Utils/index.js.map +0 -1
- package/bin/index.d.ts +0 -29
- package/bin/index.d.ts.map +0 -1
- package/bin/index.js +0 -36
- 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
|