-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stop using bitsets for now, remove registerComponents
- Loading branch information
1 parent
ae7a77f
commit 9096041
Showing
29 changed files
with
166 additions
and
889 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@arancini/core": minor | ||
"arancini": minor | ||
--- | ||
|
||
feat: stop using bitsets for query evaluation, evaluate queries using object keys | ||
|
||
The bitset implementation as-is is slower than just checking object keys, even for large numbers of component types. | ||
|
||
This may be revisited in the future, but for now, arancini will use object keys for query evaluation to improve performance and simplify the library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@arancini/core": minor | ||
"arancini": minor | ||
--- | ||
|
||
feat: remove World components constructor parameter and `registerComponents` | ||
|
||
There is no longer any need to register components when creating a world. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { BitSet } from '@arancini/core' | ||
import { ObjectPool } from '@arancini/pool' | ||
|
||
const withBitSets = (n) => { | ||
const componentRegistry = { | ||
a: 0, | ||
b: 1, | ||
c: 2, | ||
d: 3, | ||
e: 4, | ||
f: 5, | ||
g: 6, | ||
h: 7, | ||
i: 8, | ||
j: 9, | ||
k: 10, | ||
} | ||
|
||
const queryBitSet = new BitSet() | ||
queryBitSet.add(componentRegistry.foo, componentRegistry.bar) | ||
|
||
const pool = new ObjectPool(() => new BitSet()) | ||
|
||
for (let i = 0; i < n; i++) { | ||
const entityBitSet = pool.request() | ||
entityBitSet.reset() | ||
// const entityBitSet = new BitSet() | ||
entityBitSet.add(componentRegistry.foo, componentRegistry.bar) | ||
|
||
entityBitSet.containsAll(queryBitSet) | ||
|
||
pool.recycle(entityBitSet) | ||
} | ||
} | ||
|
||
const withObjects = (n) => { | ||
const query = [ | ||
'a', | ||
'b', | ||
'c', | ||
'd', | ||
'e', | ||
'f', | ||
'g', | ||
'h', | ||
'i', | ||
'j', | ||
'k', | ||
] | ||
|
||
for (let i = 0; i < n; i++) { | ||
const entity = { | ||
a: true, | ||
b: true, | ||
c: true, | ||
d: true, | ||
e: true, | ||
f: true, | ||
g: true, | ||
} | ||
|
||
query.every((key) => entity[key]) | ||
} | ||
} | ||
|
||
const bench = () => { | ||
const n = 10000000 | ||
|
||
console.time('withBitSets') | ||
withBitSets(n) | ||
console.timeEnd('withBitSets') | ||
|
||
console.time('withObjects') | ||
withObjects(n) | ||
console.timeEnd('withObjects') | ||
} | ||
|
||
bench() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.