{"size": 1046, "ext": "js", "max_stars_repo_path": "js/game-loop.js", "max_stars_repo_name": "floriico/onyx", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/game-loop.js", "max_issues_repo_name": "floriico/onyx", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/game-loop.js", "max_forks_repo_name": "floriico/onyx", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9047619048, "max_line_length": 63, "alphanum_fraction": 0.6453154876}
define([], function() {
  'use strict';

  var GameLoop = function(updater, renderer, updateFrequency) {
    this.update = updater.update.bind(updater);
    this.render = renderer.paint.bind(renderer);
    this.updateFrequency = updateFrequency || 32;
    this.lastTick = null;
    this.deltaTime = 0;
    this.run = false;
  };

  GameLoop.prototype.tick = function tick(now) {
    if (!this.lastTick) {
      this.lastTick = now;
    }
    let elapsedTime = now - this.lastTick;
    this.deltaTime += elapsedTime;
    while (this.deltaTime > this.updateFrequency) {
      this.deltaTime -= this.updateFrequency;
      this.update(this.updateFrequency);
    }
    this.render(elapsedTime);
    this.lastTick = now;
    if (this.run) {
      requestAnimationFrame(this.tick.bind(this));
    }
  };

  GameLoop.prototype.start = function start() {
    this.run = true;
    this.lastTick = null;
    requestAnimationFrame(this.tick.bind(this));
  };

  GameLoop.prototype.stop = function stop() {
    this.run = false;
  };

  return GameLoop;
});
