Archetypes & Chunks
Archetypes & Chunks, the underlying foundation and storage structure.
As you look at your entities, you realise that many of them are similar. They even have an identical structure.
And this is exactly where archetypes come into play. An archetype is something like a table in a database; it contains all entities with exactly the same component structure. They are part of the World and each new combination of entities is stored in a new archetype.
You don't need to worry about creating them, it all happens on its own under the bonnet.
Archetype
So what have we learnt? The structure of an entity determines its archetype!
Let's look at another example.
var dwarf = world.Create(new Dwarf(), new Position(), new Velocity());
var miningDwarf = world.Create(new Dwarf(), new Position(), new Velocity(), new Pickaxe());
Even though they are both dwarves, they are still in two different archetypes as their structure is different.
And now all entities with the same structure cuddle up very close to each other in their archetype, nice... right?
Chunk
So now you've learnt what an archetype is. But what is this chunk that was mentioned earlier?
Well, while archetypes do the grouping, chunks are the place where the entities and their components are stored in memory. This also happens under the bonnet and you don't notice much of it.
Each chunk has exactly 16KB of memory which is used entirely for entities and their components. This amount of data fits perfectly into an L1 cache and is therefore loaded incredibly quickly and efficiently when the entities and components are enumerated.
Another advantage is that each archetype has N chunks, so new chunks can be quickly allocated for more entities or existing chunks can be trimmed to free up memory. The best of the best to keep your world running!
Last updated
Was this helpful?