mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Improve std::hash<SMaterial> implementation
This commit is contained in:
parent
d7edf0b229
commit
89e3bc8d56
1 changed files with 10 additions and 4 deletions
|
@ -483,9 +483,15 @@ struct std::hash<irr::video::SMaterial>
|
||||||
/// @brief std::hash specialization for video::SMaterial
|
/// @brief std::hash specialization for video::SMaterial
|
||||||
std::size_t operator()(const irr::video::SMaterial &m) const noexcept
|
std::size_t operator()(const irr::video::SMaterial &m) const noexcept
|
||||||
{
|
{
|
||||||
// basic implementation that hashes the two things most likely to differ
|
std::size_t ret = 0;
|
||||||
auto h1 = std::hash<irr::video::ITexture*>{}(m.getTexture(0));
|
for (auto h : { // the three members most likely to differ
|
||||||
auto h2 = std::hash<int>{}(m.MaterialType);
|
std::hash<irr::video::ITexture*>{}(m.getTexture(0)),
|
||||||
return (h1 << 1) ^ h2;
|
std::hash<int>{}(m.MaterialType),
|
||||||
|
std::hash<irr::u32>{}(m.ColorParam.color)
|
||||||
|
}) {
|
||||||
|
ret += h;
|
||||||
|
ret ^= (ret << 6) + (ret >> 2); // distribute bits
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue