mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
some more hardcore network testing
This commit is contained in:
parent
5a3d3d0764
commit
26aa471b14
7 changed files with 123 additions and 31 deletions
|
|
@ -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(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue