reduce update packet size by ~70%
This commit is contained in:
parent
1af386d9f5
commit
0906441246
20 changed files with 219 additions and 143 deletions
|
@ -18,7 +18,6 @@ class Net {
|
|||
|
||||
this.socket.on('update', data => {
|
||||
game.world.update(data);
|
||||
//console.log('.');
|
||||
});
|
||||
|
||||
this.socket.on('world', data => {
|
||||
|
|
|
@ -31,8 +31,7 @@ class Renderer {
|
|||
if (state == 'connecting' || state == 'disconnected') {
|
||||
pallet.clear();
|
||||
pallet.fill('#111');
|
||||
var str = state == 'connecting' ? 'Connecting' : 'Shit\'s ' +
|
||||
'diconnected, yo!';
|
||||
var str = state == 'connecting' ? 'Connecting' : 'Disconnected';
|
||||
pallet.text(str, canvas.width / 2, canvas.height / 2, '#fff',
|
||||
'FreePixel', 16, 'center', 'middle');
|
||||
return;
|
||||
|
|
|
@ -16,9 +16,9 @@ Renderer.prototype.renderShip = (pallet, ship) => {
|
|||
pallet.view(x + vx, y + vy, false, pos.r);
|
||||
|
||||
let ts = ship.size / 2;
|
||||
for (let i = 0; i < ship.mounts.length; i++) {
|
||||
if (ship.turrets[i]) {
|
||||
pallet.image(turr, ship.mounts[i][0] - ts, ship.mounts[i][1] - ts, 0);
|
||||
for (let i = 0; i < ship.fixtures.length; i++) {
|
||||
if (ship.fixtures[i]) {
|
||||
pallet.image(turr, ship.fixtures[i][0] - ts, ship.fixtures[i][1] - ts, 0);
|
||||
}
|
||||
}
|
||||
pallet.image(ship.team == 'a' ? teama : teamb, 0, 0, 0);
|
||||
|
|
|
@ -6,7 +6,7 @@ class Asteroid extends Body {
|
|||
}
|
||||
|
||||
updateType(data) {
|
||||
this.debug = data[6];
|
||||
this.debug = data.debug;
|
||||
}
|
||||
|
||||
tick() {
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
class Body {
|
||||
constructor(data) {
|
||||
this.x = data.delta[0];
|
||||
this.y = data.delta[1];
|
||||
this.xvel = data.delta[2];
|
||||
this.yvel = data.delta[3];
|
||||
this.r = data.delta[4];
|
||||
this.rvel = data.delta[5];
|
||||
|
||||
console.log(data);
|
||||
this.interface = data.interface;
|
||||
let s = this.interface.order.length + this.interface.fixtures;
|
||||
this.interface.size = s;
|
||||
this.id = data.id
|
||||
this.frame = data.frame;
|
||||
this.fixtures = data.fixtures;
|
||||
this.b2body = false;
|
||||
this.updated = 0;
|
||||
|
||||
game.world.update(data.delta);
|
||||
|
||||
this.com = {
|
||||
x: 0,
|
||||
|
@ -40,15 +40,19 @@ class Body {
|
|||
}
|
||||
|
||||
update(data) {
|
||||
this.x = data[0];
|
||||
this.y = data[1];
|
||||
this.xvel = data[2]
|
||||
this.yvel = data[3];
|
||||
this.r = data[4];
|
||||
this.rvel = data[5];
|
||||
let values = {};
|
||||
Array.from(data).map((v, i) => {
|
||||
values[this.interface.order[i]] = v
|
||||
});
|
||||
this.x = values.x;
|
||||
this.y = values.y;
|
||||
this.xvel = values.xvel;
|
||||
this.yvel = values.yvel;
|
||||
this.r = values.r;
|
||||
this.rvel = values.rvel;
|
||||
this.updated = 10;
|
||||
|
||||
this.updateType(data);
|
||||
this.updateType(values);
|
||||
}
|
||||
|
||||
updateType() {
|
||||
|
@ -56,6 +60,6 @@ class Body {
|
|||
}
|
||||
|
||||
tick() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
class Ship extends Body {
|
||||
constructor(data) {
|
||||
console.log(data);
|
||||
super(data);
|
||||
this.player = new Player(data.name, data.team, this);
|
||||
this.team = data.team;
|
||||
|
@ -8,8 +7,6 @@ class Ship extends Body {
|
|||
this.hull = '01';
|
||||
this.thrust = {};
|
||||
this.power = data.power;
|
||||
this.mounts = data.mounts;
|
||||
this.turrets = data.turrets;
|
||||
this.size = {
|
||||
'small': 8,
|
||||
'medium': 16,
|
||||
|
@ -21,10 +18,10 @@ class Ship extends Body {
|
|||
|
||||
updateType(data) {
|
||||
this.thrust = {
|
||||
forward: data[6]
|
||||
forward: data.thrustForward
|
||||
}
|
||||
|
||||
this.debug = data[9];
|
||||
this.debug = data.debug;
|
||||
}
|
||||
|
||||
tick() {
|
||||
|
|
8
public/static/js/wingbase/world/turret.js
Normal file
8
public/static/js/wingbase/world/turret.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
class Turret {
|
||||
constructor(ship, type, pos) {
|
||||
this.ship = ship;
|
||||
this.type = type;
|
||||
this.pos = pos;
|
||||
this.traversal = 0;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
var SCALE = 32;
|
||||
const SCALE = 32;
|
||||
|
||||
class World {
|
||||
constructor() {
|
||||
|
@ -44,16 +44,19 @@ class World {
|
|||
};
|
||||
|
||||
update(data) {
|
||||
for (var id in data) {
|
||||
if (!this.bodies[id]) {
|
||||
let array = new Float32Array(data);
|
||||
let i = 0;
|
||||
while (i < array.length) {
|
||||
let id = array[i++];
|
||||
let body = this.bodies[id];
|
||||
|
||||
if (!body) {
|
||||
game.net.send('requestBodyData', id);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
var body = this.bodies[id];
|
||||
body.update(data[id]);
|
||||
|
||||
if (data[id].destroy) delete this.bodies[id];
|
||||
body.update(array.slice(i, i + body.interface.size));
|
||||
i += body.interface.size;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue