Skip to content

Commit 45a3a77

Browse files
committed
new pool system improvements
- add the option to use a destroy() method when pushed back into the pool (to mimic the legacy pool implementation) - rename internal import from pool to legacy_pool (internally only) - migrate tween objects to the new pool implementation - pass color arguments directly to the colorPool getter in Camera2d - export createPool directly under pools
1 parent 3e00d76 commit 45a3a77

File tree

17 files changed

+79
-30
lines changed

17 files changed

+79
-30
lines changed

packages/melonjs/src/camera/camera2d.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Matrix2d } from "../math/matrix2d.ts";
44
import { Matrix3d } from "../math/matrix3d.ts";
55
import { Rect } from "./../geometries/rectangle.ts";
66
import { renderer } from "./../video/video.js";
7-
import pool from "./../system/pooling.js";
87
import Renderable from "./../renderable/renderable.js";
98
import { clamp, toBeCloseTo } from "./../math/math.ts";
109
import { game } from "../index.js";
@@ -17,6 +16,7 @@ import {
1716
} from "../system/event.ts";
1817
import { boundsPool } from "./../physics/bounds.ts";
1918
import { colorPool } from "../math/color.ts";
19+
import { tweenPool } from "../tweens/tween.ts";
2020

2121
/**
2222
* @import {Bounds} from "./../physics/bounds.ts";
@@ -520,9 +520,9 @@ export default class Camera2d extends Renderable {
520520
* });
521521
*/
522522
fadeOut(color, duration = 1000, onComplete) {
523-
this._fadeOut.color = colorPool.get().copy(color);
524-
this._fadeOut.tween = pool
525-
.pull("Tween", this._fadeOut.color)
523+
this._fadeOut.color = colorPool.get(color);
524+
this._fadeOut.tween = tweenPool
525+
.get(this._fadeOut.color)
526526
.to({ alpha: 0.0 }, { duration })
527527
.onComplete(onComplete || null);
528528
this._fadeOut.tween.isPersistent = true;
@@ -540,11 +540,11 @@ export default class Camera2d extends Renderable {
540540
* me.game.viewport.fadeIn("#FFFFFF", 75);
541541
*/
542542
fadeIn(color, duration = 1000, onComplete) {
543-
this._fadeIn.color = colorPool.get().copy(color);
543+
this._fadeIn.color = colorPool.get(color);
544544
const _alpha = this._fadeIn.color.alpha;
545545
this._fadeIn.color.alpha = 0.0;
546-
this._fadeIn.tween = pool
547-
.pull("Tween", this._fadeIn.color)
546+
this._fadeIn.tween = tweenPool
547+
.get(this._fadeIn.color)
548548
.to({ alpha: _alpha }, { duration })
549549
.onComplete(onComplete || null);
550550
this._fadeIn.tween.isPersistent = true;

packages/melonjs/src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import Application from "./application/application.js";
5656
import { cache as plugins } from "./plugin/plugin.js";
5757
import save from "./system/save.ts";
5858
import timer from "./system/timer.ts";
59-
import pool from "./system/pooling.js";
59+
import pool from "./system/legacy_pool.js";
6060
import state from "./state/state.js";
6161
import { BOOT, DOM_READY, eventEmitter } from "./system/event.ts";
6262
import { setNocache } from "./loader/loader.js";
@@ -203,7 +203,6 @@ export function boot() {
203203
pool.register("me.Collectable", Collectable);
204204
pool.register("me.Trigger", Trigger);
205205
pool.register("me.Light2d", Light2d);
206-
pool.register("me.Tween", Tween, true);
207206
pool.register("me.Particle", Particle, true);
208207
pool.register("me.Sprite", Sprite);
209208
pool.register("me.NineSliceSprite", NineSliceSprite);

packages/melonjs/src/level/tiled/TMXTileMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pool from "./../../system/pooling.js";
1+
import pool from "../../system/legacy_pool.js";
22
import { game } from "../../index.js";
33
import { checkVersion } from "./../../utils/utils.ts";
44
import { collision } from "./../../physics/collision.js";

packages/melonjs/src/particles/emitter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pool from "./../system/pooling.js";
1+
import pool from "../system/legacy_pool.js";
22
import ParticleEmitterSettings from "./settings.js";
33
import { randomFloat } from "./../math/math.ts";
44
import Container from "./../renderable/container.js";

packages/melonjs/src/physics/body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Rect } from "./../geometries/rectangle.ts";
22
import { Ellipse } from "./../geometries/ellipse.ts";
33
import { Polygon, polygonPool } from "../geometries/polygon.ts";
44
import { Bounds, boundsPool } from "./bounds.ts";
5-
import pool from "./../system/pooling.js";
5+
import pool from "../system/legacy_pool.js";
66
import { collision } from "./collision.js";
77
import timer from "./../system/timer.ts";
88
import { clamp } from "./../math/math.ts";

packages/melonjs/src/pool.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { matrix3dPool } from "./math/matrix3d";
1010
import { vector2dPool } from "./math/vector2d";
1111
import { vector3dPool } from "./math/vector3d";
1212
import { boundsPool } from "./physics/bounds";
13+
import { tweenPool } from "./tweens/tween";
1314

1415
const pools = {
1516
vector2d: vector2dPool,
@@ -24,10 +25,13 @@ const pools = {
2425
rectangle: rectPool,
2526
roundedRectangle: roundedRectanglePool,
2627
ellipse: ellipsePool,
28+
tween: tweenPool,
2729
} as const;
2830

2931
type PoolKey = keyof typeof pools;
3032

3133
export const getPool = <K extends PoolKey>(key: K): (typeof pools)[K] => {
3234
return pools[key];
3335
};
36+
37+
export { createPool } from "./system/pool";

packages/melonjs/src/renderable/container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Renderable from "./renderable.js";
22
import { createGUID } from "../utils/utils";
33
import { defer } from "../utils/function";
44
import { game } from "../index.js";
5-
import pool from "../system/pooling.js";
5+
import pool from "../system/legacy_pool.js";
66
import state from "../state/state.js";
77
import Body from "../physics/body.js";
88
import { CANVAS_ONRESIZE, eventEmitter } from "../system/event.ts";

packages/melonjs/src/renderable/light2d.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ellipsePool } from "./../geometries/ellipse.ts";
22
import { colorPool } from "./../math/color.ts";
3-
import pool from "./../system/pooling.js";
3+
import pool from "../system/legacy_pool.js";
44
import Renderable from "./renderable.js";
55

66
/**

packages/melonjs/src/renderable/renderable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Rect } from "./../geometries/rectangle.ts";
2-
import pool from "./../system/pooling.js";
2+
import pool from "../system/legacy_pool.js";
33
import { releaseAllPointerEvents } from "./../input/input.js";
44
import { clamp } from "./../math/math.ts";
55
import Body from "./../physics/body.js";

packages/melonjs/src/renderable/text/bitmaptext.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Color } from "../../math/color.ts";
2-
import pool from "../../system/pooling.js";
2+
import pool from "../../system/legacy_pool.js";
33
import { getImage, getBinary } from "../../loader/loader.js";
44
import Renderable from "../renderable.js";
55
import TextMetrics from "./textmetrics.js";

0 commit comments

Comments
 (0)