mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-09-09 11:14:19 +08:00
Adding delta and fix physics step
This commit is contained in:
@@ -16,6 +16,7 @@ options = {
|
||||
|
||||
function GarageServer (socketio, options) {
|
||||
this.io = socketio;
|
||||
this.physicsInterval = options.physicsInterval ? options.physicsInterval : 15;
|
||||
this.game = new garageServerGame.createGame(options);
|
||||
this.registerSocketEvents(options);
|
||||
}
|
||||
@@ -27,6 +28,7 @@ GarageServer.prototype.registerSocketEvents = function (options) {
|
||||
if (options.logging) {
|
||||
console.log('garageserver.io:: socket ' + socket.id + ' connection');
|
||||
}
|
||||
socket.emit('state', { physicsDelta: self.physicsInterval });
|
||||
self.onPlayerConnect(socket, options);
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
@@ -50,9 +52,9 @@ GarageServer.prototype.registerSocketEvents = function (options) {
|
||||
self.onPing(socket, data, options);
|
||||
});
|
||||
|
||||
socket.on('state', function (data) {
|
||||
socket.on('playerState', function (data) {
|
||||
if (options.logging) {
|
||||
console.log('garageserver.io:: socket state ' + data);
|
||||
console.log('garageserver.io:: socket playerState ' + data);
|
||||
}
|
||||
self.onState(socket, data, options);
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ GarageServerGame.prototype.updateState = function (options) {
|
||||
|
||||
GarageServerGame.prototype.updatePlayers = function (options) {
|
||||
var currentTime = new Date().getTime() - this.startTime,
|
||||
state = { time: currentTime, physicsDelta: this.physicsInterval, stateDelta: this.stateInterval, playerStates: [] };
|
||||
state = { time: currentTime, playerStates: [] };
|
||||
|
||||
this.players.forEach(function (player) {
|
||||
state.playerStates.push({ id: player.client.id, state: player.state, seq: player.sequence });
|
||||
|
||||
Reference in New Issue
Block a user