Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update order of events in worker tick #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/ammo.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ const tick = () => {
setTimeout(tick, simulationRate);

if (isBufferConsumed()) {
const now = performance.now();
const dt = now - lastTick;
world.step(dt / 1000);
stepDuration = performance.now() - now;
lastTick = now;

while (messageQueue.length > 0) {
const message = messageQueue.shift();
switch (message.type) {
Expand All @@ -107,6 +101,12 @@ const tick = () => {
}
}

const now = performance.now();
const dt = now - lastTick;
world.step(dt / 1000);
stepDuration = performance.now() - now;
lastTick = now;

/** Buffer Schema
* Every physics body has 26 * 4 bytes (64bit float/int) assigned in the buffer
* 0-15: Matrix4 elements (floats)
Expand Down
6 changes: 0 additions & 6 deletions src/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function almostEqualsQuaternion(epsilon, u, v) {
* parsing the elements geometry.
*/
function Body(bodyConfig, matrix, world) {
this.loadedEvent = bodyConfig.loadedEvent ? bodyConfig.loadedEvent : "";
this.mass = bodyConfig.hasOwnProperty("mass") ? bodyConfig.mass : 1;
const worldGravity = world.physicsWorld.getGravity();
this.gravity = new Ammo.btVector3(worldGravity.x(), worldGravity.y(), worldGravity.z());
Expand All @@ -71,7 +70,6 @@ function Body(bodyConfig, matrix, world) {
? bodyConfig.activationState
: ACTIVATION_STATE.ACTIVE_TAG;
this.type = bodyConfig.type ? bodyConfig.type : TYPE.DYNAMIC;
this.emitCollisionEvents = bodyConfig.hasOwnProperty("emitCollisionEvents") ? bodyConfig.emitCollisionEvents : false;
this.disableCollision = bodyConfig.hasOwnProperty("disableCollision") ? bodyConfig.disableCollision : false;
this.collisionFilterGroup = bodyConfig.hasOwnProperty("collisionFilterGroup") ? bodyConfig.collisionFilterGroup : 1; //32-bit mask
this.collisionFilterMask = bodyConfig.hasOwnProperty("collisionFilterMask") ? bodyConfig.collisionFilterMask : 1; //32-bit mask
Expand Down Expand Up @@ -138,10 +136,6 @@ Body.prototype._initBody = (function() {
this.updateCollisionFlags();

this.world.addBody(this.physicsBody, this.matrix, this.collisionFilterGroup, this.collisionFilterMask);

if (this.emitCollisionEvents) {
this.world.addEventListener(this.physicsBody);
}
};
})();

Expand Down