X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FFrameCounter.hpp;fp=src%2Fapp%2FFrameCounter.hpp;h=069f622ce690246f5a770a75fc2f766d5d43dba4;hb=5c295a495e02b4987b63c682406f5f29402c00da;hp=0000000000000000000000000000000000000000;hpb=2c2c02796e9df82d0cda12b59aad638d40b4e8b4;p=blank.git diff --git a/src/app/FrameCounter.hpp b/src/app/FrameCounter.hpp new file mode 100644 index 0000000..069f622 --- /dev/null +++ b/src/app/FrameCounter.hpp @@ -0,0 +1,60 @@ +#ifndef BLANK_APP_FRAMECOUNTER_HPP_ +#define BLANK_APP_FRAMECOUNTER_HPP_ + +#include +#include + + +namespace blank { + +class FrameCounter { + +public: + void EnterFrame() noexcept; + void EnterHandle() noexcept; + void ExitHandle() noexcept; + void EnterUpdate() noexcept; + void ExitUpdate() noexcept; + void EnterRender() noexcept; + void ExitRender() noexcept; + void ExitFrame() noexcept; + + float AvgHandle() const noexcept { return avg.handle; } + float AvgUpdate() const noexcept { return avg.update; } + float AvgRender() const noexcept { return avg.render; } + float AvgFrame() const noexcept { return avg.total; } + float AvgRunning() const noexcept { return avg.handle + avg.update + avg.render; } + float AvgWaiting() const noexcept { return avg.total - AvgRunning(); } + + bool Changed() const noexcept { return changed; } + + void Print(std::ostream &) const; + +private: + int Tick() noexcept; + +private: + static constexpr int NUM_FRAMES = 32; + static constexpr float factor = 1.0f / float(NUM_FRAMES); + + template + struct Frame { + T handle = T(0); + T update = T(0); + T render = T(0); + T total = T(0); + }; + + Uint32 last_enter = 0; + Uint32 last_tick = 0; + + int cur_frame = 0; + Frame running = Frame{}; + Frame avg = Frame{}; + bool changed = false; + +}; + +} + +#endif