<commit_before>// Namespace GameFramework encapsulates class Game to detach it from the wild world of the deepweb!GameFramework
var GameFramework = { };

// Constructor for the Game class.
GameFramework.Game = function (canvas, backgroundColor, debugDraw) {
	// Reference to the canvas html5 object.
	this.targetFPS;
	this.backgroundColor = backgroundColor;
	
	this._debugDraw = debugDraw;
	this._canvas = canvas;
	this._context2D = canvas.getContext("2d");
	this._gameObjects = new Array();
	this._mainIntervalID;
	this._time = {
		startTime: 0, elapsedTime: 0, deltaTime: 0, _lastUpdateTime: 0
	};
	
	if (!GameFramework.Game.Instance) {
		GameFramework.Game.Instance = this;
	} else {
		console.error("Trying to instantiate Breakout.Game again. It should be a singleton.");
	}
	
	return this;
};

GameFramework.Game.Instance;

GameFramework.Game.prototype = {

	startGame: function (targetFPS) {
		var self = this;
		
		self.targetFPS = targetFPS;
		self._time.startTime = +new Date();
		self._mainIntervalID = setInterval(function() { self.update(self); } , 1000 / self.targetFPS);
	},

	update: function () {
		var self = this;
		
		var millisecondsNow = +new Date();

		self._time.deltaTime = millisecondsNow - self._time._lastUpdateTime;
		self._time.elapsedTime += self._time.deltaTime;
		
		for (var i = 0; i < self._gameObjects.length; i++) {
			self._gameObjects[i].update(self._time);
		}
		
		self._context2D.fillStyle = self.backgroundColor;
		self._context2D.fillRect(0, 0, self._canvas.width, self._canvas.height);
		
		for (var i = 0; i < self._gameObjects.length; i++) {
			self._gameObjects[i].render(self._time, 
										self._context2D, 
										self._debugDraw);
		}
		
		self._time._lastUpdateTime = millisecondsNow;
	},
	
	addGameObject: function (newGameObject) {
		var self = this;
		
		newGameObject.init();
		self._gameObjects.push(newGameObject);
		self._gameObjects.sort(self._compareGameObjects);
	},
	
	removeGameObject: function (gameObject) {
		var index = this._gameObjects.indexOf(gameObject);
		
		if (index !== -1) {
			var removedObjects = this._gameObjects.splice(index, 1);
			removedObjects[0].dispose();
		}
	},
	
	clearGameObjects: function () {
	    var self = this;
	    var gameObjects = self._gameObjects;
	    var length = gameObjects.length;

	    for (var i = 0; i < length; i++)
	       gameObjects[i].dispose();
	    
	    gameObjects.splice(0, length + 1);
	},
		
	_compareGameObjects: function (a, b) {
		if (a.zOrder === undefined || b.zOrder === undefined) {
			return 1;
		} else {
			return a.zOrder - b.zOrder;
		}
	}
};
<commit_msg>Fixing startGame function. Set lastUpdateTime to startTime.<commit_after>// Namespace GameFramework encapsulates class Game to detach it from the wild world of the deepweb!GameFramework
var GameFramework = { };

// Constructor for the Game class.
GameFramework.Game = function (canvas, backgroundColor, debugDraw) {
	// Reference to the canvas html5 object.
	this.targetFPS;
	this.backgroundColor = backgroundColor;
	
	this._debugDraw = debugDraw;
	this._canvas = canvas;
	this._context2D = canvas.getContext("2d");
	this._gameObjects = new Array();
	this._mainIntervalID;
	this._time = {
		startTime: 0, elapsedTime: 0, deltaTime: 0, _lastUpdateTime: 0
	};
	
	if (!GameFramework.Game.Instance) {
		GameFramework.Game.Instance = this;
	} else {
		console.error("Trying to instantiate Breakout.Game again. It should be a singleton.");
	}
	
	return this;
};

GameFramework.Game.Instance;

GameFramework.Game.prototype = {

	startGame: function (targetFPS) {
		var self = this;
		
		self.targetFPS = targetFPS;
		self._time.startTime = +new Date();
		self._time._lastUpdateTime = self._time.startTime;
		self._mainIntervalID = setInterval(function() { self.update(self); } , 1000 / self.targetFPS);
	},

	update: function () {
		var self = this;
		
		var millisecondsNow = +new Date();

		self._time.deltaTime = millisecondsNow - self._time._lastUpdateTime;
		self._time.elapsedTime += self._time.deltaTime;
		
		for (var i = 0; i < self._gameObjects.length; i++) {
			self._gameObjects[i].update(self._time);
		}
		
		self._context2D.fillStyle = self.backgroundColor;
		self._context2D.fillRect(0, 0, self._canvas.width, self._canvas.height);
		
		for (var i = 0; i < self._gameObjects.length; i++) {
			self._gameObjects[i].render(self._time, 
										self._context2D, 
										self._debugDraw);
		}
		
		self._time._lastUpdateTime = millisecondsNow;
	},
	
	addGameObject: function (newGameObject) {
		var self = this;
		
		newGameObject.init();
		self._gameObjects.push(newGameObject);
		self._gameObjects.sort(self._compareGameObjects);
	},
	
	removeGameObject: function (gameObject) {
		var index = this._gameObjects.indexOf(gameObject);
		
		if (index !== -1) {
			var removedObjects = this._gameObjects.splice(index, 1);
			removedObjects[0].dispose();
		}
	},
	
	clearGameObjects: function () {
	    var self = this;
	    var gameObjects = self._gameObjects;
	    var length = gameObjects.length;

	    for (var i = 0; i < length; i++)
	       gameObjects[i].dispose();
	    
	    gameObjects.splice(0, length + 1);
	},
		
	_compareGameObjects: function (a, b) {
		if (a.zOrder === undefined || b.zOrder === undefined) {
			return 1;
		} else {
			return a.zOrder - b.zOrder;
		}
	}
};

{'fraction_non_alphanumeric': 0.12927612927612928, 'fraction_numerical': 0.00945000945000945, 'mean_word_length': 3.577854671280277, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1876360', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1687, 'n_words': 390}