melonjs 14.5.0 → 15.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +6 -6
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +7 -3
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +18 -20
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +56 -56
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +8 -6
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +59 -59
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +25 -24
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +35 -13
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +3 -3
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/renderable.d.ts +6 -0
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +17 -19
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +55 -55
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +9 -4
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +24 -23
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/polyfill/index.js +0 -2
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +34 -12
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +186 -179
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
package/src/physics/quadtree.js
CHANGED
|
@@ -11,7 +11,7 @@ import * as arrayUtil from "./../utils/array.js";
|
|
|
11
11
|
* a pool of `QuadTree` objects
|
|
12
12
|
* @ignore
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
let QT_ARRAY = [];
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* will pop a quadtree object from the array
|
|
@@ -20,7 +20,7 @@ var QT_ARRAY = [];
|
|
|
20
20
|
*/
|
|
21
21
|
function QT_ARRAY_POP(world, bounds, max_objects = 4, max_levels = 4, level = 0) {
|
|
22
22
|
if (QT_ARRAY.length > 0) {
|
|
23
|
-
|
|
23
|
+
let _qt = QT_ARRAY.pop();
|
|
24
24
|
_qt.world = world;
|
|
25
25
|
_qt.bounds = bounds;
|
|
26
26
|
_qt.max_objects = max_objects;
|
|
@@ -44,7 +44,7 @@ function QT_ARRAY_PUSH(qt) {
|
|
|
44
44
|
* a temporary vector object to be reused
|
|
45
45
|
* @ignore
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
let QT_VECTOR = new Vector2d();
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* @classdesc
|
|
@@ -77,7 +77,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
77
77
|
* Split the node into 4 subnodes
|
|
78
78
|
*/
|
|
79
79
|
split() {
|
|
80
|
-
|
|
80
|
+
let nextLevel = this.level + 1,
|
|
81
81
|
subWidth = this.bounds.width / 2,
|
|
82
82
|
subHeight = this.bounds.height / 2,
|
|
83
83
|
left = this.bounds.left,
|
|
@@ -146,8 +146,8 @@ var QT_VECTOR = new Vector2d();
|
|
|
146
146
|
* @returns Integer index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node
|
|
147
147
|
*/
|
|
148
148
|
getIndex(item) {
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
let pos;
|
|
150
|
+
let bounds = item.getBounds();
|
|
151
151
|
|
|
152
152
|
// use game world coordinates for floating items
|
|
153
153
|
if (item.isFloating === true) {
|
|
@@ -156,7 +156,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
156
156
|
pos = QT_VECTOR.set(item.left, item.top);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
let index = -1,
|
|
160
160
|
rx = pos.x,
|
|
161
161
|
ry = pos.y,
|
|
162
162
|
rw = bounds.width,
|
|
@@ -194,7 +194,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
194
194
|
* @param {Container} container - group of objects to be added
|
|
195
195
|
*/
|
|
196
196
|
insertContainer(container) {
|
|
197
|
-
for (
|
|
197
|
+
for (let i = container.children.length, child; i--, (child = container.children[i]);) {
|
|
198
198
|
if (child.isKinematic !== true) {
|
|
199
199
|
if (typeof child.addChild === "function") {
|
|
200
200
|
if (child.name !== "rootContainer") {
|
|
@@ -222,7 +222,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
222
222
|
* @param {object} item - object to be added
|
|
223
223
|
*/
|
|
224
224
|
insert(item) {
|
|
225
|
-
|
|
225
|
+
let index = -1;
|
|
226
226
|
|
|
227
227
|
//if we have subnodes ...
|
|
228
228
|
if (this.nodes.length > 0) {
|
|
@@ -243,7 +243,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
243
243
|
this.split();
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
let i = 0;
|
|
247
247
|
|
|
248
248
|
//add all objects to there corresponding subnodes
|
|
249
249
|
while (i < this.objects.length) {
|
|
@@ -268,19 +268,19 @@ var QT_VECTOR = new Vector2d();
|
|
|
268
268
|
* @returns {object[]} array with all detected objects
|
|
269
269
|
*/
|
|
270
270
|
retrieve(item, fn) {
|
|
271
|
-
|
|
271
|
+
let returnObjects = this.objects;
|
|
272
272
|
|
|
273
273
|
//if we have subnodes ...
|
|
274
274
|
if (this.nodes.length > 0) {
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
let index = this.getIndex(item);
|
|
277
277
|
|
|
278
278
|
//if rect fits into a subnode ..
|
|
279
279
|
if (index !== -1) {
|
|
280
280
|
returnObjects = returnObjects.concat(this.nodes[index].retrieve(item));
|
|
281
281
|
} else {
|
|
282
282
|
//if rect does not fit into a subnode, check it against all subnodes
|
|
283
|
-
for (
|
|
283
|
+
for (let i = 0; i < this.nodes.length; i = i + 1) {
|
|
284
284
|
returnObjects = returnObjects.concat(this.nodes[i].retrieve(item));
|
|
285
285
|
}
|
|
286
286
|
}
|
|
@@ -302,7 +302,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
302
302
|
* @returns {boolean} true if the item was found and removed.
|
|
303
303
|
*/
|
|
304
304
|
remove(item) {
|
|
305
|
-
|
|
305
|
+
let found = false;
|
|
306
306
|
|
|
307
307
|
if (typeof (item.getBounds) === "undefined") {
|
|
308
308
|
// ignore object that cannot be added in the first place
|
|
@@ -312,7 +312,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
312
312
|
//if we have subnodes ...
|
|
313
313
|
if (this.nodes.length > 0) {
|
|
314
314
|
// determine to which node the item belongs to
|
|
315
|
-
|
|
315
|
+
let index = this.getIndex(item);
|
|
316
316
|
|
|
317
317
|
if (index !== -1) {
|
|
318
318
|
found = arrayUtil.remove(this.nodes[index], item);
|
|
@@ -351,8 +351,8 @@ var QT_VECTOR = new Vector2d();
|
|
|
351
351
|
* @returns {boolean} true if the node has any children
|
|
352
352
|
*/
|
|
353
353
|
hasChildren() {
|
|
354
|
-
for (
|
|
355
|
-
|
|
354
|
+
for (let i = 0; i < this.nodes.length; i = i + 1) {
|
|
355
|
+
let subnode = this.nodes[i];
|
|
356
356
|
if (subnode.length > 0 || subnode.objects.length > 0) {
|
|
357
357
|
return true;
|
|
358
358
|
}
|
|
@@ -369,7 +369,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
369
369
|
clear(bounds) {
|
|
370
370
|
this.objects.length = 0;
|
|
371
371
|
|
|
372
|
-
for (
|
|
372
|
+
for (let i = 0; i < this.nodes.length; i++) {
|
|
373
373
|
this.nodes[i].clear();
|
|
374
374
|
// recycle the quadTree object
|
|
375
375
|
QT_ARRAY_PUSH(this.nodes[i]);
|
package/src/physics/sat.js
CHANGED
|
@@ -29,16 +29,16 @@ const RIGHT_VORNOI_REGION = 1;
|
|
|
29
29
|
* @type {Array.<Vector2d>}
|
|
30
30
|
* @ignore
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
for (
|
|
32
|
+
let T_VECTORS = [];
|
|
33
|
+
for (let v = 0; v < 10; v++) { T_VECTORS.push(new Vector2d()); }
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* A pool of arrays of numbers used in calculations to avoid allocating memory.
|
|
37
37
|
* @type {Array.<Array.<number>>}
|
|
38
38
|
* @ignore
|
|
39
39
|
*/
|
|
40
|
-
|
|
41
|
-
for (
|
|
40
|
+
let T_ARRAYS = [];
|
|
41
|
+
for (let a = 0; a < 5; a++) { T_ARRAYS.push([]); }
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -53,12 +53,12 @@ for (var a = 0; a < 5; a++) { T_ARRAYS.push([]); }
|
|
|
53
53
|
* result[1] will be the maximum value.
|
|
54
54
|
*/
|
|
55
55
|
function flattenPointsOn(points, normal, result) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for (
|
|
56
|
+
let min = Number.MAX_VALUE;
|
|
57
|
+
let max = -Number.MAX_VALUE;
|
|
58
|
+
let len = points.length;
|
|
59
|
+
for (let i = 0; i < len; i++) {
|
|
60
60
|
// The magnitude of the projection of the point onto the normal
|
|
61
|
-
|
|
61
|
+
let dot = points[i].dot(normal);
|
|
62
62
|
if (dot < min) { min = dot; }
|
|
63
63
|
if (dot > max) { max = dot; }
|
|
64
64
|
}
|
|
@@ -83,11 +83,11 @@ function flattenPointsOn(points, normal, result) {
|
|
|
83
83
|
* the direction of the overlap will be populated.
|
|
84
84
|
*/
|
|
85
85
|
function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
let rangeA = T_ARRAYS.pop();
|
|
87
|
+
let rangeB = T_ARRAYS.pop();
|
|
88
88
|
// The magnitude of the offset between the two polygons
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
let offsetV = T_VECTORS.pop().copy(bPos).sub(aPos);
|
|
90
|
+
let projectedOffset = offsetV.dot(axis);
|
|
91
91
|
|
|
92
92
|
// Project the polygons onto the axis.
|
|
93
93
|
flattenPointsOn(aPoints, axis, rangeA);
|
|
@@ -105,7 +105,7 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
105
105
|
|
|
106
106
|
// This is not a separating axis. If we're calculating a response, calculate the overlap.
|
|
107
107
|
if (response) {
|
|
108
|
-
|
|
108
|
+
let overlap = 0;
|
|
109
109
|
// A starts further left than B
|
|
110
110
|
if (rangeA[0] < rangeB[0]) {
|
|
111
111
|
response.aInB = false;
|
|
@@ -115,8 +115,8 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
115
115
|
response.bInA = false;
|
|
116
116
|
// B is fully inside A. Pick the shortest way out.
|
|
117
117
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
let option1 = rangeA[1] - rangeB[0];
|
|
119
|
+
let option2 = rangeB[1] - rangeA[0];
|
|
120
120
|
overlap = option1 < option2 ? option1 : -option2;
|
|
121
121
|
}
|
|
122
122
|
// B starts further left than A
|
|
@@ -128,14 +128,14 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
128
128
|
response.aInB = false;
|
|
129
129
|
// A is fully inside B. Pick the shortest way out.
|
|
130
130
|
} else {
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
let option11 = rangeA[1] - rangeB[0];
|
|
132
|
+
let option22 = rangeB[1] - rangeA[0];
|
|
133
133
|
overlap = option11 < option22 ? option11 : -option22;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
// If this is the smallest amount of overlap we've seen so far, set it as the minimum overlap.
|
|
138
|
-
|
|
138
|
+
let absOverlap = Math.abs(overlap);
|
|
139
139
|
if (absOverlap < response.overlap) {
|
|
140
140
|
response.overlap = absOverlap;
|
|
141
141
|
response.overlapN.copy(axis);
|
|
@@ -168,8 +168,8 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
168
168
|
* RIGHT_VORNOI_REGION (1) if it is the right region.
|
|
169
169
|
*/
|
|
170
170
|
function vornoiRegion(line, point) {
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
let len2 = line.length2();
|
|
172
|
+
let dp = point.dot(line);
|
|
173
173
|
if (dp < 0) {
|
|
174
174
|
// If the point is beyond the start of the line, it is in the
|
|
175
175
|
// left vornoi region.
|
|
@@ -196,16 +196,16 @@ function vornoiRegion(line, point) {
|
|
|
196
196
|
*/
|
|
197
197
|
export function testPolygonPolygon(a, polyA, b, polyB, response) {
|
|
198
198
|
// specific point for
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
let aPoints = polyA.points;
|
|
200
|
+
let aNormals = polyA.normals;
|
|
201
|
+
let aLen = aNormals.length;
|
|
202
|
+
let bPoints = polyB.points;
|
|
203
|
+
let bNormals = polyB.normals;
|
|
204
|
+
let bLen = bNormals.length;
|
|
205
205
|
// aboslute shape position
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
let posA = T_VECTORS.pop().copy(a.pos).add(a.ancestor.getAbsolutePosition()).add(polyA.pos);
|
|
207
|
+
let posB = T_VECTORS.pop().copy(b.pos).add(b.ancestor.getAbsolutePosition()).add(polyB.pos);
|
|
208
|
+
let i;
|
|
209
209
|
|
|
210
210
|
// If any of the edge normals of A is a separating axis, no intersection.
|
|
211
211
|
for (i = 0; i < aLen; i++) {
|
|
@@ -252,13 +252,13 @@ export function testPolygonPolygon(a, polyA, b, polyB, response) {
|
|
|
252
252
|
export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
|
|
253
253
|
// Check if the distance between the centers of the two
|
|
254
254
|
// circles is greater than their combined radius.
|
|
255
|
-
|
|
255
|
+
let differenceV = T_VECTORS.pop().copy(b.pos).add(b.ancestor.getAbsolutePosition()).add(ellipseB.pos)
|
|
256
256
|
.sub(a.pos).add(a.ancestor.getAbsolutePosition()).sub(ellipseA.pos);
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
257
|
+
let radiusA = ellipseA.radius;
|
|
258
|
+
let radiusB = ellipseB.radius;
|
|
259
|
+
let totalRadius = radiusA + radiusB;
|
|
260
|
+
let totalRadiusSq = totalRadius * totalRadius;
|
|
261
|
+
let distanceSq = differenceV.length2();
|
|
262
262
|
// If the distance is bigger than the combined radius, they don't intersect.
|
|
263
263
|
if (distanceSq > totalRadiusSq) {
|
|
264
264
|
T_VECTORS.push(differenceV);
|
|
@@ -266,7 +266,7 @@ export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
|
|
|
266
266
|
}
|
|
267
267
|
// They intersect. If we're calculating a response, calculate the overlap.
|
|
268
268
|
if (response) {
|
|
269
|
-
|
|
269
|
+
let dist = Math.sqrt(distanceSq);
|
|
270
270
|
response.a = a;
|
|
271
271
|
response.b = b;
|
|
272
272
|
response.overlap = totalRadius - dist;
|
|
@@ -291,24 +291,24 @@ export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
|
|
|
291
291
|
*/
|
|
292
292
|
export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
293
293
|
// Get the position of the circle relative to the polygon.
|
|
294
|
-
|
|
294
|
+
let circlePos = T_VECTORS.pop().copy(b.pos).add(b.ancestor.getAbsolutePosition()).add(ellipseB.pos)
|
|
295
295
|
.sub(a.pos).add(a.ancestor.getAbsolutePosition()).sub(polyA.pos);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
296
|
+
let radius = ellipseB.radius;
|
|
297
|
+
let radius2 = radius * radius;
|
|
298
|
+
let points = polyA.points;
|
|
299
|
+
let edges = polyA.edges;
|
|
300
|
+
let len = edges.length;
|
|
301
|
+
let edge = T_VECTORS.pop();
|
|
302
|
+
let normal = T_VECTORS.pop();
|
|
303
|
+
let point = T_VECTORS.pop();
|
|
304
|
+
let dist = 0;
|
|
305
305
|
|
|
306
306
|
// For each edge in the polygon:
|
|
307
|
-
for (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
307
|
+
for (let i = 0; i < len; i++) {
|
|
308
|
+
let next = i === len - 1 ? 0 : i + 1;
|
|
309
|
+
let prev = i === 0 ? len - 1 : i - 1;
|
|
310
|
+
let overlap = 0;
|
|
311
|
+
let overlapN = null;
|
|
312
312
|
|
|
313
313
|
// Get the edge.
|
|
314
314
|
edge.copy(edges[i]);
|
|
@@ -323,11 +323,11 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
// Calculate which Vornoi region the center of the circle is in.
|
|
326
|
-
|
|
327
|
-
|
|
326
|
+
let region = vornoiRegion(edge, point);
|
|
327
|
+
let inRegion = true;
|
|
328
328
|
// If it's the left region:
|
|
329
329
|
if (region === LEFT_VORNOI_REGION) {
|
|
330
|
-
|
|
330
|
+
let point2 = null;
|
|
331
331
|
if (len > 1) {
|
|
332
332
|
// We need to make sure we're in the RIGHT_VORNOI_REGION of the previous edge.
|
|
333
333
|
edge.copy(edges[prev]);
|
|
@@ -401,7 +401,7 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
401
401
|
// Find the perpendicular distance between the center of the
|
|
402
402
|
// circle and the edge.
|
|
403
403
|
dist = point.dot(normal);
|
|
404
|
-
|
|
404
|
+
let distAbs = Math.abs(dist);
|
|
405
405
|
// If the circle is on the outside of the edge, there is no intersection.
|
|
406
406
|
if ((len === 1 || dist > 0) && distAbs > radius) {
|
|
407
407
|
// No intersection
|
|
@@ -458,11 +458,11 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
458
458
|
*/
|
|
459
459
|
export function testEllipsePolygon(a, ellipseA, b, polyB, response) {
|
|
460
460
|
// Test the polygon against the circle.
|
|
461
|
-
|
|
461
|
+
let result = testPolygonEllipse(b, polyB, a, ellipseA, response);
|
|
462
462
|
if (result && response) {
|
|
463
463
|
// Swap A and B in the response.
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
let resa = response.a;
|
|
465
|
+
let aInB = response.aInB;
|
|
466
466
|
response.overlapN.negateSelf();
|
|
467
467
|
response.overlapV.negateSelf();
|
|
468
468
|
response.a = response.b;
|
package/src/physics/world.js
CHANGED
|
@@ -140,7 +140,7 @@ import state from "./../state/state.js";
|
|
|
140
140
|
bodyApplyGravity(body) {
|
|
141
141
|
// apply gravity to the current velocity
|
|
142
142
|
if (!body.ignoreGravity && body.gravityScale !== 0) {
|
|
143
|
-
|
|
143
|
+
let gravity = this.gravity;
|
|
144
144
|
|
|
145
145
|
// apply gravity if defined
|
|
146
146
|
body.force.x += (body.mass * gravity.x) * body.gravityScale;
|
|
@@ -154,7 +154,7 @@ import state from "./../state/state.js";
|
|
|
154
154
|
* @returns {boolean} true if the word is dirty
|
|
155
155
|
*/
|
|
156
156
|
update(dt) {
|
|
157
|
-
|
|
157
|
+
let isPaused = state.isPaused();
|
|
158
158
|
|
|
159
159
|
// clear the quadtree
|
|
160
160
|
this.broadphase.clear();
|
|
@@ -165,7 +165,7 @@ import state from "./../state/state.js";
|
|
|
165
165
|
// iterate through all bodies
|
|
166
166
|
this.bodies.forEach((body) => {
|
|
167
167
|
if (!body.isStatic) {
|
|
168
|
-
|
|
168
|
+
let ancestor = body.ancestor;
|
|
169
169
|
// if the game is not paused, and ancestor can be updated
|
|
170
170
|
if (!(isPaused && (!ancestor.updateWhenPaused)) &&
|
|
171
171
|
(ancestor.inViewport || ancestor.alwaysUpdate)) {
|
package/src/plugin/plugin.js
CHANGED
|
@@ -6,7 +6,7 @@ import { version } from "./../index.js";
|
|
|
6
6
|
* @see plugin.register
|
|
7
7
|
* @namespace plugins
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export let plugins = {};
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class BasePlugin {
|
|
@@ -27,7 +27,7 @@ class BasePlugin {
|
|
|
27
27
|
/**
|
|
28
28
|
* @namespace plugin
|
|
29
29
|
*/
|
|
30
|
-
export
|
|
30
|
+
export let plugin = {
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* a base Object for plugin <br>
|
|
@@ -64,14 +64,14 @@ export var plugin = {
|
|
|
64
64
|
// reuse the logic behind object extends
|
|
65
65
|
if (typeof(proto[name]) === "function") {
|
|
66
66
|
// save the original function
|
|
67
|
-
|
|
67
|
+
let _parent = proto[name];
|
|
68
68
|
// override the function with the new one
|
|
69
69
|
Object.defineProperty(proto, name, {
|
|
70
70
|
"configurable" : true,
|
|
71
71
|
"value" : (function (name, fn) {
|
|
72
72
|
return function () {
|
|
73
73
|
this._patched = _parent;
|
|
74
|
-
|
|
74
|
+
let ret = fn.apply(this, arguments);
|
|
75
75
|
this._patched = null;
|
|
76
76
|
return ret;
|
|
77
77
|
};
|
|
@@ -90,7 +90,7 @@ export var plugin = {
|
|
|
90
90
|
* @see Base
|
|
91
91
|
* @public
|
|
92
92
|
* @param {plugin.Base} pluginObj - Plugin object to instantiate and register
|
|
93
|
-
* @param {string} name
|
|
93
|
+
* @param {string} [name=pluginObj.constructor.name] - a unique name for this plugin
|
|
94
94
|
* @param {object} [...arguments] - all extra parameters will be passed to the plugin constructor
|
|
95
95
|
* @example
|
|
96
96
|
* // register a new plugin
|
|
@@ -99,14 +99,14 @@ export var plugin = {
|
|
|
99
99
|
* // under then me.plugins namespace
|
|
100
100
|
* me.plugins.testPlugin.myfunction ();
|
|
101
101
|
*/
|
|
102
|
-
register : function (pluginObj, name) {
|
|
102
|
+
register : function (pluginObj, name = pluginObj.toString().match(/ (\w+)/)[1]) {
|
|
103
103
|
// ensure me.plugins[name] is not already "used"
|
|
104
104
|
if (plugins[name]) {
|
|
105
105
|
throw new Error("plugin " + name + " already registered");
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// get extra arguments
|
|
109
|
-
|
|
109
|
+
let _args = [];
|
|
110
110
|
if (arguments.length > 2) {
|
|
111
111
|
// store extra arguments if any
|
|
112
112
|
_args = Array.prototype.slice.call(arguments, 1);
|
|
@@ -114,7 +114,7 @@ export var plugin = {
|
|
|
114
114
|
|
|
115
115
|
// try to instantiate the plugin
|
|
116
116
|
_args[0] = pluginObj;
|
|
117
|
-
|
|
117
|
+
let instance = new (pluginObj.bind.apply(pluginObj, _args))();
|
|
118
118
|
|
|
119
119
|
// inheritance check
|
|
120
120
|
if (typeof instance === "undefined" || !(instance instanceof plugin.Base)) {
|
package/src/polyfill/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import pool from "./../system/pooling.js";
|
|
|
24
24
|
this.id = settings.id;
|
|
25
25
|
|
|
26
26
|
// add and configure the physic body
|
|
27
|
-
|
|
27
|
+
let shape = settings.shapes;
|
|
28
28
|
if (typeof shape === "undefined") {
|
|
29
29
|
shape = pool.pull("Polygon", 0, 0, [
|
|
30
30
|
pool.pull("Vector2d", 0, 0),
|