phetsims / energy-skate-park-basics

"Energy Skate Park: Basics" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/energy-skate-park-basics
GNU General Public License v3.0
2 stars 9 forks source link

Variables added to prototype in inherit call #406

Closed jessegreenberg closed 6 years ago

jessegreenberg commented 6 years ago

From #398 - I noticed that the curvatureTemp2 and cuvatureTemp are used to track cuvature of the track at the skater's location. They are added to the prototype in the inherit call of EnergySkateParkBasicsModel.js. I haven't seen variables declared here before. @samreid is there an allocation benefit of defining these variables here? Could they be moved to the constructor?

jessegreenberg commented 6 years ago

Also, curvatureTemp looks like:

    curvatureTemp: { r: 1, x: 0, y: 0 },

Are the initial values important?

samreid commented 6 years ago

curvatureTemp and curvatureTemp2 are not instance variables and should not be moved to the constructor--it seems they should be moved closer to this line:

  // Reuse empty object for creating SkaterStates to avoid allocations
  var EMPTY_OBJECT = {};

Since they have similar intent. The initial values are not important--these curvatureTemp objects were introduced to prevent memory allocations to get acceptable performance on iPad.

jessegreenberg commented 6 years ago

Thanks, I understand now. Sounds good.

jessegreenberg commented 6 years ago

This was done in ESP, closing this issue.