melonjs 14.4.0 → 14.5.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.
Files changed (207) hide show
  1. package/README.md +11 -55
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  8. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  10. package/dist/melonjs.mjs/application/application.js +1 -1
  11. package/dist/melonjs.mjs/application/header.js +1 -1
  12. package/dist/melonjs.mjs/application/resize.js +1 -1
  13. package/dist/melonjs.mjs/application/settings.js +1 -1
  14. package/dist/melonjs.mjs/audio/audio.js +4 -4
  15. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  16. package/dist/melonjs.mjs/const.js +1 -1
  17. package/dist/melonjs.mjs/entity/entity.js +43 -9
  18. package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
  19. package/dist/melonjs.mjs/geometries/line.js +1 -1
  20. package/dist/melonjs.mjs/geometries/path2d.js +18 -42
  21. package/dist/melonjs.mjs/geometries/point.js +1 -6
  22. package/dist/melonjs.mjs/geometries/poly.js +2 -5
  23. package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
  24. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  25. package/dist/melonjs.mjs/index.js +8 -6
  26. package/dist/melonjs.mjs/input/gamepad.js +10 -16
  27. package/dist/melonjs.mjs/input/input.js +1 -1
  28. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  29. package/dist/melonjs.mjs/input/pointer.js +1 -1
  30. package/dist/melonjs.mjs/input/pointerevent.js +2 -16
  31. package/dist/melonjs.mjs/lang/console.js +1 -1
  32. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  33. package/dist/melonjs.mjs/level/level.js +3 -3
  34. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  35. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
  36. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  37. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  38. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
  39. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
  40. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  41. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  48. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  49. package/dist/melonjs.mjs/loader/cache.js +24 -0
  50. package/dist/melonjs.mjs/loader/loader.js +331 -716
  51. package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
  52. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  53. package/dist/melonjs.mjs/loader/parser.js +281 -0
  54. package/dist/melonjs.mjs/loader/settings.js +91 -0
  55. package/dist/melonjs.mjs/math/color.js +1 -1
  56. package/dist/melonjs.mjs/math/math.js +1 -1
  57. package/dist/melonjs.mjs/math/matrix2.js +7 -9
  58. package/dist/melonjs.mjs/math/matrix3.js +18 -21
  59. package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
  60. package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
  61. package/dist/melonjs.mjs/math/vector2.js +3 -3
  62. package/dist/melonjs.mjs/math/vector3.js +3 -4
  63. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  71. package/dist/melonjs.mjs/particles/emitter.js +3 -3
  72. package/dist/melonjs.mjs/particles/particle.js +1 -1
  73. package/dist/melonjs.mjs/particles/settings.js +1 -1
  74. package/dist/melonjs.mjs/physics/body.js +18 -14
  75. package/dist/melonjs.mjs/physics/bounds.js +18 -70
  76. package/dist/melonjs.mjs/physics/collision.js +1 -1
  77. package/dist/melonjs.mjs/physics/detector.js +1 -1
  78. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  79. package/dist/melonjs.mjs/physics/response.js +1 -1
  80. package/dist/melonjs.mjs/physics/sat.js +1 -1
  81. package/dist/melonjs.mjs/physics/world.js +1 -1
  82. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  83. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  84. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  85. package/dist/melonjs.mjs/renderable/container.js +25 -19
  86. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  87. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
  88. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  89. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  90. package/dist/melonjs.mjs/renderable/renderable.js +126 -105
  91. package/dist/melonjs.mjs/renderable/sprite.js +33 -54
  92. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  93. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  94. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  95. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
  96. package/dist/melonjs.mjs/state/stage.js +1 -1
  97. package/dist/melonjs.mjs/state/state.js +2 -2
  98. package/dist/melonjs.mjs/system/device.js +1 -1
  99. package/dist/melonjs.mjs/system/dom.js +1 -1
  100. package/dist/melonjs.mjs/system/event.js +1 -1
  101. package/dist/melonjs.mjs/system/platform.js +1 -1
  102. package/dist/melonjs.mjs/system/pooling.js +8 -18
  103. package/dist/melonjs.mjs/system/save.js +1 -1
  104. package/dist/melonjs.mjs/system/timer.js +1 -1
  105. package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
  106. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  107. package/dist/melonjs.mjs/text/glyph.js +1 -1
  108. package/dist/melonjs.mjs/text/text.js +1 -1
  109. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  110. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  111. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  112. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  113. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  114. package/dist/melonjs.mjs/utils/agent.js +1 -1
  115. package/dist/melonjs.mjs/utils/array.js +1 -1
  116. package/dist/melonjs.mjs/utils/file.js +1 -1
  117. package/dist/melonjs.mjs/utils/function.js +1 -1
  118. package/dist/melonjs.mjs/utils/string.js +2 -2
  119. package/dist/melonjs.mjs/utils/utils.js +2 -4
  120. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
  121. package/dist/melonjs.mjs/video/renderer.js +1 -1
  122. package/dist/melonjs.mjs/video/texture/atlas.js +10 -9
  123. package/dist/melonjs.mjs/video/texture/cache.js +3 -3
  124. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  125. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  126. package/dist/melonjs.mjs/video/video.js +2 -2
  127. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
  128. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
  129. package/{src/video/webgl → dist/melonjs.mjs/video/webgl/compositors}/webgl_compositor.js +28 -205
  130. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  131. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  132. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  133. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +2 -2
  141. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +2 -2
  142. package/dist/melonjs.module.js +17844 -17809
  143. package/dist/types/entity/entity.d.ts +2 -2
  144. package/dist/types/geometries/path2d.d.ts +5 -31
  145. package/dist/types/geometries/point.d.ts +2 -7
  146. package/dist/types/geometries/poly.d.ts +0 -1
  147. package/dist/types/index.d.ts +2 -2
  148. package/dist/types/loader/cache.d.ts +7 -0
  149. package/dist/types/loader/loader.d.ts +166 -181
  150. package/dist/types/loader/parser.d.ts +41 -0
  151. package/dist/types/loader/settings.d.ts +57 -0
  152. package/dist/types/particles/emitter.d.ts +4 -4
  153. package/dist/types/physics/bounds.d.ts +29 -84
  154. package/dist/types/renderable/container.d.ts +0 -11
  155. package/dist/types/renderable/renderable.d.ts +37 -31
  156. package/dist/types/renderable/sprite.d.ts +3 -3
  157. package/dist/types/state/state.d.ts +1 -1
  158. package/dist/types/system/pooling.d.ts +2 -2
  159. package/dist/types/video/renderer.d.ts +1 -1
  160. package/dist/types/video/webgl/compositors/compositor.d.ts +101 -0
  161. package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
  162. package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
  163. package/dist/types/video/webgl/webgl_renderer.d.ts +1 -1
  164. package/package.json +16 -15
  165. package/src/audio/audio.js +3 -3
  166. package/src/entity/entity.js +42 -8
  167. package/src/geometries/ellipse.js +1 -2
  168. package/src/geometries/path2d.js +17 -41
  169. package/src/geometries/point.js +0 -5
  170. package/src/geometries/poly.js +1 -4
  171. package/src/geometries/rectangle.js +12 -8
  172. package/src/index.js +2 -2
  173. package/src/input/gamepad.js +9 -15
  174. package/src/input/pointerevent.js +1 -15
  175. package/src/level/level.js +2 -2
  176. package/src/level/tiled/TMXLayer.js +0 -7
  177. package/src/level/tiled/TMXTileMap.js +7 -3
  178. package/src/level/tiled/TMXTileset.js +4 -4
  179. package/src/loader/cache.js +16 -0
  180. package/src/loader/loader.js +339 -711
  181. package/src/loader/loadingscreen.js +3 -3
  182. package/src/loader/parser.js +279 -0
  183. package/src/loader/settings.js +85 -0
  184. package/src/math/matrix2.js +6 -8
  185. package/src/math/matrix3.js +17 -20
  186. package/src/math/observable_vector2.js +2 -2
  187. package/src/math/observable_vector3.js +2 -3
  188. package/src/math/vector2.js +2 -2
  189. package/src/math/vector3.js +2 -3
  190. package/src/particles/emitter.js +2 -2
  191. package/src/physics/body.js +17 -13
  192. package/src/physics/bounds.js +17 -69
  193. package/src/renderable/container.js +24 -18
  194. package/src/renderable/imagelayer.js +6 -0
  195. package/src/renderable/renderable.js +125 -104
  196. package/src/renderable/sprite.js +32 -53
  197. package/src/state/state.js +1 -1
  198. package/src/system/pooling.js +7 -17
  199. package/src/text/bitmaptext.js +65 -7
  200. package/src/utils/string.js +1 -1
  201. package/src/utils/utils.js +1 -3
  202. package/src/video/texture/atlas.js +9 -8
  203. package/src/video/texture/cache.js +2 -2
  204. package/src/video/video.js +1 -1
  205. package/src/video/webgl/compositors/compositor.js +227 -0
  206. package/src/video/webgl/compositors/webgl_compositor.js +300 -0
  207. package/src/video/webgl/webgl_renderer.js +1 -1
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @classdesc
3
+ * A WebGL Compositor object. This class handles all of the WebGL state<br>
4
+ * Pushes texture regions or shape geometry into WebGL buffers, automatically flushes to GPU
5
+ * @augments Compositor
6
+ */
7
+ export default class WebGLCompositor extends Compositor {
8
+ currentTextureUnit: any;
9
+ boundTextures: any[] | undefined;
10
+ primitiveShader: GLShader | undefined;
11
+ quadShader: GLShader | undefined;
12
+ vertexBuffer: VertexArrayBuffer | undefined;
13
+ /**
14
+ * Create a WebGL texture from an image
15
+ * @param {number} unit - Destination texture unit
16
+ * @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image - Source image
17
+ * @param {number} filter - gl.LINEAR or gl.NEAREST
18
+ * @param {string} [repeat="no-repeat"] - Image repeat behavior (see {@link ImageLayer#repeat})
19
+ * @param {number} [w] - Source image width (Only use with UInt8Array[] or Float32Array[] source image)
20
+ * @param {number} [h] - Source image height (Only use with UInt8Array[] or Float32Array[] source image)
21
+ * @param {number} [b] - Source image border (Only use with UInt8Array[] or Float32Array[] source image)
22
+ * @param {boolean} [premultipliedAlpha=true] - Multiplies the alpha channel into the other color channels
23
+ * @param {boolean} [mipmap=true] - Whether mipmap levels should be generated for this texture
24
+ * @returns {WebGLTexture} a WebGL texture
25
+ */
26
+ createTexture2D(unit: number, image: (new (width?: number | undefined, height?: number | undefined) => HTMLImageElement) | HTMLCanvasElement | ImageData | Uint8Array[] | Float32Array[], filter: number, repeat?: string | undefined, w?: number | undefined, h?: number | undefined, b?: number | undefined, premultipliedAlpha?: boolean | undefined, mipmap?: boolean | undefined): WebGLTexture;
27
+ /**
28
+ * delete the given WebGL texture
29
+ * @param {WebGLTexture} [texture] - a WebGL texture to delete
30
+ * @param {number} [unit] - Texture unit to delete
31
+ */
32
+ deleteTexture2D(texture?: WebGLTexture | undefined): void;
33
+ /**
34
+ * returns the WebGL texture associated to the given texture unit
35
+ * @param {number} unit - Texture unit to which a texture is bound
36
+ * @returns {WebGLTexture} texture a WebGL texture
37
+ */
38
+ getTexture2D(unit: number): WebGLTexture;
39
+ /**
40
+ * assign the given WebGL texture to the current batch
41
+ * @param {WebGLTexture} texture - a WebGL texture
42
+ * @param {number} unit - Texture unit to which the given texture is bound
43
+ */
44
+ bindTexture2D(texture: WebGLTexture, unit: number): void;
45
+ /**
46
+ * unbind the given WebGL texture, forcing it to be reuploaded
47
+ * @param {WebGLTexture} [texture] - a WebGL texture
48
+ * @param {number} [unit] - a WebGL texture
49
+ * @returns {number} unit the unit number that was associated with the given texture
50
+ */
51
+ unbindTexture2D(texture?: WebGLTexture | undefined, unit?: number | undefined): number;
52
+ /**
53
+ * @ignore
54
+ */
55
+ uploadTexture(texture: any, w: any, h: any, b: any, force?: boolean): any;
56
+ /**
57
+ * Select the shader to use for compositing
58
+ * @see GLShader
59
+ * @param {GLShader} shader - a reference to a GLShader instance
60
+ */
61
+ useShader(shader: GLShader): void;
62
+ /**
63
+ * Add a textured quad
64
+ * @param {TextureAtlas} texture - Source texture atlas
65
+ * @param {number} x - Destination x-coordinate
66
+ * @param {number} y - Destination y-coordinate
67
+ * @param {number} w - Destination width
68
+ * @param {number} h - Destination height
69
+ * @param {number} u0 - Texture UV (u0) value.
70
+ * @param {number} v0 - Texture UV (v0) value.
71
+ * @param {number} u1 - Texture UV (u1) value.
72
+ * @param {number} v1 - Texture UV (v1) value.
73
+ * @param {number} tint - tint color to be applied to the texture in UINT32 (argb) format
74
+ */
75
+ addQuad(texture: TextureAtlas, x: number, y: number, w: number, h: number, u0: number, v0: number, u1: number, v1: number, tint: number): void;
76
+ /**
77
+ * Draw an array of vertices
78
+ * @param {GLenum} mode - primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
79
+ * @param {Point[]} verts - an array of vertices
80
+ * @param {number} [vertexCount=verts.length] - amount of points defined in the points array
81
+ */
82
+ drawVertices(mode: GLenum, verts: Point[], vertexCount?: number | undefined): void;
83
+ }
84
+ import Compositor from "./compositor.js";
85
+ import GLShader from "../glshader.js";
86
+ import VertexArrayBuffer from "../buffer/vertex.js";
@@ -151,10 +151,10 @@ export default class WebGLCompositor {
151
151
  /**
152
152
  * Draw an array of vertices
153
153
  * @param {GLenum} mode - primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
154
- * @param {Vector2d[]} verts - vertices
154
+ * @param {Point[]} verts - an array of vertices
155
155
  * @param {number} [vertexCount=verts.length] - amount of points defined in the points array
156
156
  */
157
- drawVertices(mode: GLenum, verts: Vector2d[], vertexCount?: number | undefined): void;
157
+ drawVertices(mode: GLenum, verts: Point[], vertexCount?: number | undefined): void;
158
158
  /**
159
159
  * Clear the frame buffer
160
160
  * @param {number} [alpha = 0.0] - the alpha value used when clearing the framebuffer
@@ -171,4 +171,3 @@ export default class WebGLCompositor {
171
171
  }
172
172
  import GLShader from "./glshader.js";
173
173
  import VertexArrayBuffer from "./buffer/vertex.js";
174
- import Vector2d from "./../../math/vector2.js";
@@ -423,7 +423,7 @@ export default class WebGLRenderer extends Renderer {
423
423
  }
424
424
  import Renderer from "./../renderer.js";
425
425
  import Matrix2d from "./../../math/matrix2.js";
426
- import WebGLCompositor from "./webgl_compositor.js";
426
+ import WebGLCompositor from "./compositors/webgl_compositor.js";
427
427
  import TextureCache from "./../texture/cache.js";
428
428
  import { TextureAtlas } from "./../texture/atlas.js";
429
429
  import Color from "./../../math/color.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "melonjs",
3
- "version": "14.4.0",
3
+ "version": "14.5.0",
4
4
  "description": "melonJS Game Engine",
5
5
  "homepage": "http://www.melonjs.org/",
6
6
  "type": "module",
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "dependencies": {
55
55
  "@teppeis/multimaps": "^2.0.0",
56
- "core-js": "^3.27.1",
56
+ "core-js": "^3.27.2",
57
57
  "earcut": "2.2.4",
58
58
  "eventemitter3": "^5.0.0",
59
59
  "howler": "2.2.3"
@@ -61,36 +61,37 @@
61
61
  "devDependencies": {
62
62
  "@babel/eslint-parser": "^7.19.1",
63
63
  "@babel/plugin-syntax-import-assertions": "^7.20.0",
64
- "@fastify/static": "^6.6.0",
64
+ "@fastify/static": "^6.9.0",
65
65
  "@melonjs/webdoc-theme": "^1.1.1",
66
- "@rollup/plugin-commonjs": "^24.0.0",
67
- "@rollup/plugin-image": "^3.0.1",
66
+ "@rollup/plugin-commonjs": "^24.0.1",
67
+ "@rollup/plugin-image": "^3.0.2",
68
68
  "@rollup/plugin-node-resolve": "^15.0.1",
69
69
  "@rollup/plugin-replace": "^5.0.2",
70
70
  "@types/offscreencanvas": "^2019.7.0",
71
71
  "@webdoc/cli": "^2.2.0",
72
- "chromedriver": "^108.0.0",
72
+ "chromedriver": "^110.0.0",
73
73
  "cross-env": "^7.0.3",
74
74
  "del-cli": "^5.0.0",
75
- "eslint": "^8.31.0",
76
- "eslint-plugin-jsdoc": "^39.6.4",
77
- "expect": "^29.3.1",
75
+ "eslint": "^8.34.0",
76
+ "eslint-plugin-jsdoc": "^40.0.0",
77
+ "expect": "^29.4.2",
78
78
  "expect-mocha-image-snapshot": "^3.0.1",
79
- "fastify": "^4.11.0",
79
+ "fastify": "^4.13.0",
80
80
  "mocha": "^10.2.0",
81
81
  "npm-self-link": "^1.1.7",
82
- "puppeteer": "^19.5.0",
83
- "rollup": "^3.9.1",
82
+ "puppeteer": "^19.6.3",
83
+ "rollup": "^3.15.0",
84
84
  "rollup-plugin-bundle-size": "^1.0.3",
85
85
  "rollup-plugin-string": "^3.0.0",
86
- "terser": "^5.16.1",
87
- "typescript": "^4.9.4"
86
+ "terser": "^5.16.3",
87
+ "typescript": "^4.9.5"
88
88
  },
89
89
  "scripts": {
90
90
  "build": "npm run lint && rollup -c --silent",
91
+ "build:cd": "npm run lint && rollup -c --failAfterWarnings",
91
92
  "dist": " npm run build && mkdirp dist && cp -fR build/*.* dist/ && npm run types",
92
93
  "lint": "eslint src/** rollup.config.mjs",
93
- "pretest": "cp -f ./build/melonjs.module.js ./tests/browser/public/lib",
94
+ "pretest": "mkdirp tests/browser/public/lib && cp -f build/melonjs.module.js tests/browser/public/lib",
94
95
  "test": "npm run test-node && mocha ./tests/browser/spec/*.js --reporter spec --bail --timeout 10000",
95
96
  "test-node": "node build/melonjs.module.js",
96
97
  "doc-prod": "mkdirp docs && webdoc --quiet --site-root melonJS/docs -R README.md",
@@ -1,7 +1,7 @@
1
1
  // external import
2
2
  import {Howl, Howler} from "howler";
3
3
  import {clamp} from "./../math/math.js";
4
- import loader from "./../loader/loader.js";
4
+ import { nocache, withCredentials} from "./../loader/settings.js";
5
5
  import { isDataUrl } from "./../utils/string.js";
6
6
 
7
7
  /**
@@ -154,7 +154,7 @@ export function load(sound, html5, onload_cb, onerror_cb) {
154
154
  urls.push(sound.src);
155
155
  } else {
156
156
  for (var i = 0; i < audioExts.length; i++) {
157
- urls.push(sound.src + sound.name + "." + audioExts[i] + loader.nocache);
157
+ urls.push(sound.src + sound.name + "." + audioExts[i] + nocache);
158
158
  }
159
159
  }
160
160
 
@@ -162,7 +162,7 @@ export function load(sound, html5, onload_cb, onerror_cb) {
162
162
  src : urls,
163
163
  volume : Howler.volume(),
164
164
  html5 : html5 === true,
165
- xhrWithCredentials : loader.withCredentials,
165
+ xhrWithCredentials : withCredentials,
166
166
  /**
167
167
  * @ignore
168
168
  */
@@ -53,10 +53,10 @@ import Body from "./../physics/body.js";
53
53
 
54
54
  // Update anchorPoint
55
55
  if (settings.anchorPoint) {
56
- this.anchorPoint.set(settings.anchorPoint.x, settings.anchorPoint.y);
56
+ this.anchorPoint.setMuted(settings.anchorPoint.x, settings.anchorPoint.y);
57
57
  } else {
58
58
  // for backward compatibility
59
- this.anchorPoint.set(0, 0);
59
+ this.anchorPoint.setMuted(0, 0);
60
60
  }
61
61
 
62
62
  // set the sprite name if specified
@@ -140,6 +140,7 @@ import Body from "./../physics/body.js";
140
140
  if (value instanceof Renderable) {
141
141
  this.children[0] = value;
142
142
  this.children[0].ancestor = this;
143
+ this.updateBounds();
143
144
  } else {
144
145
  throw new Error(value + "should extend me.Renderable");
145
146
  }
@@ -154,17 +155,50 @@ import Body from "./../physics/body.js";
154
155
  }
