@@ -28,7 +28,6 @@ import inherit from '../../../../phet-core/js/inherit.js';
28
28
import TimeSpeed from '../../../../scenery-phet/js/TimeSpeed.js' ;
29
29
import PhetioGroup from '../../../../tandem/js/PhetioGroup.js' ;
30
30
import PhetioObject from '../../../../tandem/js/PhetioObject.js' ;
31
- import IOType from '../../../../tandem/js/types/IOType.js' ;
32
31
import NumberIO from '../../../../tandem/js/types/NumberIO.js' ;
33
32
import moleculesAndLight from '../../moleculesAndLight.js' ;
34
33
import Molecule from './Molecule.js' ;
@@ -128,12 +127,6 @@ function PhotonAbsorptionModel( initialPhotonTarget, tandem ) {
128
127
// @public - convenience Property, indicating whether sim is running in slow motion
129
128
this . slowMotionProperty = new DerivedProperty ( [ this . timeSpeedProperty ] , speed => speed === TimeSpeed . SLOW ) ;
130
129
131
- // @public
132
- this . photons = createObservableArray ( {
133
- tandem : tandem . createTandem ( 'photons' ) ,
134
- phetioType : createObservableArray . ObservableArrayIO ( Photon . PhotonIO )
135
- } ) ; // Elements are of type Photon
136
-
137
130
this . activeMolecules = createObservableArray ( {
138
131
tandem : tandem . createTandem ( 'molecules' ) ,
139
132
phetioType : createObservableArray . ObservableArrayIO ( Molecule . MoleculeIO )
@@ -162,11 +155,7 @@ function PhotonAbsorptionModel( initialPhotonTarget, tandem ) {
162
155
this . photonEmissionCountdownTimer = Number . POSITIVE_INFINITY ; // @private
163
156
this . photonEmissionPeriodTarget = DEFAULT_PHOTON_EMISSION_PERIOD ; // @private
164
157
165
- PhetioObject . call ( this , {
166
- tandem : tandem ,
167
- phetioType : PhotonAbsorptionModel . PhotonAbsorptionModelIO ,
168
- phetioState : false
169
- } ) ;
158
+ PhetioObject . call ( this ) ;
170
159
}
171
160
172
161
moleculesAndLight . register ( 'PhotonAbsorptionModel' , PhotonAbsorptionModel ) ;
@@ -206,9 +195,6 @@ inherit( PhetioObject, PhotonAbsorptionModel, {
206
195
*/
207
196
resetPhotons ( ) {
208
197
209
- // Remove and dispose any photons that are currently in transit.
210
- this . photons . clear ( ) ;
211
-
212
198
// If setting state, the state engine will do this step.
213
199
if ( ! phet . joist . sim . isSettingPhetioStateProperty . value ) {
214
200
this . photonGroup . clear ( ) ;
@@ -282,8 +268,8 @@ inherit( PhetioObject, PhotonAbsorptionModel, {
282
268
const photonsToRemove = [ ] ;
283
269
284
270
// check for possible interaction between each photon and molecule
285
- this . photons . forEach ( function ( photon ) {
286
- self . activeMolecules . forEach ( function ( molecule ) {
271
+ this . photonGroup . forEach ( photon => {
272
+ self . activeMolecules . forEach ( molecule => {
287
273
if ( molecule . queryAbsorbPhoton ( photon ) ) {
288
274
289
275
// the photon was absorbed, so put it on the removal list
@@ -294,15 +280,11 @@ inherit( PhetioObject, PhotonAbsorptionModel, {
294
280
} ) ;
295
281
296
282
// Remove any photons that were marked for removal.
297
- this . photons . removeAll ( photonsToRemove ) ;
298
- for ( let i = 0 ; i < photonsToRemove . length ; i ++ ) {
299
- this . photonGroup . disposeElement ( photonsToRemove [ i ] ) ;
300
- }
283
+ photonsToRemove . forEach ( photon => this . photonGroup . disposeElement ( photon ) ) ;
301
284
} ,
302
285
303
286
clearPhotons : function ( ) {
304
287
this . photonGroup . clear ( ) ;
305
- this . photons . clear ( ) ;
306
288
} ,
307
289
308
290
/**
@@ -349,7 +331,6 @@ inherit( PhetioObject, PhotonAbsorptionModel, {
349
331
photon . positionProperty . set ( new Vector2 ( PHOTON_EMISSION_POSITION . x + PHOTON_VELOCITY * advanceAmount , PHOTON_EMISSION_POSITION . y ) ) ;
350
332
const emissionAngle = 0 ; // Straight to the right.
351
333
photon . setVelocity ( PHOTON_VELOCITY * Math . cos ( emissionAngle ) , PHOTON_VELOCITY * Math . sin ( emissionAngle ) ) ;
352
- this . photons . add ( photon ) ;
353
334
354
335
// indicate that a photon has been emitted from the initial emission point
355
336
this . photonEmittedEmitter . emit ( photon ) ;
@@ -390,7 +371,8 @@ inherit( PhetioObject, PhotonAbsorptionModel, {
390
371
// so that the user doesn't have to wait too long in order to see something come out, but only if there
391
372
// are no other photons in the observation window so we don't emit unlimitted photons when turning
392
373
// on/off rapidly
393
- if ( this . photonEmissionPeriodTarget === Number . POSITIVE_INFINITY && photonEmissionPeriod !== Number . POSITIVE_INFINITY && this . photons . length === 0 ) {
374
+ if ( this . photonEmissionPeriodTarget === Number . POSITIVE_INFINITY && photonEmissionPeriod !== Number . POSITIVE_INFINITY
375
+ && this . photonGroup . count === 0 ) {
394
376
395
377
// only reset time on emission of first photon, there should still be a delay after subsequent photons
396
378
this . setEmissionTimerToInitialCountdown ( ) ;
@@ -444,11 +426,6 @@ inherit( PhetioObject, PhotonAbsorptionModel, {
444
426
// Set the photonGroup so that photons created by the molecule can be registered for PhET-iO
445
427
newMolecule . photonGroup = this . photonGroup ;
446
428
447
- // Emit a new photon from this molecule after absorption.
448
- newMolecule . photonEmittedEmitter . addListener ( function ( photon ) {
449
- self . photons . add ( photon ) ;
450
- } ) ;
451
-
452
429
// Break apart into constituent molecules.
453
430
newMolecule . brokeApartEmitter . addListener ( function ( constituentMolecule1 , constituentMolecule2 ) {
454
431
// Remove the molecule from the photonAbsorptionModel's list of active molecules.
@@ -495,40 +472,7 @@ inherit( PhetioObject, PhotonAbsorptionModel, {
495
472
}
496
473
} ) ;
497
474
498
-
499
475
// @public {number} - horizontal velocity of photons when they leave the emitter, in picometers/second
500
476
PhotonAbsorptionModel . PHOTON_VELOCITY = PHOTON_VELOCITY ;
501
477
502
- PhotonAbsorptionModel . PhotonAbsorptionModelIO = new IOType ( 'PhotonAbsorptionModelIO' , {
503
- valueType : PhotonAbsorptionModel ,
504
-
505
- /**
506
- * @public
507
- * @param photonAbsorptionModel
508
- * TODO: eliminate this legacy pattern, see https://github.com/phetsims/tandem/issues/87
509
- */
510
- clearChildInstances ( photonAbsorptionModel ) {
511
- photonAbsorptionModel . clearPhotons ( ) ;
512
- // instance.chargedParticles.clear();
513
- // instance.electricFieldSensors.clear();
514
- } ,
515
-
516
- /**
517
- * Create a dynamic particle as specified by the phetioID and state.
518
- * @public
519
- * @param {Object } photonAbsorptionModel
520
- * @param {Tandem } tandem
521
- * @param {Object } stateObject
522
- * @returns {ChargedParticle }
523
- */
524
- addChildElementDeprecated ( photonAbsorptionModel , tandem , stateObject ) {
525
- const value = Photon . PhotonIO . fromStateObject ( stateObject ) ;
526
-
527
- const photon = new phet . moleculesAndLight . Photon ( value . wavelength , tandem ) ;
528
- photon . setVelocity ( stateObject . vx , stateObject . vy ) ;
529
- photonAbsorptionModel . photons . add ( photon ) ;
530
- return photon ;
531
- }
532
- } ) ;
533
-
534
478
export default PhotonAbsorptionModel ;
0 commit comments