first attempt of implmenting asm style box2d engine

This commit is contained in:
logsol 2014-06-15 01:36:02 +02:00
parent ebf167107a
commit cca3a258ba
12 changed files with 12255 additions and 10876 deletions

View file

@ -57,13 +57,13 @@ function(Parent, Nc, Parser, Settings) {
this.player.doll.updatePositionState(update);
} else {
// HARD UPDATE FOR SELF
console.log(this.player.user.options.nickname + ' is cheating.')
console.log(this.player.user.options.nickname + ' is cheating. difference:', difference);
var body = this.player.doll.body;
var options = {
p: body.GetPosition(),
lv: body.GetLinearVelocity()
p: body.GetPosition().Copy(),
lv: body.GetLinearVelocity().Copy()
};
Nc.trigger(Nc.ns.channel.to.client.user.gameCommand.send + this.player.id, 'positionStateReset', options);

View file

@ -50,7 +50,9 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
}
GameController.prototype.onLevelLoaded = function() {
console.log("onLevelLoaded updateWorld pre")
this.updateWorld();
console.log("onLevelLoaded updateWorld post")
};
GameController.prototype.onUserJoined = function (user) {
@ -115,20 +117,22 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
getSleeping = getSleeping || false;
var update = {};
var body = this.physicsEngine.world.GetBodyList();
do {
if((getSleeping || body.IsAwake()) && body.GetType() === Box2D.Dynamics.b2Body.b2_dynamicBody) {
var userData = body.GetUserData();
if (userData instanceof GameObject) {
var gameObject = userData;
update[gameObject.uid] = {
p: body.GetPosition(),
p: body.GetPosition().Copy(),
a: body.GetAngle(),
lv: body.GetLinearVelocity(),
av: body.GetAngularVelocity()
lv: body.GetLinearVelocity().Copy(),
av: body.GetAngularVelocity().Copy()
};
if(gameObject instanceof Doll) {
@ -138,6 +142,12 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
}
}
if(Settings.USE_ASM) {
if(body.GetNext() == body) {
break;
}
}
} while (body = body.GetNext());
return update;

View file

@ -135,6 +135,12 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
body.SetAngularVelocity(update.av);
}
}
if(Settings.USE_ASM) {
if(body.GetNext() == body) {
break;
}
}
} while (body = body.GetNext());

View file

@ -59,11 +59,12 @@ define(function() {
CANVAS_DOM_ID: 'canvasContainer',
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
USE_WEBGL: true,
USE_ASM: true,
// NETWORKING
NETWORK_UPDATE_INTERVAL: 70,
CHANNEL_DESTRUCTION_TIME: 30,
NETWORK_LOG_INCOMING: false,
NETWORK_LOG_INCOMING: true,
NETWORK_LOG_OUTGOING: false,
NETWORK_LOG_FILTER: ['ping', 'pong', 'worldUpdate', 'lookAt'],

View file

@ -22,8 +22,11 @@ function (Parent, Box2D, Settings, Exception, Nc) {
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
bodyDef.position.x = (this.options.x * Settings.TILE_SIZE + Settings.TILE_SIZE / 2) / Settings.RATIO;
bodyDef.position.y = (this.options.y * Settings.TILE_SIZE + Settings.TILE_SIZE / 2) / Settings.RATIO;
var x = (this.options.x * Settings.TILE_SIZE + Settings.TILE_SIZE / 2) / Settings.RATIO;
var y = (this.options.y * Settings.TILE_SIZE + Settings.TILE_SIZE / 2) / Settings.RATIO;
bodyDef.position = new Box2D.Common.Math.b2Vec2(x, y);
bodyDef.angle = (this.options.r || 0) * 90 * Math.PI / 180;
return bodyDef;
@ -31,8 +34,14 @@ function (Parent, Box2D, Settings, Exception, Nc) {
Tile.prototype.createPhysicTile = function (tile) {
var vertices = this.createVertices(tile);
var tileShape = new Box2D.Collision.Shapes.b2PolygonShape();
tileShape.SetAsArray(vertices, vertices.length);
var tileShape;
if(Settings.USE_ASM) {
tileShape = Box2D.createPolygonShape(vertices);
} else {
tileShape = new Box2D.Collision.Shapes.b2PolygonShape();
tileShape.SetAsArray(vertices, vertices.length);
}
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
fixtureDef.shape = tileShape;