melonjs 10.7.1 → 10.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/melonjs.js +1131 -652
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +1038 -198
- package/dist/melonjs.module.js +1234 -763
- package/package.json +7 -7
- package/src/camera/camera2d.js +1 -1
- package/src/entity/entity.js +6 -7
- package/src/geometries/ellipse.js +10 -11
- package/src/geometries/line.js +3 -3
- package/src/geometries/path2d.js +319 -0
- package/src/geometries/poly.js +11 -11
- package/src/geometries/rectangle.js +15 -15
- package/src/geometries/roundrect.js +67 -0
- package/src/index.js +5 -1
- package/src/input/pointerevent.js +1 -1
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXObject.js +9 -12
- package/src/level/tiled/TMXTileMap.js +23 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +4 -4
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +1 -1
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +23 -14
- package/src/particles/particle.js +3 -2
- package/src/physics/body.js +67 -51
- package/src/physics/bounds.js +8 -9
- package/src/physics/world.js +1 -1
- package/src/renderable/collectable.js +9 -2
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +1 -1
- package/src/renderable/imagelayer.js +1 -1
- package/src/renderable/renderable.js +1 -1
- package/src/renderable/sprite.js +2 -3
- package/src/renderable/trigger.js +10 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +1 -1
- package/src/system/device.js +10 -8
- package/src/system/pooling.js +156 -149
- package/src/text/bitmaptext.js +1 -1
- package/src/text/text.js +1 -1
- package/src/video/canvas/canvas_renderer.js +89 -34
- package/src/video/renderer.js +26 -14
- package/src/video/texture.js +1 -1
- package/src/video/webgl/glshader.js +29 -193
- package/src/video/webgl/utils/attributes.js +16 -0
- package/src/video/webgl/utils/precision.js +11 -0
- package/src/video/webgl/utils/program.js +58 -0
- package/src/video/webgl/utils/string.js +16 -0
- package/src/video/webgl/utils/uniforms.js +87 -0
- package/src/video/webgl/webgl_compositor.js +1 -14
- package/src/video/webgl/webgl_renderer.js +123 -181
package/src/physics/bounds.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import pool from "./../system/pooling.js";
|
|
1
2
|
import Vector2d from "./../math/vector2.js";
|
|
2
|
-
import Polygon from "./../geometries/poly.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
@@ -10,6 +10,8 @@ class Bounds {
|
|
|
10
10
|
* @param {Vector2d[]} [vertices] an array of me.Vector2d points
|
|
11
11
|
*/
|
|
12
12
|
constructor(vertices) {
|
|
13
|
+
// @ignore
|
|
14
|
+
this._center = new Vector2d();
|
|
13
15
|
this.onResetEvent(vertices);
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -26,9 +28,6 @@ class Bounds {
|
|
|
26
28
|
if (typeof vertices !== "undefined") {
|
|
27
29
|
this.update(vertices);
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
// @ignore
|
|
31
|
-
this._center = new Vector2d();
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
/**
|
|
@@ -450,11 +449,11 @@ class Bounds {
|
|
|
450
449
|
* @returns {Polygon} a new Polygon that represents this bounds.
|
|
451
450
|
*/
|
|
452
451
|
toPolygon () {
|
|
453
|
-
return
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
452
|
+
return pool.pull("Polygon", this.x, this.y, [
|
|
453
|
+
pool.pull("Vector2d", 0, 0),
|
|
454
|
+
pool.pull("Vector2d", this.width, 0),
|
|
455
|
+
pool.pull("Vector2d", this.width, this.height),
|
|
456
|
+
pool.pull("Vector2d", 0, this.height)
|
|
458
457
|
]);
|
|
459
458
|
}
|
|
460
459
|
|
package/src/physics/world.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Sprite from "./sprite.js";
|
|
2
2
|
import Body from "./../physics/body.js";
|
|
3
|
-
import Rect from "./../geometries/rectangle.js";
|
|
4
3
|
import collision from "./../physics/collision.js";
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -24,7 +23,15 @@ class Collectable extends Sprite {
|
|
|
24
23
|
this.id = settings.id;
|
|
25
24
|
|
|
26
25
|
// add and configure the physic body
|
|
27
|
-
|
|
26
|
+
var shape = settings.shapes;
|
|
27
|
+
if (typeof shape === "undefined") {
|
|
28
|
+
shape = pool.pull("Polygon", 0, 0, [
|
|
29
|
+
pool.pull("Vector2d", 0, 0),
|
|
30
|
+
pool.pull("Vector2d", this.width, 0),
|
|
31
|
+
pool.pull("Vector2d", this.width, this.height)
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
this.body = new Body(this, shape);
|
|
28
35
|
this.body.collisionType = collision.types.COLLECTABLE_OBJECT;
|
|
29
36
|
// by default only collides with PLAYER_OBJECT
|
|
30
37
|
this.body.setCollisionMask(collision.types.PLAYER_OBJECT);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import utils from "./../utils/utils.js";
|
|
2
2
|
import * as game from "./../game.js";
|
|
3
3
|
import * as event from "./../system/event.js";
|
|
4
|
-
import
|
|
4
|
+
import pool from "./../system/pooling.js";
|
|
5
5
|
import state from "./../state/state.js";
|
|
6
6
|
import Renderable from "./renderable.js";
|
|
7
7
|
import Body from "./../physics/body.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { renderer } from "./../video/video.js";
|
|
2
2
|
import * as event from "./../system/event.js";
|
|
3
|
-
import
|
|
3
|
+
import pool from "./../system/pooling.js";
|
|
4
4
|
import { viewport } from "./../game.js";
|
|
5
5
|
import Sprite from "./sprite.js";
|
|
6
6
|
import * as stringUtil from "./../utils/string.js";
|
|
@@ -2,7 +2,7 @@ import ObservableVector2d from "./../math/observable_vector2.js";
|
|
|
2
2
|
import ObservableVector3d from "./../math/observable_vector3.js";
|
|
3
3
|
import Rect from "./../geometries/rectangle.js";
|
|
4
4
|
import Container from "./container.js";
|
|
5
|
-
import
|
|
5
|
+
import pool from "./../system/pooling.js";
|
|
6
6
|
import { releaseAllPointerEvents } from "./../input/input.js";
|
|
7
7
|
import { clamp } from "./../math/math.js";
|
|
8
8
|
|
package/src/renderable/sprite.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import Vector2d from "./../math/vector2.js";
|
|
2
1
|
import { renderer } from "./../video/video.js";
|
|
3
|
-
import
|
|
2
|
+
import pool from "./../system/pooling.js";
|
|
4
3
|
import loader from "./../loader/loader.js";
|
|
5
4
|
import { TextureAtlas } from "./../video/texture.js";
|
|
6
5
|
import Renderable from "./renderable.js";
|
|
@@ -99,7 +98,7 @@ class Sprite extends Renderable {
|
|
|
99
98
|
// length of the current animation name
|
|
100
99
|
length : 0,
|
|
101
100
|
//current frame texture offset
|
|
102
|
-
offset :
|
|
101
|
+
offset : pool.pull("Vector2d"),
|
|
103
102
|
// current frame size
|
|
104
103
|
width : 0,
|
|
105
104
|
height : 0,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Renderable from "./renderable.js";
|
|
2
2
|
import collision from "./../physics/collision.js";
|
|
3
3
|
import Body from "./../physics/body.js";
|
|
4
|
-
import Rect from "./../geometries/rectangle.js";
|
|
5
4
|
import level from "./../level/level.js";
|
|
6
5
|
import { world, viewport } from "./../game.js";
|
|
7
6
|
|
|
@@ -66,9 +65,16 @@ class Trigger extends Renderable {
|
|
|
66
65
|
}
|
|
67
66
|
}.bind(this));
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
// add and configure the physic body
|
|
69
|
+
var shape = settings.shapes;
|
|
70
|
+
if (typeof shape === "undefined") {
|
|
71
|
+
shape = pool.pull("Polygon", 0, 0, [
|
|
72
|
+
pool.pull("Vector2d", 0, 0),
|
|
73
|
+
pool.pull("Vector2d", this.width, 0),
|
|
74
|
+
pool.pull("Vector2d", this.width, this.height)
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
this.body = new Body(this, shape);
|
|
72
78
|
this.body.collisionType = collision.types.ACTION_OBJECT;
|
|
73
79
|
// by default only collides with PLAYER_OBJECT
|
|
74
80
|
this.body.setCollisionMask(collision.types.PLAYER_OBJECT);
|
package/src/state/stage.js
CHANGED
|
@@ -31,7 +31,7 @@ class Stage {
|
|
|
31
31
|
* Cameras will be renderered based on this order defined in this list.
|
|
32
32
|
* Only the "default" camera will be resized when the window or canvas is resized.
|
|
33
33
|
* @public
|
|
34
|
-
* @type {Map}
|
|
34
|
+
* @type {Map<Camera2d>}
|
|
35
35
|
* @name cameras
|
|
36
36
|
* @memberof Stage
|
|
37
37
|
*/
|
package/src/state/state.js
CHANGED
|
@@ -512,7 +512,7 @@ var state = {
|
|
|
512
512
|
// if fading effect
|
|
513
513
|
if (_fade.duration && _stages[state].transition) {
|
|
514
514
|
/** @ignore */
|
|
515
|
-
_onSwitchComplete =
|
|
515
|
+
_onSwitchComplete = () => {
|
|
516
516
|
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
517
517
|
};
|
|
518
518
|
game.viewport.fadeIn(
|
package/src/system/device.js
CHANGED
|
@@ -112,12 +112,6 @@ function _checkCapabilities() {
|
|
|
112
112
|
// detect device type/platform
|
|
113
113
|
_detectDevice();
|
|
114
114
|
|
|
115
|
-
// Mobile browser hacks
|
|
116
|
-
if (device.isMobile) {
|
|
117
|
-
// Prevent the webview from moving on a swipe
|
|
118
|
-
device.enableSwipe(false);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
115
|
// Touch/Gesture Event feature detection
|
|
122
116
|
device.TouchEvent = !!("ontouchstart" in globalThis);
|
|
123
117
|
device.PointerEvent = !!globalThis.PointerEvent;
|
|
@@ -239,6 +233,13 @@ function _checkCapabilities() {
|
|
|
239
233
|
);
|
|
240
234
|
}
|
|
241
235
|
}
|
|
236
|
+
|
|
237
|
+
// Mobile browser hacks
|
|
238
|
+
if (device.isMobile) {
|
|
239
|
+
// Prevent the webview from moving on a swipe
|
|
240
|
+
device.enableSwipe(false);
|
|
241
|
+
}
|
|
242
|
+
|
|
242
243
|
};
|
|
243
244
|
|
|
244
245
|
|
|
@@ -676,13 +677,14 @@ let device = {
|
|
|
676
677
|
* @param {boolean} [enable=true] enable or disable swipe.
|
|
677
678
|
*/
|
|
678
679
|
enableSwipe(enable) {
|
|
680
|
+
var moveEvent = device.PointerEvent ? "pointermove" : (device.TouchEvent ? "touchmove" : "mousemove");
|
|
679
681
|
if (enable !== false) {
|
|
680
682
|
if (swipeEnabled === false) {
|
|
681
|
-
globalThis.document.removeEventListener(
|
|
683
|
+
globalThis.document.removeEventListener(moveEvent, _disableSwipeFn);
|
|
682
684
|
swipeEnabled = true;
|
|
683
685
|
}
|
|
684
686
|
} else if (swipeEnabled === true) {
|
|
685
|
-
globalThis.document.addEventListener(
|
|
687
|
+
globalThis.document.addEventListener(moveEvent, _disableSwipeFn, { passive: false });
|
|
686
688
|
swipeEnabled = false;
|
|
687
689
|
}
|
|
688
690
|
},
|
package/src/system/pooling.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
var objectClass = {};
|
|
2
|
-
var instance_counter = 0;
|
|
3
|
-
|
|
4
1
|
/**
|
|
2
|
+
* @classdesc
|
|
5
3
|
* This object is used for object pooling - a technique that might speed up your game if used properly.<br>
|
|
6
4
|
* If some of your classes will be instantiated and removed a lot at a time, it is a
|
|
7
5
|
* good idea to add the class to this object pool. A separate pool for that class
|
|
@@ -12,172 +10,181 @@ var instance_counter = 0;
|
|
|
12
10
|
* which means, that on level loading the engine will try to instantiate every object
|
|
13
11
|
* found in the map, based on the user defined name in each Object Properties<br>
|
|
14
12
|
* <img src="images/object_properties.png"/><br>
|
|
15
|
-
* @
|
|
13
|
+
* @see {@link pool} a default global instance of ObjectPool
|
|
16
14
|
*/
|
|
15
|
+
class ObjectPool {
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
constructor() {
|
|
18
|
+
this.objectClass = {};
|
|
19
|
+
this.instance_counter = 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* register an object to the pool. <br>
|
|
24
|
+
* Pooling must be set to true if more than one such objects will be created. <br>
|
|
25
|
+
* (Note: for an object to be poolable, it must implements a `onResetEvent` method)
|
|
26
|
+
* @param {string} className as defined in the Name field of the Object Properties (in Tiled)
|
|
27
|
+
* @param {object} classObj corresponding Class to be instantiated
|
|
28
|
+
* @param {boolean} [recycling=false] enables object recycling for the specified class
|
|
29
|
+
* @example
|
|
30
|
+
* // implement CherryEntity
|
|
31
|
+
* class CherryEntity extends Spritesheet {
|
|
32
|
+
* onResetEvent() {
|
|
33
|
+
* // reset object mutable properties
|
|
34
|
+
* this.lifeBar = 100;
|
|
35
|
+
* }
|
|
36
|
+
* };
|
|
37
|
+
* // add our users defined entities in the object pool and enable object recycling
|
|
38
|
+
* me.pool.register("cherryentity", CherryEntity, true);
|
|
39
|
+
*/
|
|
40
|
+
register(className, classObj, recycling = false) {
|
|
41
|
+
if (typeof (classObj) !== "undefined") {
|
|
42
|
+
this.objectClass[className] = {
|
|
43
|
+
"class" : classObj,
|
|
44
|
+
"pool" : (recycling ? [] : undefined)
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error("Cannot register object '" + className + "', invalid class");
|
|
48
|
+
}
|
|
45
49
|
}
|
|
46
|
-
};
|
|
47
50
|
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
obj;
|
|
51
|
+
/**
|
|
52
|
+
* Pull a new instance of the requested object (if added into the object pool)
|
|
53
|
+
* @param {string} name as used in {@link pool.register}
|
|
54
|
+
* @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
|
|
55
|
+
* @returns {object} the instance of the requested object
|
|
56
|
+
* @example
|
|
57
|
+
* me.pool.register("bullet", BulletEntity, true);
|
|
58
|
+
* me.pool.register("enemy", EnemyEntity, true);
|
|
59
|
+
* // ...
|
|
60
|
+
* // when we need to manually create a new bullet:
|
|
61
|
+
* var bullet = me.pool.pull("bullet", x, y, direction);
|
|
62
|
+
* // ...
|
|
63
|
+
* // params aren't a fixed number
|
|
64
|
+
* // when we need new enemy we can add more params, that the object construct requires:
|
|
65
|
+
* var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
|
|
66
|
+
* // ...
|
|
67
|
+
* // when we want to destroy existing object, the remove
|
|
68
|
+
* // function will ensure the object can then be reallocated later
|
|
69
|
+
* me.game.world.removeChild(enemy);
|
|
70
|
+
* me.game.world.removeChild(bullet);
|
|
71
|
+
*/
|
|
72
|
+
pull(name) {
|
|
73
|
+
var args = new Array(arguments.length);
|
|
74
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
75
|
+
args[i] = arguments[i];
|
|
76
|
+
}
|
|
77
|
+
var className = this.objectClass[name];
|
|
78
|
+
if (className) {
|
|
79
|
+
var proto = className["class"],
|
|
80
|
+
poolArray = className.pool,
|
|
81
|
+
obj;
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
if (poolArray && ((obj = poolArray.pop()))) {
|
|
84
|
+
// pull an existing instance from the pool
|
|
85
|
+
args.shift();
|
|
86
|
+
// call the object onResetEvent function if defined
|
|
87
|
+
if (typeof(obj.onResetEvent) === "function") {
|
|
88
|
+
obj.onResetEvent.apply(obj, args);
|
|
89
|
+
}
|
|
90
|
+
this.instance_counter--;
|
|
87
91
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
obj.className = name;
|
|
92
|
+
else {
|
|
93
|
+
// create a new instance
|
|
94
|
+
args[0] = proto;
|
|
95
|
+
obj = new (proto.bind.apply(proto, args))();
|
|
96
|
+
if (poolArray) {
|
|
97
|
+
obj.className = name;
|
|
98
|
+
}
|
|
96
99
|
}
|
|
100
|
+
return obj;
|
|
97
101
|
}
|
|
98
|
-
|
|
102
|
+
throw new Error("Cannot instantiate object of type '" + name + "'");
|
|
99
103
|
}
|
|
100
|
-
throw new Error("Cannot instantiate object of type '" + name + "'");
|
|
101
|
-
};
|
|
102
104
|
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
/**
|
|
106
|
+
* purge the object pool from any inactive object <br>
|
|
107
|
+
* Object pooling must be enabled for this function to work<br>
|
|
108
|
+
* note: this will trigger the garbage collector
|
|
109
|
+
*/
|
|
110
|
+
purge() {
|
|
111
|
+
for (var className in this.objectClass) {
|
|
112
|
+
if (this.objectClass[className]) {
|
|
113
|
+
this.objectClass[className].pool = [];
|
|
114
|
+
}
|
|
113
115
|
}
|
|
116
|
+
this.instance_counter = 0;
|
|
114
117
|
}
|
|
115
|
-
instance_counter = 0;
|
|
116
|
-
};
|
|
117
118
|
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Push back an object instance into the object pool <br>
|
|
121
|
+
* Object pooling for the object class must be enabled,
|
|
122
|
+
* and object must have been instantiated using {@link pool#pull},
|
|
123
|
+
* otherwise this function won't work
|
|
124
|
+
* @throws will throw an error if the object cannot be recycled
|
|
125
|
+
* @param {object} obj instance to be recycled
|
|
126
|
+
* @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
|
|
127
|
+
* @returns {boolean} true if the object was successfully recycled in the object pool
|
|
128
|
+
*/
|
|
129
|
+
push(obj, throwOnError = true) {
|
|
130
|
+
if (!this.poolable(obj)) {
|
|
131
|
+
if (throwOnError === true ) {
|
|
132
|
+
throw new Error("me.pool: object " + obj + " cannot be recycled");
|
|
133
|
+
} else {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
135
136
|
}
|
|
136
|
-
}
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
// store back the object instance for later recycling
|
|
139
|
+
this.objectClass[obj.className].pool.push(obj);
|
|
140
|
+
this.instance_counter++;
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
}
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
144
|
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
145
|
+
/**
|
|
146
|
+
* Check if an object with the provided name is registered
|
|
147
|
+
* @param {string} name of the registered object class
|
|
148
|
+
* @returns {boolean} true if the classname is registered
|
|
149
|
+
*/
|
|
150
|
+
exists(name) {
|
|
151
|
+
return name in this.objectClass;
|
|
152
|
+
};
|
|
154
153
|
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Check if an object is poolable
|
|
156
|
+
* (was properly registered with the recycling feature enable)
|
|
157
|
+
* @see register
|
|
158
|
+
* @param {object} obj object to be checked
|
|
159
|
+
* @returns {boolean} true if the object is poolable
|
|
160
|
+
* @example
|
|
161
|
+
* if (!me.pool.poolable(myCherryEntity)) {
|
|
162
|
+
* // object was not properly registered
|
|
163
|
+
* }
|
|
164
|
+
*/
|
|
165
|
+
poolable(obj) {
|
|
166
|
+
var className = obj.className;
|
|
167
|
+
return (typeof className !== "undefined") &&
|
|
168
|
+
(typeof obj.onResetEvent === "function") &&
|
|
169
|
+
(className in this.objectClass) &&
|
|
170
|
+
(this.objectClass[className].pool !== "undefined");
|
|
171
|
+
|
|
172
|
+
}
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* returns the amount of object instance currently in the pool
|
|
176
|
+
* @returns {number} amount of object instance
|
|
177
|
+
*/
|
|
178
|
+
getInstanceCount() {
|
|
179
|
+
return this.instance_counter;
|
|
180
|
+
}
|
|
174
181
|
};
|
|
175
182
|
|
|
176
183
|
/**
|
|
177
|
-
*
|
|
178
|
-
* @
|
|
179
|
-
* @
|
|
184
|
+
* a default global object pool instance
|
|
185
|
+
* @public
|
|
186
|
+
* @type {ObjectPool}
|
|
180
187
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
188
|
+
var pool = new ObjectPool();
|
|
189
|
+
|
|
190
|
+
export default pool;
|
package/src/text/bitmaptext.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Color from "./../math/color.js";
|
|
2
2
|
import * as stringUtil from "./../utils/string.js";
|
|
3
|
-
import
|
|
3
|
+
import pool from "./../system/pooling.js";
|
|
4
4
|
import loader from "./../loader/loader.js";
|
|
5
5
|
import Renderable from "./../renderable/renderable.js";
|
|
6
6
|
import TextMetrics from "./textmetrics.js";
|
package/src/text/text.js
CHANGED
|
@@ -2,7 +2,7 @@ import Color from "./../math/color.js";
|
|
|
2
2
|
import WebGLRenderer from "./../video/webgl/webgl_renderer.js";
|
|
3
3
|
import { renderer as globalRenderer, createCanvas } from "./../video/video.js";
|
|
4
4
|
import { trimRight } from "./../utils/string.js";
|
|
5
|
-
import
|
|
5
|
+
import pool from "./../system/pooling.js";
|
|
6
6
|
import Renderable from "./../renderable/renderable.js";
|
|
7
7
|
import { nextPowerOfTwo } from "./../math/math.js";
|
|
8
8
|
import setContextStyle from "./textstyle.js";
|