17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-28 07:37:28 +01:00

feat(materials): texture randomization for loads

This commit is contained in:
jerrrrycho
2026-09-10 17:48:38 +02:00
parent d9eb705d4a
commit 277bc46a21
12 changed files with 316 additions and 21 deletions

View File

@@ -490,4 +490,42 @@ std::string deserialize_random_set(cParser &Input, char const *Break)
// shouldn't ever get here but, eh
return "";
}
}
}
// returns hash of provided string, combined with provided seed
std::uint32_t hash_string(std::string const &String, std::uint32_t const Seed)
{
// FNV-1a, 32 bit, with the seed mixed into the standard offset basis
std::uint32_t hash{2166136261u ^ Seed};
for (auto const character : String)
{
hash ^= static_cast<std::uint32_t>(static_cast<unsigned char>(character));
hash *= 16777619u;
}
return hash;
}
// extracts a group of tokens from provided data stream, returns all of them
std::vector<std::string> deserialize_set(cParser &Input, char const *Break)
{
std::vector<std::string> tokens;
auto token{Input.getToken<std::string>(true, Break)};
std::replace(token.begin(), token.end(), '\\', '/');
if (token != "[")
{
// simple case, single token
if (false == token.empty())
{
tokens.emplace_back(token);
}
return tokens;
}
// '[' marks a beginning of a set, retrieve all entries until it's closed
while ((token = deserialize_random_set(Input, Break)) != "" && token != "]")
{
tokens.emplace_back(token);
}
return tokens;
}