mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-27 16:10:34 +08:00
Cleaning up spaces
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
});
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user