function Timer(autoStart, whileAnimating) {
  this.autoStart = typeof autoStart === 'undefined' ? true : autoStart;
  this.whileAnimating = whileAnimating || false;
  this.lastStartTime = 0;
  this.lastDeltaTime = 0;
  this.elapsedTime = 0;
  this.running = false;
  /**
   * Get the time elapsed in seconds since the last time a delta was measured.
   *
   * Deltas are taken when the timer starts or stops or elapsed time is
   * measured.
   *
   * Note that if the timer is stopped and autoStart is on, calling this method
   * will start the timer again.
   */
  this.getDelta = function() {
    var diff = 0;
    if (this.running) {
      var now = this.whileAnimating ? App.physicsTimeElapsed : performance.now();
      diff = (now - this.lastDeltaTime) / 1000; // ms to s
      this.lastDeltaTime = now;
      this.elapsedTime += diff;
    }
    return diff;
  };
  /**
   * Start the timer.
   */
  this.start = function() {
    if (this.running) {
      return;
    }
    this.lastStartTime = this.lastDeltaTime = this.whileAnimating ?
        App.physicsTimeElapsed :
          performance.now();
    this.running = true;
  };
  /**
   * Stop the timer.
   */
  this.stop = function () {
    this.elapsedTime += this.getDelta();
    this.running = false;
  };
  /**
   * Get the amount of time the timer has been running, in seconds.
   */
  this.getElapsedTime = function() {
    this.getDelta();
    return this.elapsedTime;
  };
  if (this.autoStart) {
    this.start();
  }
}
/**
 * A timer.
 *
 * Adapted from the
 * [three.js clock](https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js).
 *
 * If you only care about how long something takes (e.g. when testing
 * performance) and you don't need to stop the timer, Timer#event() and
 * Timer#getTimeSince() are more efficient than instantiating a new Timer
 * object.
 *
 * @param {Boolean} [autoStart=true]
 *   Whether to start the timer immediately upon instantiation or wait until
 *   the Timer#start() method is called.
 * @param {Boolean} [whileAnimating=false]
 *   Indicates whether the amount of time measured should be the time elapsed
 *   only while animation was running (true) or the total time elapsed (false).
 */
A timer.
Adapted from the
[three.js clock].

If you only care about how long something takes  and you don't need to stop the timer, Timer#event() and
Timer#getTimeSince() are more efficient than instantiating a new Timer
object.

@param {Boolean} [autoStart=true]
Whether to start the timer immediately upon instantiation or wait until
the Timer#start() method is called.
@param {Boolean} [whileAnimating=false]
Indicates whether the amount of time measured should be the time elapsed
only while animation was running (true) or the total time elapsed (false).
A timer . Adapted from the [ three . js clock ] . If you only care about how long something takes and you don ' t need to stop the timer Timer#event () and Timer#getTimeSince () are more efficient than instantiating a new Timer object . @param { Boolean } [ autoStart = true ] Whether to start the timer immediately upon instantiation or wait until the Timer#start () method is called . @param { Boolean } [ whileAnimating = false ] Indicates whether the amount of time measured should be the time elapsed only while animation was running ( true ) or the total time elapsed ( false ) .
function Timer(autoStart, whileAnimating) {
  this.autoStart = typeof autoStart === 'undefined' ? true : autoStart;
  this.whileAnimating = whileAnimating || false;
  this.lastStartTime = 0;
  this.lastDeltaTime = 0;
  this.elapsedTime = 0;
  this.running = false;
  this.getDelta = function() {
    var diff = 0;
    if (this.running) {
      var now = this.whileAnimating ? App.physicsTimeElapsed : performance.now();
      diff = (now - this.lastDeltaTime) / 1000; 
      this.lastDeltaTime = now;
      this.elapsedTime += diff;
    }
    return diff;
  };
  this.start = function() {
    if (this.running) {
      return;
    }
    this.lastStartTime = this.lastDeltaTime = this.whileAnimating ?
        App.physicsTimeElapsed :
          performance.now();
    this.running = true;
  };
  this.stop = function () {
    this.elapsedTime += this.getDelta();
    this.running = false;
  };
  this.getElapsedTime = function() {
    this.getDelta();
    return this.elapsedTime;
  };
  if (this.autoStart) {
    this.start();
  }
}
function Timer ( autoStart , whileAnimating ) { this . autoStart = typeof autoStart === 'undefined' ? true : autoStart ; this . whileAnimating = whileAnimating || false ; this . lastStartTime = 0 ; this . lastDeltaTime = 0 ; this . elapsedTime = 0 ; this . running = false ; this . getDelta = function ( ) { var diff = 0 ; if ( this . running ) { var now = this . whileAnimating ? App . physicsTimeElapsed : performance . now ( ) ; diff = ( now - this . lastDeltaTime ) / 1000 ; this . lastDeltaTime = now ; this . elapsedTime += diff ; } return diff ; } ; this . start = function ( ) { if ( this . running ) { return ; } this . lastStartTime = this . lastDeltaTime = this . whileAnimating ? App . physicsTimeElapsed : performance . now ( ) ; this . running = true ; } ; this . stop = function ( ) { this . elapsedTime += this . getDelta ( ) ; this . running = false ; } ; this . getElapsedTime = function ( ) { this . getDelta ( ) ; return this . elapsedTime ; } ; if ( this . autoStart ) { this . start ( ) ; } }
A timer.
A timer .
/**
   * Get the time elapsed in seconds since the last time a delta was measured.
   *
   * Deltas are taken when the timer starts or stops or elapsed time is
   * measured.
   *
   * Note that if the timer is stopped and autoStart is on, calling this method
   * will start the timer again.
   */ // ms to s /**
   * Start the timer.
   */ /**
   * Stop the timer.
   */ /**
   * Get the amount of time the timer has been running, in seconds.
   */