melonjs 14.5.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 (195) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +2 -2
  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 +2 -4
  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 +1 -1
  19. package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
  20. package/dist/melonjs.mjs/geometries/line.js +1 -1
  21. package/dist/melonjs.mjs/geometries/path2d.js +4 -4
  22. package/dist/melonjs.mjs/geometries/point.js +1 -1
  23. package/dist/melonjs.mjs/geometries/poly.js +1 -1
  24. package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
  25. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  26. package/dist/melonjs.mjs/index.js +5 -3
  27. package/dist/melonjs.mjs/input/gamepad.js +1 -1
  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 +2 -2
  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 +1 -1
  35. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  36. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -1
  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 +1 -1
  40. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
  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 +1 -1
  51. package/dist/melonjs.mjs/loader/loader.js +1 -1
  52. package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
  53. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  54. package/dist/melonjs.mjs/loader/parser.js +1 -1
  55. package/dist/melonjs.mjs/loader/settings.js +1 -1
  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 +1 -1
  59. package/dist/melonjs.mjs/math/matrix3.js +1 -1
  60. package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
  61. package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
  62. package/dist/melonjs.mjs/math/vector2.js +1 -1
  63. package/dist/melonjs.mjs/math/vector3.js +1 -1
  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 +1 -1
  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 +1 -1
  76. package/dist/melonjs.mjs/physics/bounds.js +1 -1
  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 +1 -1
  87. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  88. package/dist/melonjs.mjs/renderable/imagelayer.js +1 -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 +25 -3
  92. package/dist/melonjs.mjs/renderable/sprite.js +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  120. package/dist/melonjs.mjs/utils/utils.js +1 -1
  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 +3 -9
  124. package/dist/melonjs.mjs/video/texture/cache.js +1 -1
  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 +1 -1
  128. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
  129. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +77 -77
  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/compositors/webgl_compositor.js +1 -1
  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 +25111 -25202
  145. package/dist/types/entity/entity.d.ts +1 -1
  146. package/dist/types/index.d.ts +4 -2
  147. package/dist/types/renderable/renderable.d.ts +6 -0
  148. package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
  149. package/dist/types/text/text.d.ts +6 -20
  150. package/dist/types/text/textstyle.d.ts +1 -1
  151. package/dist/types/video/canvas/canvas_renderer.d.ts +0 -5
  152. package/dist/types/video/renderer.d.ts +1 -5
  153. package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
  154. package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
  155. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
  156. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
  157. package/dist/types/video/webgl/webgl_renderer.d.ts +34 -28
  158. package/package.json +13 -14
  159. package/src/audio/audio.js +1 -3
  160. package/src/geometries/path2d.js +3 -3
  161. package/src/index.js +6 -2
  162. package/src/math/color.js +8 -7
  163. package/src/polyfill/index.js +0 -2
  164. package/src/renderable/renderable.js +24 -2
  165. package/src/renderable/ui/uitextbutton.js +0 -2
  166. package/src/system/device.js +1 -1
  167. package/src/text/text.js +55 -85
  168. package/src/text/textstyle.js +3 -5
  169. package/src/video/canvas/canvas_renderer.js +5 -9
  170. package/src/video/renderer.js +0 -11
  171. package/src/video/texture/atlas.js +2 -8
  172. package/src/video/webgl/buffer/vertex.js +20 -16
  173. package/src/video/webgl/compositors/compositor.js +76 -77
  174. package/src/video/webgl/compositors/primitive_compositor.js +68 -0
  175. package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +38 -98
  176. package/src/video/webgl/shaders/primitive.vert +2 -5
  177. package/src/video/webgl/shaders/quad.vert +3 -1
  178. package/src/video/webgl/webgl_renderer.js +137 -147
  179. package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
  180. package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
  181. package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
  182. package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
  183. package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
  184. package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
  185. package/dist/melonjs.mjs/_virtual/shared.js +0 -10
  186. package/dist/melonjs.mjs/game.js +0 -29
  187. package/dist/melonjs.mjs/polyfill/console.js +0 -18
  188. package/dist/melonjs.mjs/polyfill/performance.js +0 -27
  189. package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
  190. package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
  191. package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
  192. package/dist/melonjs.mjs/video/utils/resize.js +0 -116
  193. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
  194. package/src/polyfill/performance.js +0 -20
  195. package/src/polyfill/requestAnimationFrame.js +0 -39
