From 9038bdc6fbfb3df7e32c6e0aca3ecbf748c51f59 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Sat, 1 Jun 2013 16:22:04 -0400 Subject: [PATCH] Cleaning up spaces --- client/garageserver.io.js | 3 ++- example/public/javascripts/game.js | 20 ++++++++++---------- lib/server/garageserver.io.js | 10 +++++----- lib/server/garageservergame.js | 6 +++--- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/client/garageserver.io.js b/client/garageserver.io.js index f732a8f..c991c69 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -63,7 +63,8 @@ window.GarageServerIO = (function (window, socketio) { }, sendPlayerInput = function (input) { - socket.emit('input', { input: input, seq: sequenceNumber }); + var currentTime = new Date().getTime(); + socket.emit('input', { input: input, seq: sequenceNumber, timestamp: currentTime }); }, removePlayer = function (id) { diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index 1b5431d..0d46094 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -1,14 +1,14 @@ $(function () { GarageServerIO.connectToGarageServer('http://garageserver_io.jbillmann.c9.io', { logging: true }); - + var gameCanvas = document.getElementById('gameCanvas'), - + keyboard = new THREEx.KeyboardState(), - + ctxGameCanvas = gameCanvas.getContext('2d'), - + x = 0, y =0, fps = 0, now, lastUpdate = (new Date)*1 - 1, fpsFilter = 50, - + requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); }; })(), @@ -31,20 +31,20 @@ $(function () { GarageServerIO.addPlayerInput('up'); } }, - + update = function () { requestAnimFrame(update); handleInput(); ctxGameCanvas.clearRect(0, 0, gameCanvas.width, gameCanvas.height); ctxGameCanvas.fillRect(x, y, 10, 10); - + var thisFrameFPS = 1000 / ((now=new Date) - lastUpdate); fps += (thisFrameFPS - fps) / fpsFilter; lastUpdate = now; - + $('#fps').html('FPS: ' + Math.round(fps)); }; - + update(); - + }); \ No newline at end of file diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index 55dd45a..f2e7bb1 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -8,29 +8,29 @@ function GarageServer (socketio, options) { GarageServer.prototype.registerSocketEvents = function (options) { var self = this; - + self.io.of('/garageserver.io').on('connection', function (socket) { self.game = new garageServerGame.createGame(socket, options); - + if(options.logging) { console.log('garageserver.io:: socket ' + socket.id + ' connection'); } self.onPlayerConnect(socket, options); - + socket.on('disconnect', function () { if(options.logging) { console.log('garageserver.io:: socket ' + socket.id + ' disconnect'); } self.onPlayerDisconnect(socket, options); }); - + socket.on('input', function (data) { if(options.logging) { console.log('garageserver.io:: socket input ' + socket.id + ' ' + data.input + ' ' + data.seq); } self.onPlayerInput(socket, data, options); }); - + socket.on('ping', function (data) { if(options.logging) { console.log('garageserver.io:: socket ping'); diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index e80bbd0..537bf6d 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -1,10 +1,10 @@ function GarageServerGame (socket, options) { var self = this; - + this.players = []; this.socket = socket; this.options = options; - + this.physicsIntervalId = setInterval(function () { self.updatePhysics(options); }, options.physicsInterval ? options.physicsInterval : 15); this.playersIntervalId = setInterval(function () { self.updatePlayers(options); }, options.playersInterval ? options.playersInterval : 45); } @@ -41,7 +41,7 @@ GarageServerGame.prototype.addPlayer = function (client) { inputs: [], sequence: 1 }; - + this.players.push(player); };