commit 63d164cea737ab536f39af03d7fb29ae175cd0eb
parent e788a265dba35fa6033f06fca4297ce201554ee5
Author: Amin Mesbah <dev@aminmesbah.com>
Date: Sun, 5 May 2019 18:47:53 -0700
Actually interleave bits
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/world.c b/src/world.c
@@ -50,7 +50,7 @@ internal u32 world_index_hash(v2i index)
// TODO: profile this
for (u32 i = 0; i < sizeof(u32); i++)
{
- morton_code |= (low_x & 1u << 0) << 0 | (low_y & 1u << 0) << (0 + 1);
+ morton_code |= (low_x & 1u << i) << i | (low_y & 1u << i) << (i + 1);
}
// NOTE(amin): We're not really after any of the specific cool things about
// morton codes. I just picked a hash function that seemed sensible given
@@ -119,6 +119,7 @@ internal struct WorldChunk* world_chunk_get_or_create(struct World *world, v2i c
internal size_t world_room_get_index_within_chunk(v2i room_i)
{
+ static_assert(-1 == ~0, "implementation doesn't use two's complement");
v2u room_i_lower_bits = {
room_i.x & CHUNK_MASK_FOR_INTERNAL_ROOM_INDEX,
room_i.y & CHUNK_MASK_FOR_INTERNAL_ROOM_INDEX,