hecrj / coffee

An opinionated 2D game engine for Rust
https://docs.rs/coffee
MIT License
1.08k stars 55 forks source link

add `should_draw` to Game trait #130

Open JeanMertz opened 4 years ago

JeanMertz commented 4 years ago

I tried to implement an FPS limit solution in my game by returning early from Game::draw if the minimum time between frames wasn't met yet, but noticed that this broke horribly due to Coffee still doing a lot of pre-/post-processing on every draw call.

By exposing Game::should_draw, the game can decide when Coffee should trigger another draw. The default return value is true, which results in the same behaviour as before this change.

I haven't dug too deep into Coffee yet, but I believe timer.update() should still always run? At least anecdotally, for me, this change behaves as expected.

JeanMertz commented 4 years ago

Further testing exposed that this change isn't behaving as expected. It appears the input state is not cleared if the draw call is skipped, which causes the interact method to receive duplicate input events.

I'm not sure where/how this happens, but this PR isn't merge-able as is.