Furthered GarageServer.IO API calls to support client side prediction for entities - #20 - still have to change how client side prediction is invoked/processed.

This commit is contained in:
Jeremiah Billmann
2015-05-20 04:04:31 +00:00
parent fbdcfe3da5
commit f28dee8927
5 changed files with 89 additions and 34 deletions
+5 -2
View File
@@ -10,8 +10,11 @@ $(function () {
GarageServerIO.initializeGarageServer('', {
logging: true,
onReady: startGame,
onUpdateClientPredictionReady: function(playerId, playerCurrentState, entityCurrentStates, inputs, deltaTime) {
GarageServerIO.updatePlayerState(playerId, GamePhysics.getNewPlayerState(playerId, playerCurrentState, inputs, deltaTime));
onUpdateClientPredictionReady: function (playerId, playerCurrentState, entityCurrentStates, inputs, deltaTime) {
entityCurrentStates.forEach(function (entity) {
GarageServerIO.updateEntityState(entity.id, GamePhysics.getNewEntityState(entity.state, deltaTime));
});
GarageServerIO.updatePlayerState(playerId, GamePhysics.getNewPlayerState(playerId, playerCurrentState, inputs, deltaTime, GarageServerIO));
},
onInterpolation: GamePhysics.getInterpolatedState
});
+7 -4
View File
@@ -26,7 +26,7 @@
} else if (inputs[i].input === 'up') {
distance += (125 * deltaTime);
} else if (inputs[i].input === 'space') {
if (garageServer && (new Date().getTime() - newState.lastFire) > 1000) {
if ((new Date().getTime() - newState.lastFire) > 1000) {
var newId = guid();
garageServer.addEntity(newId, id);
garageServer.updateEntityState(newId, { x: newState.x, y: newState.y, ang: newState.ang } );
@@ -50,12 +50,15 @@
}
exports.getNewEntityState = function (state, deltaTime) {
var newState = {};
var distance = 300 * deltaTime;
var newPoint = getPoint(state.ang, distance, state.x, state.y);
state.x = newPoint.x;
state.y = newPoint.y;
newState.ang = state.ang;
newState.x = newPoint.x;
newState.y = newPoint.y;
return state;
return newState;
};
exports.getInterpolatedState = function (previousState, targetState, amount) {