64-bit hashes (#126)

- ContactEvent sample
- Improved shadows
- #120 
- Triangle collision fixes
This commit is contained in:
Erin Catto 2026-08-11 18:08:34 -07:00 • committed by GitHub
commit f42be210a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 19835 additions and 17544 deletions

View file

@ -115,7 +115,7 @@ void b3Log( const char* format, ... )
b3Version b3GetVersion( void )
{
return (b3Version){ 0, 1, 0 };
return (b3Version){ 0, 2, 0 };
}
bool b3IsDoublePrecision( void )
@ -253,3 +253,39 @@ void b3StrCpy( char* dst, int size, const char* src )
memset( dst, 0, size );
}
}
// Fowler/Noll/Vo FNV-1a salted by length, then the splitmix64 finalizer so tiny inputs
// still spread across all bits.
uint64_t b3Hash64NonZero( const uint8_t* bytes, int n )
{
uint64_t h = 0xcbf29ce484222325ull ^ (uint64_t)(uint32_t)n;
const uint64_t prime = 0x100000001b3ull;
int i = 0;
while ( i + 8 <= n )
{
uint64_t word;
memcpy( &word, bytes + i, sizeof( word ) );
#if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
word = ( ( word & 0x00000000000000FFULL ) << 56 ) | ( ( word & 0x000000000000FF00ULL ) << 40 ) |
( ( word & 0x0000000000FF0000ULL ) << 24 ) | ( ( word & 0x00000000FF000000ULL ) << 8 ) |
( ( word & 0x000000FF00000000ULL ) >> 8 ) | ( ( word & 0x0000FF0000000000ULL ) >> 24 ) |
( ( word & 0x00FF000000000000ULL ) >> 40 ) | ( ( word & 0xFF00000000000000ULL ) >> 56 );
#endif
h = ( h ^ word ) * prime;
i += 8;
}
while ( i < n )
{
h = ( h ^ (uint64_t)bytes[i] ) * prime;
i += 1;
}
h ^= h >> 30;
h *= 0xbf58476d1ce4e5b9ull;
h ^= h >> 27;
h *= 0x94d049bb133111ebull;
h ^= h >> 31;
return h == 0 ? 1 : h;
}