Cleaning up spaces

This commit is contained in:
Jeremiah Billmann
2013-06-01 16:22:04 -04:00
parent a6c6753815
commit 9038bdc6fb
4 changed files with 20 additions and 19 deletions
+2 -1
View File
@@ -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) {
+10 -10
View File
@@ -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();
});
+5 -5
View File
@@ -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');
+3 -3
View File
@@ -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);
};