replaced all tabs with 4 spaces

This commit is contained in:
logsol 2012-07-28 13:26:05 +02:00
parent 5d11540c55
commit 26f3d22db7
30 changed files with 1017 additions and 1011 deletions

View file

@ -1,108 +1,108 @@
define([
"Game/Server/GameController",
"Game/Core/NotificationCenter"
],
define([
"Game/Server/GameController",
"Game/Core/NotificationCenter"
],
function(GameController, NotificationCenter) {
function(GameController, NotificationCenter) {
function Channel(coordinatorLink) {
var self = this;
function Channel(coordinatorLink) {
var self = this;
this.coordinatorLink = coordinatorLink;
this.coordinatorLink.receive = function(message) { self.onMessage(message) };
this.users = {};
this.coordinatorLink = coordinatorLink;
this.coordinatorLink.receive = function(message) { self.onMessage(message) };
this.users = {};
this.gameController = new GameController();
this.gameController.loadLevel("default.json");
/*
var self = this;
NotificationCenter.on("processGameCommandFromUser", function(topic, args) {
self.processGameCommandFromUser.apply(self, args);
});
*/
}
this.gameController = new GameController();
this.gameController.loadLevel("default.json");
/*
var self = this;
NotificationCenter.on("processGameCommandFromUser", function(topic, args) {
self.processGameCommandFromUser.apply(self, args);
});
*/
}
Channel.validateName = function(name){
return true;
}
Channel.validateName = function(name){
return true;
}
// Messages look like:
// {channel: {setName: 'foo'}}
// {user: {jupm: null}, id: 12}
Channel.prototype.onMessage = function(message) {
// Messages look like:
// {channel: {setName: 'foo'}}
// {user: {jupm: null}, id: 12}
Channel.prototype.onMessage = function(message) {
for(var recipient in message) {
for(var recipient in message) {
switch(recipient) {
switch(recipient) {
case 'user':
this.forward(this.users[message.id], message.user);
break;
case 'id': // Do nothing, it is needed by the user
break;
case 'channel':
this.forward(this, message.channel);
break;
default:
throw 'unknown recipient';
break;
}
}
};
case 'user':
this.forward(this.users[message.id], message.user);
break;
case 'id': // Do nothing, it is needed by the user
break;
case 'channel':
this.forward(this, message.channel);
break;
default:
throw 'unknown recipient';
break;
}
}
};
Channel.prototype.forward = function(target, message) {
for(var command in message) {
if(typeof target[command] == 'function'){
target[command].call(target, message[command]);
} else {
throw 'trying to call undefined function ' + target[command];
}
}
};
Channel.prototype.forward = function(target, message) {
for(var command in message) {
if(typeof target[command] == 'function'){
target[command].call(target, message[command]);
} else {
throw 'trying to call undefined function ' + target[command];
}
}
};
Channel.prototype.setName = function(name) {
this.name = name;
console.log(' created channel ' + name);
}
/*
Channel.prototype.addUser = function(user){
var userIds = Object.keys(this.users);
Channel.prototype.setName = function(name) {
this.name = name;
console.log(' created channel ' + name);
}
/*
Channel.prototype.addUser = function(user){
var userIds = Object.keys(this.users);
this.users[user.id] = user;
this.users[user.id] = user;
user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds});
this.sendCommandToAllUsersExcept('userJoined', user.id, user);
user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds});
this.sendCommandToAllUsersExcept('userJoined', user.id, user);
NotificationCenter.trigger('user/joined', user);
}
NotificationCenter.trigger('user/joined', user);
}
Channel.prototype.releaseUser = function(user) {
this.gameController.userIdLeft(user.id);
Channel.prototype.releaseUser = function(user) {
this.gameController.userIdLeft(user.id);
this.sendCommandToAllUsersExcept("userLeft", user.id, user);
delete this.users[user.id];
}
this.sendCommandToAllUsersExcept("userLeft", user.id, user);
delete this.users[user.id];
}
Channel.prototype.sendCommandToAllUsers = function(command, options) {
for(var id in this.users) {
this.users[id].sendCommand(command, options);
}
}
Channel.prototype.sendCommandToAllUsers = function(command, options) {
for(var id in this.users) {
this.users[id].sendCommand(command, options);
}
}
Channel.prototype.sendCommandToAllUsersExcept = function(command, options, except_user) {
for(var id in this.users) {
if (id != except_user.id) {
this.users[id].sendCommand(command, options);
}
}
}
Channel.prototype.sendCommandToAllUsersExcept = function(command, options, except_user) {
for(var id in this.users) {
if (id != except_user.id) {
this.users[id].sendCommand(command, options);
}
}
}
Channel.prototype.processGameCommandFromUser = function(command, options, user) {
this.gameController.progressGameCommandFromUser(command, options, user);
}
*/
return Channel;
});
Channel.prototype.processGameCommandFromUser = function(command, options, user) {
this.gameController.progressGameCommandFromUser(command, options, user);
}
*/
return Channel;
});

View file

