Code cleanup

This commit is contained in:
Jeremiah Billmann
2013-07-09 21:40:51 -04:00
parent faf5434d23
commit 39751c8044
6 changed files with 20 additions and 26 deletions
+3 -3
View File
@@ -9,7 +9,7 @@ options = {
onGameState: function (state),
onPing: function (pingDelay),
onUpdatePlayerPhysics: function (state, inputs, deltaTime),
onInterpolation: function(id, previousState, targetState, amount)
onInterpolation: function(previousState, targetState, amount)
logging: true
}
*/
@@ -329,8 +329,8 @@ window.GarageServerIO = (function (window, socketio) {
positions = entity.surroundingPositions(_stateController.renderTime);
if (positions.previous && positions.target) {
amount = getInterpolatedAmount(positions.previous.time, positions.target.time);
newState = _options.onInterpolation(entity.id, positions.previous.state, positions.target.state, amount);
entity.state = newState = _options.onInterpolation(entity.id, entity.state, newState, _stateController.smoothingFactor);
newState = _options.onInterpolation(positions.previous.state, positions.target.state, amount);
entity.state = newState = _options.onInterpolation(entity.state, newState, _stateController.smoothingFactor);
}
}
});
+2 -2
View File
@@ -1,6 +1,6 @@
var garageServer = require('../lib/server/garageserver.io'),
gamePhysics = require('./shared/core');
exports = module.exports = Game;
function Game (sockets) {
@@ -30,7 +30,7 @@ Game.prototype.update = function () {
self = this;
players.forEach(function (player) {
var newState = gamePhysics.getNewPlayerState(player.state, player.inputs, self.physicsDelta);
var newState = gamePhysics.getNewState(player.state, player.inputs, self.physicsDelta);
self.server.updatePlayerState(player.id, newState);
});
};
+2 -7
View File
@@ -3,13 +3,8 @@ $(function () {
GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', {
logging: true,
onUpdatePlayerPhysics: getNewPlayerState,
onInterpolation: function (id, previousState, targetState, amount) {
var interpolationState = {};
interpolationState.x = (previousState.x + amount * (targetState.x - previousState.x));
interpolationState.y = (previousState.y + amount * (targetState.y - previousState.y));
return interpolationState;
}
onUpdatePlayerPhysics: GamePhysics.getNewState,
onInterpolation: GamePhysics.getInterpolatedState
});
GarageServerIO.setPlayerState({ x: 0, y: 0 });
+7 -8
View File
@@ -1,6 +1,6 @@
(function(exports){
exports.getNewPlayerState = function (state, inputs, deltaTime) {
exports.getNewState = function (state, inputs, deltaTime) {
var i = 0;
if (!state.x && !state.y) {
@@ -21,12 +21,11 @@
return state;
};
exports.onUpdateEntityPhysics = function (id, state, deltaTime) {
if (!state.x && !state.y) {
state.x = 0;
state.y = 0;
}
state.x += (10 * deltaTime);
exports.getInterpolatedState = function (previousState, targetState, amount) {
var interpolationState = {};
interpolationState.x = (previousState.x + amount * (targetState.x - previousState.x));
interpolationState.y = (previousState.y + amount * (targetState.y - previousState.y));
return interpolationState;
};
})(typeof exports === 'undefined' ? window : exports);
})(typeof exports === 'undefined' ? window.GamePhysics = {} : exports);
+2 -2
View File
@@ -1,4 +1,4 @@
var GarageServerGame = require('./garageservergame');
var garageServerGame = require('./garageservergame');
/*
options = {
@@ -19,7 +19,7 @@ options = {
function GarageServer (socketio, options) {
this.io = socketio;
this.game = new GarageServerGame(options);
this.game = new garageServerGame(options);
this.registerSocketEvents(options);
}
+4 -4
View File
@@ -1,11 +1,11 @@
var PlayerController = require('./controllers/playercontroller'),
EntityController = require('./controllers/entitycontroller');
var playerController = require('./controllers/playercontroller'),
entityController = require('./controllers/entitycontroller');
exports = module.exports = GarageServerGame;
function GarageServerGame(options) {
this.playerController = new PlayerController();
this.entityController = new EntityController();
this.playerController = new playerController();
this.entityController = new entityController();
this.options = options;
this.startTime;
this.stateInterval = options.stateInterval ? options.stateInterval : 45;