mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-08 04:20:14 -05:00
Add the ability to limit-rate the dashboard updating (#3527)
Co-authored-by: Emma Broman <emma.broman@liu.se>
This commit is contained in:
@@ -49,6 +49,14 @@ namespace {
|
||||
"in x and y-direction on screen.",
|
||||
openspace::properties::Property::Visibility::User
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo RefreshRateInfo = {
|
||||
"RefreshRate",
|
||||
"Refresh Rate (in ms)",
|
||||
"The number of milliseconds between refreshes of the dashboard items. If the "
|
||||
"value is 0 the dashboard is refreshed at the same rate as the main rendering.",
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -57,9 +65,12 @@ Dashboard::Dashboard()
|
||||
: properties::PropertyOwner({ "Dashboard" })
|
||||
, _isEnabled(EnabledInfo, true)
|
||||
, _startPositionOffset(StartPositionOffsetInfo, glm::ivec2(10, -10))
|
||||
, _refreshRate(RefreshRateInfo, 0, 0, 1000)
|
||||
, _lastRefresh(std::chrono::high_resolution_clock::now())
|
||||
{
|
||||
addProperty(_isEnabled);
|
||||
addProperty(_startPositionOffset);
|
||||
addProperty(_refreshRate);
|
||||
}
|
||||
|
||||
void Dashboard::addDashboardItem(std::unique_ptr<DashboardItem> item) {
|
||||
@@ -137,8 +148,17 @@ void Dashboard::render(glm::vec2& penPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
bool needsUpdate = (now - _lastRefresh) > std::chrono::milliseconds(_refreshRate);
|
||||
if (needsUpdate) {
|
||||
_lastRefresh = now;
|
||||
}
|
||||
|
||||
for (const std::unique_ptr<DashboardItem>& item : _items) {
|
||||
if (item->isEnabled()) {
|
||||
if (needsUpdate) {
|
||||
item->update();
|
||||
}
|
||||
item->render(penPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <optional>
|
||||
|
||||
namespace {
|
||||
@@ -85,4 +87,14 @@ DashboardTextItem::DashboardTextItem(const ghoul::Dictionary& dictionary, float
|
||||
_font = global::fontManager->font(_fontName, _fontSize);
|
||||
}
|
||||
|
||||
void DashboardTextItem::render(glm::vec2& penPosition) {
|
||||
if (_buffer.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t lines = std::count(_buffer.begin(), _buffer.end(), '\n') + 1;
|
||||
penPosition.y -= _font->height() * lines;
|
||||
RenderFont(*_font, penPosition, _buffer);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user