From f665e06aa27e431da75f9f334f18ccbf97dcd3c8 Mon Sep 17 00:00:00 2001 From: Martin Lange Date: Tue, 9 Jan 2024 11:59:00 +0100 Subject: [PATCH] fix IdMap for 265 possible IDs --- ecs/id_map.go | 2 +- ecs/id_map_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ecs/id_map.go b/ecs/id_map.go index 035bf5da..bdc89402 100644 --- a/ecs/id_map.go +++ b/ecs/id_map.go @@ -1,8 +1,8 @@ package ecs const ( - numChunks = 8 chunkSize = 16 + numChunks = MaskTotalBits / chunkSize ) // idMap maps component IDs to values. diff --git a/ecs/id_map_test.go b/ecs/id_map_test.go index 09877750..0c154f2f 100644 --- a/ecs/id_map_test.go +++ b/ecs/id_map_test.go @@ -12,10 +12,12 @@ func TestIDMap(t *testing.T) { e0 := Entity{0, 0} e1 := Entity{1, 0} e121 := Entity{121, 0} + e200 := Entity{200, 0} m.Set(0, &e0) m.Set(1, &e1) m.Set(121, &e121) + m.Set(200, &e200) e, ok := m.Get(0) assert.True(t, ok) @@ -29,6 +31,10 @@ func TestIDMap(t *testing.T) { assert.True(t, ok) assert.Equal(t, e121, *e) + e, ok = m.Get(200) + assert.True(t, ok) + assert.Equal(t, e200, *e) + e, ok = m.Get(15) assert.False(t, ok) assert.Nil(t, e) @@ -49,10 +55,12 @@ func TestIDMapPointers(t *testing.T) { e0 := Entity{0, 0} e1 := Entity{1, 0} e121 := Entity{121, 0} + e200 := Entity{200, 0} m.Set(0, e0) m.Set(1, e1) m.Set(121, e121) + m.Set(200, e200) e, ok := m.GetPointer(0) assert.True(t, ok) @@ -66,6 +74,10 @@ func TestIDMapPointers(t *testing.T) { assert.True(t, ok) assert.Equal(t, e121, *e) + e, ok = m.GetPointer(200) + assert.True(t, ok) + assert.Equal(t, e200, *e) + e, ok = m.GetPointer(15) assert.False(t, ok) assert.Nil(t, e)