Skip to content

Commit

Permalink
fix IdMap for 265 possible IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 committed Jan 9, 2024
1 parent 263274c commit f665e06
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ecs/id_map.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ecs

const (
numChunks = 8
chunkSize = 16
numChunks = MaskTotalBits / chunkSize
)

// idMap maps component IDs to values.
Expand Down
12 changes: 12 additions & 0 deletions ecs/id_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit f665e06

Please sign in to comment.