@nice2dev/game-engine 1.3.15 → 1.3.17
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/CHANGELOG.md +13 -0
- package/dist/cjs/accessibility/Accessibility.js +152 -165
- package/dist/cjs/ai/AI.js +292 -294
- package/dist/cjs/ai/BehaviorTree.js +1029 -1113
- package/dist/cjs/ai/StateMachine.js +694 -756
- package/dist/cjs/animation/Animation.js +232 -241
- package/dist/cjs/audio/AudioAdvanced.js +221 -236
- package/dist/cjs/audio/AudioBridge.js +441 -435
- package/dist/cjs/audio/AudioManager.js +242 -259
- package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
- package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
- package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
- package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
- package/dist/cjs/core/EventBus.js +51 -56
- package/dist/cjs/core/GameClock.js +62 -66
- package/dist/cjs/core/GameConfig.js +72 -79
- package/dist/cjs/core/GameLoop.js +80 -89
- package/dist/cjs/core/ServiceLocator.js +61 -65
- package/dist/cjs/core/Validation.js +72 -82
- package/dist/cjs/core/math.js +108 -112
- package/dist/cjs/devtools/DevTools.js +542 -563
- package/dist/cjs/devtools/DeveloperExperience.js +521 -559
- package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
- package/dist/cjs/dialogue/DialogueSystem.js +984 -986
- package/dist/cjs/docs/DocGenerator.js +339 -364
- package/dist/cjs/ecs/World.js +355 -371
- package/dist/cjs/editor/AchievementEditor.js +580 -636
- package/dist/cjs/editor/AdvancedEditor.js +184 -191
- package/dist/cjs/editor/AnimationRetargeting.js +696 -741
- package/dist/cjs/editor/AssetBrowser.js +1072 -1160
- package/dist/cjs/editor/AssetManager.js +187 -192
- package/dist/cjs/editor/ConsolePro.js +971 -1061
- package/dist/cjs/editor/CraftingEditor.js +680 -730
- package/dist/cjs/editor/DebugTools.js +187 -185
- package/dist/cjs/editor/DialogueSystem.js +844 -901
- package/dist/cjs/editor/LeaderboardSystem.js +429 -483
- package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
- package/dist/cjs/editor/PrefabSystem.js +772 -838
- package/dist/cjs/editor/ProfilerPanel.js +649 -700
- package/dist/cjs/editor/QuestEditor.js +792 -839
- package/dist/cjs/editor/ReplaySystem.js +585 -634
- package/dist/cjs/editor/SceneEditor.js +176 -200
- package/dist/cjs/editor/ScreenshotMode.js +621 -688
- package/dist/cjs/editor/ShaderGraph.js +1556 -1582
- package/dist/cjs/editor/TimelineEditor.js +715 -778
- package/dist/cjs/editor/UndoRedoPro.js +830 -904
- package/dist/cjs/editor/VRARMode.js +582 -645
- package/dist/cjs/engine/NiceGameEngine.js +141 -164
- package/dist/cjs/engine/SaveSystem.js +441 -495
- package/dist/cjs/enterprise/Enterprise.js +254 -261
- package/dist/cjs/export/BevyExporter.js +927 -967
- package/dist/cjs/export/CocosExporter.js +644 -673
- package/dist/cjs/export/Construct3Exporter.js +783 -794
- package/dist/cjs/export/DefoldExporter.js +1028 -1069
- package/dist/cjs/export/GDevelopExporter.js +674 -708
- package/dist/cjs/export/GameMakerExporter.js +791 -805
- package/dist/cjs/export/GodotExporter.js +1003 -1045
- package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
- package/dist/cjs/export/MonoGameExporter.js +1265 -1293
- package/dist/cjs/export/Pico8Exporter.js +766 -812
- package/dist/cjs/export/PlatformExporter.js +188 -206
- package/dist/cjs/export/RPGMakerExporter.js +860 -879
- package/dist/cjs/export/RobloxExporter.js +883 -919
- package/dist/cjs/export/Solar2DExporter.js +1218 -1256
- package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
- package/dist/cjs/export/Tic80Exporter.js +1210 -1267
- package/dist/cjs/export/UnityExporter.js +1116 -1131
- package/dist/cjs/export/UnrealExporter.js +889 -919
- package/dist/cjs/export/WebExporter.js +931 -970
- package/dist/cjs/export/index.js +42 -65
- package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
- package/dist/cjs/godot-integration/GodotImport.js +929 -1027
- package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
- package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
- package/dist/cjs/i18n/I18n.js +860 -900
- package/dist/cjs/i18n/useTranslation.js +84 -89
- package/dist/cjs/import/AsepriteImporter.js +658 -716
- package/dist/cjs/import/DragonBonesImporter.js +437 -461
- package/dist/cjs/import/GameMakerImporter.js +511 -521
- package/dist/cjs/import/GodotSceneImporter.js +788 -822
- package/dist/cjs/import/LDtkImporter.js +436 -454
- package/dist/cjs/import/Live2DImporter.js +497 -518
- package/dist/cjs/import/NdgFormat.js +424 -457
- package/dist/cjs/import/OgmoImporter.js +466 -493
- package/dist/cjs/import/RPGMakerImporter.js +451 -477
- package/dist/cjs/import/SceneImporter.js +378 -423
- package/dist/cjs/import/SpineImporter.js +511 -546
- package/dist/cjs/import/SpriterImporter.js +590 -613
- package/dist/cjs/import/TiledMapImporter.js +811 -846
- package/dist/cjs/import/UnitySceneImporter.js +687 -703
- package/dist/cjs/import/index.js +206 -251
- package/dist/cjs/index.js +275 -278
- package/dist/cjs/input/GamepadNavigation.js +185 -205
- package/dist/cjs/input/InputManager.js +397 -421
- package/dist/cjs/input/useGamepads.js +70 -81
- package/dist/cjs/integration/IconSprite.js +129 -256
- package/dist/cjs/inventory/InventorySystem.js +920 -995
- package/dist/cjs/kids/KidMode.js +997 -1022
- package/dist/cjs/kids/KidTools.js +570 -594
- package/dist/cjs/monetization/Monetization.js +170 -177
- package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
- package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
- package/dist/cjs/native-engine/AnimationSystem.js +731 -806
- package/dist/cjs/native-engine/AssetPipeline.js +454 -515
- package/dist/cjs/native-engine/AudioEngine.js +763 -804
- package/dist/cjs/native-engine/InputSystem.js +1075 -1145
- package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
- package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
- package/dist/cjs/native-engine/RenderingEngine.js +302 -350
- package/dist/cjs/native-engine/SceneGraph.js +769 -808
- package/dist/cjs/network/MultiplayerTransport.js +97 -132
- package/dist/cjs/network/Networking.js +549 -564
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
- package/dist/cjs/pathfinding/Pathfinding.js +245 -263
- package/dist/cjs/performance/AssetStreaming.js +561 -635
- package/dist/cjs/performance/BenchmarkSuite.js +283 -311
- package/dist/cjs/performance/DeltaCompression.js +467 -526
- package/dist/cjs/performance/DeterministicPhysics.js +450 -498
- package/dist/cjs/performance/ECSOptimization.js +644 -695
- package/dist/cjs/performance/GameSaveSystem.js +509 -556
- package/dist/cjs/performance/HotReload.js +447 -500
- package/dist/cjs/performance/InputRecording.js +511 -561
- package/dist/cjs/performance/InterestManagement.js +453 -500
- package/dist/cjs/performance/LocalizationRuntime.js +376 -423
- package/dist/cjs/performance/MemoryManagement.js +410 -470
- package/dist/cjs/performance/ModSupport.js +445 -496
- package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
- package/dist/cjs/performance/NetworkPrediction.js +424 -482
- package/dist/cjs/performance/ObjectPooling.js +569 -617
- package/dist/cjs/performance/Performance.js +174 -190
- package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
- package/dist/cjs/performance/WebGPURenderer.js +656 -683
- package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
- package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
- package/dist/cjs/plugins/PluginSDK.js +432 -466
- package/dist/cjs/plugins/PluginTestKit.js +307 -330
- package/dist/cjs/procedural/Procedural.js +243 -254
- package/dist/cjs/procedural/WorldBuilding.js +297 -314
- package/dist/cjs/quest/QuestSystem.js +975 -932
- package/dist/cjs/release/MobileExport.js +157 -163
- package/dist/cjs/release/Release.js +225 -238
- package/dist/cjs/rendering/Camera2D.js +121 -124
- package/dist/cjs/rendering/Renderer2D.js +321 -335
- package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
- package/dist/cjs/runtime3d/Runtime3D.js +359 -378
- package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
- package/dist/cjs/scene/SceneManager.js +177 -193
- package/dist/cjs/scripting/GraphToAST.js +574 -547
- package/dist/cjs/scripting/LanguageExporter.js +254 -279
- package/dist/cjs/scripting/NodeGraph.js +546 -570
- package/dist/cjs/scripting/ScriptAST.js +31 -39
- package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
- package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
- package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
- package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
- package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
- package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
- package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
- package/dist/cjs/social/Social.js +72 -80
- package/dist/cjs/systems/LightingSystem.js +844 -931
- package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
- package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
- package/dist/cjs/systems/TerrainSystem.js +985 -1098
- package/dist/cjs/templates/ActionTemplates.js +296 -309
- package/dist/cjs/templates/FightingTemplate.js +417 -463
- package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
- package/dist/cjs/templates/PartyTemplates.js +190 -202
- package/dist/cjs/templates/PuzzleTemplates.js +245 -261
- package/dist/cjs/templates/RPGTemplates.js +160 -178
- package/dist/cjs/templates/SportsTemplates.js +237 -250
- package/dist/cjs/templates/StrategyTemplates.js +143 -153
- package/dist/cjs/templates/SurvivalTemplate.js +336 -380
- package/dist/cjs/templates/WaveDefense.js +499 -526
- package/dist/cjs/tilemap/Tilemap.js +207 -214
- package/dist/cjs/tutorials/TutorialBranching.js +396 -417
- package/dist/cjs/tutorials/TutorialEngine.js +888 -931
- package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
- package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
- package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
- package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
- package/dist/cjs/ui/GameUI.js +295 -312
- package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
- package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
- package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
- package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
- package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
- package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
- package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
- package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
- package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
- package/dist/cjs/xr/ARVR.js +167 -175
- package/dist/esm/accessibility/Accessibility.js +160 -164
- package/dist/esm/ai/AI.js +310 -293
- package/dist/esm/ai/BehaviorTree.js +1057 -1112
- package/dist/esm/ai/StateMachine.js +709 -755
- package/dist/esm/animation/Animation.js +237 -240
- package/dist/esm/audio/AudioAdvanced.js +239 -235
- package/dist/esm/audio/AudioBridge.js +448 -434
- package/dist/esm/audio/AudioManager.js +243 -258
- package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
- package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
- package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
- package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
- package/dist/esm/core/EventBus.js +52 -55
- package/dist/esm/core/GameClock.js +63 -65
- package/dist/esm/core/GameConfig.js +77 -78
- package/dist/esm/core/GameLoop.js +81 -88
- package/dist/esm/core/ServiceLocator.js +63 -64
- package/dist/esm/core/Validation.js +82 -81
- package/dist/esm/core/math.js +109 -111
- package/dist/esm/devtools/DevTools.js +546 -562
- package/dist/esm/devtools/DeveloperExperience.js +535 -558
- package/dist/esm/devtools/GameplayAnalytics.js +647 -645
- package/dist/esm/dialogue/DialogueSystem.js +998 -985
- package/dist/esm/docs/DocGenerator.js +342 -363
- package/dist/esm/ecs/World.js +358 -370
- package/dist/esm/editor/AchievementEditor.js +584 -635
- package/dist/esm/editor/AdvancedEditor.js +191 -190
- package/dist/esm/editor/AnimationRetargeting.js +700 -740
- package/dist/esm/editor/AssetBrowser.js +1078 -1159
- package/dist/esm/editor/AssetManager.js +188 -191
- package/dist/esm/editor/ConsolePro.js +977 -1060
- package/dist/esm/editor/CraftingEditor.js +684 -729
- package/dist/esm/editor/DebugTools.js +194 -184
- package/dist/esm/editor/DialogueSystem.js +849 -900
- package/dist/esm/editor/LeaderboardSystem.js +433 -482
- package/dist/esm/editor/NiceGameEditor.js +1908 -1200
- package/dist/esm/editor/PrefabSystem.js +777 -837
- package/dist/esm/editor/ProfilerPanel.js +654 -699
- package/dist/esm/editor/QuestEditor.js +795 -838
- package/dist/esm/editor/ReplaySystem.js +591 -633
- package/dist/esm/editor/SceneEditor.js +189 -199
- package/dist/esm/editor/ScreenshotMode.js +628 -687
- package/dist/esm/editor/ShaderGraph.js +1565 -1581
- package/dist/esm/editor/TimelineEditor.js +733 -777
- package/dist/esm/editor/UndoRedoPro.js +835 -903
- package/dist/esm/editor/VRARMode.js +586 -644
- package/dist/esm/engine/NiceGameEngine.js +142 -163
- package/dist/esm/engine/SaveSystem.js +447 -494
- package/dist/esm/enterprise/Enterprise.js +265 -260
- package/dist/esm/export/BevyExporter.js +929 -966
- package/dist/esm/export/CocosExporter.js +646 -672
- package/dist/esm/export/Construct3Exporter.js +785 -793
- package/dist/esm/export/DefoldExporter.js +1030 -1068
- package/dist/esm/export/GDevelopExporter.js +676 -707
- package/dist/esm/export/GameMakerExporter.js +793 -804
- package/dist/esm/export/GodotExporter.js +1004 -1044
- package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
- package/dist/esm/export/MonoGameExporter.js +1267 -1292
- package/dist/esm/export/Pico8Exporter.js +768 -811
- package/dist/esm/export/PlatformExporter.js +193 -205
- package/dist/esm/export/RPGMakerExporter.js +862 -878
- package/dist/esm/export/RobloxExporter.js +885 -918
- package/dist/esm/export/Solar2DExporter.js +1220 -1255
- package/dist/esm/export/ThreeJSExporter.js +1007 -1072
- package/dist/esm/export/Tic80Exporter.js +1212 -1266
- package/dist/esm/export/UnityExporter.js +1117 -1130
- package/dist/esm/export/UnrealExporter.js +891 -918
- package/dist/esm/export/WebExporter.js +933 -969
- package/dist/esm/export/index.js +86 -71
- package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
- package/dist/esm/godot-integration/GodotImport.js +935 -1026
- package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
- package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
- package/dist/esm/i18n/I18n.js +871 -899
- package/dist/esm/i18n/useTranslation.js +88 -88
- package/dist/esm/import/AsepriteImporter.js +637 -715
- package/dist/esm/import/DragonBonesImporter.js +417 -460
- package/dist/esm/import/GameMakerImporter.js +491 -520
- package/dist/esm/import/GodotSceneImporter.js +767 -821
- package/dist/esm/import/LDtkImporter.js +415 -453
- package/dist/esm/import/Live2DImporter.js +477 -517
- package/dist/esm/import/NdgFormat.js +410 -456
- package/dist/esm/import/OgmoImporter.js +446 -492
- package/dist/esm/import/RPGMakerImporter.js +431 -476
- package/dist/esm/import/SceneImporter.js +385 -422
- package/dist/esm/import/SpineImporter.js +491 -545
- package/dist/esm/import/SpriterImporter.js +570 -612
- package/dist/esm/import/TiledMapImporter.js +790 -845
- package/dist/esm/import/UnitySceneImporter.js +666 -702
- package/dist/esm/import/index.js +247 -258
- package/dist/esm/index.js +1332 -188
- package/dist/esm/input/GamepadNavigation.js +187 -204
- package/dist/esm/input/InputManager.js +401 -420
- package/dist/esm/input/useGamepads.js +72 -80
- package/dist/esm/integration/IconSprite.js +143 -255
- package/dist/esm/inventory/InventorySystem.js +925 -994
- package/dist/esm/kids/KidMode.js +1003 -1021
- package/dist/esm/kids/KidTools.js +573 -593
- package/dist/esm/monetization/Monetization.js +180 -176
- package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
- package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
- package/dist/esm/native-engine/AnimationSystem.js +735 -805
- package/dist/esm/native-engine/AssetPipeline.js +456 -514
- package/dist/esm/native-engine/AudioEngine.js +765 -803
- package/dist/esm/native-engine/InputSystem.js +1079 -1144
- package/dist/esm/native-engine/NetworkingSystem.js +740 -792
- package/dist/esm/native-engine/PhysicsEngine.js +585 -606
- package/dist/esm/native-engine/RenderingEngine.js +304 -349
- package/dist/esm/native-engine/SceneGraph.js +773 -807
- package/dist/esm/network/MultiplayerTransport.js +99 -131
- package/dist/esm/network/Networking.js +556 -563
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
- package/dist/esm/pathfinding/Pathfinding.js +249 -262
- package/dist/esm/performance/AssetStreaming.js +567 -634
- package/dist/esm/performance/BenchmarkSuite.js +285 -310
- package/dist/esm/performance/DeltaCompression.js +478 -525
- package/dist/esm/performance/DeterministicPhysics.js +479 -497
- package/dist/esm/performance/ECSOptimization.js +653 -694
- package/dist/esm/performance/GameSaveSystem.js +515 -555
- package/dist/esm/performance/HotReload.js +454 -499
- package/dist/esm/performance/InputRecording.js +520 -560
- package/dist/esm/performance/InterestManagement.js +460 -499
- package/dist/esm/performance/LocalizationRuntime.js +382 -422
- package/dist/esm/performance/MemoryManagement.js +415 -469
- package/dist/esm/performance/ModSupport.js +455 -495
- package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
- package/dist/esm/performance/NetworkPrediction.js +436 -481
- package/dist/esm/performance/ObjectPooling.js +582 -616
- package/dist/esm/performance/Performance.js +182 -189
- package/dist/esm/performance/PerformanceAdvanced.js +621 -636
- package/dist/esm/performance/WebGPURenderer.js +660 -682
- package/dist/esm/physics/PhysicsAdvanced.js +359 -378
- package/dist/esm/physics/PhysicsEngine2D.js +393 -426
- package/dist/esm/plugins/PluginSDK.js +435 -465
- package/dist/esm/plugins/PluginTestKit.js +315 -329
- package/dist/esm/procedural/Procedural.js +248 -253
- package/dist/esm/procedural/WorldBuilding.js +316 -313
- package/dist/esm/quest/QuestSystem.js +982 -931
- package/dist/esm/release/MobileExport.js +163 -162
- package/dist/esm/release/Release.js +234 -237
- package/dist/esm/rendering/Camera2D.js +122 -123
- package/dist/esm/rendering/Renderer2D.js +323 -334
- package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
- package/dist/esm/runtime3d/Runtime3D.js +368 -377
- package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
- package/dist/esm/scene/SceneManager.js +178 -192
- package/dist/esm/scripting/GraphToAST.js +576 -546
- package/dist/esm/scripting/LanguageExporter.js +263 -278
- package/dist/esm/scripting/NodeGraph.js +550 -569
- package/dist/esm/scripting/ScriptAST.js +45 -38
- package/dist/esm/scripting/VisualScripting2.js +1025 -1064
- package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
- package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
- package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
- package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
- package/dist/esm/scripting/exporters/RustExporter.js +460 -511
- package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
- package/dist/esm/social/Social.js +77 -79
- package/dist/esm/systems/LightingSystem.js +855 -930
- package/dist/esm/systems/ParticleSystem2.js +1453 -1450
- package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
- package/dist/esm/systems/TerrainSystem.js +996 -1097
- package/dist/esm/templates/ActionTemplates.js +307 -308
- package/dist/esm/templates/FightingTemplate.js +439 -462
- package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
- package/dist/esm/templates/PartyTemplates.js +206 -201
- package/dist/esm/templates/PuzzleTemplates.js +260 -260
- package/dist/esm/templates/RPGTemplates.js +172 -177
- package/dist/esm/templates/SportsTemplates.js +251 -249
- package/dist/esm/templates/StrategyTemplates.js +158 -152
- package/dist/esm/templates/SurvivalTemplate.js +367 -379
- package/dist/esm/templates/WaveDefense.js +501 -525
- package/dist/esm/tilemap/Tilemap.js +209 -213
- package/dist/esm/tutorials/TutorialBranching.js +399 -416
- package/dist/esm/tutorials/TutorialEngine.js +893 -930
- package/dist/esm/tutorials/TutorialOverlay.js +603 -639
- package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
- package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
- package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
- package/dist/esm/ui/GameUI.js +296 -311
- package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
- package/dist/esm/unity-integration/UnityImport.js +1071 -1175
- package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
- package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
- package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
- package/dist/esm/unreal-integration/UnrealImport.js +395 -411
- package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
- package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
- package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
- package/dist/esm/xr/ARVR.js +181 -174
- package/package.json +7 -12
|
@@ -1,572 +1,554 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file DeterministicPhysics.ts
|
|
3
|
-
* @description Deterministic physics simulation for competitive games
|
|
4
|
-
* PRO-1.5: Runtime & Performance
|
|
5
|
-
*
|
|
6
|
-
* Features:
|
|
7
|
-
* - Fixed-point arithmetic
|
|
8
|
-
* - Deterministic collision detection
|
|
9
|
-
* - Frame-based simulation
|
|
10
|
-
* - Lockstep networking support
|
|
11
|
-
* - State hashing for desync detection
|
|
12
|
-
* - Replay validation
|
|
13
|
-
*/
|
|
14
1
|
const FIXED_SHIFT = 16;
|
|
15
2
|
const FIXED_ONE = 1 << FIXED_SHIFT;
|
|
16
3
|
const FIXED_HALF = FIXED_ONE >> 1;
|
|
17
|
-
// ============================================================
|
|
18
|
-
// Default Configuration
|
|
19
|
-
// ============================================================
|
|
20
4
|
const DEFAULT_DETERMINISTIC_CONFIG = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
gravity: { x: 0, y: fixedFromFloat(-9.81) },
|
|
6
|
+
maxBodies: 1e3,
|
|
7
|
+
maxIterations: 10,
|
|
8
|
+
substeps: 4,
|
|
9
|
+
sleepThreshold: fixedFromFloat(0.01),
|
|
10
|
+
sleepFrames: 60,
|
|
11
|
+
broadphase: "spatial",
|
|
12
|
+
cellSize: 100
|
|
29
13
|
};
|
|
30
|
-
// ============================================================
|
|
31
|
-
// Fixed-Point Math
|
|
32
|
-
// ============================================================
|
|
33
14
|
function fixedFromFloat(f) {
|
|
34
|
-
|
|
15
|
+
return Math.round(f * FIXED_ONE);
|
|
35
16
|
}
|
|
36
17
|
function fixedToFloat(f) {
|
|
37
|
-
|
|
18
|
+
return f / FIXED_ONE;
|
|
38
19
|
}
|
|
39
20
|
function fixedMul(a, b) {
|
|
40
|
-
|
|
41
|
-
return Number((BigInt(a) * BigInt(b)) >> BigInt(FIXED_SHIFT));
|
|
21
|
+
return Number(BigInt(a) * BigInt(b) >> BigInt(FIXED_SHIFT));
|
|
42
22
|
}
|
|
43
23
|
function fixedDiv(a, b) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
if (b === 0) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
return Number((BigInt(a) << BigInt(FIXED_SHIFT)) / BigInt(b));
|
|
48
28
|
}
|
|
49
29
|
function fixedSqrt(a) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return x;
|
|
30
|
+
if (a <= 0) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
let x = a;
|
|
34
|
+
let y = x + FIXED_ONE >> 1;
|
|
35
|
+
while (y < x) {
|
|
36
|
+
x = y;
|
|
37
|
+
y = x + fixedDiv(a, x) >> 1;
|
|
38
|
+
}
|
|
39
|
+
return x;
|
|
61
40
|
}
|
|
62
41
|
function fixedAbs(a) {
|
|
63
|
-
|
|
42
|
+
return a < 0 ? -a : a;
|
|
64
43
|
}
|
|
65
44
|
function fixedMin(a, b) {
|
|
66
|
-
|
|
45
|
+
return a < b ? a : b;
|
|
67
46
|
}
|
|
68
47
|
function fixedMax(a, b) {
|
|
69
|
-
|
|
48
|
+
return a > b ? a : b;
|
|
70
49
|
}
|
|
71
50
|
function fixedClamp(value, min, max) {
|
|
72
|
-
|
|
51
|
+
return fixedMin(fixedMax(value, min), max);
|
|
73
52
|
}
|
|
74
|
-
// ============================================================
|
|
75
|
-
// Fixed-Point Vector Math
|
|
76
|
-
// ============================================================
|
|
77
53
|
function vec2Add(a, b) {
|
|
78
|
-
|
|
54
|
+
return { x: a.x + b.x, y: a.y + b.y };
|
|
79
55
|
}
|
|
80
56
|
function vec2Sub(a, b) {
|
|
81
|
-
|
|
57
|
+
return { x: a.x - b.x, y: a.y - b.y };
|
|
82
58
|
}
|
|
83
59
|
function vec2Scale(v, s) {
|
|
84
|
-
|
|
60
|
+
return { x: fixedMul(v.x, s), y: fixedMul(v.y, s) };
|
|
85
61
|
}
|
|
86
62
|
function vec2Dot(a, b) {
|
|
87
|
-
|
|
63
|
+
return fixedMul(a.x, b.x) + fixedMul(a.y, b.y);
|
|
88
64
|
}
|
|
89
65
|
function vec2LengthSq(v) {
|
|
90
|
-
|
|
66
|
+
return vec2Dot(v, v);
|
|
91
67
|
}
|
|
92
68
|
function vec2Length(v) {
|
|
93
|
-
|
|
69
|
+
return fixedSqrt(vec2LengthSq(v));
|
|
94
70
|
}
|
|
95
71
|
function vec2Normalize(v) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
72
|
+
const len = vec2Length(v);
|
|
73
|
+
if (len === 0) {
|
|
74
|
+
return { x: 0, y: 0 };
|
|
75
|
+
}
|
|
76
|
+
return { x: fixedDiv(v.x, len), y: fixedDiv(v.y, len) };
|
|
101
77
|
}
|
|
102
78
|
function vec2Negate(v) {
|
|
103
|
-
|
|
79
|
+
return { x: -v.x, y: -v.y };
|
|
104
80
|
}
|
|
105
|
-
// ============================================================
|
|
106
|
-
// Collision Detection
|
|
107
|
-
// ============================================================
|
|
108
81
|
function circleVsCircle(posA, radiusA, posB, radiusB) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
82
|
+
const diff = vec2Sub(posB, posA);
|
|
83
|
+
const distSq = vec2LengthSq(diff);
|
|
84
|
+
const totalRadius = radiusA + radiusB;
|
|
85
|
+
const totalRadiusSq = fixedMul(totalRadius, totalRadius);
|
|
86
|
+
if (distSq >= totalRadiusSq) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const dist = fixedSqrt(distSq);
|
|
90
|
+
const normal = dist > 0 ? vec2Normalize(diff) : { x: FIXED_ONE, y: 0 };
|
|
91
|
+
const penetration = totalRadius - dist;
|
|
92
|
+
const contactPoint = vec2Add(posA, vec2Scale(normal, radiusA));
|
|
93
|
+
return {
|
|
94
|
+
bodyA: "",
|
|
95
|
+
bodyB: "",
|
|
96
|
+
normal,
|
|
97
|
+
penetration,
|
|
98
|
+
contactPoint
|
|
99
|
+
};
|
|
127
100
|
}
|
|
128
101
|
function aabbVsAABB(posA, halfA, posB, halfB) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
102
|
+
const dx = posB.x - posA.x;
|
|
103
|
+
const dy = posB.y - posA.y;
|
|
104
|
+
const overlapX = halfA.x + halfB.x - fixedAbs(dx);
|
|
105
|
+
const overlapY = halfA.y + halfB.y - fixedAbs(dy);
|
|
106
|
+
if (overlapX <= 0 || overlapY <= 0) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
let normal;
|
|
110
|
+
let penetration;
|
|
111
|
+
if (overlapX < overlapY) {
|
|
112
|
+
penetration = overlapX;
|
|
113
|
+
normal = { x: dx > 0 ? FIXED_ONE : -FIXED_ONE, y: 0 };
|
|
114
|
+
} else {
|
|
115
|
+
penetration = overlapY;
|
|
116
|
+
normal = { x: 0, y: dy > 0 ? FIXED_ONE : -FIXED_ONE };
|
|
117
|
+
}
|
|
118
|
+
const contactPoint = {
|
|
119
|
+
x: posA.x + fixedMul(normal.x, halfA.x),
|
|
120
|
+
y: posA.y + fixedMul(normal.y, halfA.y)
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
bodyA: "",
|
|
124
|
+
bodyB: "",
|
|
125
|
+
normal,
|
|
126
|
+
penetration,
|
|
127
|
+
contactPoint
|
|
128
|
+
};
|
|
157
129
|
}
|
|
158
130
|
function circleVsAABB(circlePos, radius, aabbPos, halfExtents) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
131
|
+
const closestX = fixedClamp(circlePos.x, aabbPos.x - halfExtents.x, aabbPos.x + halfExtents.x);
|
|
132
|
+
const closestY = fixedClamp(circlePos.y, aabbPos.y - halfExtents.y, aabbPos.y + halfExtents.y);
|
|
133
|
+
const diff = vec2Sub(circlePos, { x: closestX, y: closestY });
|
|
134
|
+
const distSq = vec2LengthSq(diff);
|
|
135
|
+
const radiusSq = fixedMul(radius, radius);
|
|
136
|
+
if (distSq >= radiusSq) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const dist = fixedSqrt(distSq);
|
|
140
|
+
const normal = dist > 0 ? vec2Normalize(diff) : { x: FIXED_ONE, y: 0 };
|
|
141
|
+
const penetration = radius - dist;
|
|
142
|
+
const contactPoint = { x: closestX, y: closestY };
|
|
143
|
+
return {
|
|
144
|
+
bodyA: "",
|
|
145
|
+
bodyB: "",
|
|
146
|
+
normal,
|
|
147
|
+
penetration,
|
|
148
|
+
contactPoint
|
|
149
|
+
};
|
|
178
150
|
}
|
|
179
|
-
// ============================================================
|
|
180
|
-
// Spatial Hash (Fixed-Point)
|
|
181
|
-
// ============================================================
|
|
182
151
|
class FixedSpatialHash {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
152
|
+
constructor(cellSize) {
|
|
153
|
+
this.cells = /* @__PURE__ */ new Map();
|
|
154
|
+
this.bodyPositions = /* @__PURE__ */ new Map();
|
|
155
|
+
this.cellSize = cellSize;
|
|
156
|
+
}
|
|
157
|
+
getCellKey(pos) {
|
|
158
|
+
const cellX = Math.floor(fixedToFloat(pos.x) / this.cellSize);
|
|
159
|
+
const cellY = Math.floor(fixedToFloat(pos.y) / this.cellSize);
|
|
160
|
+
return `${cellX},${cellY}`;
|
|
161
|
+
}
|
|
162
|
+
insert(id, position) {
|
|
163
|
+
const key = this.getCellKey(position);
|
|
164
|
+
if (!this.cells.has(key)) {
|
|
165
|
+
this.cells.set(key, /* @__PURE__ */ new Set());
|
|
166
|
+
}
|
|
167
|
+
this.cells.get(key).add(id);
|
|
168
|
+
this.bodyPositions.set(id, { ...position });
|
|
169
|
+
}
|
|
170
|
+
update(id, newPosition) {
|
|
171
|
+
const oldPosition = this.bodyPositions.get(id);
|
|
172
|
+
if (oldPosition) {
|
|
173
|
+
const oldKey = this.getCellKey(oldPosition);
|
|
174
|
+
const newKey = this.getCellKey(newPosition);
|
|
175
|
+
if (oldKey !== newKey) {
|
|
176
|
+
this.cells.get(oldKey)?.delete(id);
|
|
177
|
+
if (!this.cells.has(newKey)) {
|
|
178
|
+
this.cells.set(newKey, /* @__PURE__ */ new Set());
|
|
197
179
|
}
|
|
198
|
-
this.cells.get(
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
180
|
+
this.cells.get(newKey).add(id);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
this.bodyPositions.set(id, { ...newPosition });
|
|
184
|
+
}
|
|
185
|
+
remove(id) {
|
|
186
|
+
const position = this.bodyPositions.get(id);
|
|
187
|
+
if (position) {
|
|
188
|
+
const key = this.getCellKey(position);
|
|
189
|
+
this.cells.get(key)?.delete(id);
|
|
190
|
+
this.bodyPositions.delete(id);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
queryNearby(id) {
|
|
194
|
+
const position = this.bodyPositions.get(id);
|
|
195
|
+
if (!position) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
const results = [];
|
|
199
|
+
const cellX = Math.floor(fixedToFloat(position.x) / this.cellSize);
|
|
200
|
+
const cellY = Math.floor(fixedToFloat(position.y) / this.cellSize);
|
|
201
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
202
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
203
|
+
const key = `${cellX + dx},${cellY + dy}`;
|
|
204
|
+
const cell = this.cells.get(key);
|
|
205
|
+
if (cell) {
|
|
206
|
+
for (const otherId of cell) {
|
|
207
|
+
if (otherId !== id) {
|
|
208
|
+
results.push(otherId);
|
|
212
209
|
}
|
|
210
|
+
}
|
|
213
211
|
}
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
queryNearby(id) {
|
|
225
|
-
const position = this.bodyPositions.get(id);
|
|
226
|
-
if (!position) {
|
|
227
|
-
return [];
|
|
228
|
-
}
|
|
229
|
-
const results = [];
|
|
230
|
-
const cellX = Math.floor(fixedToFloat(position.x) / this.cellSize);
|
|
231
|
-
const cellY = Math.floor(fixedToFloat(position.y) / this.cellSize);
|
|
232
|
-
for (let dx = -1; dx <= 1; dx++) {
|
|
233
|
-
for (let dy = -1; dy <= 1; dy++) {
|
|
234
|
-
const key = `${cellX + dx},${cellY + dy}`;
|
|
235
|
-
const cell = this.cells.get(key);
|
|
236
|
-
if (cell) {
|
|
237
|
-
for (const otherId of cell) {
|
|
238
|
-
if (otherId !== id) {
|
|
239
|
-
results.push(otherId);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return results;
|
|
246
|
-
}
|
|
247
|
-
clear() {
|
|
248
|
-
this.cells.clear();
|
|
249
|
-
this.bodyPositions.clear();
|
|
250
|
-
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return results;
|
|
215
|
+
}
|
|
216
|
+
clear() {
|
|
217
|
+
this.cells.clear();
|
|
218
|
+
this.bodyPositions.clear();
|
|
219
|
+
}
|
|
251
220
|
}
|
|
252
|
-
// ============================================================
|
|
253
|
-
// Deterministic Physics World
|
|
254
|
-
// ============================================================
|
|
255
221
|
class DeterministicWorld {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
222
|
+
constructor(config) {
|
|
223
|
+
this.bodies = /* @__PURE__ */ new Map();
|
|
224
|
+
this.frame = 0;
|
|
225
|
+
this.collisionPairs = [];
|
|
226
|
+
this.config = { ...DEFAULT_DETERMINISTIC_CONFIG, ...config };
|
|
227
|
+
this.spatialHash = new FixedSpatialHash(this.config.cellSize);
|
|
228
|
+
}
|
|
229
|
+
// ─── Body Management ───────────────────────────────────
|
|
230
|
+
addBody(body) {
|
|
231
|
+
this.bodies.set(body.id, body);
|
|
232
|
+
if (this.config.broadphase === "spatial") {
|
|
233
|
+
this.spatialHash.insert(body.id, body.position);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
removeBody(id) {
|
|
237
|
+
this.bodies.delete(id);
|
|
238
|
+
if (this.config.broadphase === "spatial") {
|
|
239
|
+
this.spatialHash.remove(id);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
getBody(id) {
|
|
243
|
+
return this.bodies.get(id);
|
|
244
|
+
}
|
|
245
|
+
// ─── Simulation ────────────────────────────────────────
|
|
246
|
+
step(dt) {
|
|
247
|
+
const substepDt = fixedDiv(dt, fixedFromFloat(this.config.substeps));
|
|
248
|
+
for (let i = 0; i < this.config.substeps; i++) {
|
|
249
|
+
this.integrate(substepDt);
|
|
250
|
+
this.broadphase();
|
|
251
|
+
this.narrowphase();
|
|
252
|
+
this.resolveCollisions();
|
|
253
|
+
}
|
|
254
|
+
if (this.config.broadphase === "spatial") {
|
|
255
|
+
for (const body of this.bodies.values()) {
|
|
256
|
+
this.spatialHash.update(body.id, body.position);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
this.frame++;
|
|
260
|
+
}
|
|
261
|
+
integrate(dt) {
|
|
262
|
+
for (const body of this.bodies.values()) {
|
|
263
|
+
if (body.isStatic) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
body.acceleration = vec2Add(body.acceleration, this.config.gravity);
|
|
267
|
+
body.velocity = vec2Add(body.velocity, vec2Scale(body.acceleration, dt));
|
|
268
|
+
body.position = vec2Add(body.position, vec2Scale(body.velocity, dt));
|
|
269
|
+
body.acceleration = { x: 0, y: 0 };
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
broadphase() {
|
|
273
|
+
this.collisionPairs = [];
|
|
274
|
+
const checked = /* @__PURE__ */ new Set();
|
|
275
|
+
for (const body of this.bodies.values()) {
|
|
276
|
+
let candidates;
|
|
277
|
+
if (this.config.broadphase === "spatial") {
|
|
278
|
+
candidates = this.spatialHash.queryNearby(body.id);
|
|
279
|
+
} else {
|
|
280
|
+
candidates = Array.from(this.bodies.keys()).filter((id) => id !== body.id);
|
|
281
|
+
}
|
|
282
|
+
for (const otherId of candidates) {
|
|
283
|
+
const pairKey = body.id < otherId ? `${body.id}:${otherId}` : `${otherId}:${body.id}`;
|
|
284
|
+
if (checked.has(pairKey)) {
|
|
285
|
+
continue;
|
|
268
286
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.spatialHash.remove(id);
|
|
287
|
+
checked.add(pairKey);
|
|
288
|
+
const other = this.bodies.get(otherId);
|
|
289
|
+
if (!other) {
|
|
290
|
+
continue;
|
|
274
291
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return this.bodies.get(id);
|
|
278
|
-
}
|
|
279
|
-
// ─── Simulation ────────────────────────────────────────
|
|
280
|
-
step(dt) {
|
|
281
|
-
const substepDt = fixedDiv(dt, fixedFromFloat(this.config.substeps));
|
|
282
|
-
for (let i = 0; i < this.config.substeps; i++) {
|
|
283
|
-
this.integrate(substepDt);
|
|
284
|
-
this.broadphase();
|
|
285
|
-
this.narrowphase();
|
|
286
|
-
this.resolveCollisions();
|
|
292
|
+
if (!this.shouldCollide(body, other)) {
|
|
293
|
+
continue;
|
|
287
294
|
}
|
|
288
|
-
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
295
|
+
const pair = this.testCollision(body, other);
|
|
296
|
+
if (pair) {
|
|
297
|
+
pair.bodyA = body.id;
|
|
298
|
+
pair.bodyB = otherId;
|
|
299
|
+
this.collisionPairs.push(pair);
|
|
293
300
|
}
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
shouldCollide(a, b) {
|
|
305
|
+
return (a.collisionMask & b.collisionLayer) !== 0 && (b.collisionMask & a.collisionLayer) !== 0;
|
|
306
|
+
}
|
|
307
|
+
narrowphase() {
|
|
308
|
+
}
|
|
309
|
+
testCollision(a, b) {
|
|
310
|
+
if (a.shape.type === "circle" && b.shape.type === "circle") {
|
|
311
|
+
return circleVsCircle(a.position, a.shape.radius, b.position, b.shape.radius);
|
|
312
|
+
}
|
|
313
|
+
if (a.shape.type === "aabb" && b.shape.type === "aabb") {
|
|
314
|
+
return aabbVsAABB(a.position, { x: a.shape.halfWidth, y: a.shape.halfHeight }, b.position, {
|
|
315
|
+
x: b.shape.halfWidth,
|
|
316
|
+
y: b.shape.halfHeight
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if (a.shape.type === "circle" && b.shape.type === "aabb") {
|
|
320
|
+
return circleVsAABB(a.position, a.shape.radius, b.position, {
|
|
321
|
+
x: b.shape.halfWidth,
|
|
322
|
+
y: b.shape.halfHeight
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (a.shape.type === "aabb" && b.shape.type === "circle") {
|
|
326
|
+
const result = circleVsAABB(b.position, b.shape.radius, a.position, {
|
|
327
|
+
x: a.shape.halfWidth,
|
|
328
|
+
y: a.shape.halfHeight
|
|
329
|
+
});
|
|
330
|
+
if (result) {
|
|
331
|
+
result.normal = vec2Negate(result.normal);
|
|
332
|
+
}
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
resolveCollisions() {
|
|
338
|
+
for (let iter = 0; iter < this.config.maxIterations; iter++) {
|
|
339
|
+
for (const pair of this.collisionPairs) {
|
|
340
|
+
const bodyA = this.bodies.get(pair.bodyA);
|
|
341
|
+
const bodyB = this.bodies.get(pair.bodyB);
|
|
342
|
+
if (!bodyA || !bodyB) {
|
|
343
|
+
continue;
|
|
308
344
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const checked = new Set();
|
|
313
|
-
for (const body of this.bodies.values()) {
|
|
314
|
-
let candidates;
|
|
315
|
-
if (this.config.broadphase === 'spatial') {
|
|
316
|
-
candidates = this.spatialHash.queryNearby(body.id);
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
candidates = Array.from(this.bodies.keys()).filter((id) => id !== body.id);
|
|
320
|
-
}
|
|
321
|
-
for (const otherId of candidates) {
|
|
322
|
-
const pairKey = body.id < otherId ? `${body.id}:${otherId}` : `${otherId}:${body.id}`;
|
|
323
|
-
if (checked.has(pairKey)) {
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
checked.add(pairKey);
|
|
327
|
-
const other = this.bodies.get(otherId);
|
|
328
|
-
if (!other) {
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
// Check collision masks
|
|
332
|
-
if (!this.shouldCollide(body, other)) {
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
const pair = this.testCollision(body, other);
|
|
336
|
-
if (pair) {
|
|
337
|
-
pair.bodyA = body.id;
|
|
338
|
-
pair.bodyB = otherId;
|
|
339
|
-
this.collisionPairs.push(pair);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
345
|
+
if (bodyA.isTrigger || bodyB.isTrigger) {
|
|
346
|
+
this.onTrigger?.(pair.bodyA, pair.bodyB);
|
|
347
|
+
continue;
|
|
342
348
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
narrowphase() {
|
|
348
|
-
// Already done in broadphase for this implementation
|
|
349
|
-
}
|
|
350
|
-
testCollision(a, b) {
|
|
351
|
-
if (a.shape.type === 'circle' && b.shape.type === 'circle') {
|
|
352
|
-
return circleVsCircle(a.position, a.shape.radius, b.position, b.shape.radius);
|
|
349
|
+
this.onCollision?.(pair);
|
|
350
|
+
if (bodyA.isStatic && bodyB.isStatic) {
|
|
351
|
+
continue;
|
|
353
352
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
353
|
+
const invMassA = bodyA.isStatic ? 0 : fixedDiv(FIXED_ONE, bodyA.mass);
|
|
354
|
+
const invMassB = bodyB.isStatic ? 0 : fixedDiv(FIXED_ONE, bodyB.mass);
|
|
355
|
+
const totalInvMass = invMassA + invMassB;
|
|
356
|
+
if (totalInvMass === 0) {
|
|
357
|
+
continue;
|
|
359
358
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
359
|
+
const correction = vec2Scale(
|
|
360
|
+
pair.normal,
|
|
361
|
+
fixedDiv(pair.penetration, fixedFromFloat(fixedToFloat(totalInvMass)))
|
|
362
|
+
);
|
|
363
|
+
if (!bodyA.isStatic) {
|
|
364
|
+
const corrA = vec2Scale(correction, invMassA);
|
|
365
|
+
bodyA.position = vec2Sub(bodyA.position, corrA);
|
|
365
366
|
}
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
y: a.shape.halfHeight,
|
|
370
|
-
});
|
|
371
|
-
if (result) {
|
|
372
|
-
result.normal = vec2Negate(result.normal);
|
|
373
|
-
}
|
|
374
|
-
return result;
|
|
367
|
+
if (!bodyB.isStatic) {
|
|
368
|
+
const corrB = vec2Scale(correction, invMassB);
|
|
369
|
+
bodyB.position = vec2Add(bodyB.position, corrB);
|
|
375
370
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
for (const pair of this.collisionPairs) {
|
|
381
|
-
const bodyA = this.bodies.get(pair.bodyA);
|
|
382
|
-
const bodyB = this.bodies.get(pair.bodyB);
|
|
383
|
-
if (!bodyA || !bodyB) {
|
|
384
|
-
continue;
|
|
385
|
-
}
|
|
386
|
-
// Trigger callback
|
|
387
|
-
if (bodyA.isTrigger || bodyB.isTrigger) {
|
|
388
|
-
this.onTrigger?.(pair.bodyA, pair.bodyB);
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
this.onCollision?.(pair);
|
|
392
|
-
// Both static - skip
|
|
393
|
-
if (bodyA.isStatic && bodyB.isStatic) {
|
|
394
|
-
continue;
|
|
395
|
-
}
|
|
396
|
-
// Calculate inverse masses
|
|
397
|
-
const invMassA = bodyA.isStatic ? 0 : fixedDiv(FIXED_ONE, bodyA.mass);
|
|
398
|
-
const invMassB = bodyB.isStatic ? 0 : fixedDiv(FIXED_ONE, bodyB.mass);
|
|
399
|
-
const totalInvMass = invMassA + invMassB;
|
|
400
|
-
if (totalInvMass === 0) {
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
// Positional correction
|
|
404
|
-
const correction = vec2Scale(pair.normal, fixedDiv(pair.penetration, fixedFromFloat(fixedToFloat(totalInvMass))));
|
|
405
|
-
if (!bodyA.isStatic) {
|
|
406
|
-
const corrA = vec2Scale(correction, invMassA);
|
|
407
|
-
bodyA.position = vec2Sub(bodyA.position, corrA);
|
|
408
|
-
}
|
|
409
|
-
if (!bodyB.isStatic) {
|
|
410
|
-
const corrB = vec2Scale(correction, invMassB);
|
|
411
|
-
bodyB.position = vec2Add(bodyB.position, corrB);
|
|
412
|
-
}
|
|
413
|
-
// Velocity resolution
|
|
414
|
-
const relVel = vec2Sub(bodyB.velocity, bodyA.velocity);
|
|
415
|
-
const velAlongNormal = vec2Dot(relVel, pair.normal);
|
|
416
|
-
if (velAlongNormal > 0) {
|
|
417
|
-
continue;
|
|
418
|
-
}
|
|
419
|
-
const restitution = fixedMin(bodyA.restitution, bodyB.restitution);
|
|
420
|
-
const j = fixedDiv(fixedMul(-(FIXED_ONE + restitution), velAlongNormal), totalInvMass);
|
|
421
|
-
const impulse = vec2Scale(pair.normal, j);
|
|
422
|
-
if (!bodyA.isStatic) {
|
|
423
|
-
bodyA.velocity = vec2Sub(bodyA.velocity, vec2Scale(impulse, invMassA));
|
|
424
|
-
}
|
|
425
|
-
if (!bodyB.isStatic) {
|
|
426
|
-
bodyB.velocity = vec2Add(bodyB.velocity, vec2Scale(impulse, invMassB));
|
|
427
|
-
}
|
|
428
|
-
// Friction
|
|
429
|
-
const tangent = vec2Normalize({
|
|
430
|
-
x: relVel.x - fixedMul(velAlongNormal, pair.normal.x),
|
|
431
|
-
y: relVel.y - fixedMul(velAlongNormal, pair.normal.y),
|
|
432
|
-
});
|
|
433
|
-
const friction = fixedMul(bodyA.friction, bodyB.friction);
|
|
434
|
-
const frictionImpulse = vec2Scale(tangent, fixedMul(j, friction));
|
|
435
|
-
if (!bodyA.isStatic) {
|
|
436
|
-
bodyA.velocity = vec2Add(bodyA.velocity, vec2Scale(frictionImpulse, invMassA));
|
|
437
|
-
}
|
|
438
|
-
if (!bodyB.isStatic) {
|
|
439
|
-
bodyB.velocity = vec2Sub(bodyB.velocity, vec2Scale(frictionImpulse, invMassB));
|
|
440
|
-
}
|
|
441
|
-
}
|
|
371
|
+
const relVel = vec2Sub(bodyB.velocity, bodyA.velocity);
|
|
372
|
+
const velAlongNormal = vec2Dot(relVel, pair.normal);
|
|
373
|
+
if (velAlongNormal > 0) {
|
|
374
|
+
continue;
|
|
442
375
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
position: { ...b.position },
|
|
449
|
-
velocity: { ...b.velocity },
|
|
450
|
-
acceleration: { ...b.acceleration },
|
|
451
|
-
}));
|
|
452
|
-
return {
|
|
453
|
-
frame: this.frame,
|
|
454
|
-
bodies,
|
|
455
|
-
hash: this.calculateHash(),
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
setState(state) {
|
|
459
|
-
this.frame = state.frame;
|
|
460
|
-
this.bodies.clear();
|
|
461
|
-
this.spatialHash.clear();
|
|
462
|
-
for (const body of state.bodies) {
|
|
463
|
-
this.addBody({ ...body });
|
|
376
|
+
const restitution = fixedMin(bodyA.restitution, bodyB.restitution);
|
|
377
|
+
const j = fixedDiv(fixedMul(-(FIXED_ONE + restitution), velAlongNormal), totalInvMass);
|
|
378
|
+
const impulse = vec2Scale(pair.normal, j);
|
|
379
|
+
if (!bodyA.isStatic) {
|
|
380
|
+
bodyA.velocity = vec2Sub(bodyA.velocity, vec2Scale(impulse, invMassA));
|
|
464
381
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
let hash = this.frame;
|
|
468
|
-
for (const body of this.bodies.values()) {
|
|
469
|
-
hash ^= body.position.x;
|
|
470
|
-
hash ^= body.position.y << 8;
|
|
471
|
-
hash ^= body.velocity.x << 16;
|
|
472
|
-
hash ^= body.velocity.y << 24;
|
|
382
|
+
if (!bodyB.isStatic) {
|
|
383
|
+
bodyB.velocity = vec2Add(bodyB.velocity, vec2Scale(impulse, invMassB));
|
|
473
384
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
// ─── Force Application ─────────────────────────────────
|
|
484
|
-
applyForce(bodyId, force) {
|
|
485
|
-
const body = this.bodies.get(bodyId);
|
|
486
|
-
if (body && !body.isStatic) {
|
|
487
|
-
const accel = { x: fixedDiv(force.x, body.mass), y: fixedDiv(force.y, body.mass) };
|
|
488
|
-
body.acceleration = vec2Add(body.acceleration, accel);
|
|
385
|
+
const tangent = vec2Normalize({
|
|
386
|
+
x: relVel.x - fixedMul(velAlongNormal, pair.normal.x),
|
|
387
|
+
y: relVel.y - fixedMul(velAlongNormal, pair.normal.y)
|
|
388
|
+
});
|
|
389
|
+
const friction = fixedMul(bodyA.friction, bodyB.friction);
|
|
390
|
+
const frictionImpulse = vec2Scale(tangent, fixedMul(j, friction));
|
|
391
|
+
if (!bodyA.isStatic) {
|
|
392
|
+
bodyA.velocity = vec2Add(bodyA.velocity, vec2Scale(frictionImpulse, invMassA));
|
|
489
393
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const body = this.bodies.get(bodyId);
|
|
493
|
-
if (body && !body.isStatic) {
|
|
494
|
-
const velChange = { x: fixedDiv(impulse.x, body.mass), y: fixedDiv(impulse.y, body.mass) };
|
|
495
|
-
body.velocity = vec2Add(body.velocity, velChange);
|
|
394
|
+
if (!bodyB.isStatic) {
|
|
395
|
+
bodyB.velocity = vec2Sub(bodyB.velocity, vec2Scale(frictionImpulse, invMassB));
|
|
496
396
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
// ─── State Management ──────────────────────────────────
|
|
401
|
+
getState() {
|
|
402
|
+
const bodies = Array.from(this.bodies.values()).map((b) => ({
|
|
403
|
+
...b,
|
|
404
|
+
position: { ...b.position },
|
|
405
|
+
velocity: { ...b.velocity },
|
|
406
|
+
acceleration: { ...b.acceleration }
|
|
407
|
+
}));
|
|
408
|
+
return {
|
|
409
|
+
frame: this.frame,
|
|
410
|
+
bodies,
|
|
411
|
+
hash: this.calculateHash()
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
setState(state) {
|
|
415
|
+
this.frame = state.frame;
|
|
416
|
+
this.bodies.clear();
|
|
417
|
+
this.spatialHash.clear();
|
|
418
|
+
for (const body of state.bodies) {
|
|
419
|
+
this.addBody({ ...body });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
calculateHash() {
|
|
423
|
+
let hash = this.frame;
|
|
424
|
+
for (const body of this.bodies.values()) {
|
|
425
|
+
hash ^= body.position.x;
|
|
426
|
+
hash ^= body.position.y << 8;
|
|
427
|
+
hash ^= body.velocity.x << 16;
|
|
428
|
+
hash ^= body.velocity.y << 24;
|
|
429
|
+
}
|
|
430
|
+
return hash >>> 0;
|
|
431
|
+
}
|
|
432
|
+
// ─── Frame ─────────────────────────────────────────────
|
|
433
|
+
getFrame() {
|
|
434
|
+
return this.frame;
|
|
435
|
+
}
|
|
436
|
+
setFrame(frame) {
|
|
437
|
+
this.frame = frame;
|
|
438
|
+
}
|
|
439
|
+
// ─── Force Application ─────────────────────────────────
|
|
440
|
+
applyForce(bodyId, force) {
|
|
441
|
+
const body = this.bodies.get(bodyId);
|
|
442
|
+
if (body && !body.isStatic) {
|
|
443
|
+
const accel = { x: fixedDiv(force.x, body.mass), y: fixedDiv(force.y, body.mass) };
|
|
444
|
+
body.acceleration = vec2Add(body.acceleration, accel);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
applyImpulse(bodyId, impulse) {
|
|
448
|
+
const body = this.bodies.get(bodyId);
|
|
449
|
+
if (body && !body.isStatic) {
|
|
450
|
+
const velChange = { x: fixedDiv(impulse.x, body.mass), y: fixedDiv(impulse.y, body.mass) };
|
|
451
|
+
body.velocity = vec2Add(body.velocity, velChange);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
setVelocity(bodyId, velocity) {
|
|
455
|
+
const body = this.bodies.get(bodyId);
|
|
456
|
+
if (body && !body.isStatic) {
|
|
457
|
+
body.velocity = { ...velocity };
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
setPosition(bodyId, position) {
|
|
461
|
+
const body = this.bodies.get(bodyId);
|
|
462
|
+
if (body) {
|
|
463
|
+
body.position = { ...position };
|
|
464
|
+
if (this.config.broadphase === "spatial") {
|
|
465
|
+
this.spatialHash.update(bodyId, position);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// ─── Callbacks ─────────────────────────────────────────
|
|
470
|
+
setOnCollision(callback) {
|
|
471
|
+
this.onCollision = callback;
|
|
472
|
+
}
|
|
473
|
+
setOnTrigger(callback) {
|
|
474
|
+
this.onTrigger = callback;
|
|
475
|
+
}
|
|
476
|
+
// ─── Cleanup ───────────────────────────────────────────
|
|
477
|
+
clear() {
|
|
478
|
+
this.bodies.clear();
|
|
479
|
+
this.spatialHash.clear();
|
|
480
|
+
this.collisionPairs = [];
|
|
481
|
+
this.frame = 0;
|
|
482
|
+
}
|
|
527
483
|
}
|
|
528
|
-
// ============================================================
|
|
529
|
-
// Factory Functions
|
|
530
|
-
// ============================================================
|
|
531
484
|
function createDeterministicWorld(config) {
|
|
532
|
-
|
|
485
|
+
return new DeterministicWorld(config);
|
|
533
486
|
}
|
|
534
487
|
function createCircleBody(id, position, radius, options) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
488
|
+
return {
|
|
489
|
+
id,
|
|
490
|
+
position,
|
|
491
|
+
velocity: { x: 0, y: 0 },
|
|
492
|
+
acceleration: { x: 0, y: 0 },
|
|
493
|
+
mass: options?.mass ?? FIXED_ONE,
|
|
494
|
+
restitution: options?.restitution ?? fixedFromFloat(0.5),
|
|
495
|
+
friction: options?.friction ?? fixedFromFloat(0.3),
|
|
496
|
+
isStatic: options?.isStatic ?? false,
|
|
497
|
+
isTrigger: options?.isTrigger ?? false,
|
|
498
|
+
collisionMask: options?.collisionMask ?? 4294967295,
|
|
499
|
+
collisionLayer: options?.collisionLayer ?? 1,
|
|
500
|
+
shape: { type: "circle", radius },
|
|
501
|
+
userData: options?.userData
|
|
502
|
+
};
|
|
550
503
|
}
|
|
551
504
|
function createBoxBody(id, position, halfWidth, halfHeight, options) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
505
|
+
return {
|
|
506
|
+
id,
|
|
507
|
+
position,
|
|
508
|
+
velocity: { x: 0, y: 0 },
|
|
509
|
+
acceleration: { x: 0, y: 0 },
|
|
510
|
+
mass: options?.mass ?? FIXED_ONE,
|
|
511
|
+
restitution: options?.restitution ?? fixedFromFloat(0.5),
|
|
512
|
+
friction: options?.friction ?? fixedFromFloat(0.3),
|
|
513
|
+
isStatic: options?.isStatic ?? false,
|
|
514
|
+
isTrigger: options?.isTrigger ?? false,
|
|
515
|
+
collisionMask: options?.collisionMask ?? 4294967295,
|
|
516
|
+
collisionLayer: options?.collisionLayer ?? 1,
|
|
517
|
+
shape: { type: "aabb", halfWidth, halfHeight },
|
|
518
|
+
userData: options?.userData
|
|
519
|
+
};
|
|
567
520
|
}
|
|
568
521
|
function createStaticBody(id, position, halfWidth, halfHeight) {
|
|
569
|
-
|
|
522
|
+
return createBoxBody(id, position, halfWidth, halfHeight, { isStatic: true });
|
|
570
523
|
}
|
|
571
|
-
|
|
572
|
-
|
|
524
|
+
export {
|
|
525
|
+
DEFAULT_DETERMINISTIC_CONFIG,
|
|
526
|
+
DeterministicWorld,
|
|
527
|
+
FIXED_HALF,
|
|
528
|
+
FIXED_ONE,
|
|
529
|
+
FIXED_SHIFT,
|
|
530
|
+
aabbVsAABB,
|
|
531
|
+
circleVsAABB,
|
|
532
|
+
circleVsCircle,
|
|
533
|
+
createBoxBody,
|
|
534
|
+
createCircleBody,
|
|
535
|
+
createDeterministicWorld,
|
|
536
|
+
createStaticBody,
|
|
537
|
+
fixedAbs,
|
|
538
|
+
fixedClamp,
|
|
539
|
+
fixedDiv,
|
|
540
|
+
fixedFromFloat,
|
|
541
|
+
fixedMax,
|
|
542
|
+
fixedMin,
|
|
543
|
+
fixedMul,
|
|
544
|
+
fixedSqrt,
|
|
545
|
+
fixedToFloat,
|
|
546
|
+
vec2Add,
|
|
547
|
+
vec2Dot,
|
|
548
|
+
vec2Length,
|
|
549
|
+
vec2LengthSq,
|
|
550
|
+
vec2Negate,
|
|
551
|
+
vec2Normalize,
|
|
552
|
+
vec2Scale,
|
|
553
|
+
vec2Sub
|
|
554
|
+
};
|