diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-10-09 11:01:06 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-10-09 11:01:06 -0400 |
| commit | c3e7587dfcfb51748be7861ba0f06e1d2aa9b87b (patch) | |
| tree | 1230e805f961f75995fbe013d3bccd910eb49ea9 | |
| parent | a4deaae971f6e0869668561f251dd29ae23da189 (diff) | |
| download | balls-c3e7587dfcfb51748be7861ba0f06e1d2aa9b87b.zip | |
update ball positions in parallel
| -rw-r--r-- | balls.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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<Collision> 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); }); |