Closed ufrshubham closed 4 years ago
I remember watching Sebastian Lague's youtube video on boids. I wanted to implement it using SFML but wasn't sure how to get started. So this repo is a really great resource for me.
I am also participating in Hacktoberfest this year and I was hoping to get my PR count +1. But it seems only repositories having 'hacktoberfest' as a topic are considered. If it is fine with you guys can you add this topic to your repo.
This is great @ufrshubham, thanks for all the improvements! @chernandez7 and I wrote this back when we were learning C++ many years ago, hence all the silly design choices that we never went back and corrected. And sure, I'll add the hacktoberfest tag to the repo. Cheers.
Fixes #1 I found that all the methods were creating copy of input parameters. This included copies of vector of boids too. These copies were unnecessary, so I have converted all the parameters to const reference. This will save a lot of heap allocations.
Also there was no FPS limit set on main window. I've set that to 60 now. This is not the most correct thing to do but it will at least limit the frame rate when number of biods are less. So here are the new readings.
Release mode
Note: These reading were taken on i5 9th gen + GTX1650 + 8 GB Ram. FPS counts are now 60 because I have set the limit to 60. When left unbound, I was able to see 100+ FPS for 1000 boids.
Additional observations: Right now the motion of boids is frame rate dependent. This means if FPS count is high, boids will move faster and if FPS is low, boids will move slower. This can be solved easily by accumulating time since last frame and updating state only when accumulated time exceeds a pre-defined time (1/60 for achieving 60 FPS).
I didn't fix this in this PR because it will require so more changes and I think it will be better if a new issue is created for this.