3 releases
0.1.2 | Feb 9, 2025 |
---|---|
0.1.1 | Feb 9, 2025 |
0.1.0 | Feb 9, 2025 |
#507 in Game dev
294 downloads per month
23KB
134 lines
UuidMap
This is an ArrayHashMap (otherwise called "Dense Storage" or an enhanced "VecMap"). It is essentially a relational database table. This one is specialized to use a random u128 as the key, rather than a sequential index.
The performances are on-par with modern bitset-based entity-component-systems, while lagging behind archetypal ECS (~3x slower than legion).
However, it has the advantage that it does not constraint someone to follow the ECS pattern of entities and components, with anything else thrown into resources.
Rather, you can use this as a realtime relational database, suitable for game development and game engines.
This means you can store assets, entities, components, resources and events all in the same type Table<T>
. Having it this way cleans up the code, allows for predictable performance and, most importantly, allows for unified tooling. (In-game Table<ItemDefinition>
editor, anyone?)
You can also use it anywhere you would use an in-memory database.
Where it makes sense to use it.
Where you have:
- High performance needs
- Need centralized data storage to avoid copies and/or pointers.
- Data that will be shared between many systems.
- Don't mind paying the (small) price of u128 indices in exchange for the consistency gain.
Thread Safety
The tables are not thread-safe, by design. You should be using another crate to orchestrate safe table access (no double mutable access, no reads during writes.)
For game engines, I recommend world_dispatcher, which I made for this purpose.
Complexities
- Iterating: O(n). raw
Vec<T>
. - Inserting: O(n) amortized. 2x vec insert + 1x hashmap insert.
- Deleting: O(1). two swap remove. one hashmap get.
- Get element by key: O(1). hash of u128 + array access.
Dependencies
~1.5MB
~21K SLoC