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
|
|
@ -1,4 +1,14 @@
|
|||
var id = null;
|
||||
var id = null;
|
||||
|
||||
//window.setInterval(ping, 1000);
|
||||
|
||||
function ping(){
|
||||
var packet = {
|
||||
m: 'ping',
|
||||
d: new Date().getTime()
|
||||
}
|
||||
socket.send(JSON.stringify(packet));
|
||||
}
|
||||
|
||||
function setupCanvas() {
|
||||
var debugDraw = new b2DebugDraw();
|
||||
|
|
@ -13,12 +23,13 @@ function setupCanvas() {
|
|||
}
|
||||
|
||||
function _jump() {
|
||||
console.log('---jump---');
|
||||
jump();
|
||||
|
||||
var data = {
|
||||
var packet = {
|
||||
m: 'jump'
|
||||
};
|
||||
socket.send(JSON.stringify(data));
|
||||
socket.send(JSON.stringify(packet));
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
|
@ -63,11 +74,18 @@ function updateWorld(data) {
|
|||
var body = world.GetBodyList();
|
||||
do {
|
||||
var userData = body.GetUserData();
|
||||
if(userData && userData.bodyId){
|
||||
if(userData && userData.bodyId && data[userData.bodyId]){
|
||||
var update = data[userData.bodyId];
|
||||
|
||||
console.log('position difference:', (body.GetPosition().y - update.p.y) * 30, body.GetLinearVelocity().y);
|
||||
|
||||
/*body.SetAwake(true);
|
||||
body.SetPosition(update.p);
|
||||
body.SetAngle(update.a);
|
||||
body.SetLinearVelocity(update.v);
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
} while (body = body.GetNext());
|
||||
}
|
||||
|
|
@ -91,6 +109,9 @@ socket.on('message', function(packet) {
|
|||
case 'world-update':
|
||||
updateWorld(packet.d);
|
||||
break;
|
||||
case 'pong':
|
||||
console.log('pong', new Date().getTime() - packet.d);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue