melonjs 14.4.0 → 15.0.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 (245) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +13 -57
  3. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  8. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  10. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  11. package/dist/melonjs.mjs/application/application.js +1 -1
  12. package/dist/melonjs.mjs/application/header.js +1 -1
  13. package/dist/melonjs.mjs/application/resize.js +1 -1
  14. package/dist/melonjs.mjs/application/settings.js +1 -1
  15. package/dist/melonjs.mjs/audio/audio.js +5 -7
  16. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  17. package/dist/melonjs.mjs/const.js +1 -1
  18. package/dist/melonjs.mjs/entity/entity.js +43 -9
  19. package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
  20. package/dist/melonjs.mjs/geometries/line.js +1 -1
  21. package/dist/melonjs.mjs/geometries/path2d.js +20 -44
  22. package/dist/melonjs.mjs/geometries/point.js +1 -6
  23. package/dist/melonjs.mjs/geometries/poly.js +2 -5
  24. package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
  25. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  26. package/dist/melonjs.mjs/index.js +10 -6
  27. package/dist/melonjs.mjs/input/gamepad.js +10 -16
  28. package/dist/melonjs.mjs/input/input.js +1 -1
  29. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  30. package/dist/melonjs.mjs/input/pointer.js +1 -1
  31. package/dist/melonjs.mjs/input/pointerevent.js +3 -17
  32. package/dist/melonjs.mjs/lang/console.js +1 -1
  33. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  34. package/dist/melonjs.mjs/level/level.js +3 -3
  35. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  36. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
  37. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  38. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  39. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
  40. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
  41. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  48. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  49. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  50. package/dist/melonjs.mjs/loader/cache.js +24 -0
  51. package/dist/melonjs.mjs/loader/loader.js +331 -716
  52. package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
  53. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  54. package/dist/melonjs.mjs/loader/parser.js +281 -0
  55. package/dist/melonjs.mjs/loader/settings.js +91 -0
  56. package/dist/melonjs.mjs/math/color.js +9 -8
  57. package/dist/melonjs.mjs/math/math.js +1 -1
  58. package/dist/melonjs.mjs/math/matrix2.js +7 -9
  59. package/dist/melonjs.mjs/math/matrix3.js +18 -21
  60. package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
  61. package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
  62. package/dist/melonjs.mjs/math/vector2.js +3 -3
  63. package/dist/melonjs.mjs/math/vector3.js +3 -4
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  71. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  72. package/dist/melonjs.mjs/particles/emitter.js +3 -3
  73. package/dist/melonjs.mjs/particles/particle.js +1 -1
  74. package/dist/melonjs.mjs/particles/settings.js +1 -1
  75. package/dist/melonjs.mjs/physics/body.js +18 -14
  76. package/dist/melonjs.mjs/physics/bounds.js +18 -70
  77. package/dist/melonjs.mjs/physics/collision.js +1 -1
  78. package/dist/melonjs.mjs/physics/detector.js +1 -1
  79. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  80. package/dist/melonjs.mjs/physics/response.js +1 -1
  81. package/dist/melonjs.mjs/physics/sat.js +1 -1
  82. package/dist/melonjs.mjs/physics/world.js +1 -1
  83. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  84. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  85. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  86. package/dist/melonjs.mjs/renderable/container.js +25 -19
  87. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  88. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
  89. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  90. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  91. package/dist/melonjs.mjs/renderable/renderable.js +148 -105
  92. package/dist/melonjs.mjs/renderable/sprite.js +33 -54
  93. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  94. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  95. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  96. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -3
  97. package/dist/melonjs.mjs/state/stage.js +1 -1
  98. package/dist/melonjs.mjs/state/state.js +2 -2
  99. package/dist/melonjs.mjs/system/device.js +2 -2
  100. package/dist/melonjs.mjs/system/dom.js +1 -1
  101. package/dist/melonjs.mjs/system/event.js +1 -1
  102. package/dist/melonjs.mjs/system/platform.js +1 -1
  103. package/dist/melonjs.mjs/system/pooling.js +8 -18
  104. package/dist/melonjs.mjs/system/save.js +1 -1
  105. package/dist/melonjs.mjs/system/timer.js +1 -1
  106. package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
  107. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  108. package/dist/melonjs.mjs/text/glyph.js +1 -1
  109. package/dist/melonjs.mjs/text/text.js +56 -86
  110. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  111. package/dist/melonjs.mjs/text/textstyle.js +4 -6
  112. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  113. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  114. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  115. package/dist/melonjs.mjs/utils/agent.js +1 -1
  116. package/dist/melonjs.mjs/utils/array.js +1 -1
  117. package/dist/melonjs.mjs/utils/file.js +1 -1
  118. package/dist/melonjs.mjs/utils/function.js +1 -1
  119. package/dist/melonjs.mjs/utils/string.js +2 -2
  120. package/dist/melonjs.mjs/utils/utils.js +2 -4
  121. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +7 -11
  122. package/dist/melonjs.mjs/video/renderer.js +2 -13
  123. package/dist/melonjs.mjs/video/texture/atlas.js +12 -17
  124. package/dist/melonjs.mjs/video/texture/cache.js +3 -3
  125. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  126. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  127. package/dist/melonjs.mjs/video/video.js +2 -2
  128. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
  129. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
  130. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
  131. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +249 -0
  132. package/dist/melonjs.mjs/video/webgl/{webgl_compositor.js → compositors/webgl_compositor.js} +20 -205
  133. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
  136. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
  138. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  141. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  143. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +139 -149
  144. package/dist/melonjs.module.js +26320 -26376
  145. package/dist/types/entity/entity.d.ts +3 -3
  146. package/dist/types/geometries/path2d.d.ts +5 -31
  147. package/dist/types/geometries/point.d.ts +2 -7
  148. package/dist/types/geometries/poly.d.ts +0 -1
  149. package/dist/types/index.d.ts +5 -3
  150. package/dist/types/loader/cache.d.ts +7 -0
  151. package/dist/types/loader/loader.d.ts +166 -181
  152. package/dist/types/loader/parser.d.ts +41 -0
  153. package/dist/types/loader/settings.d.ts +57 -0
  154. package/dist/types/particles/emitter.d.ts +4 -4
  155. package/dist/types/physics/bounds.d.ts +29 -84
  156. package/dist/types/renderable/container.d.ts +0 -11
  157. package/dist/types/renderable/renderable.d.ts +43 -31
  158. package/dist/types/renderable/sprite.d.ts +3 -3
  159. package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
  160. package/dist/types/state/state.d.ts +1 -1
  161. package/dist/types/system/pooling.d.ts +2 -2
  162. package/dist/types/text/text.d.ts +6 -20
  163. package/dist/types/text/textstyle.d.ts +1 -1
  164. package/dist/types/video/canvas/canvas_renderer.d.ts +0 -5
  165. package/dist/types/video/renderer.d.ts +1 -5
  166. package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
  167. package/dist/types/video/webgl/compositors/compositor.d.ts +107 -0
  168. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
  169. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
  170. package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
  171. package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
  172. package/dist/types/video/webgl/webgl_renderer.d.ts +34 -28
  173. package/package.json +18 -18
  174. package/src/audio/audio.js +4 -6
  175. package/src/entity/entity.js +42 -8
  176. package/src/geometries/ellipse.js +1 -2
  177. package/src/geometries/path2d.js +19 -43
  178. package/src/geometries/point.js +0 -5
  179. package/src/geometries/poly.js +1 -4
  180. package/src/geometries/rectangle.js +12 -8
  181. package/src/index.js +7 -3
  182. package/src/input/gamepad.js +9 -15
  183. package/src/input/pointerevent.js +1 -15
  184. package/src/level/level.js +2 -2
  185. package/src/level/tiled/TMXLayer.js +0 -7
  186. package/src/level/tiled/TMXTileMap.js +7 -3
  187. package/src/level/tiled/TMXTileset.js +4 -4
  188. package/src/loader/cache.js +16 -0
  189. package/src/loader/loader.js +339 -711
  190. package/src/loader/loadingscreen.js +3 -3
  191. package/src/loader/parser.js +279 -0
  192. package/src/loader/settings.js +85 -0
  193. package/src/math/color.js +8 -7
  194. package/src/math/matrix2.js +6 -8
  195. package/src/math/matrix3.js +17 -20
  196. package/src/math/observable_vector2.js +2 -2
  197. package/src/math/observable_vector3.js +2 -3
  198. package/src/math/vector2.js +2 -2
  199. package/src/math/vector3.js +2 -3
  200. package/src/particles/emitter.js +2 -2
  201. package/src/physics/body.js +17 -13
  202. package/src/physics/bounds.js +17 -69
  203. package/src/polyfill/index.js +0 -2
  204. package/src/renderable/container.js +24 -18
  205. package/src/renderable/imagelayer.js +6 -0
  206. package/src/renderable/renderable.js +147 -104
  207. package/src/renderable/sprite.js +32 -53
  208. package/src/renderable/ui/uitextbutton.js +0 -2
  209. package/src/state/state.js +1 -1
  210. package/src/system/device.js +1 -1
  211. package/src/system/pooling.js +7 -17
  212. package/src/text/bitmaptext.js +65 -7
  213. package/src/text/text.js +55 -85
  214. package/src/text/textstyle.js +3 -5
  215. package/src/utils/string.js +1 -1
  216. package/src/utils/utils.js +1 -3
  217. package/src/video/canvas/canvas_renderer.js +5 -9
  218. package/src/video/renderer.js +0 -11
  219. package/src/video/texture/atlas.js +11 -16
  220. package/src/video/texture/cache.js +2 -2
  221. package/src/video/video.js +1 -1
  222. package/src/video/webgl/buffer/vertex.js +20 -16
  223. package/src/video/webgl/compositors/compositor.js +226 -0
  224. package/src/video/webgl/compositors/primitive_compositor.js +68 -0
  225. package/src/video/webgl/compositors/quad_compositor.js +240 -0
  226. package/src/video/webgl/shaders/primitive.vert +2 -5
  227. package/src/video/webgl/shaders/quad.vert +3 -1
  228. package/src/video/webgl/webgl_renderer.js +137 -147
  229. package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
  230. package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
  231. package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
  232. package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
  233. package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
  234. package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
  235. package/dist/melonjs.mjs/_virtual/shared.js +0 -10
  236. package/dist/melonjs.mjs/game.js +0 -29
  237. package/dist/melonjs.mjs/polyfill/console.js +0 -18
  238. package/dist/melonjs.mjs/polyfill/performance.js +0 -27
  239. package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
  240. package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
  241. package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
  242. package/dist/melonjs.mjs/video/utils/resize.js +0 -116
  243. package/src/polyfill/performance.js +0 -20
  244. package/src/polyfill/requestAnimationFrame.js +0 -39
  245. package/src/video/webgl/webgl_compositor.js +0 -486
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -12,7 +12,7 @@ import Ellipse from '../../geometries/ellipse.js';
12
12
  import RoundRect from '../../geometries/roundrect.js';
