Batch and Bulk

How great would it be if you could execute a command on ALL your creatures... oh... you can do that!

So... you don't want to edit all your entities individually, but all at once? How good that I know what makes you tick, come here my son, I can still teach you something!

Mass production

So after your long journey you have finally arrived in the industrial age... Now you want to mass produce entities? Let's take a look at that...

var signature = 
world.Reserve(signature, 1_000_000);

The world.reserve method reserves memory for entities of a specific component structure. The archetype that contains entities of this specific structure is therefore enlarged so that there is enough space for them.

However, these have not yet been created, the space has only been reserved. This still has to happen, the moment does not matter, the reserved memory does not expire. All in all, it looks like this:

var signature = new Signature(typeof(Dwarf), typeof(Position), typeof(Velocity));
world.Reserve(signature, 1_000_000);
for(var index = 0; index < 1_000_000; index++){
    var dwarf = world.Create(signature);
}

So space is created for around one million dwarves and this space is then filled by creating the entities through world.create. This is fast and efficient, it only needs to allocate memory once.

And within a short space of time, you've built up a huge army... and it's incredibly efficient! Whats your... next... step?!

Mass customisation

A further step of every good dictator, uhh leader, is to adapt his troops for the coming campaigns. Customising each one individually is too much effort, so it's a good thing that there are modern production lines for this!

// Giving our dwarfs equipment
var allDwarfs = new QueryDescription().WithAll<Dwarf>().WithNone<Axe, Armor, Boots>();


// Repairing the axe of all ours dwarfs 
var dwarfsWithAxe = new QueryDescription().WithAll<Dwarf, Axe>();
world.Set(in dwarfsWithAxe, new Axe(state = State.Repaired));

// Deciding that our dwarfs are too heavy and they dont need any armor
var dwarfsWithArmor = new QueryDescription().WithAll<Armor>();
world.Remove<Armor>(in dwarfsWithArmor);

// Destroying all dwarfs

Each of these operations uses generics and is available in many variations and overloads. Up to 25 parameters are accepted, but do not have to be passed, in which case the default values are used.

These perform their operations on all entities that match the query. The entities are not processed individually but as a set, making this incredibly fast and efficient. Perfect for our huge army!

Last updated