Drives the per-frame cycle: poll input, begin frame, run the draw callback, end frame. Backend-agnostic so it can be unit-tested against a fake.
| 35 | /// Drives the per-frame cycle: poll input, begin frame, run the draw callback, |
| 36 | /// end frame. Backend-agnostic so it can be unit-tested against a fake. |
| 37 | class FrameLoop { |
| 38 | public: |
| 39 | FrameLoop(HostBackend& backend, std::function<void()> draw_frame); |
| 40 | |
| 41 | /// Run one iteration. Returns false if the backend requested close (in |
| 42 | /// which case nothing was drawn), true after a rendered frame. |
| 43 | bool tick(); |
| 44 | |
| 45 | /// Loop until tick() returns false. |
| 46 | void run(); |
| 47 | |
| 48 | [[nodiscard]] int frame_count() const { |
| 49 | return frame_count_; |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | HostBackend& backend_; |
| 54 | std::function<void()> draw_frame_; |
| 55 | int frame_count_{0}; |
| 56 | }; |
| 57 | |
| 58 | } // namespace oid::host |
| 59 |
nothing calls this directly
no outgoing calls
no test coverage detected