mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed problems with first world update
This commit is contained in:
parent
283a1ef48b
commit
93e8133c89
13 changed files with 353 additions and 166 deletions
|
|
@ -40,6 +40,7 @@
|
|||
var user = new User(userId, this);
|
||||
var joinedUsers = Object.keys(this.users);
|
||||
var spawnedPlayers = this.gameController.getSpawnedPlayersAndTheirPositions();
|
||||
var worldUpdate = this.gameController.getWorldUpdateObject(true);
|
||||
|
||||
this.users[user.id] = user;
|
||||
|
||||
|
|
@ -47,7 +48,9 @@
|
|||
userId: user.id,
|
||||
channelName: this.name,
|
||||
joinedUsers: joinedUsers,
|
||||
spawnedPlayers: spawnedPlayers
|
||||
spawnedPlayers: spawnedPlayers,
|
||||
worldUpdate: worldUpdate
|
||||
|
||||
};
|
||||
|
||||
NotificationCenter.trigger('user/' + user.id + "/joinSuccess", options);
|
||||
|
|
|
|||
|
|
@ -71,12 +71,23 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
GameController.prototype.updateWorld = function () {
|
||||
|
||||
var update = this.getWorldUpdateObject(false);
|
||||
|
||||
if(Object.getOwnPropertyNames(update).length > 0) {
|
||||
NotificationCenter.trigger("sendControlCommandToAllUsers", 'gameCommand', {worldUpdate:update});
|
||||
}
|
||||
|
||||
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
|
||||
}
|
||||
|
||||
GameController.prototype.getWorldUpdateObject = function(getSleeping) {
|
||||
getSleeping = getSleeping || false;
|
||||
|
||||
var update = {};
|
||||
var isUpdateNeeded = false;
|
||||
|
||||
var body = this.physicsEngine.world.GetBodyList();
|
||||
do {
|
||||
if(body.IsAwake()) {
|
||||
if(getSleeping || body.IsAwake()) {
|
||||
var userData = body.GetUserData();
|
||||
|
||||
if (userData instanceof GameObject) {
|
||||
|
|
@ -93,28 +104,12 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
update[gameObject.uid].as = gameObject.getActionState();
|
||||
update[gameObject.uid].laxy = gameObject.lookAtXY;
|
||||
}
|
||||
|
||||
isUpdateNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
} while (body = body.GetNext());
|
||||
|
||||
if(isUpdateNeeded) {
|
||||
NotificationCenter.trigger("sendControlCommandToAllUsers", 'gameCommand', {worldUpdate:update});
|
||||
}
|
||||
|
||||
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
|
||||
}
|
||||
|
||||
GameController.prototype.getSpawnedPlayers = function() {
|
||||
var spawnedPlayers = {};
|
||||
for(player in this.players) {
|
||||
if(player.isSpawned) {
|
||||
spawnedPlayers[player.id] = player;
|
||||
}
|
||||
}
|
||||
return spawnedPlayers;
|
||||
return update;
|
||||
};
|
||||
|
||||
GameController.prototype.getSpawnedPlayersAndTheirPositions = function() {
|
||||
|
|
@ -130,11 +125,9 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: OR: use get Spawned Players and fetch them into a sort of transfer objects
|
||||
// that contains only necessary data
|
||||
|
||||
return spawnedPlayers;
|
||||
};
|
||||
|
||||
|
||||
return GameController;
|
||||
});
|
||||
|
|
|
|||
9
app/Game/Server/GameObjects/Item.js
Normal file
9
app/Game/Server/GameObjects/Item.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Item"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
|
||||
return Parent;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue