18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 23:57:09 +01:00

fix: a seed is the whole text and 0 is a seed; Linux honours XDG_CONFIG_HOME and XDG_CACHE_HOME (#469)

* fix(settings): a seed is the whole text as a number, and 0 is a seed

seed_of() took the digits in front of a word for the number, so 4242abc
was seed 4242, and 12abc and 12xyz were the same seed. Now the whole text
has to be the number; anything else is hashed as a word, and a word that
starts with digits is said in the log.

A seed of 0 also stood for no seed, so -seed 0 and randomseed 0 drew a
random one. Whether a seed was given is now kept apart, in
random_seed_given, set by -seed, randomseed, the test mode and the server
of a network session. random_seed keeps its type. randomseed with nothing
after it still gives no seed.

Follows up #176.

* fix(paths): Linux keeps the settings and the cache where XDG says

user_config_path() ignored XDG_CONFIG_HOME, and user_cache_path() took
XDG_CACHE_HOME even when it held a relative path. Both now follow the XDG
base directory spec: the variable when it is set to an absolute path, else
.config or .cache in the home folder. The choice is made by
xdg_base_directory(), which takes the values of the variables, so it is
tested on every system. Windows and macOS are unchanged.

Follows up #29 and #124.

* fix(paths): Linux keeps the settings in ~/.config/MaSzyna until XDG_CONFIG_HOME has its own

With XDG_CONFIG_HOME set (or under Flatpak), the settings of earlier
releases in ~/.config/MaSzyna were silently left behind: the profile
eu07.ini, the bindings, the odometers, the editor's settings. The old
folder is now used while it exists and $XDG_CONFIG_HOME/MaSzyna doesn't,
said once in the log; the one-time move of the orthophoto cache finds the
old cache there too.

* test: keep the XDG settings test folder out of the shared temp folder
This commit is contained in:
jerrrrycho
2026-11-26 22:29:18 +01:00
committed by GitHub
parent 919b4af043
commit bc6df7ea61
9 changed files with 208 additions and 20 deletions

View File

@@ -419,7 +419,7 @@ int eu07_application::init(int Argc, char *Argv[])
// the run's seed, settled once and kept in Globals: the engines come out of it.
// narrowed on purpose - mt19937 and seed_of() both work on 32 bits, and that is
// the seed somebody can write down and pass on
if (!Global.random_seed)
if (false == Global.random_seed_given)
Global.random_seed = static_cast<std::uint32_t>(true_random_seed());
Global.random_engine.seed(Global.random_seed);
Global.local_random_engine.seed(Global.random_seed);
@@ -1360,11 +1360,16 @@ int eu07_application::init_settings(int Argc, char *Argv[])
else if (token == "-seed")
{
// a number is the seed; anything else is a word that stands for one. said in the
// log as it was given, because that is what gets passed on to somebody else
// log as it was given, because that is what gets passed on to somebody else. 0 is a seed
// too; an empty word gives none, as randomseed with nothing after it
if (i + 1 < Argc)
{
Global.random_seed = seed_of(Argv[++i]);
WriteLog(std::format("seed given on the command line: {} -> {}", Argv[i], Global.random_seed));
if (auto const seed{seed_given(Argv[++i])})
{
Global.random_seed = *seed;
Global.random_seed_given = true;
WriteLog(std::format("seed given on the command line: {} -> {}", Argv[i], Global.random_seed));
}
}
}
else if (token == "--test")