excalibur 0.25.2 → 0.25.3
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 +7 -2
- package/build/dist/Actions/Action/Blink.js +51 -0
- package/build/dist/Actions/Action/Blink.js.map +1 -0
- package/build/dist/Actions/Action/CallMethod.js +21 -0
- package/build/dist/Actions/Action/CallMethod.js.map +1 -0
- package/build/dist/Actions/Action/Delay.js +25 -0
- package/build/dist/Actions/Action/Delay.js.map +1 -0
- package/build/dist/Actions/Action/Die.js +22 -0
- package/build/dist/Actions/Action/Die.js.map +1 -0
- package/build/dist/Actions/Action/EaseTo.js +69 -0
- package/build/dist/Actions/Action/EaseTo.js.map +1 -0
- package/build/dist/Actions/Action/Fade.js +46 -0
- package/build/dist/Actions/Action/Fade.js.map +1 -0
- package/build/dist/Actions/Action/Follow.js +55 -0
- package/build/dist/Actions/Action/Follow.js.map +1 -0
- package/build/dist/Actions/Action/Meet.js +52 -0
- package/build/dist/Actions/Action/Meet.js.map +1 -0
- package/build/dist/Actions/Action/MoveBy.js +47 -0
- package/build/dist/Actions/Action/MoveBy.js.map +1 -0
- package/build/dist/Actions/Action/MoveTo.js +40 -0
- package/build/dist/Actions/Action/MoveTo.js.map +1 -0
- package/build/dist/Actions/Action/Repeat.js +31 -0
- package/build/dist/Actions/Action/Repeat.js.map +1 -0
- package/build/dist/Actions/Action/RepeatForever.js +37 -0
- package/build/dist/Actions/Action/RepeatForever.js.map +1 -0
- package/build/dist/Actions/Action/RotateBy.js +91 -0
- package/build/dist/Actions/Action/RotateBy.js.map +1 -0
- package/build/dist/Actions/Action/RotateTo.js +90 -0
- package/build/dist/Actions/Action/RotateTo.js.map +1 -0
- package/build/dist/Actions/Action/ScaleBy.js +45 -0
- package/build/dist/Actions/Action/ScaleBy.js.map +1 -0
- package/build/dist/Actions/Action/ScaleTo.js +56 -0
- package/build/dist/Actions/Action/ScaleTo.js.map +1 -0
- package/build/dist/Actions/Action.js +2 -0
- package/build/dist/Actions/Action.js.map +1 -0
- package/build/dist/Actions/ActionContext.js +305 -0
- package/build/dist/Actions/ActionContext.js.map +1 -0
- package/build/dist/Actions/ActionQueue.js +87 -0
- package/build/dist/Actions/ActionQueue.js.map +1 -0
- package/build/dist/Actions/Actionable.js +2 -0
- package/build/dist/Actions/Actionable.js.map +1 -0
- package/build/dist/Actions/ActionsComponent.js +198 -0
- package/build/dist/Actions/ActionsComponent.js.map +1 -0
- package/build/dist/Actions/ActionsSystem.js +18 -0
- package/build/dist/Actions/ActionsSystem.js.map +1 -0
- package/build/dist/Actions/Index.js +22 -0
- package/build/dist/Actions/Index.js.map +1 -0
- package/build/dist/Actions/RotationType.js +27 -0
- package/build/dist/Actions/RotationType.js.map +1 -0
- package/build/dist/Actor.js +831 -0
- package/build/dist/Actor.js.map +1 -0
- package/build/dist/Camera.js +663 -0
- package/build/dist/Camera.js.map +1 -0
- package/build/dist/Class.js +48 -0
- package/build/dist/Class.js.map +1 -0
- package/build/dist/Collision/BodyComponent.js +351 -0
- package/build/dist/Collision/BodyComponent.js.map +1 -0
- package/build/dist/Collision/BoundingBox.js +361 -0
- package/build/dist/Collision/BoundingBox.js.map +1 -0
- package/build/dist/Collision/ColliderComponent.js +198 -0
- package/build/dist/Collision/ColliderComponent.js.map +1 -0
- package/build/dist/Collision/Colliders/CircleCollider.js +264 -0
- package/build/dist/Collision/Colliders/CircleCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js +211 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/Collider.js +26 -0
- package/build/dist/Collision/Colliders/Collider.js.map +1 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js +301 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/CompositeCollider.js +232 -0
- package/build/dist/Collision/Colliders/CompositeCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js +253 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js +389 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js +67 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js.map +1 -0
- package/build/dist/Collision/Colliders/Shape.js +102 -0
- package/build/dist/Collision/Colliders/Shape.js.map +1 -0
- package/build/dist/Collision/CollisionSystem.js +116 -0
- package/build/dist/Collision/CollisionSystem.js.map +1 -0
- package/build/dist/Collision/CollisionType.js +33 -0
- package/build/dist/Collision/CollisionType.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionContact.js +46 -0
- package/build/dist/Collision/Detection/CollisionContact.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js +2 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js.map +1 -0
- package/build/dist/Collision/Detection/DynamicTree.js +442 -0
- package/build/dist/Collision/Detection/DynamicTree.js.map +1 -0
- package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js +211 -0
- package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js.map +1 -0
- package/build/dist/Collision/Detection/Pair.js +92 -0
- package/build/dist/Collision/Detection/Pair.js.map +1 -0
- package/build/dist/Collision/Group/CollisionGroup.js +114 -0
- package/build/dist/Collision/Group/CollisionGroup.js.map +1 -0
- package/build/dist/Collision/Group/CollisionGroupManager.js +52 -0
- package/build/dist/Collision/Group/CollisionGroupManager.js.map +1 -0
- package/build/dist/Collision/Index.js +29 -0
- package/build/dist/Collision/Index.js.map +1 -0
- package/build/dist/Collision/Integrator.js +11 -0
- package/build/dist/Collision/Integrator.js.map +1 -0
- package/build/dist/Collision/MotionSystem.js +42 -0
- package/build/dist/Collision/MotionSystem.js.map +1 -0
- package/build/dist/Collision/Physics.js +163 -0
- package/build/dist/Collision/Physics.js.map +1 -0
- package/build/dist/Collision/Side.js +51 -0
- package/build/dist/Collision/Side.js.map +1 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js +101 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js.map +1 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js +83 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js.map +1 -0
- package/build/dist/Collision/Solver/RealisticSolver.js +248 -0
- package/build/dist/Collision/Solver/RealisticSolver.js.map +1 -0
- package/build/dist/Collision/Solver/Solver.js +37 -0
- package/build/dist/Collision/Solver/Solver.js.map +1 -0
- package/build/dist/Color.js +461 -0
- package/build/dist/Color.js.map +1 -0
- package/build/dist/Configurable.js +32 -0
- package/build/dist/Configurable.js.map +1 -0
- package/build/dist/Debug/Debug.js +375 -0
- package/build/dist/Debug/Debug.js.map +1 -0
- package/build/dist/Debug/DebugFlags.js +40 -0
- package/build/dist/Debug/DebugFlags.js.map +1 -0
- package/build/dist/Debug/DebugSystem.js +251 -0
- package/build/dist/Debug/DebugSystem.js.map +1 -0
- package/build/dist/Debug/index.js +4 -0
- package/build/dist/Debug/index.js.map +1 -0
- package/build/dist/Deprecated.js +2 -0
- package/build/dist/Deprecated.js.map +1 -0
- package/build/dist/Drawing/Animation.js +294 -0
- package/build/dist/Drawing/Animation.js.map +1 -0
- package/build/dist/Drawing/CanvasDrawComponent.js +16 -0
- package/build/dist/Drawing/CanvasDrawComponent.js.map +1 -0
- package/build/dist/Drawing/CanvasDrawingSystem.js +95 -0
- package/build/dist/Drawing/CanvasDrawingSystem.js.map +1 -0
- package/build/dist/Drawing/Index.js +10 -0
- package/build/dist/Drawing/Index.js.map +1 -0
- package/build/dist/Drawing/Polygon.js +139 -0
- package/build/dist/Drawing/Polygon.js.map +1 -0
- package/build/dist/Drawing/Sprite.js +355 -0
- package/build/dist/Drawing/Sprite.js.map +1 -0
- package/build/dist/Drawing/SpriteEffects.js +246 -0
- package/build/dist/Drawing/SpriteEffects.js.map +1 -0
- package/build/dist/Drawing/SpriteSheet.js +413 -0
- package/build/dist/Drawing/SpriteSheet.js.map +1 -0
- package/build/dist/Drawing/Texture.js +69 -0
- package/build/dist/Drawing/Texture.js.map +1 -0
- package/build/dist/Engine.d.ts +4 -1
- package/build/dist/Engine.js +985 -0
- package/build/dist/Engine.js.map +1 -0
- package/build/dist/EntityComponentSystem/Component.js +65 -0
- package/build/dist/EntityComponentSystem/Component.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js +33 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js +249 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Entity.js +452 -0
- package/build/dist/EntityComponentSystem/Entity.js.map +1 -0
- package/build/dist/EntityComponentSystem/EntityManager.js +128 -0
- package/build/dist/EntityComponentSystem/EntityManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Query.js +91 -0
- package/build/dist/EntityComponentSystem/Query.js.map +1 -0
- package/build/dist/EntityComponentSystem/QueryManager.js +90 -0
- package/build/dist/EntityComponentSystem/QueryManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/System.js +76 -0
- package/build/dist/EntityComponentSystem/System.js.map +1 -0
- package/build/dist/EntityComponentSystem/SystemManager.js +102 -0
- package/build/dist/EntityComponentSystem/SystemManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Util.js +5 -0
- package/build/dist/EntityComponentSystem/Util.js.map +1 -0
- package/build/dist/EntityComponentSystem/World.js +55 -0
- package/build/dist/EntityComponentSystem/World.js.map +1 -0
- package/build/dist/EntityComponentSystem/index.js +11 -0
- package/build/dist/EntityComponentSystem/index.js.map +1 -0
- package/build/dist/EventDispatcher.js +114 -0
- package/build/dist/EventDispatcher.js.map +1 -0
- package/build/dist/Events/ExEvent.js +12 -0
- package/build/dist/Events/ExEvent.js.map +1 -0
- package/build/dist/Events/MediaEvents.js +75 -0
- package/build/dist/Events/MediaEvents.js.map +1 -0
- package/build/dist/Events/PointerEvents.js +52 -0
- package/build/dist/Events/PointerEvents.js.map +1 -0
- package/build/dist/Events.js +497 -0
- package/build/dist/Events.js.map +1 -0
- package/build/dist/Flags.js +90 -0
- package/build/dist/Flags.js.map +1 -0
- package/build/dist/Graphics/Animation.js +310 -0
- package/build/dist/Graphics/Animation.js.map +1 -0
- package/build/dist/Graphics/Canvas.js +38 -0
- package/build/dist/Graphics/Canvas.js.map +1 -0
- package/build/dist/Graphics/Circle.js +47 -0
- package/build/dist/Graphics/Circle.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js +2 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js +207 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js +331 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js +160 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/debug-text.js +47 -0
- package/build/dist/Graphics/Context/debug-text.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js +209 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js +87 -0
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js +82 -0
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/quad-index-buffer.js +69 -0
- package/build/dist/Graphics/Context/quad-index-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js +272 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/render-source.js +16 -0
- package/build/dist/Graphics/Context/render-source.js.map +1 -0
- package/build/dist/Graphics/Context/render-target.js +65 -0
- package/build/dist/Graphics/Context/render-target.js.map +1 -0
- package/build/dist/Graphics/Context/renderer.js +2 -0
- package/build/dist/Graphics/Context/renderer.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js +53 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js.map +1 -0
- package/build/dist/Graphics/Context/shader.js +236 -0
- package/build/dist/Graphics/Context/shader.js.map +1 -0
- package/build/dist/Graphics/Context/state-stack.js +27 -0
- package/build/dist/Graphics/Context/state-stack.js.map +1 -0
- package/build/dist/Graphics/Context/texture-loader.d.ts +8 -0
- package/build/dist/Graphics/Context/texture-loader.js +121 -0
- package/build/dist/Graphics/Context/texture-loader.js.map +1 -0
- package/build/dist/Graphics/Context/transform-stack.js +30 -0
- package/build/dist/Graphics/Context/transform-stack.js.map +1 -0
- package/build/dist/Graphics/Context/vertex-buffer.js +45 -0
- package/build/dist/Graphics/Context/vertex-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/vertex-layout.js +93 -0
- package/build/dist/Graphics/Context/vertex-layout.js.map +1 -0
- package/build/dist/Graphics/Context/webgl-adapter.js +19 -0
- package/build/dist/Graphics/Context/webgl-adapter.js.map +1 -0
- package/build/dist/Graphics/Context/webgl-util.js +105 -0
- package/build/dist/Graphics/Context/webgl-util.js.map +1 -0
- package/build/dist/Graphics/DebugGraphicsComponent.js +15 -0
- package/build/dist/Graphics/DebugGraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/Filtering.js +17 -0
- package/build/dist/Graphics/Filtering.js.map +1 -0
- package/build/dist/Graphics/Font.js +293 -0
- package/build/dist/Graphics/Font.js.map +1 -0
- package/build/dist/Graphics/FontCommon.js +109 -0
- package/build/dist/Graphics/FontCommon.js.map +1 -0
- package/build/dist/Graphics/Graphic.js +200 -0
- package/build/dist/Graphics/Graphic.js.map +1 -0
- package/build/dist/Graphics/GraphicsComponent.js +290 -0
- package/build/dist/Graphics/GraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js +9 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js.map +1 -0
- package/build/dist/Graphics/GraphicsGroup.js +69 -0
- package/build/dist/Graphics/GraphicsGroup.js.map +1 -0
- package/build/dist/Graphics/GraphicsSystem.js +153 -0
- package/build/dist/Graphics/GraphicsSystem.js.map +1 -0
- package/build/dist/Graphics/ImageSource.js +116 -0
- package/build/dist/Graphics/ImageSource.js.map +1 -0
- package/build/dist/Graphics/Polygon.js +59 -0
- package/build/dist/Graphics/Polygon.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js +7 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js +52 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js +2 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js +56 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js.map +1 -0
- package/build/dist/Graphics/Raster.js +207 -0
- package/build/dist/Graphics/Raster.js.map +1 -0
- package/build/dist/Graphics/Rectangle.js +29 -0
- package/build/dist/Graphics/Rectangle.js.map +1 -0
- package/build/dist/Graphics/Sprite.js +103 -0
- package/build/dist/Graphics/Sprite.js.map +1 -0
- package/build/dist/Graphics/SpriteFont.js +120 -0
- package/build/dist/Graphics/SpriteFont.js.map +1 -0
- package/build/dist/Graphics/SpriteSheet.js +115 -0
- package/build/dist/Graphics/SpriteSheet.js.map +1 -0
- package/build/dist/Graphics/Text.js +94 -0
- package/build/dist/Graphics/Text.js.map +1 -0
- package/build/dist/Graphics/index.js +42 -0
- package/build/dist/Graphics/index.js.map +1 -0
- package/build/dist/Id.js +8 -0
- package/build/dist/Id.js.map +1 -0
- package/build/dist/Input/CapturePointerConfig.js +5 -0
- package/build/dist/Input/CapturePointerConfig.js.map +1 -0
- package/build/dist/Input/EngineInput.js +2 -0
- package/build/dist/Input/EngineInput.js.map +1 -0
- package/build/dist/Input/Gamepad.js +358 -0
- package/build/dist/Input/Gamepad.js.map +1 -0
- package/build/dist/Input/Index.js +22 -0
- package/build/dist/Input/Index.js.map +1 -0
- package/build/dist/Input/Keyboard.js +267 -0
- package/build/dist/Input/Keyboard.js.map +1 -0
- package/build/dist/Input/NativePointerButton.js +12 -0
- package/build/dist/Input/NativePointerButton.js.map +1 -0
- package/build/dist/Input/PointerAbstraction.js +41 -0
- package/build/dist/Input/PointerAbstraction.js.map +1 -0
- package/build/dist/Input/PointerButton.js +12 -0
- package/build/dist/Input/PointerButton.js.map +1 -0
- package/build/dist/Input/PointerComponent.js +28 -0
- package/build/dist/Input/PointerComponent.js.map +1 -0
- package/build/dist/Input/PointerEvent.js +25 -0
- package/build/dist/Input/PointerEvent.js.map +1 -0
- package/build/dist/Input/PointerEventReceiver.js +414 -0
- package/build/dist/Input/PointerEventReceiver.js.map +1 -0
- package/build/dist/Input/PointerScope.js +16 -0
- package/build/dist/Input/PointerScope.js.map +1 -0
- package/build/dist/Input/PointerSystem.js +217 -0
- package/build/dist/Input/PointerSystem.js.map +1 -0
- package/build/dist/Input/PointerType.js +11 -0
- package/build/dist/Input/PointerType.js.map +1 -0
- package/build/dist/Input/WheelDeltaMode.js +7 -0
- package/build/dist/Input/WheelDeltaMode.js.map +1 -0
- package/build/dist/Input/WheelEvent.js +21 -0
- package/build/dist/Input/WheelEvent.js.map +1 -0
- package/build/dist/Interfaces/Audio.js +2 -0
- package/build/dist/Interfaces/Audio.js.map +1 -0
- package/build/dist/Interfaces/AudioImplementation.js +11 -0
- package/build/dist/Interfaces/AudioImplementation.js.map +1 -0
- package/build/dist/Interfaces/Clonable.js +2 -0
- package/build/dist/Interfaces/Clonable.js.map +1 -0
- package/build/dist/Interfaces/Drawable.js +2 -0
- package/build/dist/Interfaces/Drawable.js.map +1 -0
- package/build/dist/Interfaces/Evented.js +2 -0
- package/build/dist/Interfaces/Evented.js.map +1 -0
- package/build/dist/Interfaces/Index.js +10 -0
- package/build/dist/Interfaces/Index.js.map +1 -0
- package/build/dist/Interfaces/LifecycleEvents.js +51 -0
- package/build/dist/Interfaces/LifecycleEvents.js.map +1 -0
- package/build/dist/Interfaces/Loadable.js +2 -0
- package/build/dist/Interfaces/Loadable.js.map +1 -0
- package/build/dist/Interfaces/PointerEventHandlers.js +2 -0
- package/build/dist/Interfaces/PointerEventHandlers.js.map +1 -0
- package/build/dist/Interfaces/Trait.js +2 -0
- package/build/dist/Interfaces/Trait.js.map +1 -0
- package/build/dist/Label.js +273 -0
- package/build/dist/Label.js.map +1 -0
- package/build/dist/Loader.js +367 -0
- package/build/dist/Loader.js.map +1 -0
- package/build/dist/Math/Index.js +10 -0
- package/build/dist/Math/Index.js.map +1 -0
- package/build/dist/Math/Random.js +239 -0
- package/build/dist/Math/Random.js.map +1 -0
- package/build/dist/Math/global-coordinates.js +30 -0
- package/build/dist/Math/global-coordinates.js.map +1 -0
- package/build/dist/Math/line.js +194 -0
- package/build/dist/Math/line.js.map +1 -0
- package/build/dist/Math/matrix.js +446 -0
- package/build/dist/Math/matrix.js.map +1 -0
- package/build/dist/Math/projection.js +24 -0
- package/build/dist/Math/projection.js.map +1 -0
- package/build/dist/Math/ray.js +52 -0
- package/build/dist/Math/ray.js.map +1 -0
- package/build/dist/Math/util.js +82 -0
- package/build/dist/Math/util.js.map +1 -0
- package/build/dist/Math/vector-view.js +25 -0
- package/build/dist/Math/vector-view.js.map +1 -0
- package/build/dist/Math/vector.js +326 -0
- package/build/dist/Math/vector.js.map +1 -0
- package/build/dist/Particles.js +449 -0
- package/build/dist/Particles.js.map +1 -0
- package/build/dist/Polyfill.js +56 -0
- package/build/dist/Polyfill.js.map +1 -0
- package/build/dist/Promises.js +205 -0
- package/build/dist/Promises.js.map +1 -0
- package/build/dist/Resources/Gif.js +479 -0
- package/build/dist/Resources/Gif.js.map +1 -0
- package/build/dist/Resources/Index.js +4 -0
- package/build/dist/Resources/Index.js.map +1 -0
- package/build/dist/Resources/Resource.js +74 -0
- package/build/dist/Resources/Resource.js.map +1 -0
- package/build/dist/Resources/Sound/AudioContext.js +16 -0
- package/build/dist/Resources/Sound/AudioContext.js.map +1 -0
- package/build/dist/Resources/Sound/Index.js +4 -0
- package/build/dist/Resources/Sound/Index.js.map +1 -0
- package/build/dist/Resources/Sound/Sound.js +240 -0
- package/build/dist/Resources/Sound/Sound.js.map +1 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js +160 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js.map +1 -0
- package/build/dist/Scene.js +458 -0
- package/build/dist/Scene.js.map +1 -0
- package/build/dist/Screen.js +634 -0
- package/build/dist/Screen.js.map +1 -0
- package/build/dist/ScreenElement.js +29 -0
- package/build/dist/ScreenElement.js.map +1 -0
- package/build/dist/TileMap.js +488 -0
- package/build/dist/TileMap.js.map +1 -0
- package/build/dist/Timer.js +198 -0
- package/build/dist/Timer.js.map +1 -0
- package/build/dist/Traits/Index.js +5 -0
- package/build/dist/Traits/Index.js.map +1 -0
- package/build/dist/Traits/OffscreenCulling.js +35 -0
- package/build/dist/Traits/OffscreenCulling.js.map +1 -0
- package/build/dist/Trigger.js +113 -0
- package/build/dist/Trigger.js.map +1 -0
- package/build/dist/Util/Actors.js +19 -0
- package/build/dist/Util/Actors.js.map +1 -0
- package/build/dist/Util/Browser.js +66 -0
- package/build/dist/Util/Browser.js.map +1 -0
- package/build/dist/Util/Clock.js +219 -0
- package/build/dist/Util/Clock.js.map +1 -0
- package/build/dist/Util/CullingBox.js +104 -0
- package/build/dist/Util/CullingBox.js.map +1 -0
- package/build/dist/Util/Decorators.js +78 -0
- package/build/dist/Util/Decorators.js.map +1 -0
- package/build/dist/Util/Detector.js +167 -0
- package/build/dist/Util/Detector.js.map +1 -0
- package/build/dist/Util/DrawUtil.js +117 -0
- package/build/dist/Util/DrawUtil.js.map +1 -0
- package/build/dist/Util/EasingFunctions.js +118 -0
- package/build/dist/Util/EasingFunctions.js.map +1 -0
- package/build/dist/Util/Fps.js +47 -0
- package/build/dist/Util/Fps.js.map +1 -0
- package/build/dist/Util/Index.js +7 -0
- package/build/dist/Util/Index.js.map +1 -0
- package/build/dist/Util/Log.js +195 -0
- package/build/dist/Util/Log.js.map +1 -0
- package/build/dist/Util/Observable.js +60 -0
- package/build/dist/Util/Observable.js.map +1 -0
- package/build/dist/Util/Pool.js +66 -0
- package/build/dist/Util/Pool.js.map +1 -0
- package/build/dist/Util/SortedList.js +261 -0
- package/build/dist/Util/SortedList.js.map +1 -0
- package/build/dist/Util/Sound.js +22 -0
- package/build/dist/Util/Sound.js.map +1 -0
- package/build/dist/Util/Util.js +294 -0
- package/build/dist/Util/Util.js.map +1 -0
- package/build/dist/Util/Watch.js +67 -0
- package/build/dist/Util/Watch.js.map +1 -0
- package/build/dist/Util/WebAudio.js +62 -0
- package/build/dist/Util/WebAudio.js.map +1 -0
- package/build/dist/excalibur.js +101 -22
- package/build/dist/excalibur.js.map +1 -1
- package/build/dist/excalibur.min.js +1 -1
- package/build/dist/excalibur.min.js.LICENSE.txt +1 -1
- package/build/dist/excalibur.min.js.map +1 -1
- package/build/dist/index.js +74 -0
- package/build/dist/index.js.map +1 -0
- package/build/esm/Engine.d.ts +4 -1
- package/build/esm/Graphics/Context/texture-loader.d.ts +8 -0
- package/build/esm/excalibur.js +101 -22
- package/build/esm/excalibur.js.map +1 -1
- package/build/esm/excalibur.min.js +1 -1
- package/build/esm/excalibur.min.js.LICENSE.txt +1 -1
- package/build/esm/excalibur.min.js.map +1 -1
- package/package.json +23 -22
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { Physics } from '../Physics';
|
|
2
|
+
import { BoundingBox } from '../BoundingBox';
|
|
3
|
+
import { Logger } from '../../Util/Log';
|
|
4
|
+
import { BodyComponent } from '../BodyComponent';
|
|
5
|
+
import { Color } from '../..';
|
|
6
|
+
/**
|
|
7
|
+
* Dynamic Tree Node used for tracking bounds within the tree
|
|
8
|
+
*/
|
|
9
|
+
export class TreeNode {
|
|
10
|
+
constructor(parent) {
|
|
11
|
+
this.parent = parent;
|
|
12
|
+
this.parent = parent || null;
|
|
13
|
+
this.data = null;
|
|
14
|
+
this.bounds = new BoundingBox();
|
|
15
|
+
this.left = null;
|
|
16
|
+
this.right = null;
|
|
17
|
+
this.height = 0;
|
|
18
|
+
}
|
|
19
|
+
isLeaf() {
|
|
20
|
+
return !this.left && !this.right;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The DynamicTrees provides a spatial partitioning data structure for quickly querying for overlapping bounding boxes for
|
|
25
|
+
* all tracked bodies. The worst case performance of this is O(n*log(n)) where n is the number of bodies in the tree.
|
|
26
|
+
*
|
|
27
|
+
* Internally the bounding boxes are organized as a balanced binary tree of bounding boxes, where the leaf nodes are tracked bodies.
|
|
28
|
+
* Every non-leaf node is a bounding box that contains child bounding boxes.
|
|
29
|
+
*/
|
|
30
|
+
export class DynamicTree {
|
|
31
|
+
constructor(worldBounds = new BoundingBox(-Number.MAX_VALUE, -Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE)) {
|
|
32
|
+
this.worldBounds = worldBounds;
|
|
33
|
+
this.root = null;
|
|
34
|
+
this.nodes = {};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Inserts a node into the dynamic tree
|
|
38
|
+
*/
|
|
39
|
+
_insert(leaf) {
|
|
40
|
+
// If there are no nodes in the tree, make this the root leaf
|
|
41
|
+
if (this.root === null) {
|
|
42
|
+
this.root = leaf;
|
|
43
|
+
this.root.parent = null;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Search the tree for a node that is not a leaf and find the best place to insert
|
|
47
|
+
const leafAABB = leaf.bounds;
|
|
48
|
+
let currentRoot = this.root;
|
|
49
|
+
while (!currentRoot.isLeaf()) {
|
|
50
|
+
const left = currentRoot.left;
|
|
51
|
+
const right = currentRoot.right;
|
|
52
|
+
const area = currentRoot.bounds.getPerimeter();
|
|
53
|
+
const combinedAABB = currentRoot.bounds.combine(leafAABB);
|
|
54
|
+
const combinedArea = combinedAABB.getPerimeter();
|
|
55
|
+
// Calculate cost heuristic for creating a new parent and leaf
|
|
56
|
+
const cost = 2 * combinedArea;
|
|
57
|
+
// Minimum cost of pushing the leaf down the tree
|
|
58
|
+
const inheritanceCost = 2 * (combinedArea - area);
|
|
59
|
+
// Cost of descending
|
|
60
|
+
let leftCost = 0;
|
|
61
|
+
const leftCombined = leafAABB.combine(left.bounds);
|
|
62
|
+
let newArea;
|
|
63
|
+
let oldArea;
|
|
64
|
+
if (left.isLeaf()) {
|
|
65
|
+
leftCost = leftCombined.getPerimeter() + inheritanceCost;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
oldArea = left.bounds.getPerimeter();
|
|
69
|
+
newArea = leftCombined.getPerimeter();
|
|
70
|
+
leftCost = newArea - oldArea + inheritanceCost;
|
|
71
|
+
}
|
|
72
|
+
let rightCost = 0;
|
|
73
|
+
const rightCombined = leafAABB.combine(right.bounds);
|
|
74
|
+
if (right.isLeaf()) {
|
|
75
|
+
rightCost = rightCombined.getPerimeter() + inheritanceCost;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
oldArea = right.bounds.getPerimeter();
|
|
79
|
+
newArea = rightCombined.getPerimeter();
|
|
80
|
+
rightCost = newArea - oldArea + inheritanceCost;
|
|
81
|
+
}
|
|
82
|
+
// cost is acceptable
|
|
83
|
+
if (cost < leftCost && cost < rightCost) {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
// Descend to the depths
|
|
87
|
+
if (leftCost < rightCost) {
|
|
88
|
+
currentRoot = left;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
currentRoot = right;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Create the new parent node and insert into the tree
|
|
95
|
+
const oldParent = currentRoot.parent;
|
|
96
|
+
const newParent = new TreeNode(oldParent);
|
|
97
|
+
newParent.bounds = leafAABB.combine(currentRoot.bounds);
|
|
98
|
+
newParent.height = currentRoot.height + 1;
|
|
99
|
+
if (oldParent !== null) {
|
|
100
|
+
// The sibling node was not the root
|
|
101
|
+
if (oldParent.left === currentRoot) {
|
|
102
|
+
oldParent.left = newParent;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
oldParent.right = newParent;
|
|
106
|
+
}
|
|
107
|
+
newParent.left = currentRoot;
|
|
108
|
+
newParent.right = leaf;
|
|
109
|
+
currentRoot.parent = newParent;
|
|
110
|
+
leaf.parent = newParent;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// The sibling node was the root
|
|
114
|
+
newParent.left = currentRoot;
|
|
115
|
+
newParent.right = leaf;
|
|
116
|
+
currentRoot.parent = newParent;
|
|
117
|
+
leaf.parent = newParent;
|
|
118
|
+
this.root = newParent;
|
|
119
|
+
}
|
|
120
|
+
// Walk up the tree fixing heights and AABBs
|
|
121
|
+
let currentNode = leaf.parent;
|
|
122
|
+
while (currentNode) {
|
|
123
|
+
currentNode = this._balance(currentNode);
|
|
124
|
+
if (!currentNode.left) {
|
|
125
|
+
throw new Error('Parent of current leaf cannot have a null left child' + currentNode);
|
|
126
|
+
}
|
|
127
|
+
if (!currentNode.right) {
|
|
128
|
+
throw new Error('Parent of current leaf cannot have a null right child' + currentNode);
|
|
129
|
+
}
|
|
130
|
+
currentNode.height = 1 + Math.max(currentNode.left.height, currentNode.right.height);
|
|
131
|
+
currentNode.bounds = currentNode.left.bounds.combine(currentNode.right.bounds);
|
|
132
|
+
currentNode = currentNode.parent;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Removes a node from the dynamic tree
|
|
137
|
+
*/
|
|
138
|
+
_remove(leaf) {
|
|
139
|
+
if (leaf === this.root) {
|
|
140
|
+
this.root = null;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const parent = leaf.parent;
|
|
144
|
+
const grandParent = parent.parent;
|
|
145
|
+
let sibling;
|
|
146
|
+
if (parent.left === leaf) {
|
|
147
|
+
sibling = parent.right;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
sibling = parent.left;
|
|
151
|
+
}
|
|
152
|
+
if (grandParent) {
|
|
153
|
+
if (grandParent.left === parent) {
|
|
154
|
+
grandParent.left = sibling;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
grandParent.right = sibling;
|
|
158
|
+
}
|
|
159
|
+
sibling.parent = grandParent;
|
|
160
|
+
let currentNode = grandParent;
|
|
161
|
+
while (currentNode) {
|
|
162
|
+
currentNode = this._balance(currentNode);
|
|
163
|
+
currentNode.bounds = currentNode.left.bounds.combine(currentNode.right.bounds);
|
|
164
|
+
currentNode.height = 1 + Math.max(currentNode.left.height, currentNode.right.height);
|
|
165
|
+
currentNode = currentNode.parent;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.root = sibling;
|
|
170
|
+
sibling.parent = null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Tracks a body in the dynamic tree
|
|
175
|
+
*/
|
|
176
|
+
trackCollider(collider) {
|
|
177
|
+
const node = new TreeNode();
|
|
178
|
+
node.data = collider;
|
|
179
|
+
node.bounds = collider.bounds;
|
|
180
|
+
node.bounds.left -= 2;
|
|
181
|
+
node.bounds.top -= 2;
|
|
182
|
+
node.bounds.right += 2;
|
|
183
|
+
node.bounds.bottom += 2;
|
|
184
|
+
this.nodes[collider.id.value] = node;
|
|
185
|
+
this._insert(node);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Updates the dynamic tree given the current bounds of each body being tracked
|
|
189
|
+
*/
|
|
190
|
+
updateCollider(collider) {
|
|
191
|
+
var _a;
|
|
192
|
+
const node = this.nodes[collider.id.value];
|
|
193
|
+
if (!node) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const b = collider.bounds;
|
|
197
|
+
// if the body is outside the world no longer update it
|
|
198
|
+
if (!this.worldBounds.contains(b)) {
|
|
199
|
+
Logger.getInstance().warn('Collider with id ' + collider.id.value + ' is outside the world bounds and will no longer be tracked for physics');
|
|
200
|
+
this.untrackCollider(collider);
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (node.bounds.contains(b)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
this._remove(node);
|
|
207
|
+
b.left -= Physics.boundsPadding;
|
|
208
|
+
b.top -= Physics.boundsPadding;
|
|
209
|
+
b.right += Physics.boundsPadding;
|
|
210
|
+
b.bottom += Physics.boundsPadding;
|
|
211
|
+
// THIS IS CAUSING UNECESSARY CHECKS
|
|
212
|
+
if (collider.owner) {
|
|
213
|
+
const body = (_a = collider.owner) === null || _a === void 0 ? void 0 : _a.get(BodyComponent);
|
|
214
|
+
if (body) {
|
|
215
|
+
const multdx = ((body.vel.x * 32) / 1000) * Physics.dynamicTreeVelocityMultiplier;
|
|
216
|
+
const multdy = ((body.vel.y * 32) / 1000) * Physics.dynamicTreeVelocityMultiplier;
|
|
217
|
+
if (multdx < 0) {
|
|
218
|
+
b.left += multdx;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
b.right += multdx;
|
|
222
|
+
}
|
|
223
|
+
if (multdy < 0) {
|
|
224
|
+
b.top += multdy;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
b.bottom += multdy;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
node.bounds = b;
|
|
232
|
+
this._insert(node);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Untracks a body from the dynamic tree
|
|
237
|
+
*/
|
|
238
|
+
untrackCollider(collider) {
|
|
239
|
+
const node = this.nodes[collider.id.value];
|
|
240
|
+
if (!node) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
this._remove(node);
|
|
244
|
+
this.nodes[collider.id.value] = null;
|
|
245
|
+
delete this.nodes[collider.id.value];
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Balances the tree about a node
|
|
249
|
+
*/
|
|
250
|
+
_balance(node) {
|
|
251
|
+
if (node === null) {
|
|
252
|
+
throw new Error('Cannot balance at null node');
|
|
253
|
+
}
|
|
254
|
+
if (node.isLeaf() || node.height < 2) {
|
|
255
|
+
return node;
|
|
256
|
+
}
|
|
257
|
+
const left = node.left;
|
|
258
|
+
const right = node.right;
|
|
259
|
+
const a = node;
|
|
260
|
+
const b = left;
|
|
261
|
+
const c = right;
|
|
262
|
+
const d = left.left;
|
|
263
|
+
const e = left.right;
|
|
264
|
+
const f = right.left;
|
|
265
|
+
const g = right.right;
|
|
266
|
+
const balance = c.height - b.height;
|
|
267
|
+
// Rotate c node up
|
|
268
|
+
if (balance > 1) {
|
|
269
|
+
// Swap the right node with it's parent
|
|
270
|
+
c.left = a;
|
|
271
|
+
c.parent = a.parent;
|
|
272
|
+
a.parent = c;
|
|
273
|
+
// The original node's old parent should point to the right node
|
|
274
|
+
// this is mega confusing
|
|
275
|
+
if (c.parent) {
|
|
276
|
+
if (c.parent.left === a) {
|
|
277
|
+
c.parent.left = c;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
c.parent.right = c;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
this.root = c;
|
|
285
|
+
}
|
|
286
|
+
// Rotate
|
|
287
|
+
if (f.height > g.height) {
|
|
288
|
+
c.right = f;
|
|
289
|
+
a.right = g;
|
|
290
|
+
g.parent = a;
|
|
291
|
+
a.bounds = b.bounds.combine(g.bounds);
|
|
292
|
+
c.bounds = a.bounds.combine(f.bounds);
|
|
293
|
+
a.height = 1 + Math.max(b.height, g.height);
|
|
294
|
+
c.height = 1 + Math.max(a.height, f.height);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
c.right = g;
|
|
298
|
+
a.right = f;
|
|
299
|
+
f.parent = a;
|
|
300
|
+
a.bounds = b.bounds.combine(f.bounds);
|
|
301
|
+
c.bounds = a.bounds.combine(g.bounds);
|
|
302
|
+
a.height = 1 + Math.max(b.height, f.height);
|
|
303
|
+
c.height = 1 + Math.max(a.height, g.height);
|
|
304
|
+
}
|
|
305
|
+
return c;
|
|
306
|
+
}
|
|
307
|
+
// Rotate left node up
|
|
308
|
+
if (balance < -1) {
|
|
309
|
+
// swap
|
|
310
|
+
b.left = a;
|
|
311
|
+
b.parent = a.parent;
|
|
312
|
+
a.parent = b;
|
|
313
|
+
// node's old parent should point to b
|
|
314
|
+
if (b.parent) {
|
|
315
|
+
if (b.parent.left === a) {
|
|
316
|
+
b.parent.left = b;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
if (b.parent.right !== a) {
|
|
320
|
+
throw 'Error rotating Dynamic Tree';
|
|
321
|
+
}
|
|
322
|
+
b.parent.right = b;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
this.root = b;
|
|
327
|
+
}
|
|
328
|
+
// rotate
|
|
329
|
+
if (d.height > e.height) {
|
|
330
|
+
b.right = d;
|
|
331
|
+
a.left = e;
|
|
332
|
+
e.parent = a;
|
|
333
|
+
a.bounds = c.bounds.combine(e.bounds);
|
|
334
|
+
b.bounds = a.bounds.combine(d.bounds);
|
|
335
|
+
a.height = 1 + Math.max(c.height, e.height);
|
|
336
|
+
b.height = 1 + Math.max(a.height, d.height);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
b.right = e;
|
|
340
|
+
a.left = d;
|
|
341
|
+
d.parent = a;
|
|
342
|
+
a.bounds = c.bounds.combine(d.bounds);
|
|
343
|
+
b.bounds = a.bounds.combine(e.bounds);
|
|
344
|
+
a.height = 1 + Math.max(c.height, d.height);
|
|
345
|
+
b.height = 1 + Math.max(a.height, e.height);
|
|
346
|
+
}
|
|
347
|
+
return b;
|
|
348
|
+
}
|
|
349
|
+
return node;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Returns the internal height of the tree, shorter trees are better. Performance drops as the tree grows
|
|
353
|
+
*/
|
|
354
|
+
getHeight() {
|
|
355
|
+
if (this.root === null) {
|
|
356
|
+
return 0;
|
|
357
|
+
}
|
|
358
|
+
return this.root.height;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Queries the Dynamic Axis Aligned Tree for bodies that could be colliding with the provided body.
|
|
362
|
+
*
|
|
363
|
+
* In the query callback, it will be passed a potential collider. Returning true from this callback indicates
|
|
364
|
+
* that you are complete with your query and you do not want to continue. Returning false will continue searching
|
|
365
|
+
* the tree until all possible colliders have been returned.
|
|
366
|
+
*/
|
|
367
|
+
query(collider, callback) {
|
|
368
|
+
const bounds = collider.bounds;
|
|
369
|
+
const helper = (currentNode) => {
|
|
370
|
+
if (currentNode && currentNode.bounds.intersect(bounds)) {
|
|
371
|
+
if (currentNode.isLeaf() && currentNode.data !== collider) {
|
|
372
|
+
if (callback.call(collider, currentNode.data)) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
return helper(currentNode.left) || helper(currentNode.right);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return false;
|
|
381
|
+
};
|
|
382
|
+
helper(this.root);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Queries the Dynamic Axis Aligned Tree for bodies that could be intersecting. By default the raycast query uses an infinitely
|
|
386
|
+
* long ray to test the tree specified by `max`.
|
|
387
|
+
*
|
|
388
|
+
* In the query callback, it will be passed a potential body that intersects with the raycast. Returning true from this
|
|
389
|
+
* callback indicates that your are complete with your query and do not want to continue. Return false will continue searching
|
|
390
|
+
* the tree until all possible bodies that would intersect with the ray have been returned.
|
|
391
|
+
*/
|
|
392
|
+
rayCastQuery(ray, max = Infinity, callback) {
|
|
393
|
+
const helper = (currentNode) => {
|
|
394
|
+
if (currentNode && currentNode.bounds.rayCast(ray, max)) {
|
|
395
|
+
if (currentNode.isLeaf()) {
|
|
396
|
+
if (callback.call(ray, currentNode.data)) {
|
|
397
|
+
// ray hit a leaf! return the body
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
// ray hit but not at a leaf, recurse deeper
|
|
403
|
+
return helper(currentNode.left) || helper(currentNode.right);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return false; // ray missed
|
|
407
|
+
};
|
|
408
|
+
helper(this.root);
|
|
409
|
+
}
|
|
410
|
+
getNodes() {
|
|
411
|
+
const helper = (currentNode) => {
|
|
412
|
+
if (currentNode) {
|
|
413
|
+
return [currentNode].concat(helper(currentNode.left), helper(currentNode.right));
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
return [];
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
return helper(this.root);
|
|
420
|
+
}
|
|
421
|
+
debug(ex) {
|
|
422
|
+
// draw all the nodes in the Dynamic Tree
|
|
423
|
+
const helper = (currentNode) => {
|
|
424
|
+
if (currentNode) {
|
|
425
|
+
if (currentNode.isLeaf()) {
|
|
426
|
+
currentNode.bounds.draw(ex, Color.Green);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
currentNode.bounds.draw(ex, Color.White);
|
|
430
|
+
}
|
|
431
|
+
if (currentNode.left) {
|
|
432
|
+
helper(currentNode.left);
|
|
433
|
+
}
|
|
434
|
+
if (currentNode.right) {
|
|
435
|
+
helper(currentNode.right);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
helper(this.root);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
//# sourceMappingURL=DynamicTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicTree.js","sourceRoot":"","sources":["../../../../src/engine/Collision/Detection/DynamicTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,KAAK,EAA4B,MAAM,OAAO,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,QAAQ;IAMnB,YAAmB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAEM,MAAM;QACX,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACnC,CAAC;CACF;AAQD;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IAGtB,YAAmB,cAA2B,IAAI,WAAW,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC;QAApH,gBAAW,GAAX,WAAW,CAAyG;QACrI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IAED;;OAEG;IACK,OAAO,CAAC,IAAiB;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vC,yCAAyC;QACzC,MAAM,MAAM,GAAG,CAAC,WAAwB,EAAE,EAAE;YAC1C,IAAI,WAAW,EAAE;gBACf,IAAI,WAAW,CAAC,MAAM,EAAE,EAAE;oBACxB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;iBAC1C;qBAAM;oBACL,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;iBAC1C;gBAED,IAAI,WAAW,CAAC,IAAI,EAAE;oBACpB,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;iBAC1B;gBACD,IAAI,WAAW,CAAC,KAAK,EAAE;oBACrB,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;iBAC3B;aACF;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Physics } from '../Physics';
|
|
2
|
+
import { DynamicTree } from './DynamicTree';
|
|
3
|
+
import { Pair } from './Pair';
|
|
4
|
+
import { Vector } from '../../Math/vector';
|
|
5
|
+
import { Ray } from '../../Math/ray';
|
|
6
|
+
import { Logger } from '../../Util/Log';
|
|
7
|
+
import { CollisionType } from '../CollisionType';
|
|
8
|
+
import { BodyComponent } from '../BodyComponent';
|
|
9
|
+
import { CompositeCollider } from '../Colliders/CompositeCollider';
|
|
10
|
+
/**
|
|
11
|
+
* Responsible for performing the collision broadphase (locating potential collisions) and
|
|
12
|
+
* the narrowphase (actual collision contacts)
|
|
13
|
+
*/
|
|
14
|
+
export class DynamicTreeCollisionProcessor {
|
|
15
|
+
constructor() {
|
|
16
|
+
this._dynamicCollisionTree = new DynamicTree();
|
|
17
|
+
this._pairs = new Set();
|
|
18
|
+
this._collisionPairCache = [];
|
|
19
|
+
this._colliders = [];
|
|
20
|
+
}
|
|
21
|
+
getColliders() {
|
|
22
|
+
return this._colliders;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Tracks a physics body for collisions
|
|
26
|
+
*/
|
|
27
|
+
track(target) {
|
|
28
|
+
if (!target) {
|
|
29
|
+
Logger.getInstance().warn('Cannot track null collider');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (target instanceof CompositeCollider) {
|
|
33
|
+
const colliders = target.getColliders();
|
|
34
|
+
for (const c of colliders) {
|
|
35
|
+
c.owner = target.owner;
|
|
36
|
+
this._colliders.push(c);
|
|
37
|
+
this._dynamicCollisionTree.trackCollider(c);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this._colliders.push(target);
|
|
42
|
+
this._dynamicCollisionTree.trackCollider(target);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Untracks a physics body
|
|
47
|
+
*/
|
|
48
|
+
untrack(target) {
|
|
49
|
+
if (!target) {
|
|
50
|
+
Logger.getInstance().warn('Cannot untrack a null collider');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (target instanceof CompositeCollider) {
|
|
54
|
+
const colliders = target.getColliders();
|
|
55
|
+
for (const c of colliders) {
|
|
56
|
+
const index = this._colliders.indexOf(c);
|
|
57
|
+
if (index !== -1) {
|
|
58
|
+
this._colliders.splice(index, 1);
|
|
59
|
+
}
|
|
60
|
+
this._dynamicCollisionTree.untrackCollider(c);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const index = this._colliders.indexOf(target);
|
|
65
|
+
if (index !== -1) {
|
|
66
|
+
this._colliders.splice(index, 1);
|
|
67
|
+
}
|
|
68
|
+
this._dynamicCollisionTree.untrackCollider(target);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
_pairExists(colliderA, colliderB) {
|
|
72
|
+
// if the collision pair has been calculated already short circuit
|
|
73
|
+
const hash = Pair.calculatePairHash(colliderA.id, colliderB.id);
|
|
74
|
+
return this._pairs.has(hash);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Detects potential collision pairs in a broadphase approach with the dynamic AABB tree strategy
|
|
78
|
+
*/
|
|
79
|
+
broadphase(targets, delta, stats) {
|
|
80
|
+
const seconds = delta / 1000;
|
|
81
|
+
// Retrieve the list of potential colliders, exclude killed, prevented, and self
|
|
82
|
+
const potentialColliders = targets.filter((other) => {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const body = (_a = other.owner) === null || _a === void 0 ? void 0 : _a.get(BodyComponent);
|
|
85
|
+
return ((_b = other.owner) === null || _b === void 0 ? void 0 : _b.active) && body.collisionType !== CollisionType.PreventCollision;
|
|
86
|
+
});
|
|
87
|
+
// clear old list of collision pairs
|
|
88
|
+
this._collisionPairCache = [];
|
|
89
|
+
this._pairs.clear();
|
|
90
|
+
// check for normal collision pairs
|
|
91
|
+
let collider;
|
|
92
|
+
for (let j = 0, l = potentialColliders.length; j < l; j++) {
|
|
93
|
+
collider = potentialColliders[j];
|
|
94
|
+
// Query the collision tree for potential colliders
|
|
95
|
+
this._dynamicCollisionTree.query(collider, (other) => {
|
|
96
|
+
if (!this._pairExists(collider, other) && Pair.canCollide(collider, other)) {
|
|
97
|
+
const pair = new Pair(collider, other);
|
|
98
|
+
this._pairs.add(pair.id);
|
|
99
|
+
this._collisionPairCache.push(pair);
|
|
100
|
+
}
|
|
101
|
+
// Always return false, to query whole tree. Returning true in the query method stops searching
|
|
102
|
+
return false;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (stats) {
|
|
106
|
+
stats.physics.pairs = this._collisionPairCache.length;
|
|
107
|
+
}
|
|
108
|
+
// Check dynamic tree for fast moving objects
|
|
109
|
+
// Fast moving objects are those moving at least there smallest bound per frame
|
|
110
|
+
if (Physics.checkForFastBodies) {
|
|
111
|
+
for (const collider of potentialColliders) {
|
|
112
|
+
const body = collider.owner.get(BodyComponent);
|
|
113
|
+
// Skip non-active objects. Does not make sense on other collision types
|
|
114
|
+
if (body.collisionType !== CollisionType.Active) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// Maximum travel distance next frame
|
|
118
|
+
const updateDistance = body.vel.size * seconds + // velocity term
|
|
119
|
+
body.acc.size * 0.5 * seconds * seconds; // acc term
|
|
120
|
+
// Find the minimum dimension
|
|
121
|
+
const minDimension = Math.min(collider.bounds.height, collider.bounds.width);
|
|
122
|
+
if (Physics.disableMinimumSpeedForFastBody || updateDistance > minDimension / 2) {
|
|
123
|
+
if (stats) {
|
|
124
|
+
stats.physics.fastBodies++;
|
|
125
|
+
}
|
|
126
|
+
// start with the oldPos because the integration for actors has already happened
|
|
127
|
+
// objects resting on a surface may be slightly penetrating in the current position
|
|
128
|
+
const updateVec = body.pos.sub(body.oldPos);
|
|
129
|
+
const centerPoint = collider.center;
|
|
130
|
+
const furthestPoint = collider.getFurthestPoint(body.vel);
|
|
131
|
+
const origin = furthestPoint.sub(updateVec);
|
|
132
|
+
const ray = new Ray(origin, body.vel);
|
|
133
|
+
// back the ray up by -2x surfaceEpsilon to account for fast moving objects starting on the surface
|
|
134
|
+
ray.pos = ray.pos.add(ray.dir.scale(-2 * Physics.surfaceEpsilon));
|
|
135
|
+
let minCollider;
|
|
136
|
+
let minTranslate = new Vector(Infinity, Infinity);
|
|
137
|
+
this._dynamicCollisionTree.rayCastQuery(ray, updateDistance + Physics.surfaceEpsilon * 2, (other) => {
|
|
138
|
+
if (!this._pairExists(collider, other) && Pair.canCollide(collider, other)) {
|
|
139
|
+
const hitPoint = other.rayCast(ray, updateDistance + Physics.surfaceEpsilon * 10);
|
|
140
|
+
if (hitPoint) {
|
|
141
|
+
const translate = hitPoint.sub(origin);
|
|
142
|
+
if (translate.size < minTranslate.size) {
|
|
143
|
+
minTranslate = translate;
|
|
144
|
+
minCollider = other;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
});
|
|
150
|
+
if (minCollider && Vector.isValid(minTranslate)) {
|
|
151
|
+
const pair = new Pair(collider, minCollider);
|
|
152
|
+
if (!this._pairs.has(pair.id)) {
|
|
153
|
+
this._pairs.add(pair.id);
|
|
154
|
+
this._collisionPairCache.push(pair);
|
|
155
|
+
}
|
|
156
|
+
// move the fast moving object to the other body
|
|
157
|
+
// need to push into the surface by ex.Physics.surfaceEpsilon
|
|
158
|
+
const shift = centerPoint.sub(furthestPoint);
|
|
159
|
+
body.pos = origin
|
|
160
|
+
.add(shift)
|
|
161
|
+
.add(minTranslate)
|
|
162
|
+
.add(ray.dir.scale(10 * Physics.surfaceEpsilon)); // needed to push the shape slightly into contact
|
|
163
|
+
collider.update(body.transform);
|
|
164
|
+
if (stats) {
|
|
165
|
+
stats.physics.fastBodyCollisions++;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// return cache
|
|
172
|
+
return this._collisionPairCache;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Applies narrow phase on collision pairs to find actual area intersections
|
|
176
|
+
* Adds actual colliding pairs to stats' Frame data
|
|
177
|
+
*/
|
|
178
|
+
narrowphase(pairs, stats) {
|
|
179
|
+
let contacts = [];
|
|
180
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
181
|
+
const newContacts = pairs[i].collide();
|
|
182
|
+
contacts = contacts.concat(newContacts);
|
|
183
|
+
if (stats && newContacts.length > 0) {
|
|
184
|
+
for (const c of newContacts) {
|
|
185
|
+
stats.physics.contacts.set(c.id, c);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (stats) {
|
|
190
|
+
stats.physics.collisions += contacts.length;
|
|
191
|
+
}
|
|
192
|
+
return contacts;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Update the dynamic tree positions
|
|
196
|
+
*/
|
|
197
|
+
update(targets) {
|
|
198
|
+
let updated = 0;
|
|
199
|
+
const len = targets.length;
|
|
200
|
+
for (let i = 0; i < len; i++) {
|
|
201
|
+
if (this._dynamicCollisionTree.updateCollider(targets[i])) {
|
|
202
|
+
updated++;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return updated;
|
|
206
|
+
}
|
|
207
|
+
debug(ex) {
|
|
208
|
+
this._dynamicCollisionTree.debug(ex);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=DynamicTreeCollisionProcessor.js.map
|