13
13
  import Rect from '../../geometries/rectangle.js';
14
14
  import Bounds from '../../physics/bounds.js';
15
- import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js';
15
+ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../system/event.js';
16
16
 
17
17
  /**
18
18
  * @classdesc
@@ -66,6 +66,11 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
66
66
  this.isContextValid = true;
67
67
  emit(ONCONTEXT_RESTORED, this);
68
68
  }, false );
69
+
70
+ // reset the renderer on game reset
71
+ on(GAME_RESET, () => {
72
+ this.reset();
73
+ });
69
74
  }
70
75
 
71
76
  /**
@@ -541,15 +546,6 @@ import { emit, ONCONTEXT_LOST, ONCONTEXT_RESTORED } from '../../system/event.js'
541
546
  this.strokePoint(x, y);
542
547
  }
543
548
 
544
- /**
545
- * return a reference to the font 2d Context
546
- * @ignore
547
- */
548
- getFontContext() {
549
- // in canvas mode we can directly use the 2d context
550
- return this.getContext();
551
- }
552
-
553
549
  /**
554
550
  * save the canvas context
555
551
  * @name save
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -8,7 +8,7 @@
8
8
  import Color from '../math/color.js';
9
9
  import Matrix3d from '../math/matrix3.js';
10
10
  import { createCanvas } from './video.js';
11
- import { on, emit, GAME_RESET, CANVAS_ONRESIZE } from '../system/event.js';
11
+ import { emit, CANVAS_ONRESIZE } from '../system/event.js';
12
12
  import { platform } from '../system/device.js';
13
13
  import { setPrefixed } from '../utils/agent.js';
14
14
  import Rect from '../geometries/rectangle.js';
@@ -122,11 +122,6 @@ import Point from '../geometries/point.js';
122
122
 
123
123
  // default uvOffset
124
124
  this.uvOffset = 0;
125
-
126
- // reset the renderer on game reset
127
- on(GAME_RESET, () => {
128
- this.reset();
129
- });
130
125
  }
131
126
 
132
127
  /**
@@ -419,12 +414,6 @@ import Point from '../geometries/point.js';
419
414
  // reset to default
420
415
  this.currentTint.setColor(255, 255, 255, 1.0);
421
416
  }
422
-
423
- /**
424
- * @ignore
425
- */
426
- drawFont(/*bounds*/) {}
427
-
428
417
  }
