mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[hud] Implement FPS display as a HUD item
This commit is contained in:
parent
0da5aac357
commit
2d5f44a7ff
@ -37,6 +37,7 @@ namespace dxvk::hud {
|
|||||||
addItem<HudVersionItem>("version");
|
addItem<HudVersionItem>("version");
|
||||||
addItem<HudClientApiItem>("api", m_device);
|
addItem<HudClientApiItem>("api", m_device);
|
||||||
addItem<HudDeviceInfoItem>("devinfo", m_device);
|
addItem<HudDeviceInfoItem>("devinfo", m_device);
|
||||||
|
addItem<HudFpsItem>("fps");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,4 +147,38 @@ namespace dxvk::hud {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HudFpsItem::HudFpsItem() { }
|
||||||
|
HudFpsItem::~HudFpsItem() { }
|
||||||
|
|
||||||
|
|
||||||
|
void HudFpsItem::update(dxvk::high_resolution_clock::time_point time) {
|
||||||
|
m_frameCount += 1;
|
||||||
|
|
||||||
|
auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(time - m_lastUpdate);
|
||||||
|
|
||||||
|
if (elapsed.count() >= UpdateInterval) {
|
||||||
|
int64_t fps = (10'000'000ll * m_frameCount) / elapsed.count();
|
||||||
|
|
||||||
|
m_frameRate = str::format("FPS: ", fps / 10, ".", fps % 10);
|
||||||
|
m_frameCount = 0;
|
||||||
|
m_lastUpdate = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HudPos HudFpsItem::render(
|
||||||
|
HudRenderer& renderer,
|
||||||
|
HudPos position) {
|
||||||
|
position.y += 16.0f;
|
||||||
|
|
||||||
|
renderer.drawText(16.0f,
|
||||||
|
{ position.x, position.y },
|
||||||
|
{ 1.0f, 1.0f, 1.0f, 1.0f },
|
||||||
|
m_frameRate);
|
||||||
|
|
||||||
|
position.y += 8.0f;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -160,4 +160,31 @@ namespace dxvk::hud {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief HUD item to display the frame rate
|
||||||
|
*/
|
||||||
|
class HudFpsItem : public HudItem {
|
||||||
|
constexpr static int64_t UpdateInterval = 500'000;
|
||||||
|
public:
|
||||||
|
|
||||||
|
HudFpsItem();
|
||||||
|
|
||||||
|
~HudFpsItem();
|
||||||
|
|
||||||
|
void update(dxvk::high_resolution_clock::time_point time);
|
||||||
|
|
||||||
|
HudPos render(
|
||||||
|
HudRenderer& renderer,
|
||||||
|
HudPos position);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint32_t m_frameCount = 0;
|
||||||
|
dxvk::high_resolution_clock::time_point m_lastUpdate
|
||||||
|
= dxvk::high_resolution_clock::now();
|
||||||
|
|
||||||
|
std::string m_frameRate;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user