Sfoglia il codice sorgente

send and receive arrays of pixls.

preparation for possible batching later.
Lucas Stadler 12 anni fa
parent
commit
d03cc45643
2 ha cambiato i file con 6 aggiunte e 5 eliminazioni
  1. 1 1
      js/pixl/index.html
  2. 5 4
      js/pixl/server.js

+ 1 - 1
js/pixl/index.html

53
			pixl.ctx.fillRect(screen_pos.x, screen_pos.y, pixl.size, pixl.size);
53
			pixl.ctx.fillRect(screen_pos.x, screen_pos.y, pixl.size, pixl.size);
54
			pixl.world[pos.x + "," + pos.y] = {};
54
			pixl.world[pos.x + "," + pos.y] = {};
55
			if (pixl.online) {
55
			if (pixl.online) {
56
				pixl.ws.send(JSON.stringify({x: pos.x, y: pos.y, color: color || "black"}));
56
				pixl.ws.send(JSON.stringify([{x: pos.x, y: pos.y, color: color || "black"}]));
57
			}
57
			}
58
		}
58
		}
59
59

+ 5 - 4
js/pixl/server.js

8
	socket.send(JSON.stringify(world));
8
	socket.send(JSON.stringify(world));
9
9
10
	socket.on('message', function(msg) {
10
	socket.on('message', function(msg) {
11
		var pixl = JSON.parse(msg);
12
		world[pixl.x + "," + pixl.y] = {color: pixl.color};
13
14
		console.log(pixl);
11
		var pixls = JSON.parse(msg);
12
		pixls.forEach(function(pixl) {
13
			world[pixl.x + "," + pixl.y] = {color: pixl.color};
14
			console.log(pixl);
15
		});
15
16
16
		server.clients.forEach(function(client) {
17
		server.clients.forEach(function(client) {
17
			if (socket != client) {
18
			if (socket != client) {