chore: add comments to swarm.hpp

This commit is contained in:
2024-11-25 14:44:01 +01:00
parent 2b20e90a08
commit fe62617beb
2 changed files with 38 additions and 1 deletions

View File

@@ -65,12 +65,21 @@ main(int argc, char **argv) {
scr.draw();
};
// We draw to the screen at a rate of `kFPS', but step()ing the swarm at
// this rate would be far too fast to be interesting to look at. On the
// other hand, step()ing once a second is too slow.
//
// So, we step() every quarter second. To line up the move() so that a unit
// move() happens preceding each step(), we also need to move as fast as
// we've shortened our step() interval.
for(int i = 0; i < iter_count * kFPS/4;) {
if(!pause) {
scr.clear();
update_and_draw();
// Since we step() 4x a second, we need to move() 4x as fast as moving by dt
// each frame.
swarm.move(kDT * 4);
if(i % (kFPS/4) == (kFPS/4)-1)
swarm.step();
@@ -152,6 +161,7 @@ main(int argc, char **argv) {
break;
}
// Wait for kDT (time between two frames)
usleep(1000 * 1000 / kFPS);
}