Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] ECS cleanup & improvements #122

wants to merge 34 commits into
base: master


Copy link

commented Aug 26, 2019

A number of changes are just to make the code easier to read, maintain, and reason about.

  • Split EntityId management to EntityMapper
  • Split Archetype storage to ArchetypeMapper
  • Split Chunk recycling to ChunkAllocator

Other changes relate to performance:

  • Query now actually caches Archetypes and layouts for fast execution
  • Various memory layout changes to match usage

And yet other changes are just quality of life improvements:

  • No longer need to have a mandatory EntityId const* field in selectors


  • Data-oriented Archetype storage
  • Remove ArchetypeComponentLimit and the code that relies on fixed-size buffers
  • Duplicate Component checks
  • Ability to interogate an EntityId for all its Components, somehow
  • Optimize destroyEntity's need to lookup Entity component and Layout in general
  • Chunk storage data structure for fast chunk searching for Entity allocation
  • Considerations for "shared" (one-per-Chunk) Components
  • Entity command buffers (for delayed creations/deletions/changes)
  • Checks/asserts to make things multi-threading safe when we add scheduling
Reduce Entity mapping to 64-bit
This limits us to 65,536 Archetypes and fewer generations.
Don't treat EntityId as magic in chunk layout or queries
Mostly. It still has to be especially handled when creating or moving entities.

I'm not super fond of how this was achieved. I actually think a _little_ specialness
might be in order.
Replace generic Location
Use C++17 destructuring assignments. Neat.
Don't fill deleted entities from other chunks
Better cache locality, at risk of some fragmentation of the chunk space.

Could make a separate compaction pass if that's an issue, though.
Get rid of boxes in archetype list
Warning: this has a crash bug lurking! Archetype* pointers can be invalidated by
createArchetype calls, and we definitely break those rules in world.cpp currently.
Add tie_struct.h
tie_struct binds a structure as a tuple of references.

tuple_to_typelist extracts the types of a tuple to a typelist

member_typelist_t extracts the types of members of a struct as a typelist.
Added value_list to const_util.h
The other helpers in const_util don't yet work on value_lists.
Added soa_layout.h
soa_layout<T, Size> is a helper to calculate pointer offsets into a strided SoA
memory region of Size bytes. The T must be a structure of pointers. This can
be used to do efficient static SoA layouts for fixed-size chunks, similar to what
we do for ECS Chunks, but statically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.