Skip to content

Instantly share code, notes, and snippets.

@SammyJames
Created September 7, 2018 05:38
Show Gist options
  • Save SammyJames/57e656d6c6c1d6d66cdf188935b96473 to your computer and use it in GitHub Desktop.
Save SammyJames/57e656d6c6c1d6d66cdf188935b96473 to your computer and use it in GitHub Desktop.
#include <cstdint>
#include <cstdio>
constexpr uint32_t val_32_const = 0x811c9dc5;
constexpr uint32_t prime_32_const = 0x1000193;
inline constexpr uint32_t FNV1a(const char* const str, const uint32_t value = val_32_const)
{
return (str[0] == '\0') ? value : FNV1a(&str[1], (value ^ uint32_t(str[0])) * prime_32_const);
}
template <uint32_t Hash>
constexpr uint32_t TForceEval = Hash;
#define HASH(text) TForceEval<FNV1a(text)>
void SetTexture(uint32_t test, void* param)
{
printf("%u\n", test);
}
int main()
{
SetTexture(HASH("Butts"), nullptr);
SetTexture(HASH("Rule"), nullptr);
SetTexture(HASH("The"), nullptr);
SetTexture(HASH("World"), nullptr);
}
@SammyJames
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment