mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 18:11:01 -05:00
Fix error with time quantizer string conversion
Fix error with uninitialized memory in GlobeBrowsing Remove dynamic memory allocation from on-screen rendering
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -352,6 +353,7 @@ DashboardItemAngle::DashboardItemAngle(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_destination.nodeName);
|
||||
|
||||
_font = global::fontManager.font(_fontName, _fontSize);
|
||||
_buffer.resize(128);
|
||||
}
|
||||
|
||||
std::pair<glm::dvec3, std::string> DashboardItemAngle::positionAndLabel(
|
||||
@@ -391,6 +393,8 @@ std::pair<glm::dvec3, std::string> DashboardItemAngle::positionAndLabel(
|
||||
}
|
||||
|
||||
void DashboardItemAngle::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
std::pair<glm::dvec3, std::string> sourceInfo = positionAndLabel(_source);
|
||||
std::pair<glm::dvec3, std::string> referenceInfo = positionAndLabel(_reference);
|
||||
std::pair<glm::dvec3, std::string> destinationInfo = positionAndLabel(_destination);
|
||||
@@ -398,16 +402,16 @@ void DashboardItemAngle::render(glm::vec2& penPosition) {
|
||||
const glm::dvec3 a = referenceInfo.first - sourceInfo.first;
|
||||
const glm::dvec3 b = destinationInfo.first - sourceInfo.first;
|
||||
|
||||
std::fill(_buffer.begin(), _buffer.end(), 0);
|
||||
if (glm::length(a) == 0.0 || glm::length(b) == 0) {
|
||||
penPosition.y -= _font->height();
|
||||
RenderFont(
|
||||
*_font,
|
||||
penPosition,
|
||||
fmt::format(
|
||||
"Could not compute angle at {} between {} and {}",
|
||||
sourceInfo.second, destinationInfo.second, referenceInfo.second
|
||||
)
|
||||
char* end = fmt::format_to(
|
||||
_buffer.data(),
|
||||
"Could not compute angle at {} between {} and {}",
|
||||
sourceInfo.second, destinationInfo.second, referenceInfo.second
|
||||
);
|
||||
std::string_view text = std::string_view(_buffer.data(), end - _buffer.data());
|
||||
RenderFont(*_font, penPosition, text);
|
||||
}
|
||||
else {
|
||||
const double angle = glm::degrees(
|
||||
@@ -415,18 +419,19 @@ void DashboardItemAngle::render(glm::vec2& penPosition) {
|
||||
);
|
||||
|
||||
penPosition.y -= _font->height();
|
||||
RenderFont(
|
||||
*_font,
|
||||
penPosition,
|
||||
fmt::format(
|
||||
"Angle at {} between {} and {}: {} degrees",
|
||||
sourceInfo.second, destinationInfo.second, referenceInfo.second, angle
|
||||
)
|
||||
char* end = fmt::format_to(
|
||||
_buffer.data(),
|
||||
"Angle at {} between {} and {}: {} degrees",
|
||||
sourceInfo.second, destinationInfo.second, referenceInfo.second, angle
|
||||
);
|
||||
std::string_view text = std::string_view(_buffer.data(), end - _buffer.data());
|
||||
RenderFont(*_font, penPosition, text);
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemAngle::size() const {
|
||||
ZoneScoped
|
||||
|
||||
constexpr const double Angle = 120;
|
||||
|
||||
return _font->boundingBox("Angle: " + std::to_string(Angle));
|
||||
|
||||
@@ -73,6 +73,7 @@ private:
|
||||
properties::StringProperty _fontName;
|
||||
properties::FloatProperty _fontSize;
|
||||
|
||||
std::vector<char> _buffer;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -110,6 +111,8 @@ DashboardItemDate::DashboardItemDate(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
void DashboardItemDate::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
penPosition.y -= _font->height();
|
||||
RenderFont(
|
||||
*_font,
|
||||
@@ -119,6 +122,8 @@ void DashboardItemDate::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemDate::size() const {
|
||||
ZoneScoped
|
||||
|
||||
return _font->boundingBox(
|
||||
fmt::format("Date: {} UTC", global::timeManager.time().UTC())
|
||||
);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -358,6 +359,8 @@ DashboardItemDistance::DashboardItemDistance(const ghoul::Dictionary& dictionary
|
||||
addProperty(_requestedUnit);
|
||||
|
||||
_font = global::fontManager.font(_fontName, _fontSize);
|
||||
|
||||
_buffer.resize(256);
|
||||
}
|
||||
|
||||
std::pair<glm::dvec3, std::string> DashboardItemDistance::positionAndLabel(
|
||||
@@ -419,6 +422,8 @@ std::pair<glm::dvec3, std::string> DashboardItemDistance::positionAndLabel(
|
||||
}
|
||||
|
||||
void DashboardItemDistance::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
std::pair<glm::dvec3, std::string> sourceInfo = positionAndLabel(
|
||||
_source,
|
||||
_destination
|
||||
@@ -440,18 +445,20 @@ void DashboardItemDistance::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
penPosition.y -= _font->height();
|
||||
|
||||
RenderFont(
|
||||
*_font,
|
||||
penPosition,
|
||||
fmt::format(
|
||||
"Distance from {} to {}: {:f} {}",
|
||||
sourceInfo.second, destinationInfo.second, dist.first, dist.second
|
||||
)
|
||||
std::fill(_buffer.begin(), _buffer.end(), 0);
|
||||
char* end = fmt::format_to(
|
||||
_buffer.data(),
|
||||
"Distance from {} to {}: {:f} {}\0",
|
||||
sourceInfo.second, destinationInfo.second, dist.first, dist.second
|
||||
);
|
||||
|
||||
std::string_view text = std::string_view(_buffer.data(), end - _buffer.data());
|
||||
RenderFont(*_font, penPosition, text);
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemDistance::size() const {
|
||||
ZoneScoped
|
||||
|
||||
const double d = glm::length(1e20);
|
||||
std::pair<double, std::string> dist;
|
||||
if (_doSimplification) {
|
||||
|
||||
@@ -79,6 +79,8 @@ private:
|
||||
Component _source;
|
||||
Component _destination;
|
||||
|
||||
std::vector<char> _buffer;
|
||||
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -70,17 +71,22 @@ namespace {
|
||||
constexpr const char* ValueFpsAvg = "Average frames per second";
|
||||
constexpr const char* ValueNone = "None";
|
||||
|
||||
std::string formatDt() {
|
||||
return fmt::format(
|
||||
"Avg. Frametime: {:.2f} ms",
|
||||
[[ nodiscard ]] char* formatDt(std::vector<char>& buffer) {
|
||||
return fmt::format_to(
|
||||
buffer.data(),
|
||||
"Avg. Frametime: {:.2f} ms\0",
|
||||
openspace::global::windowDelegate.averageDeltaTime() * 1000.0
|
||||
);
|
||||
}
|
||||
|
||||
std::string formatDtExtremes(double minFrametimeCache, double maxFrametimeCache) {
|
||||
return fmt::format(
|
||||
[[ nodiscard ]] char* formatDtExtremes(std::vector<char>& buffer,
|
||||
double minFrametimeCache,
|
||||
double maxFrametimeCache)
|
||||
{
|
||||
return fmt::format_to(
|
||||
buffer.data(),
|
||||
"Last frametimes between: {:.2f} and {:.2f} ms\n"
|
||||
"Overall between: {:.2f} and {:.2f} ms",
|
||||
"Overall between: {:.2f} and {:.2f} ms\0",
|
||||
openspace::global::windowDelegate.minDeltaTime() * 1000.0,
|
||||
openspace::global::windowDelegate.maxDeltaTime() * 1000.0,
|
||||
minFrametimeCache,
|
||||
@@ -88,54 +94,59 @@ namespace {
|
||||
);
|
||||
}
|
||||
|
||||
std::string formatDtStandardDeviation() {
|
||||
return fmt::format(
|
||||
"Frametime standard deviation : {:.2f} ms",
|
||||
[[ nodiscard ]] char* formatDtStandardDeviation(std::vector<char>& buffer) {
|
||||
return fmt::format_to(
|
||||
buffer.data(),
|
||||
"Frametime standard deviation : {:.2f} ms\0",
|
||||
openspace::global::windowDelegate.deltaTimeStandardDeviation() * 1000.0
|
||||
);
|
||||
}
|
||||
|
||||
std::string formatDtCoefficientOfVariation() {
|
||||
return fmt::format(
|
||||
"Frametime coefficient of variation : {:.2f} %",
|
||||
[[ nodiscard ]] char* formatDtCoefficientOfVariation(std::vector<char>& buffer) {
|
||||
return fmt::format_to(
|
||||
buffer.data(),
|
||||
"Frametime coefficient of variation : {:.2f} %\0",
|
||||
openspace::global::windowDelegate.deltaTimeStandardDeviation() /
|
||||
openspace::global::windowDelegate.averageDeltaTime() * 100.0
|
||||
);
|
||||
}
|
||||
|
||||
std::string formatFps() {
|
||||
return fmt::format(
|
||||
"FPS: {:3.2f}",
|
||||
[[ nodiscard ]] char* formatFps(std::vector<char>& buffer) {
|
||||
return fmt::format_to(
|
||||
buffer.data(),
|
||||
"FPS: {:3.2f}\0",
|
||||
1.0 / openspace::global::windowDelegate.deltaTime()
|
||||
);
|
||||
}
|
||||
|
||||
std::string formatAverageFps() {
|
||||
return fmt::format(
|
||||
"Avg. FPS: {:3.2f}",
|
||||
[[ nodiscard ]] char* formatAverageFps(std::vector<char>& buffer) {
|
||||
return fmt::format_to(
|
||||
buffer.data(),
|
||||
"Avg. FPS: {:3.2f}\0",
|
||||
1.0 / openspace::global::windowDelegate.averageDeltaTime()
|
||||
);
|
||||
}
|
||||
|
||||
std::string format(openspace::DashboardItemFramerate::FrametimeType frametimeType,
|
||||
double minFrametimeCache, double maxFrametimeCache)
|
||||
[[ nodiscard ]] char* format(std::vector<char>& buffer,
|
||||
openspace::DashboardItemFramerate::FrametimeType frametimeType,
|
||||
double minFrametimeCache, double maxFrametimeCache)
|
||||
{
|
||||
using namespace openspace;
|
||||
switch (frametimeType) {
|
||||
case DashboardItemFramerate::FrametimeType::DtTimeAvg:
|
||||
return formatDt();
|
||||
return formatDt(buffer);
|
||||
case DashboardItemFramerate::FrametimeType::DtTimeExtremes:
|
||||
return formatDtExtremes(minFrametimeCache, maxFrametimeCache);
|
||||
return formatDtExtremes(buffer, minFrametimeCache, maxFrametimeCache);
|
||||
case DashboardItemFramerate::FrametimeType::DtStandardDeviation:
|
||||
return formatDtStandardDeviation();
|
||||
return formatDtStandardDeviation(buffer);
|
||||
case DashboardItemFramerate::FrametimeType::DtCoefficientOfVariation:
|
||||
return formatDtCoefficientOfVariation();
|
||||
return formatDtCoefficientOfVariation(buffer);
|
||||
case DashboardItemFramerate::FrametimeType::FPS:
|
||||
return formatFps();
|
||||
return formatFps(buffer);
|
||||
case DashboardItemFramerate::FrametimeType::FPSAvg:
|
||||
return formatAverageFps();
|
||||
return formatAverageFps(buffer);
|
||||
default:
|
||||
return "";
|
||||
throw ghoul::MissingCaseException();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
@@ -262,9 +273,13 @@ DashboardItemFramerate::DashboardItemFramerate(const ghoul::Dictionary& dictiona
|
||||
addProperty(_clearCache);
|
||||
|
||||
_font = global::fontManager.font(_fontName, _fontSize);
|
||||
|
||||
_buffer.resize(128);
|
||||
}
|
||||
|
||||
void DashboardItemFramerate::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
if (_shouldClearCache) {
|
||||
_minDeltaTimeCache = 1.0;
|
||||
_maxDeltaTimeCache = -1.0;
|
||||
@@ -282,11 +297,14 @@ void DashboardItemFramerate::render(glm::vec2& penPosition) {
|
||||
|
||||
FrametimeType frametimeType = FrametimeType(_frametimeType.value());
|
||||
|
||||
const std::string output = format(
|
||||
std::fill(_buffer.begin(), _buffer.end(), 0);
|
||||
char* end = format(
|
||||
_buffer,
|
||||
frametimeType,
|
||||
_minDeltaTimeCache,
|
||||
_maxDeltaTimeCache
|
||||
);
|
||||
std::string_view output = std::string_view(_buffer.data(), end - _buffer.data());
|
||||
|
||||
int nLines = output.empty() ? 0 :
|
||||
static_cast<int>((std::count(output.begin(), output.end(), '\n') + 1));
|
||||
@@ -301,8 +319,11 @@ void DashboardItemFramerate::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemFramerate::size() const {
|
||||
ZoneScoped
|
||||
|
||||
const FrametimeType t = FrametimeType(_frametimeType.value());
|
||||
const std::string output = format(t, _minDeltaTimeCache, _maxDeltaTimeCache);
|
||||
format(_buffer, t, _minDeltaTimeCache, _maxDeltaTimeCache);
|
||||
std::string_view output = _buffer.data();
|
||||
|
||||
if (output.empty()) {
|
||||
return { 0.f, 0.f };
|
||||
|
||||
@@ -68,6 +68,7 @@ private:
|
||||
double _minDeltaTimeCache = 1.0;
|
||||
double _maxDeltaTimeCache = -1.0;
|
||||
bool _shouldClearCache = true;
|
||||
mutable std::vector<char> _buffer;
|
||||
};
|
||||
|
||||
} // openspace
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
#include <stack>
|
||||
|
||||
namespace {
|
||||
@@ -129,6 +130,8 @@ DashboardItemMission::DashboardItemMission(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
void DashboardItemMission::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
if (!global::missionManager.hasCurrentMission()) {
|
||||
return;
|
||||
}
|
||||
@@ -245,6 +248,8 @@ void DashboardItemMission::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemMission::size() const {
|
||||
ZoneScoped
|
||||
|
||||
// @TODO fix this up ---abock
|
||||
return { 0.f, 0.f };
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -114,6 +115,8 @@ DashboardItemParallelConnection::DashboardItemParallelConnection(
|
||||
}
|
||||
|
||||
void DashboardItemParallelConnection::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
const ParallelConnection::Status status = global::parallelPeer.status();
|
||||
const size_t nConnections = global::parallelPeer.nConnections();
|
||||
const std::string& hostName = global::parallelPeer.hostName();
|
||||
@@ -164,6 +167,8 @@ void DashboardItemParallelConnection::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemParallelConnection::size() const {
|
||||
ZoneScoped
|
||||
|
||||
ParallelConnection::Status status = global::parallelPeer.status();
|
||||
size_t nConnections = global::parallelPeer.nConnections();
|
||||
const std::string& hostName = global::parallelPeer.hostName();
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -151,6 +152,8 @@ DashboardItemPropertyValue::DashboardItemPropertyValue(
|
||||
}
|
||||
|
||||
void DashboardItemPropertyValue::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
if (_propertyIsDirty) {
|
||||
_property = openspace::property(_propertyUri);
|
||||
_propertyIsDirty = false;
|
||||
@@ -166,6 +169,8 @@ void DashboardItemPropertyValue::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemPropertyValue::size() const {
|
||||
ZoneScoped
|
||||
|
||||
return _font->boundingBox(_displayString.value());
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <ghoul/font/font.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -176,6 +177,8 @@ DashboardItemSimulationIncrement::DashboardItemSimulationIncrement(
|
||||
}
|
||||
|
||||
void DashboardItemSimulationIncrement::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
const double targetDt = global::timeManager.targetDeltaTime();
|
||||
const double currentDt = global::timeManager.deltaTime();
|
||||
std::pair<double, std::string> targetDeltaTime;
|
||||
@@ -227,6 +230,8 @@ void DashboardItemSimulationIncrement::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemSimulationIncrement::size() const {
|
||||
ZoneScoped
|
||||
|
||||
double t = global::timeManager.targetDeltaTime();
|
||||
std::pair<double, std::string> deltaTime;
|
||||
if (_doSimplification) {
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyFontMono = "Mono";
|
||||
@@ -187,6 +188,8 @@ DashboardItemVelocity::DashboardItemVelocity(const ghoul::Dictionary& dictionary
|
||||
}
|
||||
|
||||
void DashboardItemVelocity::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
const glm::dvec3 currentPos = global::renderEngine.scene()->camera()->positionVec3();
|
||||
const glm::dvec3 dt = currentPos - _prevPosition;
|
||||
const double speedPerFrame = glm::length(dt);
|
||||
@@ -218,6 +221,8 @@ void DashboardItemVelocity::render(glm::vec2& penPosition) {
|
||||
}
|
||||
|
||||
glm::vec2 DashboardItemVelocity::size() const {
|
||||
ZoneScoped
|
||||
|
||||
const double d = glm::length(1e20);
|
||||
std::pair<double, std::string> dist;
|
||||
if (_doSimplification) {
|
||||
|
||||
Reference in New Issue
Block a user