4 ms·
The nested loop in the UpdateFlock function could be optimized. The nested j loop should start at j=i+1, not j=0. Currently the author is making each comparison
by fromthestart 8y ago
The nested loop in the UpdateFlock function could be optimized. The nested j loop should start at j=i+1, not j=0. Currently the author is making each comparison twice.
- plopz 8y agoIf you did that the later boids in the list wouldn't know about any of their own neighbors.
- fromthestart 8y agoIn the current implementation, yes. But the code should be structured to append neighbors to both boids[i] and boids[j] simultaneously. This is especially critical in physics simulations like these, where niave particle interaction algorithms can be an expensive O(n^2).