@@ -1,12 +1,11 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.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 Color from '../math/color.js';
9
- import WebGLRenderer from '../video/webgl/webgl_renderer.js';
10
9
  import { renderer } from '../video/video.js';
11
10
  import pool from '../system/pooling.js';
12
11
  import Renderable from '../renderable/renderable.js';
@@ -26,18 +25,6 @@ import TextMetrics from './textmetrics.js';
26
25
  const runits = ["ex", "em", "pt", "px"];
27
26
  const toPX = [12, 24, 0.75, 1];
28
27
 
29
- // return a valid 2d context for Text rendering/styling
30
- var getContext2d = function (renderer$1, text) {
31
- if (text.offScreenCanvas === true) {
32
- return text.canvasTexture.context;
33
- } else {
34
- if (typeof renderer$1 === "undefined") {
35
- renderer$1 = renderer;
36
- }
37
- return renderer$1.getFontContext();
38
- }
39
- };
40
-
41
28
  /**
42
29
  * @classdesc
43
30
  * a generic system font object.
@@ -52,12 +39,11 @@ var getContext2d = function (renderer$1, text) {
52
39
  * @param {number|string} settings.size - size, or size + suffix (px, em, pt)
53
40
  * @param {Color|string} [settings.fillStyle="#000000"] - a CSS color value
54
41
  * @param {Color|string} [settings.strokeStyle="#000000"] - a CSS color value
55
- * @param {number} [settings.lineWidth=1] - line width, in pixels, when drawing stroke
42
+ * @param {number} [settings.lineWidth=0] - line width, in pixels, when drawing stroke
56
43
  * @param {string} [settings.textAlign="left"] - horizontal text alignment
57
44
  * @param {string} [settings.textBaseline="top"] - the text baseline
58
45
  * @param {number} [settings.lineHeight=1.0] - line spacing height
59
46
  * @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at
60
- * @param {boolean} [settings.offScreenCanvas=false] - whether to draw the font to an individual "cache" texture first
61
47
  * @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
62
48
  * @param {(string|string[])} [settings.text=""] - a string, or an array of strings
63
49
  * @example
@@ -112,9 +98,9 @@ var getContext2d = function (renderer$1, text) {
112
98
  * sets the current line width, in pixels, when drawing stroke
113
99
  * @public
114
100
  * @type {number}
115
- * @default 1
101
+ * @default 0
116
102
  */
117
- this.lineWidth = settings.lineWidth || 1;
103
+ this.lineWidth = settings.lineWidth || 0;
118
104
 
119
105
  /**
120
106
  * Set the default text alignment (or justification),<br>
@@ -143,16 +129,6 @@ var getContext2d = function (renderer$1, text) {
143
129
  */
144
130
  this.lineHeight = settings.lineHeight || 1.0;
145
131
 
