mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-29 01:24:37 +01:00
Merge staging into feat/gl46-migration
origin/staging7ac2472c3into feat/gl46-migrationdb26a33ed, so that #468 merges into staging. Merge base037158104. Staging carries master up to571487612(squashed in #514); this branch had merged master up to7c12b83ba. Conflicts, file by file: - README.md: WITH_BETTER_RENDERER row dropped (gl46), USE_SYSTEM_JSON row kept (staging) - CMakeLists.txt: gl46 lists, plus staging's new core sources (hardwareinfo, sn_utils, regionfile, inionlysettings, fieldshunting, gaugewrap, drivingaid, signalpassing, brakereleaser, crew, brakecharge); none listed twice - tests/unit/CMakeLists.txt: both (texturealpha, freecameramotion; editorSwitchDrives, Camera) - vehicle/brakingcurve.{h,cpp}, tests/unit/test_braking_curve.cpp (add/add): staging (#479 brake_acting on the same #409 code) - editor/editorHttp.cpp: staging (it has gl46's #432 and certificate fixes, plus #439 libcurl loaded at run time) - tests/unit/test_editor_http.cpp (add/add): staging (adds the available() case of #439) - utilities/Globals.h: gl46 crashdump_full (staging's CrashDumpFull is #425, replaced here by utilities/crashdump.cpp); fmradio and staging's OpenAL options both; gfx_headlights_beamwidth (#481) not taken - utilities/Globals.cpp: both (odometer.expiry, OpenAL keys, fmradio, gl46 gfx keys); gfx.headlights.beamwidth (#481) not taken - utilities/Logs.cpp: staging's log_file_name() for both files, with gl46's crashdump_set_log_file() for both - utilities/utilities.h: gl46 set_thread_random_engine(); Random(int, int) gone on both sides - tests/unit/test_utilities.cpp: staging's includes - simulation/simulationtest.cpp: gl46 (no NvRenderer, LegacyRenderer, BasicRenderer here) - ci_shadervalidator/* (incl. add/add utilities/Logs.h): gl46's validator of shaders/ogl46 and shaders/vk14; staging's #437 fixed the GL 3.3 one - gl/shader.cpp, gl/glsl_common.cpp: gl46 (shaders come from rendering/common/shadersource.cpp); HEADLIGHT_BEAM_WIDTH (#481) not taken - shaders/mat_wire.frag: gl46. Rename detection paired staging's mat_colored.frag (#481) with it - lang/editor_pl.po: union; the 12 camera speed / orthophoto entries staging adds are here already (master #312) - audio/audiorenderer.{h,cpp}: both (fmradio; startsample and the low-pass filter); the destructor releases the radio, then the filter - application/editormode.h, application/editormodeswitchdrive.cpp: staging (#509 on #330, which is all this side had) - application/application.cpp: gl46's start sequence (no init_ogl, ANGLE or NvRenderer; crash window after init_ui) with staging's hardware::log_system() (#389) - EU07.cpp: gl46 (crash reports of utilities/crashdump.cpp); staging's side was #425's handler, replaced here - model/Texture.{h,cpp}: gl46 (texture_source); staging's side is master #399/#411/#362/#386, merged here before - world/Track.h, world/TrackSleepers.h: both (TrackBlend, lay(Fastened)/fasten; TrackBuckle, pack_models) - world/Segment.cpp: staging's track buckling on the split stray factors both sides have - vehicle/Driver.h: staging's additions (#444, #494, #473, #346, timetable flags) - vehicle/Driver.cpp: staging's file, with this branch'sf4f8c75e4(road orders measured along the lane) and8fbf05674(a holding road order blocks the ones past it) applied again; #409's SeenAheadTolerance gives way to #473 - vehicle/DynObj.h: friend opengl46_renderer and friend class vehicle_table - vehicle/DynObj.cpp: gl46's vehicle_table::update() with staging's update_off_track_contacts() and update_brake_pipes() - McZapkie/Mover.cpp: staging's function splits (#239) and hose exchange (#388); every line this branch added to Mover.cpp/MOVER.h is kept - .github/workflows/build_bin.yml: staging's apt-install step (#497) and pinned download-artifact (#331) Modify/delete, kept deleted: - rendering/opengl33renderer.{cpp,h}, rendering/openglparticles.cpp, rendering/openglrenderer.{cpp,h}: staging's versions are master's, and every master change to them is in this branch's history already - shaders/light_common.glsl, shaders/mat_sunlessnormalmap_specgloss.frag: see below Carried into this branch's code: - the hose exchange after each sub-step (#387/#388) also in update_steps_parallel(), per group of vehicles, as update() does it single-threaded - physics.pipewake (pipe_wakes(), wake_cause::scndpipe) in staging's GetScndDVc(), where the main reservoir hose exchange went - hardware::log_gl_context() (#389) in after_window() of the GL 4.6 backend, init_ogl() being gone Taken back out of the auto-merge (renderers this branch removed): - shaders/vk14/tonemapping.glsl: #481's switch to ACES, applied there by rename detection - environment/skydome.cpp, simulation/simulationenvironment.cpp: #415, the sky of the legacy renderer - application/application.cpp: #384's fallback of an unknown gfxrenderer, which this branch had dropped Not carried from staging (renderer files removed here): - master #481 (571487612): old assets drawn as in 26.05 (metal diffuse, sun highlight tint, ACES, SUN_DIFFUSE_SCALE 2.5, untinted Diffuse, mat_colored base) and gfx.headlights.beamwidth. Made for the GL 3.3 shaders; the PBR shaders of shaders/ogl46 and vk14 (and their SPIR-V binaries) are the author's call - #437: the unique temporary file of the shader validator (Sonar S5443); gl46's validator still writes /tmp/shader* Unit tests: 1133 of 1137 cases pass. Four staging tests fail (derailment: a repaired vehicle is back on the rails; three pullee cases): the vehicle stands, and with physics.sleepheld (on by default here) its physics sleeps with the Fb / FStand of before. With physics.sleepheld off they pass. Left to the author.
This commit is contained in:
@@ -16,6 +16,7 @@ Copyright (C) 2007-2014 Maciej Cierniak
|
||||
//#include <sys/types.h>
|
||||
//#include <sys/stat.h>
|
||||
#include <charconv>
|
||||
#include <mutex>
|
||||
#include <ranges>
|
||||
#include <format>
|
||||
//#ifndef WIN32
|
||||
@@ -57,6 +58,33 @@ std::string Now()
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path xdg_base_directory(char const *Variable, char const *Home, char const *Fallback)
|
||||
{
|
||||
// as the spec has it: a variable which isn't set, is empty or holds a relative path counts as not set. absolute is
|
||||
// said the way a posix system says it, so the answer is the same on every system the tests run on
|
||||
if (Variable != nullptr && Variable[0] == '/')
|
||||
return std::filesystem::path(Variable);
|
||||
if (Home != nullptr && Home[0] != '\0')
|
||||
return std::filesystem::path(Home) / Fallback;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::filesystem::path xdg_config_folder(char const *Variable, char const *Home)
|
||||
{
|
||||
auto const base{xdg_base_directory(Variable, Home, ".config")};
|
||||
if (base.empty())
|
||||
return {};
|
||||
auto folder{base / "MaSzyna"};
|
||||
if (Home != nullptr && Home[0] != '\0')
|
||||
{
|
||||
auto legacy{std::filesystem::path(Home) / ".config" / "MaSzyna"};
|
||||
std::error_code error;
|
||||
if (legacy != folder && false == std::filesystem::exists(folder, error) && std::filesystem::is_directory(legacy, error))
|
||||
return legacy;
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
||||
std::filesystem::path user_config_path(const std::string &filename)
|
||||
{
|
||||
namespace fs = std::filesystem;
|
||||
@@ -67,8 +95,17 @@ std::filesystem::path user_config_path(const std::string &filename)
|
||||
if (const char *home = std::getenv("HOME"))
|
||||
return fs::path(home) / "Library" / "Application Support" / "MaSzyna" / filename;
|
||||
#else
|
||||
if (const char *home = std::getenv("HOME"))
|
||||
return fs::path(home) / ".config" / "MaSzyna" / filename;
|
||||
if (auto const folder{xdg_config_folder(std::getenv("XDG_CONFIG_HOME"), std::getenv("HOME"))}; false == folder.empty())
|
||||
{
|
||||
if (auto const wanted{xdg_base_directory(std::getenv("XDG_CONFIG_HOME"), std::getenv("HOME"), ".config") / "MaSzyna"};
|
||||
folder != wanted)
|
||||
{
|
||||
// said once, so whoever set XDG_CONFIG_HOME knows why the settings aren't there
|
||||
static std::once_flag told;
|
||||
std::call_once(told, [&] { WriteLog(std::format("Settings kept in \"{}\", the folder of the earlier releases, since \"{}\" doesn't exist", folder.string(), wanted.string())); });
|
||||
}
|
||||
return folder / filename;
|
||||
}
|
||||
#endif
|
||||
return {}; // env var missing → caller falls back to CWD-relative filename
|
||||
}
|
||||
@@ -83,10 +120,8 @@ std::filesystem::path user_cache_path(const std::string &filename)
|
||||
if (const char *home = std::getenv("HOME"))
|
||||
return fs::path(home) / "Library" / "Caches" / "MaSzyna" / filename;
|
||||
#else
|
||||
if (const char *cache = std::getenv("XDG_CACHE_HOME"); cache != nullptr && *cache != '\0')
|
||||
return fs::path(cache) / "MaSzyna" / filename;
|
||||
if (const char *home = std::getenv("HOME"))
|
||||
return fs::path(home) / ".cache" / "MaSzyna" / filename;
|
||||
if (auto const base{xdg_base_directory(std::getenv("XDG_CACHE_HOME"), std::getenv("HOME"), ".cache")}; false == base.empty())
|
||||
return base / "MaSzyna" / filename;
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
@@ -198,10 +233,19 @@ std::uint64_t true_random_seed()
|
||||
|
||||
std::uint32_t seed_of(std::string const &Text)
|
||||
{
|
||||
if (std::uint32_t number{}; std::from_chars(Text.data(), Text.data() + Text.size(), number).ec == std::errc{})
|
||||
auto const *const end{Text.data() + Text.size()};
|
||||
std::uint32_t number{};
|
||||
auto const [last, error]{std::from_chars(Text.data(), end, number)};
|
||||
if (error == std::errc{} && last == end)
|
||||
{
|
||||
return number;
|
||||
}
|
||||
if (error == std::errc{})
|
||||
{
|
||||
// digits with something after them are a word like any other, not the number in front of them: "4242abc"
|
||||
// isn't seed 4242. said in the log, since whoever wrote it most likely meant a number
|
||||
WriteLog(std::format("seed \"{}\" isn't a number, taken as a word", Text));
|
||||
}
|
||||
std::uint32_t hash{};
|
||||
for (auto const character : Text)
|
||||
{
|
||||
@@ -210,6 +254,15 @@ std::uint32_t seed_of(std::string const &Text)
|
||||
return hash;
|
||||
}
|
||||
|
||||
std::optional<std::uint32_t> seed_given(std::string const &Text)
|
||||
{
|
||||
if (Text.empty())
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
return seed_of(Text);
|
||||
}
|
||||
|
||||
std::string generate_uuid_v4()
|
||||
{
|
||||
std::uniform_int_distribution dist(0, 255);
|
||||
@@ -338,7 +391,7 @@ std::string ToUpper(std::string const &text)
|
||||
void win1250_to_ascii(std::string &Input)
|
||||
{
|
||||
|
||||
std::unordered_map<char, char> const charmap{{165, 'A'}, {198, 'C'}, {202, 'E'}, {163, 'L'}, {209, 'N'}, {211, 'O'}, {140, 'S'}, {143, 'Z'}, {175, 'Z'},
|
||||
static std::unordered_map<char, char> const charmap{{165, 'A'}, {198, 'C'}, {202, 'E'}, {163, 'L'}, {209, 'N'}, {211, 'O'}, {140, 'S'}, {143, 'Z'}, {175, 'Z'},
|
||||
{185, 'a'}, {230, 'c'}, {234, 'e'}, {179, 'l'}, {241, 'n'}, {243, 'o'}, {156, 's'}, {159, 'z'}, {191, 'z'}};
|
||||
std::unordered_map<char, char>::const_iterator lookup;
|
||||
for (auto &input : Input)
|
||||
@@ -472,9 +525,126 @@ void win1250_to_utf32(std::string const &Text, std::u32string &Output)
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void append_utf8(std::string &Output, char32_t const Codepoint)
|
||||
{
|
||||
if (Codepoint < 0x80)
|
||||
{
|
||||
Output += static_cast<char>(Codepoint);
|
||||
}
|
||||
else if (Codepoint < 0x800)
|
||||
{
|
||||
Output += static_cast<char>(0xC0 | (Codepoint >> 6));
|
||||
Output += static_cast<char>(0x80 | (Codepoint & 0x3F));
|
||||
}
|
||||
else if (Codepoint < 0x10000)
|
||||
{
|
||||
Output += static_cast<char>(0xE0 | (Codepoint >> 12));
|
||||
Output += static_cast<char>(0x80 | ((Codepoint >> 6) & 0x3F));
|
||||
Output += static_cast<char>(0x80 | (Codepoint & 0x3F));
|
||||
}
|
||||
else
|
||||
{
|
||||
Output += static_cast<char>(0xF0 | (Codepoint >> 18));
|
||||
Output += static_cast<char>(0x80 | ((Codepoint >> 12) & 0x3F));
|
||||
Output += static_cast<char>(0x80 | ((Codepoint >> 6) & 0x3F));
|
||||
Output += static_cast<char>(0x80 | (Codepoint & 0x3F));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string data_text_to_utf8(std::string const &Text)
|
||||
{
|
||||
if (std::ranges::all_of(Text, [](char const Character) { return static_cast<unsigned char>(Character) < 0x80; }))
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
std::u32string codepoints;
|
||||
// a text in windows-1250 can happen to be valid utf-8 as well: two capital letters with marks in a row, as the bytes
|
||||
// D3 A3 of "WOLKA" with its marks, make a sequence of two bytes. such a pair decodes to a letter between U+0180 and
|
||||
// U+07FF (cyrillic, greek and the like), which the texts of the data files, when they are in utf-8, don't have
|
||||
if (utf8_to_utf32(Text, codepoints) && std::ranges::none_of(codepoints, [](char32_t const Codepoint) { return Codepoint >= 0x180 && Codepoint < 0x800; }))
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
// the code page the data files are written in
|
||||
win1250_to_utf32(Text, codepoints);
|
||||
std::string output;
|
||||
output.reserve(Text.size() + 8);
|
||||
for (auto const codepoint : codepoints)
|
||||
{
|
||||
// the bytes the code page has no character for come as 0
|
||||
append_utf8(output, codepoint != 0 ? codepoint : U'?');
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string data_name_to_utf8(std::string const &Name, bool const Underscorestospaces)
|
||||
{
|
||||
auto name{data_text_to_utf8(Name)};
|
||||
// in utf-8 the bytes below 0x80 are characters of their own, never a part of another one
|
||||
for (auto &character : name)
|
||||
{
|
||||
if (static_cast<unsigned char>(character) < 0x20 || (Underscorestospaces && character == '_'))
|
||||
{
|
||||
character = ' ';
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
// number of bytes of the character of a text in utf-8 which starts at given position; 1 for a byte which starts no valid sequence
|
||||
std::size_t utf8_character_size(std::string_view const Text, std::size_t const Position)
|
||||
{
|
||||
auto const length{utf8_sequence_length(static_cast<std::byte>(Text[Position]))};
|
||||
if (length < 2 || Position + length > Text.size())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
for (std::size_t offset = 1; offset < length; ++offset)
|
||||
{
|
||||
if ((static_cast<std::byte>(Text[Position + offset]) & std::byte{0xC0}) != std::byte{0x80})
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::size_t utf8_length(std::string_view const Text)
|
||||
{
|
||||
std::size_t length{0};
|
||||
for (std::size_t position = 0; position < Text.size(); position += utf8_character_size(Text, position))
|
||||
{
|
||||
++length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
std::string utf8_fit(std::string_view const Text, std::size_t const Width)
|
||||
{
|
||||
std::size_t length{0};
|
||||
std::size_t position{0};
|
||||
while (position < Text.size() && length < Width)
|
||||
{
|
||||
position += utf8_character_size(Text, position);
|
||||
++length;
|
||||
}
|
||||
std::string output{Text.substr(0, position)};
|
||||
output.append(Width - length, ' ');
|
||||
return output;
|
||||
}
|
||||
|
||||
// Ra: tymczasowe rozwiązanie kwestii zagranicznych (czeskich) napisów
|
||||
// NOTE: the entry of 0xB1 (the plus-minus sign of windows-1250, left as it is) is written as its byte. written as the
|
||||
// character it took two bytes in the builds which keep the texts of the sources in utf-8 (GCC, Clang, MSVC with /utf-8),
|
||||
// and every entry after it was off by one
|
||||
char const charsetconversiontable[] = "E?,?\"_++?%S<STZZ?`'\"\".--??s>stzz"
|
||||
" ^^L$A|S^CS<--RZo±,l'uP.,as>L\"lz"
|
||||
" ^^L$A|S^CS<--RZo\xB1,l'uP.,as>L\"lz"
|
||||
"RAAAALCCCEEEEIIDDNNOOOOxRUUUUYTB"
|
||||
"raaaalccceeeeiiddnnoooo-ruuuuyt?";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user