added ASSERT, fixed #103

This commit is contained in:
Jeena 2015-03-15 16:51:38 +01:00
parent 55eff36f34
commit dfa71bc8e5
17 changed files with 249 additions and 153 deletions

View file

@ -7,6 +7,8 @@ define([
],
function (Parent, KeyboardInput, DomController, Settings, Swiper) {
"use strict";
function KeyboardAndMouse(playerController) {
Parent.call(this);
@ -42,7 +44,7 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
minus: 189,
minusfx: 173,
zero: 48
}
};
this.playerController = playerController;
this.keyboardInit();
@ -87,7 +89,7 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
this.lastLookDirection = -1;
this.onXyChange(this.lastLookDirection * Settings.VIEWPORT_LOOK_AHEAD, 0);
}
this.playerController.moveLeft()
this.playerController.moveLeft();
};
KeyboardAndMouse.prototype.moveRight = function() {
@ -129,7 +131,8 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
if(!self.playerController.player.isHoldingSomething()) {
var options = {
x: self.x,
y: self.y
y: self.y,
av: 0
};
self.playerController.handActionRequest(options);
} else {

View file

@ -13,10 +13,11 @@ define([
"Lib/Utilities/Protocol/Helper",
"Game/Client/Me",
"Game/Client/AudioPlayer",
"Game/Client/PointerLockManager"
"Game/Client/PointerLockManager",
"Lib/Utilities/Assert"
],
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me, AudioPlayer, PointerLockManager) {
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me, AudioPlayer, PointerLockManager, Assert) {
"use strict";
@ -39,7 +40,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
GameController.prototype.getMe = function () {
return this.me;
}
};
GameController.prototype.update = function () {
@ -59,7 +60,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
this.view.render();
DomController.fpsStep();
}
};
GameController.prototype.mePositionStateUpdate = function() {
if(this.me.isPositionStateUpdateNeeded()) {
@ -68,27 +69,28 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
};
GameController.prototype.onClientReadyResponse = function(options) {
var i;
if (options.worldUpdate) {
this.onWorldUpdate(options.worldUpdate);
}
if (options.runtimeItems) {
for (var i = 0; i < options.runtimeItems.length; i++) {
for (i = 0; i < options.runtimeItems.length; i++) {
var itemDef = options.runtimeItems[i];
var alreadyExists = false;
for (var i = 0; i < this.gameObjects.animated.length; i++) {
if(this.gameObjects.animated[i].uid == itemDef.uid) {
for (var j = 0; j < this.gameObjects.animated.length; j++) {
if(this.gameObjects.animated[j].uid == itemDef.uid) {
alreadyExists = true;
break;
}
};
}
if(!alreadyExists) {
var item = this.level.createItem(itemDef.uid, itemDef.options);
this.level.createItem(itemDef.uid, itemDef.options);
}
};
}
}
this.setMe();
@ -96,7 +98,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
this.clientIsReady = true; // needs to stay before onSpawnPlayer
if (options.spawnedPlayers) {
for(var i = 0; i < options.spawnedPlayers.length; i++) {
for(i = 0; i < options.spawnedPlayers.length; i++) {
this.onSpawnPlayer(options.spawnedPlayers[i]);
}
}
@ -126,6 +128,11 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
gameObject.lookAt(update.laxy.x, update.laxy.y);
}
Assert.number(update.p.x, update.p.y);
Assert.number(update.a);
Assert.number(update.lv.x, update.lv.y);
Assert.number(update.av);
body.SetAwake(true);
body.SetPosition(update.p);
body.SetAngle(update.a);
@ -133,10 +140,10 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
body.SetAngularVelocity(update.av);
}
}
} while (body = body.GetNext());
}
};
GameController.prototype.createMe = function(user) {
this.me = new Me(user.id, this.physicsEngine, user);
@ -146,7 +153,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
GameController.prototype.setMe = function() {
this.me.setPlayerController(new PlayerController(this.me));
this.view.setMe(this.me);
}
};
GameController.prototype.onGameCommand = function(message) {
ProtocolHelper.applyCommand(message, this);
@ -172,7 +179,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
playerId: playerId
});
}
}
};
GameController.prototype.onHandActionResponse = function(options) {
var player = this.players[options.playerId];
@ -184,7 +191,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
item = currentItem;
break;
}
};
}
if(item) {
if(options.action == "throw") {
@ -193,7 +200,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
player.grab(item);
}
} else {
console.warn("Item for joint can not be found locally. " + options.itemUid)
console.warn("Item for joint can not be found locally. " + options.itemUid);
}
};
@ -243,18 +250,18 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
GameController.prototype.loadLevel = function (path) {
Parent.prototype.loadLevel.call(this, path);
}
};
GameController.prototype.onLevelLoaded = function () {
PointerLockManager.update(null, {start:true});
}
};
GameController.prototype.toggleGameStats = function(show) {
var playersArray = [];
for (var key in this.players) {
playersArray.push(this.players[key]);
};
}
var sortedPlayers = playersArray.sort(function(a,b) {
if(a.stats.score > b.stats.score) return -1;

View file

@ -1,10 +1,11 @@
define([
"Game/Client/Player",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert"
],
function (Parent, Settings, Nc) {
function (Parent, Settings, Nc, Assert) {
"use strict";
@ -15,7 +16,7 @@ function (Parent, Settings, Nc) {
this.lookAtXY = {
x: Settings.VIEWPORT_LOOK_AHEAD,
y: 0
}
};
this.lastServerPositionState = {
p: {
@ -34,7 +35,7 @@ function (Parent, Settings, Nc) {
this.lookAtXY = {
x: x,
y: y
}
};
Parent.prototype.lookAt.call(this, x, y);
};
@ -63,10 +64,10 @@ function (Parent, Settings, Nc) {
var difference = {
x: Math.abs(this.lastServerPositionState.p.x - this.doll.body.GetPosition().x),
y: Math.abs(this.lastServerPositionState.p.y - this.doll.body.GetPosition().y)
}
};
if(difference.x > Settings.ME_STATE_MAX_DIFFERENCE_METERS
|| difference.y > Settings.ME_STATE_MAX_DIFFERENCE_METERS) {
if(difference.x > Settings.ME_STATE_MAX_DIFFERENCE_METERS ||
difference.y > Settings.ME_STATE_MAX_DIFFERENCE_METERS) {
return true;
}
return false;
@ -76,7 +77,7 @@ function (Parent, Settings, Nc) {
return {
p: this.doll.body.GetPosition().Copy(),
lv: this.doll.body.GetLinearVelocity().Copy()
}
};
};
Me.prototype.acceptPositionStateUpdateFromServer = function() {
@ -85,11 +86,13 @@ function (Parent, Settings, Nc) {
};
Me.prototype.resetPositionState = function(options) {
Assert.number(options.p.x, options.p.y);
Assert.number(options.lv.x, options.lv.y);
this.doll.body.SetPosition(options.p);
this.doll.body.SetLinearVelocity(options.lv);
};
Me.prototype.createAndAddArrow = function(visible) {
Me.prototype.createAndAddArrow = function() {
var self = this;
var position = this.getPosition();
@ -101,7 +104,7 @@ function (Parent, Settings, Nc) {
var callback = function(arrowMesh) {
self.arrowMesh = arrowMesh;
}
};
Nc.trigger(Nc.ns.client.view.playerArrow.createAndAdd, callback, options);
};
@ -113,7 +116,7 @@ function (Parent, Settings, Nc) {
var options = {
x: position.x * Settings.RATIO,
y: position.y * Settings.RATIO,
}
};
Nc.trigger(Nc.ns.client.view.playerArrow.update, this.arrowMesh, options);
};