Skip to content

Commit

Permalink
Pooling improvements for phetsims/phet-core#103
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Mar 1, 2023
1 parent f563cec commit aeaeeb6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
9 changes: 8 additions & 1 deletion js/display/SVGLinearGradient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import Pool, { TPoolable } from '../../../phet-core/js/Pool.js';
import { LinearGradient, scenery, SVGBlock, SVGGradient, svgns } from '../imports.js';

export default class SVGLinearGradient extends SVGGradient implements TPoolable {
public override initialize( svgBlock: SVGBlock, gradient: LinearGradient ): void {

public constructor( svgBlock: SVGBlock, gradient: LinearGradient ) {
super( svgBlock, gradient );
}

public override initialize( svgBlock: SVGBlock, gradient: LinearGradient ): this {
sceneryLog && sceneryLog.Paints && sceneryLog.Paints( `[SVGLinearGradient] initialize ${gradient.id}` );
sceneryLog && sceneryLog.Paints && sceneryLog.push();

Expand All @@ -37,6 +42,8 @@ export default class SVGLinearGradient extends SVGGradient implements TPoolable
this.definition.setAttribute( 'y2', '' + linearGradient.end.y );

sceneryLog && sceneryLog.Paints && sceneryLog.pop();

return this;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions js/display/SVGRadialGradient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import Pool, { TPoolable } from '../../../phet-core/js/Pool.js';
import { RadialGradient, scenery, SVGBlock, SVGGradient, svgns } from '../imports.js';

export default class SVGRadialGradient extends SVGGradient implements TPoolable {

public constructor( svgBlock: SVGBlock, gradient: RadialGradient ) {
super( svgBlock, gradient );
}

public override initialize( svgBlock: SVGBlock, radialGradient: RadialGradient ): this {
sceneryLog && sceneryLog.Paints && sceneryLog.Paints( `[SVGRadialGradient] initialize ${radialGradient.id}` );
sceneryLog && sceneryLog.Paints && sceneryLog.push();
Expand Down
4 changes: 3 additions & 1 deletion js/input/BatchedDOMEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export default class BatchedDOMEvent implements TPoolable {
this.initialize( domEvent, type, callback );
}

public initialize( domEvent: Event, type: BatchedDOMEventType, callback: BatchedDOMEventCallback ): void {
public initialize( domEvent: Event, type: BatchedDOMEventType, callback: BatchedDOMEventCallback ): this {
// called multiple times due to pooling, this should be re-entrant
assert && assert( domEvent, 'for some reason, there is no DOM event?' );

this.domEvent = domEvent;
this.type = type;
this.callback = callback;

return this;
}

public run( input: Input ): void {
Expand Down
4 changes: 3 additions & 1 deletion js/layout/LayoutProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ export default class LayoutProxy {
*
* DO not call it twice without in-between disposals (follow the above pattern).
*/
public initialize( trail: Trail ): void {
public initialize( trail: Trail ): this {
this.trail = trail;

return this;
}

private checkPreconditions(): void {
Expand Down
6 changes: 4 additions & 2 deletions js/layout/constraints/FlowLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export default class FlowLine extends LayoutLine {
/**
* (scenery-internal)
*/
public initialize( orientation: Orientation, cells: FlowCell[] ): void {
public initialize( orientation: Orientation, cells: FlowCell[] ): this {

this.orientation = orientation;
this.cells = cells;

this.initializeLayoutLine();

return this;
}

/**
Expand All @@ -53,7 +55,7 @@ export default class FlowLine extends LayoutLine {
/**
* (scenery-internal)
*/
public static readonly pool = new Pool<typeof FlowLine, [Orientation, FlowCell[]]>( FlowLine, {
public static readonly pool = new Pool( FlowLine, {
defaultArguments: [ Orientation.HORIZONTAL, [] ]
} );
}
Expand Down
6 changes: 4 additions & 2 deletions js/layout/constraints/GridLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ export default class GridLine extends LayoutLine {
/**
* (scenery-internal)
*/
public initialize( index: number, cells: GridCell[], grow: number ): void {
public initialize( index: number, cells: GridCell[], grow: number ): this {
this.index = index;

this.cells = cells;

this.grow = grow;

this.initializeLayoutLine();

return this;
}

/**
Expand All @@ -48,7 +50,7 @@ export default class GridLine extends LayoutLine {
/**
* (scenery-internal)
*/
public static readonly pool = new Pool<typeof GridLine, [number, GridCell[], number]>( GridLine, {
public static readonly pool = new Pool( GridLine, {
defaultArguments: [ 0, [], 0 ]
} );
}
Expand Down
4 changes: 3 additions & 1 deletion js/util/SpriteInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export default class SpriteInstance {
/**
* For pooling. Please use SpriteInstance.dirtyFromPool() to grab a copy
*/
private initialize(): void {
public initialize(): this {
// We need an empty initialization method here, so that we can grab dirty versions and use them for higher
// performance.

return this;
}

/**
Expand Down

0 comments on commit aeaeeb6

Please sign in to comment.