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