Skip to content

Commit

Permalink
instrumented blast for phet-io, #5
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jun 9, 2017
1 parent 7419a12 commit 2b20319
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 25 deletions.
29 changes: 18 additions & 11 deletions js/blast-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down
10 changes: 6 additions & 4 deletions js/blast/BlastScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
}

Expand Down
5 changes: 3 additions & 2 deletions js/blast/model/BlastModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
14 changes: 11 additions & 3 deletions js/blast/model/Particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions js/blast/view/BlastScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 4 additions & 2 deletions js/blast/view/ParticleNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2b20319

Please sign in to comment.