Skip to content

Commit

Permalink
Added "This exists for the lifetime of the sim and doesn't require di…
Browse files Browse the repository at this point in the history
…sposal." where appropriate, see #191
  • Loading branch information
samreid committed Nov 26, 2018
1 parent 4dee503 commit 2585e81
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 11 deletions.
2 changes: 1 addition & 1 deletion js/common/view/LatticeCanvasNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ define( require => {
* @param {Vector2} point - point in the local coordinate frame
* @returns {Vector2}
*/
localPointToLatticePoint( point ) {
static localPointToLatticePoint( point ) {
return new Vector2( Math.floor( point.x / CELL_WIDTH ), Math.floor( point.y / CELL_WIDTH ) );
}

Expand Down
7 changes: 5 additions & 2 deletions js/common/view/LightEmitterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ define( require => {
*/
constructor( model, waveAreaNode, isPrimarySource ) {
let scene = model.lightScene;
super( model, scene, waveAreaNode, 70, isPrimarySource, new LaserPointerNode( scene.button1PressedProperty, _.extend( {

// This exists for the lifetime of the sim and doesn't require disposal.
const laserPointerNode = new LaserPointerNode( scene.button1PressedProperty, _.extend( {
rightCenter: waveAreaNode.leftCenter.plusXY( 20, 0 )
}, DEFAULTS ) ) );
}, DEFAULTS ) );
super( model, scene, waveAreaNode, 70, isPrimarySource, laserPointerNode );
}

/**
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/SceneToggleNode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2018, University of Colorado Boulder

/**
* A ToggleNode that shows something different for each scene.
* A ToggleNode that shows something different for each scene. All SceneToggleNodes in this sim exist for the lifetime
* of the sim and doesn't require disposal.
*
* @author Sam Reid (PhET Interactive Simulations)
*/
Expand Down
15 changes: 13 additions & 2 deletions js/common/view/SoundParticleDevPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,36 @@ define( require => {
children: [

// TODO: delete or keep? Fine tuning and discussion in https://github.com/phetsims/wave-interference/issues/142
// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'cutoff',
WaveInterferenceConstants.CUTOFF,
new Range( 0, 1 ),
_.extend( { delta: 0.01, decimalPlaces: 2 }, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS )
),

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'randomness',
WaveInterferenceConstants.SOUND_PARTICLE_RANDOMNESS_PROPERTY,
new Range( 0, 30 ),
_.extend( { delta: 0.25, decimalPlaces: 2 }, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS )
),

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'ADJUST home force',
WaveInterferenceConstants.SOUND_PARTICLE_RESTORATION_SCALE,
new Range( 0.1, 2 ),
_.extend( { delta: 0.01, decimalPlaces: 2 }, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS )
), new NumberControl( 'friction (1=none)',
),

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'friction (1=none)',
WaveInterferenceConstants.SOUND_PARTICLE_FRICTION_SCALE_PROPERTY,
new Range( 0.7, 1.0 ),
_.extend( { delta: 0.005, decimalPlaces: 3 }, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS )
), new NumberControl( 'ADJUST gradient force',
),

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'ADJUST gradient force',
WaveInterferenceConstants.SOUND_PARTICLE_GRADIENT_FORCE_SCALE_PROPERTY,
new Range( 0.1, 2 ),
_.extend( { delta: 0.01, decimalPlaces: 2 }, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS )
Expand Down
4 changes: 3 additions & 1 deletion js/common/view/TimeControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ define( require => {
*/
constructor( model, options ) {

// This exists for the lifetime of the sim and doesn't require disposal.
const playPauseButton = new PlayPauseButton( model.isRunningProperty, {
scale: BUTTON_SCALE
} );

// This exists for the lifetime of the sim and doesn't require disposal.
const radioButtonGroup = new WaveInterferenceVerticalAquaRadioButtonGroup( [ {
node: new WaveInterferenceText( normalString ),
value: PlaySpeedEnum.NORMAL,
Expand All @@ -48,7 +50,7 @@ define( require => {
} ] );

const stepButton = new StepButton( {
scale: BUTTON_SCALE
scale: BUTTON_SCALE // TODO: can listener be inlined?
} );

// If we need to move forward further than one frame, call advanceTime several times rather than increasing the
Expand Down
1 change: 1 addition & 0 deletions js/common/view/WaterEmitterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ define( require => {
*/
constructor( model, waveAreaNode, isPrimarySource ) {

// This exists for the lifetime of the sim and doesn't require disposal.
const faucetNode = new FaucetNode(
// This value is irrelevant because we use our own faucet water emitting model, but must be nonzero
// to prevent a divide by zero problem
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/WaveAreaGraphNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ define( require => {
// the bottom tab will fit the largest label.
const horizontalAxisLabel = new SceneToggleNode( model, scene => new WaveInterferenceText( scene.graphHorizontalAxisLabel ) );

// Scene-specific title of the chart
// Scene-specific title of the chart.
const title = new SceneToggleNode( model, scene => new WaveInterferenceText( scene.graphTitle ) );

const HORIZONTAL_LABEL_VERTICAL_MARGIN = 2;
Expand Down Expand Up @@ -85,6 +85,7 @@ define( require => {
);
const lastTickLabel = horizontalAxisTickLabels[ horizontalAxisTickLabels.length - 1 ];
const tickBubbleXMargin = 2;

const verticalAxisLabel = new SceneToggleNode( model, scene => new WaveInterferenceText( scene.verticalAxisTitle ), {
rotation: 3 * Math.PI / 2,
right: -TEXT_MARGIN_Y,
Expand Down
11 changes: 10 additions & 1 deletion js/common/view/WaveInterferenceControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ define( require => {

lightFrequencySlider.centerTop = soundFrequencySlider.centerTop.plusXY( 0, 10 );
const frequencySliderContainer = new Node( { children: [ waterFrequencySlider, soundFrequencySlider, lightFrequencySlider ] } );

const amplitudeSliderContainer = new SceneToggleNode( model, scene => {

// For water scene, control the desiredAmplitude (which determines the size of the water drops)
// For other scenes, control the amplitude directly.
// For other scenes, control the amplitude directly. This exists for the lifetime of the sim and doesn't require disposal.
return new WaveInterferenceSlider( scene.desiredAmplitudeProperty || scene.amplitudeProperty, scene.amplitudeProperty.range.min, scene.amplitudeProperty.range.max );
} );

// This exists for the lifetime of the sim and doesn't require disposal.
const viewSelectionRadioButtonGroup = new VerticalAquaRadioButtonGroup( [ {
node: new WaveInterferenceText( wavesString ),
value: SoundViewType.WAVES,
Expand All @@ -121,9 +123,14 @@ define( require => {
radius: 6.5
}
} );

// This exists for the lifetime of the sim and doesn't require disposal.
const graphCheckbox = new Checkbox( new WaveInterferenceText( graphString ), model.showGraphProperty, CHECKBOX_OPTIONS );

// This exists for the lifetime of the sim and doesn't require disposal.
const screenCheckbox = new Checkbox( new WaveInterferenceText( screenString ), model.showScreenProperty, CHECKBOX_OPTIONS );

// This exists for the lifetime of the sim and doesn't require disposal.
const intensityCheckbox = new Checkbox( new WaveInterferenceText( intensityString ), model.showIntensityGraphProperty, CHECKBOX_OPTIONS );

// Only enable the intensity checkbox when the screen is selected
Expand All @@ -141,6 +148,8 @@ define( require => {

// Create faucet icon, and rasterize to clip out invisible parts (like the ShooterNode)
const sceneIcons = new WaveInterferenceSceneIcons();

// This exists for the lifetime of the sim and doesn't require disposal.
const sceneRadioButtons = new RadioButtonGroup( model.sceneProperty, [
{ value: model.waterScene, node: sceneIcons.faucetIcon },
{ value: model.soundScene, node: sceneIcons.speakerIcon },
Expand Down
2 changes: 2 additions & 0 deletions js/common/view/WaveInterferenceSceneIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ define( require => {
constructor() {

// @public - Faucet icon, and rasterize to clip out invisible parts (like the ShooterNode)
// This exists for the lifetime of the sim and doesn't require disposal.
this.faucetIcon = new FaucetNode( 1, new Property( 0 ), new Property( true ), {
interactiveProperty: new Property( false )
} ).rasterized();
Expand All @@ -30,6 +31,7 @@ define( require => {
this.speakerIcon = new Image( speakerImage );

// @public - Laser Pointer icon
// This exists for the lifetime of the sim and doesn't require disposal.
this.laserPointerIcon = new LaserPointerNode( new BooleanProperty( false ), LightEmitterNode.DEFAULT_OPTIONS );

// Uniform sizing.
Expand Down
3 changes: 2 additions & 1 deletion js/common/view/WaveInterferenceSlider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2018, University of Colorado Boulder

/**
* Slider abstraction for the frequency and amplitude sliders.
* Slider abstraction for the frequency and amplitude sliders. All instances exist for the lifetime of the sim
* and do not require disposal.
*
* @author Sam Reid (PhET Interactive Simulations)
*/
Expand Down
8 changes: 7 additions & 1 deletion js/common/view/WaveMeterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ define( require => {
model.rotationAmountProperty.link( snapToCenter );

// Add the wire behind the probe.
// This exists for the lifetime of the sim and doesn't require disposal.
this.addChild( new WireNode( connectionProperty, new Property( new Vector2( -NORMAL_DISTANCE, 0 ) ),
new NodeProperty( probeNode, 'bounds', 'centerBottom' ), new Property( new Vector2( 0, NORMAL_DISTANCE ) ), {
lineWidth: WIRE_LINE_WIDTH,
Expand All @@ -127,7 +128,7 @@ define( require => {
this.on( 'visibility', alignProbes );
this.alignProbesEmitter.addListener( alignProbes );

const dynamicSeries = new DynamicSeries( { color } );
const dynamicSeries = new DynamicSeries( { color: color } );
dynamicSeries.probeNode = probeNode;

const updateSamples = function() {
Expand Down Expand Up @@ -176,7 +177,10 @@ define( require => {
return dynamicSeries;
};

// This exists for the lifetime of the sim and doesn't require disposal.
const aboveBottomLeft1 = new DerivedProperty( [ leftBottomProperty ], position => position.isFinite() ? position.plusXY( 0, -20 ) : Vector2.ZERO );

// This exists for the lifetime of the sim and doesn't require disposal.
const aboveBottomLeft2 = new DerivedProperty( [ leftBottomProperty ], position => position.isFinite() ? position.plusXY( 0, -10 ) : Vector2.ZERO );
const series1 = initializeSeries( SERIES_1_COLOR, WIRE_1_COLOR, 5, 10, aboveBottomLeft1 );
const series2 = initializeSeries( SERIES_2_COLOR, WIRE_2_COLOR, 36, 54, aboveBottomLeft2 );
Expand All @@ -198,7 +202,9 @@ define( require => {
const timeProperty = new DynamicProperty( model.sceneProperty, {
derive: 'timeProperty'
} );

const scrollingChartNode = new LabeledScrollingChartNode(
// This exists for the lifetime of the sim and doesn't require disposal.
new ScrollingChartNode( timeProperty, [ series1, series2 ], {
width: 150,
height: 110
Expand Down
16 changes: 16 additions & 0 deletions js/diffraction/view/DiffractionScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ define( require => {

// @private
this.model = model;

// This exists for the lifetime of the sim and doesn't require disposal.
const laserPointerNode = new LaserPointerNode( model.onProperty, {
left: 10,
centerY: 50,
Expand All @@ -72,6 +74,8 @@ define( require => {
value: 'circle',
node: new Circle( 10, { fill: 'black' } )
} ];

// This exists for the lifetime of the sim and doesn't require disposal.
const radioButtonGroup = new RadioButtonGroup( model.sceneProperty, toggleButtonsContent, {
left: 10,
bottom: this.layoutBounds.bottom - 10
Expand Down Expand Up @@ -129,9 +133,13 @@ define( require => {
this.squareControlPanel = new Panel( new VBox( {
spacing: BOX_SPACING,
children: [

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'width', model.squareWidthProperty, new Range( 2, 30 ), _.extend( {
delta: 2 // avoid odd/even artifacts
}, NUMBER_CONTROL_OPTIONS ) ),

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'height', model.squareHeightProperty, new Range( 2, 30 ), _.extend( {
delta: 2 // avoid odd/even artifacts
}, NUMBER_CONTROL_OPTIONS ) ) ]
Expand All @@ -143,7 +151,11 @@ define( require => {
this.gaussianControlPanel = new Panel( new VBox( {
spacing: BOX_SPACING,
children: [

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'sigmaX', model.sigmaXProperty, new Range( 2, 10 ), NUMBER_CONTROL_OPTIONS ),

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'sigmaY', model.sigmaYProperty, new Range( 2, 10 ), NUMBER_CONTROL_OPTIONS )
]
} ), _.extend( {
Expand All @@ -154,7 +166,11 @@ define( require => {
this.slitsControlPanel = new Panel( new VBox( {
spacing: BOX_SPACING,
children: [

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'number of lines', model.numberOfLinesProperty, new Range( 2, 200 ), NUMBER_CONTROL_OPTIONS ),

// This exists for the lifetime of the sim and doesn't require disposal.
new NumberControl( 'angle', model.angleProperty, new Range( 0, Math.PI * 2 ), _.extend( {
delta: 0.01
}, NUMBER_CONTROL_OPTIONS ) )
Expand Down
8 changes: 8 additions & 0 deletions js/interference/view/InterferenceScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ define( require => {

const createLabelText = string => new WaveInterferenceText( string, { fontSize: 10 } );

// This exists for the lifetime of the sim and doesn't require disposal.
// TODO: use SceneToggleNode?
const toggleNode = new ToggleNode( model.sceneProperty, [ {
value: model.waterScene,

// This exists for the lifetime of the sim and doesn't require disposal.
node: new NumberControl( separationString, model.waterScene.desiredSourceSeparationProperty, new Range( 1, 5 ), _.extend( {
delta: 1,
valuePattern: cmValueString,
Expand All @@ -45,6 +49,8 @@ define( require => {
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
}, {
value: model.soundScene,

// This exists for the lifetime of the sim and doesn't require disposal.
node: new NumberControl( separationString, model.soundScene.sourceSeparationProperty, new Range( 100, 200 ), _.extend( {
delta: 5,
valuePattern: cmValueString,
Expand All @@ -54,6 +60,8 @@ define( require => {
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) )
}, {
value: model.lightScene,

// This exists for the lifetime of the sim and doesn't require disposal.
node: new NumberControl( separationString, model.lightScene.sourceSeparationProperty, new Range( 500, 2500 ), _.extend( {
delta: 500,
valuePattern: nmValueString,
Expand Down
1 change: 1 addition & 0 deletions js/slits/view/BarriersNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ define( require => {
// @private - Convert from model coordinates to view coordinates
this.modelViewTransform = ModelViewTransform2.createRectangleMapping( this.scene.getWaveAreaBounds(), viewBounds );

// This exists for the lifetime of the sim and doesn't require disposal.
this.addInputListener( new DragListener( {
locationProperty: scene.barrierLocationProperty,
transform: this.modelViewTransform,
Expand Down
17 changes: 17 additions & 0 deletions js/slits/view/SlitsControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ define( require => {
derive: 'barrierTypeProperty',
bidirectional: true
} );

// This exists for the lifetime of the sim and doesn't require disposal.
const comboBox = new ComboBox( [
ComboBox.createItem( new WaveInterferenceText( noBarrierString ), BarrierTypeEnum.NO_BARRIER ),
ComboBox.createItem( new WaveInterferenceText( oneSlitString ), BarrierTypeEnum.ONE_SLIT ),
Expand All @@ -60,22 +62,30 @@ define( require => {
];

const waterRange = new Range( 0, 5 );

// This exists for the lifetime of the sim and doesn't require disposal.
const waterSlitWidthControl = new NumberControl( slitWidthString, model.waterScene.slitWidthProperty, waterRange, _.extend( {
valuePattern: cmValueString,
majorTicks: createTicks( waterRange )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const soundRange = new Range( 0, 100 );

// This exists for the lifetime of the sim and doesn't require disposal.
const soundSlitWidthControl = new NumberControl( slitWidthString, model.soundScene.slitWidthProperty, soundRange, _.extend( {
valuePattern: cmValueString,
majorTicks: createTicks( soundRange )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const lightRange = new Range( 0, 2000 );

// This exists for the lifetime of the sim and doesn't require disposal.
const lightSlitWidthControl = new NumberControl( slitWidthString, model.lightScene.slitWidthProperty, lightRange, _.extend( {
valuePattern: nmValueString,
majorTicks: createTicks( lightRange )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

// This exists for the lifetime of the sim and doesn't require disposal.
const slitWidthControl = new ToggleNode( model.sceneProperty, [
{ value: model.waterScene, node: waterSlitWidthControl },
{ value: model.soundScene, node: soundSlitWidthControl },
Expand All @@ -89,23 +99,30 @@ define( require => {
} );

const waterSeparationRange = new Range( 0, 5 );

// This exists for the lifetime of the sim and doesn't require disposal.
const waterSeparationControl = new NumberControl( slitSeparationString, model.waterScene.slitSeparationProperty, waterSeparationRange, _.extend( {
valuePattern: cmValueString,
majorTicks: createTicks( waterSeparationRange )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const soundSeparationRange = new Range( 0, 200 );

// This exists for the lifetime of the sim and doesn't require disposal.
const soundSeparationControl = new NumberControl( slitSeparationString, model.soundScene.slitSeparationProperty, soundSeparationRange, _.extend( {
valuePattern: cmValueString,
majorTicks: createTicks( soundSeparationRange )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

const lightSeparationRange = new Range( 0, 2000 );

// This exists for the lifetime of the sim and doesn't require disposal.
const lightSeparationControl = new NumberControl( slitSeparationString, model.lightScene.slitSeparationProperty, lightSeparationRange, _.extend( {
valuePattern: nmValueString,
majorTicks: createTicks( lightSeparationRange )
}, WaveInterferenceConstants.NUMBER_CONTROL_OPTIONS ) );

// This exists for the lifetime of the sim and doesn't require disposal.
const slitSeparationControl = new ToggleNode( model.sceneProperty, [
{ value: model.waterScene, node: waterSeparationControl },
{ value: model.soundScene, node: soundSeparationControl },
Expand Down
Loading

0 comments on commit 2585e81

Please sign in to comment.