From 2b20319ab8eca8c62a6d3cd938d27ec0517c6291 Mon Sep 17 00:00:00 2001 From: zepumph Date: Fri, 9 Jun 2017 13:50:53 -0800 Subject: [PATCH] instrumented blast for phet-io, https://github.com/phetsims/blast/issues/5 --- js/blast-main.js | 29 ++++++++++++++++++----------- js/blast/BlastScreen.js | 10 ++++++---- js/blast/model/BlastModel.js | 5 +++-- js/blast/model/Particle.js | 14 +++++++++++--- js/blast/view/BlastScreenView.js | 7 ++++--- js/blast/view/ParticleNode.js | 6 ++++-- 6 files changed, 46 insertions(+), 25 deletions(-) diff --git a/js/blast-main.js b/js/blast-main.js index 25d8741..1e0b617 100644 --- a/js/blast-main.js +++ b/js/blast-main.js @@ -13,25 +13,32 @@ define( function( require ) { var Sim = require( 'JOIST/Sim' ); var BlastScreen = require( 'BLAST/blast/BlastScreen' ); var Property = require( 'AXON/Property' ); + var Tandem = require( 'TANDEM/Tandem' ); // strings var blastTitleString = require( 'string!BLAST/blast.title' ); SimLauncher.launch( function() { + var tandem = Tandem.createRootTandem(); + // add 2 instances of the same screen for memory leak testing, see phetsims/tasks#546. var screens = [ - new BlastScreen( { - name: 'Blast 1', - backgroundColorProperty: new Property( 'white' ), - particleColor: 'red' - } ), - new BlastScreen( { - name: 'Blast 2', - backgroundColorProperty: new Property( 'rgb( 255, 227, 204 )' ), - particleColor: 'green' - } ) - ]; + new BlastScreen( tandem.createTandem( 'blast1Screen' ), + { + name: 'Blast 1', + backgroundColorProperty: new Property( 'white' ), + particleColor: 'red' + } + ), + new BlastScreen( tandem.createTandem( 'blast2Screen' ), + { + name: 'Blast 2', + backgroundColorProperty: new Property( 'rgb( 255, 227, 204 )' ), + particleColor: 'green' + } ) + ] + ; new Sim( blastTitleString, screens ).start(); } ); diff --git a/js/blast/BlastScreen.js b/js/blast/BlastScreen.js index 304ffe3..0ef7563 100644 --- a/js/blast/BlastScreen.js +++ b/js/blast/BlastScreen.js @@ -17,13 +17,15 @@ define( function( require ) { var Screen = require( 'JOIST/Screen' ); /** + * @param {Tandem} tandem * @param {Object} [options] * @constructor */ - function BlastScreen( options ) { + function BlastScreen( tandem, options ) { options = _.extend( { - particleColor: 'black' + particleColor: 'black', + tandem: tandem }, options ); assert && assert( !options.homeScreenIcon ); @@ -32,8 +34,8 @@ define( function( require ) { } ); Screen.call( this, - function() { return new BlastModel(); }, - function( model ) { return new BlastScreenView( model, options.particleColor ); }, + function() { return new BlastModel( tandem ); }, + function( model ) { return new BlastScreenView( model, options.particleColor, tandem ); }, options ); } diff --git a/js/blast/model/BlastModel.js b/js/blast/model/BlastModel.js index bbca19a..6ea8e15 100644 --- a/js/blast/model/BlastModel.js +++ b/js/blast/model/BlastModel.js @@ -14,10 +14,11 @@ define( function( require ) { var inherit = require( 'PHET_CORE/inherit' ); /** + * @param {Tandem} tandem * @constructor */ - function BlastModel() { - this.particle = new Particle(); // @public + function BlastModel( tandem ) { + this.particle = new Particle( tandem ); // @public } blast.register( 'BlastModel', BlastModel ); diff --git a/js/blast/model/Particle.js b/js/blast/model/Particle.js index b420ee8..ceb4ab5 100644 --- a/js/blast/model/Particle.js +++ b/js/blast/model/Particle.js @@ -12,15 +12,23 @@ define( function( require ) { var blast = require( 'BLAST/blast' ); var inherit = require( 'PHET_CORE/inherit' ); var Property = require( 'AXON/Property' ); + var TNumber = require( 'ifphetio!PHET_IO/types/TNumber' ); /** * @constructor + * @param {Tandem} tandem */ - function Particle() { + function Particle( tandem ) { // @public - this.xProperty = new Property( 50 ); - this.velocityProperty = new Property( 5 ); + this.xProperty = new Property( 50, { + tandem: tandem.createTandem( 'xProperty' ), + phetioValueType: TNumber() + } ); + this.velocityProperty = new Property( 5, { + tandem: tandem.createTandem( 'velocityProperty' ), + phetioValueType: TNumber() + } ); // @public (read-only) y is constant this.y = 50; diff --git a/js/blast/view/BlastScreenView.js b/js/blast/view/BlastScreenView.js index 24fac51..a661f2d 100644 --- a/js/blast/view/BlastScreenView.js +++ b/js/blast/view/BlastScreenView.js @@ -17,11 +17,12 @@ define( function( require ) { /** * @param {BlastModel} model * @param {Color|string} particleColor + * @param {Tandem} tandem * @constructor */ - function BlastScreenView( model, particleColor ) { - ScreenView.call( this, { cssTransform: true } ); - this.addChild( new ParticleNode( model.particle, particleColor ) ); + function BlastScreenView( model, particleColor, tandem ) { + ScreenView.call( this, { cssTransform: true, tandem: tandem } ); + this.addChild( new ParticleNode( model.particle, particleColor, tandem.createTandem( 'particleNode' ) ) ); } blast.register( 'BlastScreenView', BlastScreenView ); diff --git a/js/blast/view/ParticleNode.js b/js/blast/view/ParticleNode.js index f7629bf..4c4a77f 100644 --- a/js/blast/view/ParticleNode.js +++ b/js/blast/view/ParticleNode.js @@ -19,14 +19,16 @@ define( function( require ) { /** * @param {Particle} particle * @param {String|color} color + * @param {Tandem} tandem * @constructor */ - function ParticleNode( particle, color ) { + function ParticleNode( particle, color, tandem ) { Rectangle.call( this, -PARTICLE_SIZE / 2, 0, PARTICLE_SIZE, PARTICLE_SIZE, { x: particle.x, y: particle.y, - fill: color + fill: color, + tandem: tandem } ); var self = this;