(flyover)
in world class
//b2BlockAllocator m_blockAllocator;
//b2StackAllocator m_stackAllocator;
// Size the island for the worst case.
/** @type {box2d.b2Island} */
var island = this.m_island;
island.Initialize(this.m_bodyCount,
this.m_contactManager.m_contactCount,
this.m_jointCount,
null, // this.m_stackAllocator,
this.m_contactManager.m_contactListener);
box2d.b2World.prototype.SolveTOI = function(step) {
// box2d.b2Island island(2 * box2d.b2_maxTOIContacts, box2d.b2_maxTOIContacts, 0, &m_stackAllocator, m_contactManager.m_contactListener);
/** @type {box2d.b2Island} */
var island = this.m_island;
island.Initialize(2 * box2d.b2_maxTOIContacts, box2d.b2_maxTOIContacts, 0, null, this.m_contactManager.m_contactListener);
in island class
box2d.b2Island.prototype.m_allocator = null;
box2d.b2Island.prototype.Initialize = function(bodyCapacity, contactCapacity, jointCapacity, allocator, listener) {
this.m_bodyCapacity = bodyCapacity;
this.m_contactCapacity = contactCapacity;
this.m_jointCapacity = jointCapacity;
this.m_bodyCount = 0;
this.m_contactCount = 0;
this.m_jointCount = 0;
this.m_allocator = allocator;
this.m_listener = listener;
// Initialize velocity constraints.
/*box2d.b2ContactSolverDef*/
var contactSolverDef = box2d.b2Island.s_contactSolverDef;
contactSolverDef.step.Copy(step);
contactSolverDef.contacts = this.m_contacts;
contactSolverDef.count = this.m_contactCount;
contactSolverDef.positions = this.m_positions;
contactSolverDef.velocities = this.m_velocities;
contactSolverDef.allocator = this.m_allocator;
contactfactory
box2d.b2ContactFactory = function(allocator) {
this.m_allocator = allocator;
this.InitializeRegisters();
}
box2d.b2ContactFactory.prototype.m_allocator = null;
box2d.b2ContactFactory.prototype.AddType = function(createFcn, destroyFcn, type1, type2) {
var pool = box2d.b2MakeArray(256, function(i) {
return createFcn();
}); // TODO: b2Settings
var poolCreateFcn = function(allocator) {
if (pool.length > 0) {
return pool.pop();
}
return createFcn(allocator);
}
var poolDestroyFcn = function(contact, allocator) {
pool.push(contact);
}
box2d.b2ContactFactory.prototype.Create = function(fixtureA, indexA, fixtureB, indexB) {
var type1 = fixtureA.GetType();
var type2 = fixtureB.GetType();
if (box2d.ENABLE_ASSERTS) {
box2d.b2Assert(0 <= type1 && type1 < box2d.b2ShapeType.e_shapeTypeCount);
}
if (box2d.ENABLE_ASSERTS) {
box2d.b2Assert(0 <= type2 && type2 < box2d.b2ShapeType.e_shapeTypeCount);
}
var reg = this.m_registers[type1][type2];
var createFcn = reg.createFcn;
if (createFcn !== null) {
if (reg.primary) {
var c = createFcn(this.m_allocator);
c.Reset(fixtureA, indexA, fixtureB, indexB);
return c;
} else {
var c = createFcn(this.m_allocator);
c.Reset(fixtureB, indexB, fixtureA, indexA);
return c;
}
} else {
return null;
}
}
in individual contact classes, eg circlecontact class - isnt used in practice
box2d.b2CircleContact.Create = function(allocator) {
return new box2d.b2CircleContact();
}
box2d.b2CircleContact.Destroy = function(contact, allocator) {}
in contactsolver class
box2d.b2ContactSolverDef.prototype.allocator = null;
box2d.b2ContactSolver.prototype.m_allocator = null;
box2d.b2ContactSolver.prototype.Initialize = function(def) {
this.m_step.Copy(def.step);
this.m_allocator = def.allocator;
this.m_count = def.count;
// TODO:
if (this.m_positionConstraints.length < this.m_count) {
var new_length = box2d.b2Max(this.m_positionConstraints.length * 2, this.m_count);
if (box2d.DEBUG) {
window.console.log("box2d.b2ContactSolver.m_positionConstraints: " + new_length);
}
while (this.m_positionConstraints.length < new_length) {
this.m_positionConstraints[this.m_positionConstraints.length] = new box2d.b2ContactPositionConstraint();
}
}
contactmanager classs
box2d.b2ContactManager = function() {
this.m_broadPhase = new box2d.b2BroadPhase();
this.m_contactFactory = new box2d.b2ContactFactory(this.m_allocator);
}
box2d.b2ContactManager.prototype.m_allocator = null;
Commentaires