Skip to content

Commit

Permalink
Converting away from Poolable2 => Pool, see phetsims/phet-core#103
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Mar 3, 2022
1 parent 3d773a8 commit 67bcb64
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion js/display/RelativeTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ class RelativeTransform {
// get the relative matrix, computed to be up-to-date, and ignores any flags/counts so we can check whether our
// state is consistent
function currentRelativeMatrix( instance ) {
const resultMatrix = Matrix3.dirtyFromPool();
const resultMatrix = Matrix3.pool.fetch();
const nodeMatrix = instance.node.getMatrix();

if ( !instance.parent ) {
Expand Down
2 changes: 1 addition & 1 deletion js/display/drawables/CircleDOMDrawable.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CircleDOMDrawable extends CircleStatefulDrawable( DOMSelfDrawable ) {
super.initialize( renderer, instance );

// @protected {Matrix3} - We need to store an independent matrix, as our CSS transform actually depends on the radius.
this.matrix = this.matrix || Matrix3.dirtyFromPool();
this.matrix = this.matrix || Matrix3.pool.fetch();

// only create elements if we don't already have them (we pool visual states always, and depending on the platform may also pool the actual elements to minimize
// allocation and performance costs)
Expand Down
2 changes: 1 addition & 1 deletion js/display/drawables/RectangleDOMDrawable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { scenery, Features, Utils, DOMSelfDrawable, RectangleStatefulDrawable }
const keepDOMRectangleElements = true; // whether we should pool DOM elements for the DOM rendering states, or whether we should free them when possible for memory

// scratch matrix used in DOM rendering
const scratchMatrix = Matrix3.dirtyFromPool();
const scratchMatrix = Matrix3.pool.fetch();

class RectangleDOMDrawable extends RectangleStatefulDrawable( DOMSelfDrawable ) {
/**
Expand Down
2 changes: 1 addition & 1 deletion js/display/drawables/TextDOMDrawable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { scenery, Utils, DOMSelfDrawable, TextStatefulDrawable } from '../../imp
const keepDOMTextElements = true; // whether we should pool DOM elements for the DOM rendering states, or whether we should free them when possible for memory

// scratch matrix used in DOM rendering
const scratchMatrix = Matrix3.dirtyFromPool();
const scratchMatrix = Matrix3.pool.fetch();

class TextDOMDrawable extends TextStatefulDrawable( DOMSelfDrawable ) {
/**
Expand Down
16 changes: 9 additions & 7 deletions js/input/BatchedDOMEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import Enumeration from '../../../phet-core/js/Enumeration.js';
import EnumerationValue from '../../../phet-core/js/EnumerationValue.js';
import Poolable2 from '../../../phet-core/js/Poolable2.js';
import { scenery, Input } from '../imports.js';
import Pool, { IPoolable } from '../../../phet-core/js/Pool.js';
import { Input, scenery } from '../imports.js';

type BatchedDOMEventCallback = ( ...args: any[] ) => void;

Expand All @@ -26,15 +26,13 @@ class BatchedDOMEventType extends EnumerationValue {
} );
}

class BatchedDOMEvent extends Poolable2<[Event, BatchedDOMEventType, ( ...args: any[] ) => void], BatchedDOMEvent>( Object ) { // eslint-disable-line
class BatchedDOMEvent implements IPoolable {

domEvent!: Event | null;
type!: BatchedDOMEventType | null;
callback!: BatchedDOMEventCallback | null;

constructor( domEvent: Event, type: BatchedDOMEventType, callback: BatchedDOMEventCallback ) {
super();

this.initialize( domEvent, type, callback );
}

Expand Down Expand Up @@ -103,9 +101,13 @@ class BatchedDOMEvent extends Poolable2<[Event, BatchedDOMEventType, ( ...args:
this.callback = null;
this.freeToPool();
}
}

BatchedDOMEvent.initializePool();
freeToPool() {
BatchedDOMEvent.pool.freeToPool( this );
}

static pool = new Pool( BatchedDOMEvent );
}

scenery.register( 'BatchedDOMEvent', BatchedDOMEvent );

Expand Down
4 changes: 2 additions & 2 deletions js/input/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ class Input {

// If our display is not interactive, do not respond to any events (but still prevent default)
if ( this.display.interactive ) {
this.batchedEvents.push( BatchedDOMEvent.createFromPool( domEvent, batchType, callback ) );
this.batchedEvents.push( BatchedDOMEvent.pool.create( domEvent, batchType, callback ) );
if ( triggerImmediate || !this.batchDOMEvents ) {
this.fireBatchedEvents();
}
Expand Down Expand Up @@ -951,7 +951,7 @@ class Input {
* Extract a {Vector2} global coordinate point from an arbitrary DOM event. (scenery-internal)
*/
pointFromEvent( domEvent: MouseEvent | WindowTouch ): Vector2 {
const position = Vector2.createFromPool( domEvent.clientX, domEvent.clientY );
const position = Vector2.pool.create( domEvent.clientX, domEvent.clientY );
if ( !this.assumeFullWindow ) {
const domBounds = this.display.domElement.getBoundingClientRect();

Expand Down
2 changes: 1 addition & 1 deletion js/util/LinearGradient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LinearGradient extends Gradient {
* Creates an SVG paint object for creating/updating the SVG equivalent definition.
*/
createSVGPaint( svgBlock: SVGBlock ): SVGLinearGradient {
return SVGLinearGradient.pool.createFromPool( svgBlock, this );
return SVGLinearGradient.pool.create( svgBlock, this );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/util/Pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Pattern extends Paint {
* Creates an SVG paint object for creating/updating the SVG equivalent definition.
*/
createSVGPaint( svgBlock: SVGBlock ): SVGPattern {
return SVGPattern.pool.createFromPool( this );
return SVGPattern.pool.create( this );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/util/RadialGradient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class RadialGradient extends Gradient {
* Creates an SVG paint object for creating/updating the SVG equivalent definition.
*/
createSVGPaint( svgBlock: SVGBlock ): SVGRadialGradient {
return SVGRadialGradient.pool.createFromPool( svgBlock, this );
return SVGRadialGradient.pool.create( svgBlock, this );
}

/**
Expand Down

0 comments on commit 67bcb64

Please sign in to comment.