From c3e7587dfcfb51748be7861ba0f06e1d2aa9b87b Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Wed, 9 Oct 2024 11:01:06 -0400 Subject: update ball positions in parallel --- balls.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/balls.cpp b/balls.cpp index b98b322..de3aa54 100644 --- a/balls.cpp +++ b/balls.cpp @@ -198,18 +198,20 @@ volume(double radius) { void animate(int v) { - /* TODO: parallel */ - for (Ball *ball : balls) { - ball->v.y -=G; - ball->p = ptAddVec(ball->p, ball->v); - } + /* Update position. */ + parallel_for(size_t(0), balls.size(), [] (size_t i) { + balls[i]->v.y -=G; + balls[i]->p = ptAddVec(balls[i]->p, balls[i]->v); + }); + /* Collide with balls. */ for (vector cell : collisionPartition) { parallel_for(size_t(0), cell.size(), [cell] (size_t i) { collideBall(cell[i].b1, cell[i].b2); }); } + /* Collide with walls. */ parallel_for(size_t(0), balls.size(), [] (size_t i) { collideWall(balls[i], bounds); }); -- cgit v1.2.3