mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-08-11 11:12:33 +08:00
Progress: Interpolation
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user