mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-08-11 11:12:33 +08:00
Code cleanup
This commit is contained in:
+26
-29
@@ -3,31 +3,31 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var express = require('express')
|
||||
, routes = require('./routes')
|
||||
, user = require('./routes/user')
|
||||
, http = require('http')
|
||||
, path = require('path')
|
||||
, io = require('socket.io')
|
||||
, garageServer = require('../lib/server/garageserver.io');
|
||||
var express = require('express'),
|
||||
routes = require('./routes'),
|
||||
user = require('./routes/user'),
|
||||
http = require('http'),
|
||||
path = require('path'),
|
||||
io = require('socket.io'),
|
||||
garageServer = require('../lib/server/garageserver.io');
|
||||
|
||||
var app = express();
|
||||
|
||||
app.configure(function(){
|
||||
app.set('port', process.env.PORT || 2121);
|
||||
app.set('views', __dirname + '/views');
|
||||
app.set('view engine', 'jade');
|
||||
app.use(express.favicon());
|
||||
app.use(express.logger('dev'));
|
||||
app.use(express.bodyParser());
|
||||
app.use(express.methodOverride());
|
||||
app.use(app.router);
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.use(express.static(path.join(__dirname, '..', 'client')));
|
||||
app.configure(function () {
|
||||
app.set('port', process.env.PORT || 2121);
|
||||
app.set('views', __dirname + '/views');
|
||||
app.set('view engine', 'jade');
|
||||
app.use(express.favicon());
|
||||
app.use(express.logger('dev'));
|
||||
app.use(express.bodyParser());
|
||||
app.use(express.methodOverride());
|
||||
app.use(app.router);
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.use(express.static(path.join(__dirname, '..', 'client')));
|
||||
});
|
||||
|
||||
app.configure('development', function(){
|
||||
app.use(express.errorHandler());
|
||||
app.configure('development', function () {
|
||||
app.use(express.errorHandler());
|
||||
});
|
||||
|
||||
app.get('/', routes.index);
|
||||
@@ -35,15 +35,15 @@ app.get('/users', user.list);
|
||||
|
||||
var server = http.createServer(app);
|
||||
|
||||
server.listen(app.get('port'), function(){
|
||||
console.log("Express server listening on port " + app.get('port'));
|
||||
server.listen(app.get('port'), function () {
|
||||
console.log("Express server listening on port " + app.get('port'));
|
||||
});
|
||||
|
||||
var sockets = io.listen(server);
|
||||
|
||||
sockets.set('log level', 0);
|
||||
|
||||
garageServer.createGarageServer(sockets, {
|
||||
garageServer.createGarageServer(sockets,{
|
||||
logging: true,
|
||||
onUpdatePhysics: function (state, inputs) {
|
||||
var i = 0;
|
||||
@@ -54,14 +54,11 @@ garageServer.createGarageServer(sockets, {
|
||||
for (i = 0; i < inputs.length; i ++) {
|
||||
if (inputs[i].input === 'left') {
|
||||
state.x -= 1;
|
||||
}
|
||||
else if (inputs[i].input === 'right') {
|
||||
} else if (inputs[i].input === 'right') {
|
||||
state.x += 1;
|
||||
}
|
||||
else if (inputs[i].input === 'down') {
|
||||
} else if (inputs[i].input === 'down') {
|
||||
state.y += 1;
|
||||
}
|
||||
else if (inputs[i].input === 'up') {
|
||||
} else if (inputs[i].input === 'up') {
|
||||
state.y -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,60 +3,64 @@ $(function () {
|
||||
|
||||
var gameCanvas = document.getElementById('gameCanvas'),
|
||||
|
||||
keyboard = new THREEx.KeyboardState(),
|
||||
keyboard = new THREEx.KeyboardState(),
|
||||
|
||||
ctxGameCanvas = gameCanvas.getContext('2d'),
|
||||
ctxGameCanvas = gameCanvas.getContext('2d'),
|
||||
|
||||
x = 0, y =0, fps = 0, now, lastUpdate = (new Date)*1 - 1, fpsFilter = 50,
|
||||
fps = 0,
|
||||
|
||||
requestAnimFrame = (function(){
|
||||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); };
|
||||
})(),
|
||||
now,
|
||||
|
||||
processClientInput = function () {
|
||||
if (keyboard.pressed('left')) {
|
||||
GarageServerIO.addPlayerInput('left');
|
||||
}
|
||||
if (keyboard.pressed('right')) {
|
||||
GarageServerIO.addPlayerInput('right');
|
||||
}
|
||||
if (keyboard.pressed('down')) {
|
||||
GarageServerIO.addPlayerInput('down');
|
||||
}
|
||||
if (keyboard.pressed('up')) {
|
||||
GarageServerIO.addPlayerInput('up');
|
||||
}
|
||||
},
|
||||
|
||||
processServerInput = function () {
|
||||
//GarageServerIO.processPlayerInput
|
||||
|
||||
//GarageServerIO.processClientInput
|
||||
},
|
||||
|
||||
draw = function () {
|
||||
ctxGameCanvas.clearRect(0, 0, gameCanvas.width, gameCanvas.height);
|
||||
|
||||
GarageServerIO.getPlayerStates(function (state) {
|
||||
ctxGameCanvas.fillRect(state.x, state.y, 10, 10);
|
||||
});
|
||||
},
|
||||
lastUpdate = (new Date()) * 1 - 1,
|
||||
|
||||
update = function () {
|
||||
requestAnimFrame(update);
|
||||
|
||||
processClientInput();
|
||||
processServerInput();
|
||||
fpsFilter = 50,
|
||||
|
||||
draw();
|
||||
requestAnimFrame = (function () {
|
||||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); };
|
||||
})(),
|
||||
|
||||
var thisFrameFPS = 1000 / ((now=new Date) - lastUpdate);
|
||||
fps += (thisFrameFPS - fps) / fpsFilter;
|
||||
lastUpdate = now;
|
||||
processClientInput = function () {
|
||||
if (keyboard.pressed('left')) {
|
||||
GarageServerIO.addPlayerInput('left');
|
||||
}
|
||||
if (keyboard.pressed('right')) {
|
||||
GarageServerIO.addPlayerInput('right');
|
||||
}
|
||||
if (keyboard.pressed('down')) {
|
||||
GarageServerIO.addPlayerInput('down');
|
||||
}
|
||||
if (keyboard.pressed('up')) {
|
||||
GarageServerIO.addPlayerInput('up');
|
||||
}
|
||||
},
|
||||
|
||||
$('#fps').html('FPS: ' + Math.round(fps));
|
||||
};
|
||||
processServerInput = function () {
|
||||
//GarageServerIO.processPlayerInput
|
||||
//GarageServerIO.processClientInput
|
||||
},
|
||||
|
||||
draw = function () {
|
||||
ctxGameCanvas.clearRect(0, 0, gameCanvas.width, gameCanvas.height);
|
||||
|
||||
GarageServerIO.getPlayerStates(function (state) {
|
||||
ctxGameCanvas.fillRect(state.x, state.y, 10, 10);
|
||||
});
|
||||
},
|
||||
|
||||
update = function () {
|
||||
requestAnimFrame(update);
|
||||
|
||||
processClientInput();
|
||||
processServerInput();
|
||||
|
||||
draw();
|
||||
|
||||
var thisFrameFPS = 1000 / ((now = new Date()) - lastUpdate);
|
||||
fps += (thisFrameFPS - fps) / fpsFilter;
|
||||
lastUpdate = now;
|
||||
|
||||
$('#fps').html('FPS: ' + Math.round(fps));
|
||||
};
|
||||
|
||||
update();
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user