diff --git a/src/C4HudBars.cpp b/src/C4HudBars.cpp index ff5d4cd6..893945dd 100644 --- a/src/C4HudBars.cpp +++ b/src/C4HudBars.cpp @@ -209,11 +209,6 @@ int32_t C4HudBarDef::DefaultIndex(const C4HudBarDef::Physical physical) noexcept } } -std::size_t C4HudBarDef::GetHash() const noexcept -{ - return HashArguments(name, physical, hide, gfx, index, advance, valueIndex, value, max, visible); -} - void C4HudBarDef::CompileFunc(StdCompiler *const comp) { comp->Value(mkNamingAdapt(name, "Name")); @@ -245,6 +240,11 @@ void C4HudBarDef::CompileFunc(StdCompiler *const comp) // gfx and scale are restored from def.gfxs } +std::size_t std::hash::operator()(const C4HudBarDef &bar) const noexcept +{ + return HashArguments(bar.name, bar.physical, bar.hide, bar.gfx, bar.index, bar.advance, bar.valueIndex, bar.value, bar.max, bar.visible); +} + namespace { template @@ -289,27 +289,22 @@ bool C4HudBarsDef::operator==(const C4HudBarsDef &rhs) const noexcept return MapCompare(gfxs, rhs.gfxs) && bars == rhs.bars; } -std::size_t C4HudBarsDef::GetHash() const noexcept +std::size_t std::hash::operator()(const C4HudBarsDef &value) const noexcept { std::size_t result{0}; - for (const auto &gfx : gfxs) + for (const auto &gfx : value.gfxs) { HashCombineArguments(result, gfx.second.Key, gfx.second.File, gfx.second.Amount, gfx.second.Scale); } - for (const auto &bardef : bars) + for (const auto &bardef : value.bars) { - HashCombine(result, bardef.GetHash()); + HashCombineArguments(result, bardef); } return result; } -std::size_t std::hash::operator()(const C4HudBarsDef &value) const noexcept -{ - return value.GetHash(); -} - bool C4HudBarsUniquifier::LoadDefaultBars() { static constexpr auto File = "EnergyBars"; diff --git a/src/C4HudBars.h b/src/C4HudBars.h index 9d3cf025..3dd2dee7 100644 --- a/src/C4HudBars.h +++ b/src/C4HudBars.h @@ -81,7 +81,6 @@ class C4HudBarDef static Hide DefaultHide(Physical physical) noexcept; static std::int32_t DefaultIndex(Physical physical) noexcept; - std::size_t GetHash() const noexcept; void CompileFunc(StdCompiler *comp); public: @@ -101,7 +100,6 @@ class C4HudBarDef float scale{1.0f}; // calculated from gfx.scale }; - constexpr C4HudBarDef::Hide operator &(const C4HudBarDef::Hide a, const C4HudBarDef::Hide b) noexcept { return static_cast(std::to_underlying(a) & std::to_underlying(b)); @@ -118,6 +116,12 @@ constexpr C4HudBarDef::Hide operator~(const C4HudBarDef::Hide a) noexcept return static_cast(~std::to_underlying(a)); } +template<> +struct std::hash +{ + std::size_t operator()(const C4HudBarDef &bar) const noexcept; +}; + class C4HudBarsDef { public: @@ -150,8 +154,6 @@ class C4HudBarsDef bool operator==(const C4HudBarsDef &rhs) const noexcept; - std::size_t GetHash() const noexcept; - public: // the definiton is processed and flattened into a vector of energy bar values // they contain everything needed to draw the energy bars @@ -160,6 +162,15 @@ class C4HudBarsDef Names names; }; +namespace std +{ + template<> + struct hash + { + std::size_t operator()(const C4HudBarsDef &value) const noexcept; + }; +} + class C4HudBars { public: @@ -176,15 +187,6 @@ class C4HudBars C4HudBar &BarVal(std::string_view name); }; -namespace std -{ - template<> - struct hash - { - std::size_t operator()(const C4HudBarsDef &value) const noexcept; - }; -} - class C4HudBarsUniquifier { public: