src/hft/scripts/misc/gameclock.js
function(clock) {
    clock = clock || new LocalClock();

    this.gameTime = 0;
    this.callCount = 0;

    var then = clock.getTime();

    /**
     * Gets the time elapsed in seconds since the last time this was
     * called
     * @return {number} The time elapsed in seconds since this was
     *     last called. Note will never return a time more than
     *     1/20th of second. This is to help prevent giant time
     *     range that might overflow the math on a game.
     *
     */
    this.getElapsedTime = function() {
      ++this.callCount;

      var now = clock.getTime();
      var elapsedTime = Math.min(now - then, 0.05);  // Don't return a time less than 0.05 second
      this.gameTime += elapsedTime;

      then = now;

      return elapsedTime;
    }.bind(this);
  }
function(clock) {
    clock = clock || new LocalClock();

    this.gameTime = 0;
    this.callCount = 0;

    var then = clock.getTime();

    /**
     * Gets the time elapsed in seconds since the last time this was
     * called
     * @return {number} The time elapsed in seconds since this was
     *     last called. Note will never return a time more than
     *     1/20th of second. This is to help prevent giant time
     *     range that might overflow the math on a game.
     *
     */
    this.getElapsedTime = function() {
      ++this.callCount;

      var now = clock.getTime();
      var elapsedTime = Math.min(now - then, 0.05);  // Don't return a time less than 0.05 second
      this.gameTime += elapsedTime;

      then = now;

      return elapsedTime;
    }.bind(this);
  }
function ( clock ) { clock = clock || new LocalClock ( ) ; this . gameTime = 0 ; this . callCount = 0 ; var then = clock . getTime ( ) ; /**
     * Gets the time elapsed in seconds since the last time this was
     * called
     * @return {number} The time elapsed in seconds since this was
     *     last called. Note will never return a time more than
     *     1/20th of second. This is to help prevent giant time
     *     range that might overflow the math on a game.
     *
     */ this . getElapsedTime = function ( ) { ++ this . callCount ; var now = clock . getTime ( ) ; var elapsedTime = Math . min ( now - then , 0.05 ) ; // Don't return a time less than 0.05 second this . gameTime += elapsedTime ; then = now ; return elapsedTime ; } . bind ( this ) ; }
A clock that returns the time elapsed since the last time it
was queried
@constructor
@alias GameClock
@param {Clock?} The clock to use for this GameClock (pass it
a SyncedClock of you want the clock to be synced or
nothing if you just want a local clock.
A clock that returns the time elapsed since the last time it was queried