146
- /**
147
- * whether to draw the font to a indidividual offscreen canvas texture first <br>
148
- * Note: this will improve performances when using WebGL, but will impact
149
- * memory consumption as every text element will have its own canvas texture
150
- * @public
151
- * @type {boolean}
152
- * @default false
153
- */
154
- this.offScreenCanvas = false;
155
-
156
132
  /**
157
133
  * the maximum length in CSS pixel for a single segment of text.
158
134
  * (use -1 to disable word wrapping)
@@ -199,10 +175,8 @@ var getContext2d = function (renderer$1, text) {
199
175
  this.italic();
200
176
  }
201
177
 
202
- if (settings.offScreenCanvas === true) {
203
- this.offScreenCanvas = true;
204
- this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
205
- }
178
+ // the canvas Texture used to render this text
179
+ this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
206
180
 
207
181
  // instance to text metrics functions
208
182
  this.metrics = new TextMetrics(this);
@@ -291,38 +265,38 @@ var getContext2d = function (renderer$1, text) {
291
265
 
292
266
  // word wrap if necessary
293
267
  if (this._text.length > 0 && this.wordWrapWidth > 0) {
294
- this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, getContext2d(renderer, this));
268
+ this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, this.canvasTexture.context);
295
269
  }
296
270
 
297
271
  // calculcate the text size and update the bounds accordingly
298
- bounds.addBounds(this.metrics.measureText(this._text, getContext2d(renderer, this)), true);
272
+ bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
299
273
 
300
274
  // update the offScreenCanvas texture if required
301
- if (this.offScreenCanvas === true) {
302
- var width = Math.ceil(this.metrics.width),
303
- height = Math.ceil(this.metrics.height);
304
-
305
- if (renderer instanceof WebGLRenderer) {
306
- // invalidate the previous corresponding texture so that it can reuploaded once changed
307
- this.glTextureUnit = renderer.cache.getUnit(renderer.cache.get(this.canvasTexture.canvas));
308
- renderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
309
-
310
- if (renderer.WebGLVersion === 1) {
311
- // round size to next Pow2
312
- width = nextPowerOfTwo(this.metrics.width);
313
- height = nextPowerOfTwo(this.metrics.height);
314
- }
315
- }
316
-
317
- // resize the cache canvas if necessary
318
- if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
319
- this.canvasTexture.resize(width, height);
275
+ var width = Math.ceil(this.metrics.width),
276
+ height = Math.ceil(this.metrics.height);
277
+
278
+ if (typeof renderer.gl !== "undefined") {
279
+ // make sure the right compositor is active
280
+ renderer.setCompositor("quad");
281
+ // invalidate the previous corresponding texture so that it can reuploaded once changed
282
+ this.glTextureUnit = renderer.cache.getUnit(renderer.cache.get(this.canvasTexture.canvas));
283
+ renderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
284
+
285
+ if (renderer.WebGLVersion === 1) {
286
+ // round size to next Pow2
287
+ width = nextPowerOfTwo(this.metrics.width);
288
+ height = nextPowerOfTwo(this.metrics.height);
320
289
  }
290
+ }
321
291
 
322
- this.canvasTexture.clear();
323
- this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y, false);
292
+ // resize the cache canvas if necessary
293
+ if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
294
+ this.canvasTexture.resize(width, height);
324
295
  }
325
296
 
297
+ this.canvasTexture.clear();
298
+ this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y);
299
+
326
300
  this.isDirty = true;
327
301
 
328
302
  return this;
@@ -335,7 +309,7 @@ var getContext2d = function (renderer$1, text) {
335
309
  * @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
336
310
  */
337
311
  measureText(renderer, text = this._text) {
338
- return this.metrics.measureText(text, getContext2d(renderer, this));
312
+ return this.metrics.measureText(text, this.canvasTexture.context);
339
313
  }
340
314
 
341
315
 