155
156
 
156
157
  /**
157
- * update the bounds position when the body is modified
158
+ * update the bounding box for this entity.
159
+ * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
160
+ * @returns {Bounds} this entity bounding box Rectangle object
161
+ */
162
+ updateBounds(absolute = true) {
163
+ var bounds = this.getBounds();
164
+
165
+ bounds.clear();
166
+ bounds.addFrame(
167
+ 0,
168
+ 0,
169
+ this.width,
170
+ this.height
171
+ );
172
+
173
+ // add each renderable bounds
174
+ if (this.children && this.children.length > 0) {
175
+ bounds.addBounds(this.children[0].getBounds());
176
+ }
177
+
178
+ if (this.body) {
179
+ bounds.addBounds(this.body.getBounds());
180
+ }
181
+
182
+ if (absolute === true) {
183
+ bounds.centerOn(this.pos.x + bounds.x + bounds.width / 2, this.pos.y + bounds.y + bounds.height / 2);
184
+ if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
185
+ bounds.translate(this.ancestor.getAbsolutePosition());
186
+ }
187
+
188
+ }
189
+
190
+ return bounds;
191
+ }
192
+
193
+ /**
194
+ * update the bounds when the body is modified
158
195
  * @ignore
159
196
  * @name onBodyUpdate
160
197
  * @memberof Entity
161
198
  * @param {Body} body - the body whose bounds to update
162
199
  */