429
418
 
430
419
  export { Renderer as default };
@@ -1,17 +1,15 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
6
6
  * @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
7
7
  */
8
8
  import Vector2d from '../../math/vector2.js';
9
- import WebGLRenderer from '../webgl/webgl_renderer.js';
10
- import TextureCache from './cache.js';
11
9
  import Sprite from '../../renderable/sprite.js';
12
10
  import { renderer } from '../video.js';
13
11
  import pool from '../../system/pooling.js';
14
- import loader from '../../loader/loader.js';
12
+ import { getImage } from '../../loader/loader.js';
15
13
  import { ETA } from '../../math/math.js';
16
14
 
17
15
  /**
@@ -105,7 +103,7 @@ class TextureAtlas {
105
103
  // set the texture
106
104
  if (typeof(src) === "undefined") {
107
105
  // get the texture name from the atlas meta data
108
- var image = loader.getImage(atlas.meta.image);
106
+ var image = getImage(atlas.meta.image);
109
107
  if (!image) {
110
108
  throw new Error(
111
109
  "Atlas texture '" + image + "' not found"
@@ -113,7 +111,7 @@ class TextureAtlas {
113
111
  }
114
112
  this.sources.set(atlas.meta.image, image);
115
113
  } else {
116
- this.sources.set(atlas.meta.image || "default", typeof src === "string" ? loader.getImage(src) : src);
114
+ this.sources.set(atlas.meta.image || "default", typeof src === "string" ? getImage(src) : src);
117
115
  }
118
116
  this.repeat = "no-repeat";
119
117
  }
@@ -127,13 +125,13 @@ class TextureAtlas {
127
125
  }
128
126
  this.format = "ShoeBox";
129
127
  this.repeat = "no-repeat";
130
- this.sources.set("default", typeof src === "string" ? loader.getImage(src) : src);
128
+ this.sources.set("default", typeof src === "string" ? getImage(src) : src);
131
129
  }
132
130
  // Internal texture atlas
133
131
  else if (atlas.meta.app.includes("melonJS")) {
134
132
  this.format = "melonJS";
135
133
  this.repeat = atlas.meta.repeat || "no-repeat";
136
- this.sources.set("default", typeof src === "string" ? loader.getImage(src) : src);
134
+ this.sources.set("default", typeof src === "string" ? getImage(src) : src);
137
135
  }
138
136
  // initialize the atlas
139
137
  this.atlases.set(atlas.meta.image || "default", this.parse(atlas));
@@ -147,7 +145,7 @@ class TextureAtlas {
147
145
 
148
146
  if (typeof(src) !== "undefined") {
149
147
  // overwrite if specified
150
- atlas.image = typeof src === "string" ? loader.getImage(src) : src;
148
+ atlas.image = typeof src === "string" ? getImage(src) : src;
151
149
  }
152
150
  // initialize the atlas
153
151
  this.atlases.set("default", this.parseFromSpriteSheet(atlas));
@@ -166,11 +164,7 @@ class TextureAtlas {
166
164
  // Add self to TextureCache if cache !== false
167
165
  if (cache !== false) {
168
166
  this.sources.forEach((source) => {
169
- if (cache instanceof TextureCache) {
170
- cache.set(source, this);
171
- } else {
172
- renderer.cache.set(source, this);
173
- }
167
+ renderer.cache.set(source, this);
174
168
  });
175
169
  }
176
170
  }
@@ -353,12 +347,13 @@ class TextureAtlas {
353
347
  region = this.getAtlas(atlas)[name];
354
348
  } else {
355
349
  // look for the given region in each existing atlas
356
- this.atlases.forEach((atlas) => {
350
+ for (let atlas of this.atlases.values()) {
357
351
  if (typeof atlas[name] !== "undefined") {
358
352
  // there should be only one
359
353
  region = atlas[name];
354
+ break;
360
355
  }
361
- });
356
+ }
362
357
  }
363
358
  return region;
364
359
  }
@@ -394,7 +389,7 @@ class TextureAtlas {
394
389
  */