@@ -345,9 +319,8 @@ var getContext2d = function (renderer$1, text) {
345
319
  * @param {string} [text]
346
320
  * @param {number} [x]
347
321
  * @param {number} [y]
348
- * @param {boolean} [stroke=false] - draw stroke the the text if true
349
322
  */
350
- draw(renderer, text, x = this.pos.x, y = this.pos.y, stroke = false) {
323
+ draw(renderer, text, x = this.pos.x, y = this.pos.y) {
351
324
  // "hacky patch" for backward compatibilty
352
325
  if (typeof this.ancestor === "undefined") {
353
326
 
@@ -361,21 +334,18 @@ var getContext2d = function (renderer$1, text) {
361
334
  // update text cache
362
335
  this.setText(text);
363
336
 
364
- x = this.metrics.x;
365
- y = this.metrics.y;
366
-
367
337
  // save the previous context
368
338
  renderer.save();
369
339
 
370
340
  // apply the defined alpha value
371
341
  renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
372
342
 
373
- } else {
374
- // added directly to an object container
375
- x = this.pos.x;
376
- y = this.pos.y;
377
343
  }
378
344
 
345
+ // adjust x,y position based on the bounding box
346
+ x = this.metrics.x;
347
+ y = this.metrics.y;
348
+
379
349
  // clamp to pixel grid if required
380
350
  if (renderer.settings.subPixel === false) {
381
351
  x = ~~x;
@@ -383,12 +353,7 @@ var getContext2d = function (renderer$1, text) {
383
353
  }
384
354
 
385
355
  // draw the text
386
- if (this.offScreenCanvas === true) {
387
- renderer.drawImage(this.canvasTexture.canvas, x, y);
388
- } else {
389
- renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke));
390
- }
391
-
356
+ renderer.drawImage(this.canvasTexture.canvas, x, y);
392
357
 
393
358
  // for backward compatibilty
394
359
  if (typeof this.ancestor === "undefined") {
@@ -398,28 +363,33 @@ var getContext2d = function (renderer$1, text) {
398
363
  }
399
364
 
400
365
  /**
401
- * draw a stroke text at the specified coord, as defined <br>
402
- * by the `lineWidth` and `fillStroke` properties. <br>
403
- * Note : using drawStroke is not recommended for performance reasons
366
+ * draw a stroke text at the specified coord, as defined by the `lineWidth` and `fillStroke` properties.
367
+ * @deprecated since 15.0.0
404
368
  * @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
405
369
  * @param {string} text
406
370
  * @param {number} x
407
371
  * @param {number} y
408
372
  */
409
373
  drawStroke(renderer, text, x, y) {
410
- this.draw(renderer, text, x, y, true);
374
+ this.draw(renderer, text, x, y);
411
375
  }
412
376
 
413
377
  /**
414
378
  * @ignore
415
379
  */
416
- _drawFont(context, text, x, y, stroke = false) {
417
- setContextStyle(context, this, stroke);
380
+ _drawFont(context, text, x, y) {
381
+ setContextStyle(context, this);
418
382
 
419
383
  for (var i = 0; i < text.length; i++) {
420
384
  var string = text[i].trimEnd();
421
385
  // draw the string
422
- context[stroke ? "strokeText" : "fillText"](string, x, y);
386
+ if (this.fillStyle.alpha > 0) {
387
+ context.fillText(string, x, y);
388
+ }
389
+ // stroke the text
390
+ if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
391
+ context.strokeText(string, x, y);
392
+ }
423
393
  // add leading space
424
394
  y += this.metrics.lineHeight();
425
395
  }
@@ -431,15 +401,15 @@ var getContext2d = function (renderer$1, text) {
431
401
  * @ignore
432
402
  */
433
403
  destroy() {
434
- if (this.offScreenCanvas === true) {
435
- if (renderer instanceof WebGLRenderer) {
436
- renderer.currentCompositor.deleteTexture2D(renderer.currentCompositor.getTexture2D(this.glTextureUnit));
437
- this.glTextureUnit = undefined;
438
- }
439
- renderer.cache.delete(this.canvasTexture.canvas);
440
- pool.push(this.canvasTexture);
441
- this.canvasTexture = undefined;
404
+ if (typeof renderer.gl !== "undefined") {
405
+ // make sure the right compositor is active
406
+ renderer.setCompositor("quad");
407
+ renderer.currentCompositor.deleteTexture2D(renderer.currentCompositor.getTexture2D(this.glTextureUnit));
408
+ this.glTextureUnit = undefined;
442
409
  }
410
+ renderer.cache.delete(this.canvasTexture.canvas);
411
+ pool.push(this.canvasTexture);
412
+ this.canvasTexture = undefined;
443
413
  pool.push(this.fillStyle);
444
414
  pool.push(this.strokeStyle);
445
415
  this.fillStyle = this.strokeStyle = undefined;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.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.5.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
@@ -9,13 +9,11 @@
9
9
  * apply the current text style to the given context
10
10
  * @ignore
11
11
  */
12
- function setContextStyle(context, style, stroke = false) {
12
+ function setContextStyle(context, style) {
13
13
  context.font = style.font;
14
14
  context.fillStyle = style.fillStyle.toRGBA();
15
- if (stroke === true) {
16
- context.strokeStyle = style.strokeStyle.toRGBA();
17
- context.lineWidth = style.lineWidth;
18
- }
15
+ context.strokeStyle = style.strokeStyle.toRGBA();
16
+ context.lineWidth = style.lineWidth;
19
17
  context.textAlign = style.textAlign;
20
18
  context.textBaseline = style.textBaseline;
21
19
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.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.5.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.5.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.5.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.5.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.5.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.5.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.5.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.5.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.5.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.5.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,13 +1,11 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.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';
@@ -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
  }
@@ -395,7 +389,7 @@ class TextureAtlas {
395
389
  */
396
390
  addUVs(atlas, name, w, h) {
397
391
  // ignore if using the Canvas Renderer
398
- if (renderer instanceof WebGLRenderer) {
392
+ if (typeof renderer.gl !== "undefined") {
399
393
  // Source coordinates
400
394
  var s = atlas[name].offset;
401
395
  var sw = atlas[name].width;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.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.5.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.5.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.5.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.5.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++;