载入中...
搜索中...
未找到
FrameStatsPanel.cpp
浏览该文件的文档.
2
4
5#include <cmath>
6#include <sstream>
7
8namespace eve::dev {
9namespace {
10FrameStatsPanel::ImGuiDrawer g_imguiDrawer = nullptr;
11constexpr float kEmaAlpha = 0.12f;
12} // namespace
13
17
19 std::lock_guard lock(mu_);
20 visible_ = on;
21}
22
24 std::lock_guard lock(mu_);
25 return visible_;
26}
27
29
30void FrameStatsPanel::sample(float dtSeconds) {
31 if (!std::isfinite(dtSeconds) || dtSeconds <= 0.f || dtSeconds > 10.f) return;
32 const float instant = 1.f / dtSeconds;
33 std::lock_guard lock(mu_);
34 lastDt_ = dtSeconds;
35 if (emaFps_ <= 0.f)
36 emaFps_ = instant;
37 else
38 emaFps_ = emaFps_ * (1.f - kEmaAlpha) + instant * kEmaAlpha;
39}
40
42 std::lock_guard lock(mu_);
43 entityCount_ = count < 0 ? -1 : count;
44}
45
47 std::lock_guard lock(mu_);
48 entityCount_ = -1;
49}
50
51float FrameStatsPanel::fps() const {
52 std::lock_guard lock(mu_);
53 return emaFps_;
54}
55
57 std::lock_guard lock(mu_);
58 return lastDt_ > 0.f ? lastDt_ * 1000.f : 0.f;
59}
60
62 std::lock_guard lock(mu_);
63 return entityCount_;
64}
65
67 std::lock_guard lock(mu_);
68 return entityCount_ >= 0;
69}
70
71std::string FrameStatsPanel::format() const {
72 std::lock_guard lock(mu_);
73 std::ostringstream oss;
74 oss.setf(std::ios::fixed);
75 oss.precision(1);
76 oss << emaFps_ << " fps | " << (lastDt_ > 0.f ? lastDt_ * 1000.f : 0.f) << " ms";
77 if (entityCount_ >= 0) oss << " | " << entityCount_ << " entities";
78 return oss.str();
79}
80
82
84 if (g_imguiDrawer) g_imguiDrawer(*this);
85}
86
87} // namespace eve::dev
std::uint32_t count
Lightweight FPS / frame-time overlay for DevTools (0.6 closeout).
void setEntityCount(int count)
Optional entity / actor count shown in the overlay; negative clears.
int entityCount() const
-1 when unset
void(*)(FrameStatsPanel &panel) ImGuiDrawer
static FrameStatsPanel & instance()
static void setImGuiDrawer(ImGuiDrawer fn)
void sample(float dtSeconds)
Feed one frame duration in seconds (must be finite and > 0). Updates EMA FPS and last frame milliseco...
std::string format() const
One-line summary for logs / scripts, e.g. 60.1 fps | 16.6 ms | 128 entities.
SettlementPipeline::Stage fn
static T & get()
Returns the process-lifetime instance.
Definition Immortal.hpp:21