Skip to content
30 changes: 30 additions & 0 deletions src/global/TextUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#include "Charset.h"
#include "Consts.h"
#include "RAII.h"
#include "tests.h"

#include <clocale>
#include <cstring>
#include <iostream>
#include <sstream>

#include <QRegularExpression>
#include <QString>
Expand Down Expand Up @@ -39,6 +42,15 @@ bool isAbbrev(const std::string_view abbr, const std::string_view fullText)
}

namespace text_utils {

std::string formatFloatClassic(const float val)
{
std::ostringstream ss;
ss.imbue(std::locale::classic());
ss << std::showpoint << val;
return ss.str();
}

SplitResult<std::string_view> split_at(const std::string_view sv, const size_t pos)
{
assert(pos <= sv.size());
Expand Down Expand Up @@ -216,12 +228,30 @@ void testTrim()
}
}

void testFormatFloatClassic()
{
const char *oldLocale = std::setlocale(LC_ALL, nullptr);
const std::string savedLocale = oldLocale ? oldLocale : "C";
RAIICallback restoreLocale{[savedLocale]() { std::setlocale(LC_ALL, savedLocale.c_str()); }};

std::setlocale(LC_ALL, "de_DE.UTF-8");

const std::string radStr = text_utils::formatFloatClassic(14.0f);
TEST_ASSERT(radStr.find(',') == std::string::npos);
TEST_ASSERT(radStr.find('.') != std::string::npos);

const std::string extStr = text_utils::formatFloatClassic(28.5f);
TEST_ASSERT(extStr.find(',') == std::string::npos);
TEST_ASSERT(extStr.find('.') != std::string::npos);
}

} // namespace

namespace test {
void testTextUtils()
{
testPrefixSuffix();
testTrim();
testFormatFloatClassic();
}
} // namespace test
2 changes: 2 additions & 0 deletions src/global/TextUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ NODISCARD extern bool isAbbrev(std::string_view abbr, std::string_view fullText)

namespace text_utils {

NODISCARD std::string formatFloatClassic(float val);

template<typename T>
struct NODISCARD SplitResult final
{
Expand Down
12 changes: 8 additions & 4 deletions src/opengl/legacy/ShaderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,19 @@ NODISCARD static GLuint compileShader(Functions &gl, const GLenum type, const So
std::string defineNamedColors = "#define MAX_NAMED_COLORS " + std::to_string(MAX_NAMED_COLORS)
+ "\n";
std::string defineWeatherRadius = "#define WEATHER_RADIUS "
+ std::to_string(WeatherConstants::WEATHER_RADIUS) + "\n";
+ text_utils::formatFloatClassic(
WeatherConstants::WEATHER_RADIUS)
+ "\n";
std::string defineWeatherExtent = "#define WEATHER_EXTENT "
+ std::to_string(WeatherConstants::WEATHER_EXTENT) + "\n";
+ text_utils::formatFloatClassic(
WeatherConstants::WEATHER_EXTENT)
+ "\n";
std::string defineWeatherMaskOuter = "#define WEATHER_MASK_RADIUS_OUTER "
+ std::to_string(
+ text_utils::formatFloatClassic(
WeatherConstants::WEATHER_MASK_RADIUS_OUTER)
+ "\n";
std::string defineWeatherMaskInner = "#define WEATHER_MASK_RADIUS_INNER "
+ std::to_string(
+ text_utils::formatFloatClassic(
WeatherConstants::WEATHER_MASK_RADIUS_INNER)
+ "\n";

Expand Down
4 changes: 2 additions & 2 deletions src/resources/shaders/legacy/room/tex/acolor/vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ void main()
// | /| Triangles 012 and 023 both use CCW order.
// |/ | Notice that the four vertices are in CCW order.
// 0--1
const ivec3[4] ioffsets = ivec3[4](ivec3(0, 0, 0), ivec3(1, 0, 0), ivec3(1, 1, 0), ivec3(0, 1, 0)); // fan
const ivec3 ioffsets[4] = ivec3[4](ivec3(0, 0, 0), ivec3(1, 0, 0), ivec3(1, 1, 0), ivec3(0, 1, 0)); // fan
#else
// GL_TRIANGLE_STRIP
// 2--3 Note: Triangle strips alternate CCW/CW winding on every other triangle. This means...
// |\ | triangle 012 is CCW order, but triangle 123 is CW order (backwards).
// | \| Keep in mind that OpenGL does not actually draw the triangle backwards,
// 0--1 so it does not affect glFrontFace() or the gl_FrontFacing variable.
const ivec3[4] ioffsets = ivec3[4](ivec3(0, 0, 0), ivec3(1, 0, 0), ivec3(0, 1, 0), ivec3(1, 1, 0)); // strip
const ivec3 ioffsets[4] = ivec3[4](ivec3(0, 0, 0), ivec3(1, 0, 0), ivec3(0, 1, 0), ivec3(1, 1, 0)); // strip
#endif
ivec3 ioffset = ioffsets[gl_VertexID];

Expand Down
Loading