mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-08-12 11:40:29 +08:00
Progress: #3
This commit is contained in:
@@ -16,14 +16,14 @@ GarageServerGame.prototype.start = function () {
|
||||
var self = this;
|
||||
|
||||
this.startTime = new Date().getTime();
|
||||
this.stateIntervalId = setInterval(function () { self.updateState(); }, this.stateInterval);
|
||||
this.stateIntervalId = setInterval(function () { self.broadcastState(); }, this.stateInterval);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.stop = function () {
|
||||
clearInterval(this.stateIntervalId);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.updateState = function () {
|
||||
GarageServerGame.prototype.broadcastState = function () {
|
||||
var currentTime = new Date().getTime() - this.startTime,
|
||||
state = { time: currentTime, playerStates: [], entityStates: [] };
|
||||
|
||||
@@ -64,9 +64,17 @@ GarageServerGame.prototype.getPlayer = function (id) {
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.updatePlayerState = function (id, state) {
|
||||
var currentTime = new Date().getTime() - this.startTime;
|
||||
this.updateState(this.playerController, id, state);
|
||||
};
|
||||
|
||||
this.playerController.entities.some(function (player) {
|
||||
GarageServerGame.prototype.updateEntityState = function (id, state) {
|
||||
this.updateState(this.entityController, id, state);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.updateState = function (controller, id, state) {
|
||||
var currentTime = new Date().getTime() - this.startTime;
|
||||
|
||||
controller.entities.some(function (player) {
|
||||
if (player.id === id) {
|
||||
player.addState(state, currentTime);
|
||||
player.sequence += player.inputs.length;
|
||||
|
||||
Reference in New Issue
Block a user