Progress: Interpolation

This commit is contained in:
Jeremiah Billmann
2013-06-21 20:50:51 -04:00
parent cd95410f00
commit 7f3c9219ba
2 changed files with 19 additions and 3 deletions
+18 -2
View File
@@ -6,7 +6,10 @@ options = {
onPing: function (data),
logging: true,
clientSidePrediction: true,
onUpdatePhysics: function (state, inputs)
onUpdatePhysics: function (state, inputs),
interpolation: true,
interpolationDelay: 100,
pingInterval: 2000
}
*/
@@ -20,12 +23,14 @@ window.GarageServerIO = (function (window, socketio) {
inputs = [],
updates = [],
options = null,
pingDelay = 100,
// TODO: DONE CALLBACK
connectToGarageServer = function (path, opts) {
socket = io.connect(path + '/garageserver.io');
options = opts;
registerSocketEvents();
registerPinger();
},
registerSocketEvents = function () {
@@ -36,8 +41,9 @@ window.GarageServerIO = (function (window, socketio) {
}
});
socket.on('ping', function(data) {
pingDelay = new Date() - Date.parse(data);
if (options.logging) {
console.log('garageserver.io:: socket ping ' + data);
console.log('garageserver.io:: socket ping delay ' + pingDelay);
}
});
socket.on('removePlayer', function(id) {
@@ -47,6 +53,16 @@ window.GarageServerIO = (function (window, socketio) {
}
});
},
registerPinger = function () {
var interval = 2000;
if (options.pingInterval) {
interval = options.pingInterval;
}
setInterval(function (){
socket.emit('ping', new Date());
}, interval);
},
updatePlayerInput = function (data) {
var playerFound = false,
+1 -1
View File
@@ -44,7 +44,7 @@ GarageServer.prototype.registerSocketEvents = function (options) {
socket.on('ping', function (data) {
if (options.logging) {
console.log('garageserver.io:: socket ping');
console.log('garageserver.io:: socket ping ' + data);
}
self.onPing(socket, data, options);
});