Hands-on Rust: Does Flappy Dragon need to crush a core?

I am finding that when I run the completed Flappy Dragon project, one of my cpu cores is pinned. It seems like we are running the simulation just as fast as a single thread can muster. Does Rust have the tools to reduce or avoid this? It seems like a lot of our “ticks” may not be meaningful relative to the previous one.

1 Like

Thanks for the report. This was a tricky one when I was setting up the chapter; I wanted to include timing, as a teaching vehicle for tackling that side of things. I also wanted to keep it simple - avoid overloading the reader too much with the introductory game.

You can greatly reduce the amount of CPU usage by adding .with_fps_cap(30.0) to the builder call in main(). That adds CPU sleep time in between frames.

I’ll do a bit of testing/playing around and see what the impact would be on the book as a whole to include this in by default.

1 Like