From 483da49759da28fe7540ae6edf43aa4c7971faf2 Mon Sep 17 00:00:00 2001 From: phosit Date: Fri, 16 Feb 2024 17:31:40 +0000 Subject: [PATCH] More generic hash function for FSM The hash function introduced in 6faf704731 doesn't work on 32 bit systems. This one should. Accepted By: @vladislavbelov Differential Revision: https://code.wildfiregames.com/D5237 This was SVN commit r28033. --- source/network/FSM.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/network/FSM.h b/source/network/FSM.h index f27d3d6a1b..fab678421b 100644 --- a/source/network/FSM.h +++ b/source/network/FSM.h @@ -170,10 +170,10 @@ private: { size_t operator()(const TransitionKey& key) const noexcept { - static_assert(sizeof(UnderlyingType) <= sizeof(size_t) / 2); - return (static_cast(key.state) << - ((sizeof(size_t) / 2) * std::numeric_limits::digits)) + - static_cast(key.eventType); + constexpr size_t count{std::numeric_limits::digits / 2}; + const size_t wideState{static_cast(key.state)}; + const size_t rotatedState{(wideState << count) | (wideState >> count)}; + return static_cast(key.eventType) ^ rotatedState; } };