163
- onBodyUpdate(body) {
164
- // update the entity bounds to include the body bounds
165
- this.getBounds().addBounds(body.getBounds(), true);
166
- // update the bounds pos
167
- this.updateBoundsPos(this.pos.x, this.pos.y);
200
+ onBodyUpdate() {
201
+ this.updateBounds();
168
202
  }
169
203
 
170
204
  preDraw(renderer) {
@@ -126,8 +126,7 @@ import pool from "./../system/pooling.js";
126
126
  * @param {number} [y=x]
127
127
  * @returns {Ellipse} Reference to this object for method chaining
128
128
  */
129
- scale(x, y) {
130
- y = typeof (y) !== "undefined" ? y : x;
129
+ scale(x, y = x) {
131
130
  return this.setShape(
132
131
  this.pos.x,
133
132
  this.pos.y,
@@ -10,20 +10,14 @@ import earcut from "earcut";
10
10
  constructor() {
11
11
  /**
12
12
  * the points defining the current path
13
- * @public
14
- * @type {Vector2d[]}
15
- * @name points
16
- * @memberof Path2D#
13
+ * @type {Point[]}
17
14
  */
18
15
  this.points = [];
19
16
 
20
17
  /**
21
18
  * space between interpolated points for quadratic and bezier curve approx. in pixels.
22
- * @public
23
19
  * @type {number}
24
- * @name arcResolution
25
20
  * @default 5
26
- * @memberof Path2D#
27
21
  */
28
22
  this.arcResolution = 5;
29
23
 
@@ -33,8 +27,6 @@ import earcut from "earcut";
33
27
 
34
28
  /**
35
29
  * begin a new path
36
- * @name beginPath
37
- * @memberof Path2D
38
30
  */
39
31
  beginPath() {
40
32
  // empty the cache and recycle all vectors
@@ -48,21 +40,17 @@ import earcut from "earcut";
48
40
  * causes the point of the pen to move back to the start of the current path.
49
41
  * It tries to draw a straight line from the current point to the start.
50
42
  * If the shape has already been closed or has only one point, this function does nothing.
51
- * @name closePath
52
- * @memberof Path2D
53
43
  */
54
44
  closePath() {
55
45
  var points = this.points;
56
46
  if (points.length > 1 && !points[points.length-1].equals(points[0])) {
57
- points.push(pool.pull("Vector2d", points[0].x, points[0].y));
47
+ points.push(pool.pull("Point", points[0].x, points[0].y));
58
48
  }
59
49
  }
60
50
 
61
51
  /**
62
52
  * triangulate the shape defined by this path into an array of triangles
63
- * @name triangulatePath
64
- * @memberof Path2D
65
- * @returns {Vector2d[]}
53
+ * @returns {Point[]}
66
54
  */
67
55
  triangulatePath() {
68
56
  var i = 0;
@@ -70,13 +58,15 @@ import earcut from "earcut";
70
58
  var vertices = this.vertices;
71
59
  var indices = earcut(points.flatMap(p => [p.x, p.y]));
72
60
 
61
+ // pre-allocate vertices if necessary
62
+ while (vertices.length < indices.length) {
63
+ vertices.push(pool.pull("Point"));
64
+ }
65
+
73
66
  // calculate all vertices
74
67
  for (i = 0; i < indices.length; i++ ) {
75
- if (typeof vertices[i] === "undefined") {
76
- // increase cache buffer if necessary
77
- vertices[i] = pool.pull("Vector2d");
78
- }
79
- vertices[i].set(points[indices[i]].x, points[indices[i]].y);
68
+ var point = points[indices[i]];
69
+ vertices[i].set(point.x, point.y);
80
70
  }
81
71
 
82
72
  // recycle overhead from a previous triangulation
@@ -90,31 +80,25 @@ import earcut from "earcut";
90
80
 
91
81
  /**
92
82
  * moves the starting point of the current path to the (x, y) coordinates.
93
- * @name moveTo
94
- * @memberof Path2D
95
83
  * @param {number} x - the x-axis (horizontal) coordinate of the point.
96
84
  * @param {number} y - the y-axis (vertical) coordinate of the point.
97
85
  */
98
86
  moveTo(x, y) {
99
- this.points.push(pool.pull("Vector2d", x, y));
87
+ this.points.push(pool.pull("Point", x, y));
100
88
  }
101
89
 
102
90
  /**
103
91
  * connects the last point in the current patch to the (x, y) coordinates with a straight line.
104
- * @name lineTo
105
- * @memberof Path2D
106
92
  * @param {number} x - the x-axis coordinate of the line's end point.
107
93
  * @param {number} y - the y-axis coordinate of the line's end point.
108
94
  */
109
95
  lineTo(x, y) {
110
- this.points.push(pool.pull("Vector2d", x, y));
96
+ this.points.push(pool.pull("Point", x, y));
111
97
  }
112
98
 
113
99
  /**
114
100
  * adds an arc to the current path which is centered at (x, y) position with the given radius,
115
101
  * starting at startAngle and ending at endAngle going in the given direction by counterclockwise (defaulting to clockwise).
116
- * @name arc
117
- * @memberof Path2D
118
102
  * @param {number} x - the horizontal coordinate of the arc's center.
119
103
  * @param {number} y - the vertical coordinate of the arc's center.
120
104
  * @param {number} radius - the arc's radius. Must be positive.
@@ -154,16 +138,14 @@ import earcut from "earcut";
154
138
 
155
139
  var angle = startAngle;
156
140
  for (var j = 0; j < nr_of_interpolation_points; j++) {
157
- points.push(pool.pull("Vector2d", x + radius * Math.cos(angle), y + radius * Math.sin(angle)));
141
+ points.push(pool.pull("Point", x + radius * Math.cos(angle), y + radius * Math.sin(angle)));
158
142
  angle += direction * dangle;
159
143
  }
160
- points.push(pool.pull("Vector2d", x + radius * Math.cos(endAngle), y + radius * Math.sin(endAngle)));
144
+ points.push(pool.pull("Point", x + radius * Math.cos(endAngle), y + radius * Math.sin(endAngle)));
161
145
  }
162
146
 
163
147
  /**
164
148
  * adds a circular arc to the path with the given control points and radius, connected to the previous point by a straight line.
165
- * @name arcTo
166
- * @memberof Path2D
167
149
  * @param {number} x1 - the x-axis coordinate of the first control point.
168
150
  * @param {number} y1 - the y-axis coordinate of the first control point.
169
151
  * @param {number} x2 - the x-axis coordinate of the second control point.
@@ -192,7 +174,7 @@ import earcut from "earcut";
192
174
  var tangent_point1 = [x1 + a[0] * adj_l, y1 + a[1] * adj_l];
193
175
  var tangent_point2 = [x1 + b[0] * adj_l, y1 + b[1] * adj_l];
194
176
 
195
- points.push(pool.pull("Vector2d", tangent_point1[0], tangent_point1[1]));
177
+ points.push(pool.pull("Point", tangent_point1[0], tangent_point1[1]));
196
178
 
197
179
  var bisec = [(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0];
198
180
  var bisec_l = Math.sqrt(Math.pow(bisec[0], 2) + Math.pow(bisec[1], 2));
@@ -210,8 +192,6 @@ import earcut from "earcut";
210
192
  /**
211
193
  * adds an elliptical arc to the path which is centered at (x, y) position with the radii radiusX and radiusY
212
194
  * starting at startAngle and ending at endAngle going in the given direction by counterclockwise.
213
- * @name ellipse
214
- * @memberof Path2D
215
195
  * @param {number} x - the x-axis (horizontal) coordinate of the ellipse's center.
216
196
  * @param {number} y - the y-axis (vertical) coordinate of the ellipse's center.
217
197
  * @param {number} radiusX - the ellipse's major-axis radius. Must be non-negative.
@@ -259,18 +239,16 @@ import earcut from "earcut";
259
239
  var _y1 = radiusY * Math.sin(angle);
260
240
  var _x2 = x + _x1 * cos_rotation - _y1 * sin_rotation;
261
241
  var _y2 = y + _x1 * sin_rotation + _y1 * cos_rotation;
262
- points.push(pool.pull("Vector2d", _x2, _y2));
242
+ points.push(pool.pull("Point", _x2, _y2));
263
243
  angle += direction * dangle;
264
244
  }
265
245
  //var x1 = radiusX * Math.cos(endAngle);
266
246
  //var y1 = radiusY * Math.sin(endAngle);
267
- //points.push(pool.pull("Vector2d", x + x1 * cos_rotation - y1 * sin_rotation, y + x1 * sin_rotation + y1 * cos_rotation));
247
+ //points.push(pool.pull("Point", x + x1 * cos_rotation - y1 * sin_rotation, y + x1 * sin_rotation + y1 * cos_rotation));
268
248
  }
269
249
 
270
250
  /**
271
251
  * creates a path for a rectangle at position (x, y) with a size that is determined by width and height.
272
- * @name rect
273
- * @memberof Path2D
274
252
  * @param {number} x - the x-axis coordinate of the rectangle's starting point.
275
253
  * @param {number} y - the y-axis coordinate of the rectangle's starting point.
276
254
  * @param {number} width - the rectangle's width. Positive values are to the right, and negative to the left.
@@ -286,8 +264,6 @@ import earcut from "earcut";
286
264
 
287
265
  /**
288
266
  * adds an rounded rectangle to the current path.
289
- * @name roundRect
290
- * @memberof Path2D
291
267
  * @param {number} x - the x-axis coordinate of the rectangle's starting point.
292
268
  * @param {number} y - the y-axis coordinate of the rectangle's starting point.
293
269
  * @param {number} width - the rectangle's width. Positive values are to the right, and negative to the left.
@@ -6,7 +6,6 @@
6
6
  constructor(x = 0, y = 0) {
7
7
  /**
8
8
  * the position of the point on the horizontal axis
9
- * @public
10
9
  * @type {Number}
11
10
  * @default 0
12
11
  */
@@ -14,7 +13,6 @@
14
13
 
15
14
  /**
16
15
  * the position of the point on the vertical axis
17
- * @public
18
16
  * @type {Number}
19
17
  * @default 0
20
18
  */
@@ -48,8 +46,6 @@
48
46
  */
49
47
  /**
50
48
  * return true if this point is equal to the given values
51
- * @name equals
52
- * @memberof Point
53
49
  * @param {number} x
54
50
  * @param {number} y
55
51
  * @returns {boolean}
@@ -70,7 +66,6 @@
70
66
 
71
67
  /**
72
68
  * clone this Point
73
- * @name clone
74
69
  * @returns {Point} new Point
75
70
  */
76
71
  clone() {
@@ -200,9 +200,7 @@ import pool from "./../system/pooling.js";
200
200
  * @param {number} [y=x]
201
201
  * @returns {Polygon} Reference to this object for method chaining
202
202
  */
203
- scale(x, y) {
204
- y = typeof (y) !== "undefined" ? y : x;
205
-
203
+ scale(x, y = x) {
206
204
  var points = this.points;
207
205
  var len = points.length;
208
206
  for (var i = 0; i < len; i++) {
@@ -458,7 +456,6 @@ import pool from "./../system/pooling.js";
458
456
 
459
457
  /**
460
458
  * update the bounding box for this shape.
461
- * @ignore
462
459
  * @name updateBounds
463
460
  * @memberof Polygon
464
461
  * @returns {Bounds} this shape bounding box Rectangle object
@@ -77,7 +77,7 @@ import Polygon from "./poly.js";
77
77
  */
78
78
  get right() {
79
79
  var w = this.width;
80
- return (this.pos.x + w) || w;
80
+ return (this.left + w) || w;
81
81
  }
82
82
 
83
83
  /**
@@ -100,7 +100,7 @@ import Polygon from "./poly.js";
100
100
  */
101
101
  get bottom() {
102
102
  var h = this.height;
103
- return (this.pos.y + h) || h;
103
+ return (this.top + h) || h;
104
104
  }
105
105
 
106
106
  /**
@@ -144,13 +144,15 @@ import Polygon from "./poly.js";
144
144
  */
145
145
  get centerX() {
146
146
  if (isFinite(this.width)) {
147
- return this.pos.x + (this.width / 2);
147
+ return this.left + (this.width / 2);
148
148
  } else {
149
149
  return this.width;
150
150
  }
151
151
  }
152
152
  set centerX (value) {
153
153
  this.pos.x = value - (this.width / 2);
154
+ this.recalc();
155
+ this.updateBounds();
154
156
  }
155
157
 
156
158
  /**
@@ -162,13 +164,15 @@ import Polygon from "./poly.js";
162
164
  */
163
165
  get centerY() {
164
166
  if (isFinite(this.height)) {
165
- return this.pos.y + (this.height / 2);
167
+ return this.top + (this.height / 2);
166
168
  } else {
167
169
  return this.height;
168
170
  }
169
171
  }
170
172
  set centerY(value) {
171
173
  this.pos.y = value - (this.height / 2);
174
+ this.recalc();
175
+ this.updateBounds();
172
176
  }
173
177
 
174
178
  /**
@@ -220,7 +224,7 @@ import Polygon from "./poly.js";
220
224
  * @returns {Rect} new rectangle
221
225
  */
222
226
  clone() {
223
- return new Rect(this.pos.x, this.pos.y, this.width, this.height);
227
+ return new Rect(this.left, this.top, this.width, this.height);
224
228
  }
225
229
 
226
230
  /**
@@ -231,7 +235,7 @@ import Polygon from "./poly.js";
231
235
  * @returns {Rect} new rectangle
232
236
  */
233
237
  copy(rect) {
234
- return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
238
+ return this.setShape(rect.left, rect.top, rect.width, rect.height);
235
239
  }
236
240
 
237
241
  /**
@@ -348,7 +352,7 @@ import Polygon from "./poly.js";
348
352
  * @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
349
353
  */
350
354
  isFinite() {
351
- return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this.width) && isFinite(this.height));
355
+ return (isFinite(this.left) && isFinite(this.top) && isFinite(this.width) && isFinite(this.height));
352
356
  }
353
357
 
354
358
  /**
@@ -359,7 +363,7 @@ import Polygon from "./poly.js";
359
363
  */
360
364
  toPolygon() {
361
365
  return pool.pull("Polygon",
362
- this.pos.x, this.pos.y, this.points
366
+ this.left, this.top, this.points
363
367
  );
364
368
  }
365
369
  }
package/src/index.js CHANGED
@@ -20,7 +20,7 @@ import Body from "./physics/body.js";
20
20
  import Bounds from "./physics/bounds.js";
21
21
  import Tween from "./tweens/tween.js";
22
22
  import GLShader from "./video/webgl/glshader.js";
23
- import WebGLCompositor from "./video/webgl/webgl_compositor.js";
23
+ import WebGLCompositor from "./video/webgl/compositors/webgl_compositor.js";
24
24
  import Renderer from "./video/renderer.js";
25
25
  import WebGLRenderer from "./video/webgl/webgl_renderer.js";
26
26
  import CanvasRenderer from "./video/canvas/canvas_renderer.js";
@@ -67,7 +67,7 @@ import * as audio from "./audio/audio.js";
67
67
  import collision from "./physics/collision.js";
68
68
  import * as event from "./system/event.js";
69
69
  import * as device from "./system/device.js";
70
- import loader from "./loader/loader.js";
70
+ import * as loader from "./loader/loader.js";
71
71
  import * as Math from "./math/math.js";
72
72
  import utils from "./utils/utils.js";
73
73
  import * as input from "./input/input.js";
@@ -55,23 +55,17 @@ var leadingZeroRE = /^0+/;
55
55
  * @ignore
56
56
  */
57
57
  function addMapping(id, mapping) {
58
- var expanded_id = id.replace(vendorProductRE, (_, a, b) => {
59
- return (
60
- "000".slice(a.length - 1) + a + "-" +
61
- "000".slice(b.length - 1) + b + "-"
62
- );
63
- });
64
- var sparse_id = id.replace(vendorProductRE, (_, a, b) => {
65
- return (
66
- a.replace(leadingZeroRE, "") + "-" +
67
- b.replace(leadingZeroRE, "") + "-"
68
- );
69
- });
58
+ var expanded_id = id.replace(vendorProductRE, (_, a, b) =>
59
+ "000".slice(a.length - 1) + a + "-" +
60
+ "000".slice(b.length - 1) + b + "-"
61
+ );
62
+ var sparse_id = id.replace(vendorProductRE, (_, a, b) =>
63
+ a.replace(leadingZeroRE, "") + "-" +
64
+ b.replace(leadingZeroRE, "") + "-"
65
+ );
70
66
 
71
67
  // Normalize optional parameters
72
- mapping.analog = mapping.analog || mapping.buttons.map(() => {
73
- return -1;
74
- });
68
+ mapping.analog = mapping.analog || mapping.buttons.map(() => -1);
75
69
  mapping.normalize_fn = mapping.normalize_fn || function (value) { return value; };
76
70
 
77
71
  remap.set(expanded_id, mapping);