<commit_before>window.onload = function () {
	var container = document.getElementById('container');
	var tester = new FeatureTester();
	tester.run();
	if (!tester.pass()) {
		container.innerHeight = '';
		container.appendChild(tester.errors());
		return;
	}

	var conn = new Conn(getWSURI("main/"));
	var clock = new Clock(conn);
	var clientID;

	async.parallel([
		function (callback) {
			Models.init(callback);
		},
		function (callback) {
			conn.on('handshake-reply', function (payload) {
				console.log("Got handshake reply:", payload);
				clock.init(payload.ServerTime);
				clientID = payload.ClientID;
				conn.setImmediate(false);
				callback();
			});
			conn.on('handshake-error', function (payload) {
				throw payload.Message;
			});
			conn.queue('handshake-init', {
				DesiredName: localStorage.playerName,
			});
		}
	], function (err, results) {
		console.log(results);
		startGame();
	})

	function startGame() {
		var scene = new THREE.Scene();
		var chunkManager = new ChunkManager(scene, clientID);
		var world = new World(scene, conn, clock, container, chunkManager);
		world.resize();

		var renderer = new THREE.WebGLRenderer();
		renderer.setSize(window.innerWidth, window.innerHeight);

		container.querySelector('#opengl').appendChild(renderer.domElement);
		document.querySelector('#splash h1').innerHTML = 'Click to play!';

		var speed = new PerfChart({
			title: ' render',
			maxValue: 50,
		});
		speed.elm.style.position = 'absolute';
		speed.elm.style.top = '74px';
		speed.elm.style.right = '0px';
		container.appendChild(speed.elm);

		window.addEventListener('resize', onWindowResize, false);

		animate();

		function onWindowResize() {
			world.resize();
			renderer.setSize(window.innerWidth, window.innerHeight);
		}

		var previousTime = clock.time();
		function animate() {
			clock.update();
			var newTime = clock.time();
			var dt = newTime - previousTime;
			previousTime = newTime;
			conn.update();
			world.update(dt);
			world.render(renderer, scene);
			speed.addDataPoint(dt);

			if (fatalErrorTriggered) return;
			requestAnimationFrame(animate);
		}
	}
};

window.onerror = function (msg, url, lineno) {
	fatalError({<commit_msg>Fix NaN dt on first update (was occasionally causing chat messages to never fade)<commit_after>window.onload = function () {
	var container = document.getElementById('container');
	var tester = new FeatureTester();
	tester.run();
	if (!tester.pass()) {
		container.innerHeight = '';
		container.appendChild(tester.errors());
		return;
	}

	var conn = new Conn(getWSURI("main/"));
	var clock = new Clock(conn);
	var clientID;

	async.parallel([
		function (callback) {
			Models.init(callback);
		},
		function (callback) {
			conn.on('handshake-reply', function (payload) {
				console.log("Got handshake reply:", payload);
				clock.init(payload.ServerTime);
				clientID = payload.ClientID;
				conn.setImmediate(false);
				callback();
			});
			conn.on('handshake-error', function (payload) {
				throw payload.Message;
			});
			conn.queue('handshake-init', {
				DesiredName: localStorage.playerName,
			});
		}
	], function (err, results) {
		console.log(results);
		startGame();
	})

	function startGame() {
		var scene = new THREE.Scene();
		var chunkManager = new ChunkManager(scene, clientID);
		var world = new World(scene, conn, clock, container, chunkManager);
		world.resize();

		var renderer = new THREE.WebGLRenderer();
		renderer.setSize(window.innerWidth, window.innerHeight);

		container.querySelector('#opengl').appendChild(renderer.domElement);
		document.querySelector('#splash h1').innerHTML = 'Click to play!';

		var speed = new PerfChart({
			title: ' render',
			maxValue: 50,
		});
		speed.elm.style.position = 'absolute';
		speed.elm.style.top = '74px';
		speed.elm.style.right = '0px';
		container.appendChild(speed.elm);

		window.addEventListener('resize', onWindowResize, false);

		function onWindowResize() {
			world.resize();
			renderer.setSize(window.innerWidth, window.innerHeight);
		}

		var previousTime = clock.time();
		function animate() {
			clock.update();
			var newTime = clock.time();
			var dt = newTime - previousTime;
			previousTime = newTime;
			
			conn.update();
			world.update(dt);
			world.render(renderer, scene);
			speed.addDataPoint(dt);

			if (fatalErrorTriggered) return;
			requestAnimationFrame(animate);
		}

		animate();
	}
};

window.onerror = function (msg, url, lineno) {
	fatalError({
{'fraction_non_alphanumeric': 0.14997754827121687, 'fraction_numerical': 0.002694207453973956, 'mean_word_length': 4.0972540045766594, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5854472', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1391, 'n_words': 296}