From 649fece9f09c38d57311f29cea9f0363485a1c21 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Wed, 12 Jun 2013 21:39:33 -0400 Subject: [PATCH] Progress: Client Side Prediction --- client/garageserver.io.js | 25 ++++++------------------- example/public/javascripts/game.js | 6 ------ lib/server/garageserver.io.js | 2 +- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/client/garageserver.io.js b/client/garageserver.io.js index a6b03b4..3bf903b 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -5,6 +5,9 @@ options = { onPlayerUpdate: function (data), onPlayerDisconnect: function (id), onPing: function (data), + logging: true, + clientSidePrediction: true, + onUpdatePhysics: function (state, inputs) } */ @@ -111,6 +114,9 @@ window.GarageServerIO = (function (window, socketio) { addPlayerInput = function (input) { sequenceNumber += 1; inputs.push(input); + if (options.clientSidePrediction && options.onUpdatePhysics) { + + } sendPlayerInput(input); }, @@ -119,23 +125,6 @@ window.GarageServerIO = (function (window, socketio) { socket.emit('input', { input: input, seq: sequenceNumber, timestamp: currentTime }); }, - processPlayerInput = function () { - for (var i = 0; i < players.length; i ++) { - if (players[i].id !== socket.socket.sessionid) { - - } - } - }, - - processClientInput = function () { - for (var i = 0; i < players.length; i ++) { - if (players[i].id === socket.socket.sessionid) { - - break; - } - } - }, - getPlayerStates = function (stateCallback) { var maxUpdate = 0; for (var i = 0; i < players.length; i ++) { @@ -153,8 +142,6 @@ window.GarageServerIO = (function (window, socketio) { return { connectToGarageServer: connectToGarageServer, addPlayerInput: addPlayerInput, - processPlayerInput: processPlayerInput, - processClientInput: processClientInput, getPlayerStates: getPlayerStates }; diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index f965f9c..c5fedcb 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -34,11 +34,6 @@ $(function () { } }, - processServerInput = function () { - //GarageServerIO.processPlayerInput - //GarageServerIO.processClientInput - }, - draw = function () { ctxGameCanvas.clearRect(0, 0, gameCanvas.width, gameCanvas.height); @@ -51,7 +46,6 @@ $(function () { requestAnimFrame(update); processClientInput(); - processServerInput(); draw(); diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index ff664c3..586c253 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -2,7 +2,7 @@ var garageServerGame = require('./garageservergame'); /* options = { - onUpdatePhysics: function (state, input), + onUpdatePhysics: function (state, inputs), physicsInterval: 15, playersInterval: 45, logging: true,