395
390
  addUVs(atlas, name, w, h) {
396
391
  // ignore if using the Canvas Renderer
397
- if (renderer instanceof WebGLRenderer) {
392
+ if (typeof renderer.gl !== "undefined") {
398
393
  // Source coordinates
399
394
  var s = atlas[name].offset;
400
395
  var sw = atlas[name].width;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -64,8 +64,8 @@ class TextureCache {
64
64
  } else {
65
65
  // manage cases where a specific atlas is specified
66
66
  this.cache.forEach((value, key) => {
67
- var _atlas = value.getAtlas();
68
- if (key === image && _atlas[0].width === atlas.framewidth && _atlas[0].height === atlas.frameheight) {
67
+ var _atlas = value.getAtlas()[0];
68
+ if (key === image && _atlas.width === atlas.framewidth && _atlas.height === atlas.frameheight) {
69
69
  entry = value;
70
70
  }
71
71
  });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -94,7 +94,7 @@ function init(width, height, options) {
94
94
  // initialize the default game Application with the given options
95
95
  game.init(width, height, options);
96
96
  } catch (e) {
97
- console(e.message);
97
+ console.log(e.message);
98
98
  // me.video.init() historically returns false if failing at creating/using a HTML5 canvas
99
99
  return false;
100
100
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v15.0.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -14,18 +14,18 @@
14
14
 
15
15
  class VertexArrayBuffer {
16
16
 
17
- constructor(vertex_size, vertex_per_quad) {
17
+ constructor(vertex_size, vertex_per_obj) {
18
18
  // the size of one vertex in float
19
19
  this.vertexSize = vertex_size;
20
- // size of a quad in vertex
21
- this.quadSize = vertex_per_quad;
20
+ // size of an object in vertex
21
+ this.objSize = vertex_per_obj;
22
22
  // the maximum number of vertices the vertex array buffer can hold
23
- this.maxVertex = 256;
23
+ this.maxVertex = 256; // (note: this seems to be the sweet spot performance-wise when using batching)
24
24
  // the current number of vertices added to the vertex array buffer
25
25
  this.vertexCount = 0;
26
26
 
27
27
  // the actual vertex data buffer
28
- this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
28
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
29
29
  // Float32 and Uint32 view of the vertex data array buffer
30
30
  this.bufferF32 = new Float32Array(this.buffer);
31
31
  this.bufferU32 = new Uint32Array(this.buffer);
@@ -44,7 +44,7 @@
44
44
  * return true if full
45
45
  * @ignore
46
46
  */
47
- isFull(vertex = this.quadSize) {
47
+ isFull(vertex = this.objSize) {
48
48
  return (this.vertexCount + vertex >= this.maxVertex);
49
49
  }
50
50
 
@@ -52,14 +52,18 @@
52
52
  * resize the vertex buffer, retaining its original contents
53
53
  * @ignore
54
54
  */
55
- resize() {
56
- // double the vertex size
57
- this.maxVertex <<= 1;
55
+ resize(vertexCount) {
56
+
57
+ while (vertexCount > this.maxVertex) {
58
+ // double the vertex size
59
+ this.maxVertex <<= 1;
60
+ }
61
+
58
62
  // save a reference to the previous data
59
63
  var data = this.bufferF32;
60
64
 
61
65
  // recreate ArrayBuffer and views
62
- this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
66
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
63
67
  this.bufferF32 = new Float32Array(this.buffer);
64
68
  this.bufferU32 = new Uint32Array(this.buffer);
65
69
 
@@ -77,19 +81,19 @@
77
81
  var offset = this.vertexCount * this.vertexSize;
78
82
 
79
83
  if (this.vertexCount >= this.maxVertex) {
80
- this.resize();
84
+ this.resize(this.vertexCount);
81
85
  }
82
86
 
83
- this.bufferF32[offset + 0] = x;
84
- this.bufferF32[offset + 1] = y;
87
+ this.bufferF32[offset] = x;
88
+ this.bufferF32[++offset] = y;
85
89
 
86
90
  if (typeof u !== "undefined") {
87
- this.bufferF32[offset + 2] = u;
88
- this.bufferF32[offset + 3] = v;
91
+ this.bufferF32[++offset] = u;
92
+ this.bufferF32[++offset] = v;
89
93
  }
90
94
 
91
95
  if (typeof tint !== "undefined") {
92
- this.bufferU32[offset + 4] = tint;
96
+ this.bufferU32[++offset] = tint;
93
97
  }
94
98
 
95
99
  this.vertexCount++;
@@ -0,0 +1,235 @@
1
+ /*!
2
+ * melonJS Game Engine - v15.0.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import VertexArrayBuffer from '../buffer/vertex.js';
9
+ import GLShader from '../glshader.js';
10
+
11
+ /**
12
+ * @classdesc
13
+ * A base Compositor object.
14
+ */
15
+ class Compositor {
16
+ /**
17
+ * @param {WebGLRenderer} renderer - the current WebGL renderer session
18
+ * @param {Object} settings - additional settings to initialize this compositors
19
+ * @param {object[]} attribute - an array of attributes definition
20
+ * @param {string} attribute.name - name of the attribute in the vertex shader
21
+ * @param {number} attribute.size - number of components per vertex attribute. Must be 1, 2, 3, or 4.
22
+ * @param {GLenum} attribute.type - data type of each component in the array
23
+ * @param {boolean} attribute.normalized - whether integer data values should be normalized into a certain range when being cast to a float
24
+ * @param {number} attribute.offset - offset in bytes of the first component in the vertex attribute array
25
+ * @param {object} shader - an array of attributes definition
26
+ * @param {string} shader.vertex - a string containing the GLSL source code to set
27
+ * @param {string} shader.fragment - a string containing the GLSL source code to set
28
+ */
29
+ constructor (renderer, settings) {
30
+ this.init(renderer, settings);
31
+ }
32
+
33
+ /**
34
+ * Initialize the compositor
35
+ * @ignore
36
+ */
37
+ init (renderer, settings) {
38
+ // the associated renderer
39
+ this.renderer = renderer;
40
+
41
+ // WebGL context
42
+ this.gl = renderer.gl;
43
+
44
+ // Global fill color
45
+ this.color = renderer.currentColor;
46
+
47
+ // Global transformation matrix
48
+ this.viewMatrix = renderer.currentTransform;
49
+
50
+ /**
51
+ * the default shader created by this compositor
52
+ * @type {GLShader}
53
+ */
54
+ this.defaultShader = undefined;
55
+
56
+ /**
57
+ * the shader currently used by this compositor
58
+ * @type {GLShader}
59
+ */
60
+ this.currentShader = undefined;
61
+
62
+ /**
63
+ * primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
64
+ * @type {number}
65
+ * @default gl.TRIANGLES
66
+ */
67
+ this.mode = this.gl.TRIANGLES;
68
+
69
+ /**
70
+ * an array of vertex attribute properties
71
+ * @see WebGLCompositor.addAttribute
72
+ * @type {Array}
73
+ */
74
+ this.attributes = [];
75
+
76
+ /**
77
+ * the size of a single vertex in bytes
78
+ * (will automatically be calculated as attributes definitions are added)
79
+ * @see WebGLCompositor.addAttribute
80
+ * @type {number}
81
+ */
82
+ this.vertexByteSize = 0;
83
+
84
+ /**
85
+ * the size of a single vertex in floats
86
+ * (will automatically be calculated as attributes definitions are added)
87
+ * @see WebGLCompositor.addAttribute
88
+ * @type {number}
89
+ */
90
+ this.vertexSize = 0;
91
+
92
+ /**
93
+ * the vertex data buffer used by this compositor
94
+ * @type {VertexArrayBuffer}
95
+ */
96
+ this.vertexData = null;
97
+
98
+ // parse given attibrutes
99
+ if (typeof settings !== "undefined" && Array.isArray(settings.attributes)) {
100
+ settings.attributes.forEach((attr) => {
101
+ this.addAttribute(attr.name, attr.size, attr.type, attr.normalized, attr.offset);
102
+ this.vertexData = new VertexArrayBuffer(this.vertexSize, 6);
103
+ });
104
+ } else {
105
+ throw new Error("attributes definition missing");
106
+ }
107
+
108
+ // parse and instantiate the default shader
109
+ if (typeof settings !== "undefined" && typeof settings.shader !== "undefined") {
110
+ this.defaultShader = new GLShader(this.gl, settings.shader.vertex, settings.shader.fragment);
111
+ } else {
112
+ throw new Error("shader definition missing");
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Reset compositor internal state
118
+ * @ignore
119
+ */
120
+ reset() {
121
+ // WebGL context
122
+ this.gl = this.renderer.gl;
123
+
124
+ // clear the vertex data buffer
125
+ this.vertexData.clear();
126
+ }
127
+
128
+ /**
129
+ * @ignore
130
+ * called by the WebGL renderer when a compositor become the current one
131
+ */
132
+ bind() {
133
+ if (this.renderer.currentProgram !== this.defaultShader.program) {
134
+ this.useShader(this.defaultShader);
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Select the shader to use for compositing
140
+ * @see GLShader
141
+ * @param {GLShader} shader - a reference to a GLShader instance
142
+ */
143
+ useShader(shader) {
144
+ if (this.renderer.currentProgram !== shader.program) {
145
+ this.flush();
146
+ shader.bind();
147
+ shader.setUniform("uProjectionMatrix", this.renderer.projectionMatrix);
148
+ shader.setVertexAttributes(this.gl, this.attributes, this.vertexByteSize);
149
+
150
+ this.currentShader = shader;
151
+ this.renderer.currentProgram = this.currentShader.program;
152
+ }
153
+ }
154
+
155
+ /**
156
+ * add vertex attribute property definition to the compositor
157
+ * @param {string} name - name of the attribute in the vertex shader
158
+ * @param {number} size - number of components per vertex attribute. Must be 1, 2, 3, or 4.
159
+ * @param {GLenum} type - data type of each component in the array
160
+ * @param {boolean} normalized - whether integer data values should be normalized into a certain range when being cast to a float
161
+ * @param {number} offset - offset in bytes of the first component in the vertex attribute array
162
+ */
163
+ addAttribute(name, size, type, normalized, offset) {
164
+ this.attributes.push({
165
+ name: name,
166
+ size: size,
167
+ type: type,
168
+ normalized: normalized,
169
+ offset: offset
170
+ });
171
+
172
+ switch (type) {
173
+ case this.gl.BYTE:
174
+ this.vertexByteSize += size * Int8Array.BYTES_PER_ELEMENT;
175
+ break;
176
+ case this.gl.UNSIGNED_BYTE:
177
+ this.vertexByteSize += size * Uint8Array.BYTES_PER_ELEMENT;
178
+ break;
179
+ case this.gl.SHORT:
180
+ this.vertexByteSize += size * Int16Array.BYTES_PER_ELEMENT;
181
+ break;
182
+ case this.gl.UNSIGNED_SHORT:
183
+ this.vertexByteSize += size * Uint16Array.BYTES_PER_ELEMENT;
184
+ break;
185
+ case this.gl.INT:
186
+ this.vertexByteSize += size * Int32Array.BYTES_PER_ELEMENT;
187
+ break;
188
+ case this.gl.UNSIGNED_INT:
189
+ this.vertexByteSize += size * Uint32Array.BYTES_PER_ELEMENT;
190
+ break;
191
+ case this.gl.FLOAT:
192
+ this.vertexByteSize += size * Float32Array.BYTES_PER_ELEMENT;
193
+ break;
194
+ default:
195
+ throw new Error("Invalid GL Attribute type");
196
+ }
197
+ this.vertexSize = this.vertexByteSize / Float32Array.BYTES_PER_ELEMENT;
198
+ }
199
+
200
+ /**
201
+ * set/change the current projection matrix
202
+ * @param {Matrix3d} matrix
203
+ */
204
+ setProjection(matrix) {
205
+ this.currentShader.setUniform("uProjectionMatrix", matrix);
206
+ }
207
+
208
+ /**
209
+ * Flush batched vertex data to the GPU
210
+ * @param {number} [mode=gl.TRIANGLES] - the GL drawing mode
211
+ */
212
+ flush(mode = this.mode) {
213
+ var vertex = this.vertexData;
214
+ var vertexCount = vertex.vertexCount;
215
+
216
+ if (vertexCount > 0) {
217
+ var gl = this.gl;
218
+ var vertexSize = vertex.vertexSize;
219
+
220
+ // Copy data into stream buffer
221
+ if (this.renderer.WebGLVersion > 1) {
222
+ gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(), gl.STREAM_DRAW, 0, vertexCount * vertexSize);
223
+ } else {
224
+ gl.bufferData(gl.ARRAY_BUFFER, vertex.toFloat32(0, vertexCount * vertexSize), gl.STREAM_DRAW);
225
+ }
226
+
227
+ gl.drawArrays(mode, 0, vertexCount);
228
+
229
+ // clear the vertex buffer
230
+ vertex.clear();
231
+ }
232
+ }
233
+ }
234
+
235
+ export { Compositor as default };
@@ -0,0 +1,77 @@
1
+ /*!
2
+ * melonJS Game Engine - v15.0.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import primitiveVertex from '../shaders/primitive.vert.js';
9
+ import primitiveFragment from '../shaders/primitive.frag.js';
10
+ import Compositor from './compositor.js';
11
+
12
+ /**
13
+ * @classdesc
14
+ * A WebGL Compositor object. This class handles all of the WebGL state<br>
15
+ * Pushes texture regions or shape geometry into WebGL buffers, automatically flushes to GPU
16
+ * @augments Compositor
17
+ */
18
+ class PrimitiveCompositor extends Compositor {
19
+
20
+ /**
21
+ * Initialize the compositor
22
+ * @ignore
23
+ */
24
+ init(renderer) {
25
+ super.init(renderer, {
26
+ attributes: [
27
+ {name: "aVertex", size: 2, type: renderer.gl.FLOAT, normalized: false, offset: 0 * Float32Array.BYTES_PER_ELEMENT},
28
+ {name: "aColor", size: 4, type: renderer.gl.UNSIGNED_BYTE, normalized: true, offset: 2 * Float32Array.BYTES_PER_ELEMENT}
29
+ ],
30
+ shader: {
31
+ vertex: primitiveVertex, fragment: primitiveFragment
32
+ }
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Draw an array of vertices
38
+ * @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)
39
+ * @param {Point[]} verts - an array of vertices
40
+ * @param {number} [vertexCount=verts.length] - amount of points defined in the points array
41
+ */
42
+ drawVertices(mode, verts, vertexCount = verts.length) {
43
+ var viewMatrix = this.viewMatrix;
44
+ var vertexData = this.vertexData;
45
+ var color = this.renderer.currentColor;
46
+ var alpha = this.renderer.getGlobalAlpha();
47
+
48
+ if (vertexData.isFull(vertexCount)) {
49
+ // is the vertex buffer full if we add more vertices
50
+ this.flush();
51
+ }
52
+
53
+ // flush if drawing vertices with a different drawing mode
54
+ if (mode !== this.mode) {
55
+ this.flush(this.mode);
56
+ this.mode = mode;
57
+ }
58
+
59
+ if (!viewMatrix.isIdentity()) {
60
+ verts.forEach((vert) => {
61
+ viewMatrix.apply(vert);
62
+ vertexData.push(vert.x, vert.y, undefined, undefined, color.toUint32(alpha));
63
+ });
64
+ } else {
65
+ verts.forEach((vert) => {
66
+ vertexData.push(vert.x, vert.y, undefined, undefined, color.toUint32(alpha));
67
+ });
68
+ }
69
+
70
+ // force flush for primitive using LINE_STRIP or LINE_LOOP
71
+ if (this.mode === this.gl.LINE_STRIP || this.mode === this.gl.LINE_LOOP) {
72
+ this.flush(this.mode);
73
+ }
74
+ }
75
+ }
76
+
77
+ export { PrimitiveCompositor as default };