@ -3,18 +3,18 @@ define([
function() {
function CoordinatorLink(process) {
this.process = process;
}
function CoordinatorLink(process) {
this.process = process;
}
CoordinatorLink.prototype.send = function(message) {
this.process.send(message);
};
CoordinatorLink.prototype.send = function(message) {
this.process.send(message);
};
CoordinatorLink.prototype.receive = function(message) {
throw 'This method is abstract and must be overwritten by Channel';
};
CoordinatorLink.prototype.receive = function(message) {
throw 'This method is abstract and must be overwritten by Channel';
};
return CoordinatorLink;
return CoordinatorLink;
});

View file

@ -1,84 +1,84 @@
define([
"Game/Core/GameController",
"Game/Core/Physics/Engine",
"Game/Config/Settings",
"Game/Core/Control/InputController",
"Lib/Utilities/RequestAnimFrame",
"Game/Core/NotificationCenter"
"Game/Core/GameController",
"Game/Core/Physics/Engine",
"Game/Config/Settings",
"Game/Core/Control/InputController",
"Lib/Utilities/RequestAnimFrame",
"Game/Core/NotificationCenter"
],
function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, NotificationCenter) {
function GameController () {
Parent.call(this, new PhysicsEngine());
function GameController () {
Parent.call(this, new PhysicsEngine());
this.inputControllers = {};
this.inputControllers = {};
//this.update();
//this.updateWorld();
//this.update();
//this.updateWorld();
//NotificationCenter.on('user/joined', this.userJoined, this);
//NotificationCenter.on('user/left', this.userLeft, this);
}
//NotificationCenter.on('user/joined', this.userJoined, this);
//NotificationCenter.on('user/left', this.userLeft, this);
}
GameController.prototype = Object.create(Parent.prototype);
GameController.prototype = Object.create(Parent.prototype);
/*
GameController.prototype.update = function() {
GameController.prototype.update = function() {
requestAnimFrame(this.update.bind(this));
requestAnimFrame(this.update.bind(this));
this.physicsEngine.update();
for(var id in this.players) {
this.players[id].update();
}
}
this.physicsEngine.update();
for(var id in this.players) {
this.players[id].update();
}
}
GameController.prototype.userJoined = function(user) {
Parent.prototype.userJoined.call(this, user);
var id = user.id;
var player = this.players[id];
this.inputControllers[id] = new InputController(player);
}
GameController.prototype.userJoined = function(user) {
Parent.prototype.userJoined.call(this, user);
var id = user.id;
var player = this.players[id];
this.inputControllers[id] = new InputController(player);
}
GameController.prototype.userLeft = function(user) {
Parent.prototype.userLeft.call(this, user);
delete this.inputControllers[user.id];
}
GameController.prototype.userLeft = function(user) {
Parent.prototype.userLeft.call(this, user);
delete this.inputControllers[user.id];
}
GameController.prototype.progressGameCommandFromUser = function(command, options, user) {
var inputController = this.inputControllers[user.id];
if (typeof inputController[command] == 'function') {
inputController[command](options);
}
}
GameController.prototype.progressGameCommandFromUser = function(command, options, user) {
var inputController = this.inputControllers[user.id];
if (typeof inputController[command] == 'function') {
inputController[command](options);
}
}
GameController.prototype.updateWorld = function() {
var update = {};
var isUpdateNeeded = false;
GameController.prototype.updateWorld = function() {
var update = {};
var isUpdateNeeded = false;
var body = this.physicsEngine.world.GetBodyList();
do {
var userData = body.GetUserData();
var body = this.physicsEngine.world.GetBodyList();
do {
var userData = body.GetUserData();
if(userData && body.IsAwake()){
update[userData] = {
p: body.GetPosition(),
a: body.GetAngle(),
lv: body.GetLinearVelocity(),
av: body.GetAngularVelocity()
};
isUpdateNeeded = true;
}
} while (body = body.GetNext());
if(isUpdateNeeded) {
//NotificationCenter.trigger("sendCommandToAllUsers", ['gameCommand', {worldUpdate:update}]);
}
if(userData && body.IsAwake()){
update[userData] = {
p: body.GetPosition(),
a: body.GetAngle(),
lv: body.GetLinearVelocity(),
av: body.GetAngularVelocity()
};
isUpdateNeeded = true;
}
} while (body = body.GetNext());
if(isUpdateNeeded) {
//NotificationCenter.trigger("sendCommandToAllUsers", ['gameCommand', {worldUpdate:update}]);
}
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
}
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
}
*/
return GameController;
return GameController;
});

View file

@ -1,45 +1,45 @@
define([
"Game/Core/User",
"Game/Core/Protocol/Helper",
"Game/Core/NotificationCenter"
"Game/Core/User",
"Game/Core/Protocol/Helper",
"Game/Core/NotificationCenter"
],
function(Parent, ProtocolHelper, NotificationCenter) {
function User(id, coordinator) {
Parent.call(this, id);
this.id = socketLink.id;
this.socketLink = socketLink;
this.coordinator = coordinator;
this.channel = null;
this.init(socketLink);
}
function User(id, coordinator) {
Parent.call(this, id);
this.id = socketLink.id;
this.socketLink = socketLink;
this.coordinator = coordinator;
this.channel = null;
this.init(socketLink);
}
User.prototype = Object.create(Parent.prototype);
User.prototype = Object.create(Parent.prototype);
User.prototype.init = function(socketLink){
User.prototype.init = function(socketLink){
var self = this;
var self = this;
}
}
/*
User.prototype.setChannel = function(channel) {
this.channel = channel;
}
User.prototype.setChannel = function(channel) {
this.channel = channel;
}
User.prototype.sendCommand = function(command, options) {
User.prototype.sendCommand = function(command, options) {
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
}
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
}
User.prototype.toString = function() {
return "[User " + this.id + "]";
};
User.prototype.toString = function() {
return "[User " + this.id + "]";
};
*/
return User;
return User;
});