some more hardcore network testing

This commit is contained in:
logsol 2012-06-17 00:42:28 +02:00
parent 5a3d3d0764
commit 26aa471b14
7 changed files with 123 additions and 31 deletions

View file

@ -18,20 +18,26 @@ setInterval(updateClients, 500);
function updateClients() {
var body = world.GetBodyList();
var update = {};
var isUpdateNeeded = false;
do {
var userData = body.GetUserData();
if(userData && userData.bodyId){
if(userData && userData.bodyId && body.IsAwake()){
console.log(body.IsAwake());
update[userData.bodyId] = {
p: body.GetPosition(),
a: body.GetAngle(),
v: body.GetLinearVelocity(),
};
isUpdateNeeded = true;
}
} while (body = body.GetNext());
sendToClients('world-update', update);
if(isUpdateNeeded) {
sendToClients('world-update', update);
}
}
function sendToClients(message, data) {
@ -41,7 +47,7 @@ function sendToClients(message, data) {
}
//console.log(JSON.stringify(packet));
for (var i = 0; i < clients.length; i++) {
clients[i].send(JSON.stringify(packet));
clients[i].send( JSON.stringify(packet));
}
}
@ -86,6 +92,7 @@ socket.on('connection', function(client) {
break;
}
}
updateClients();
});
client.on('disconnect', function(){