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

Refactor simulation code into web-worker. #9

Open
kochie opened this issue Apr 3, 2019 · 0 comments
Open

Refactor simulation code into web-worker. #9

kochie opened this issue Apr 3, 2019 · 0 comments
Assignees

Comments

@kochie
Copy link
Owner

kochie commented Apr 3, 2019

The code to calculate the kinematics of the system should be placed into a web-worker that's separate from the rendering code. Currently the kinematics are calculated in a separate interval loop

const intervalId = setInterval(calculate(), timeStep)

while the rendering of the particles is done in an animation frame loop

function animate() {
    updateMeshPositions()
    requestAnimationFrame(animate)
}

What should happen is the kinematic code should be entirely contained in a web-worker and every 1/60 of a second it should send the updated positions of the mesh to the renderer.

while (true) {
    const positions = calcKinematics()
    postMessage(positions)
}
var myWorker = new Worker('worker-kinematics.js');

myWorker.onmessage = function(e) {
    const positions = e.data
    updateMeshPositions()
}

function animate() {
    requestAnimationFrame(animate)
}
@kochie kochie self-assigned this Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant