Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 2.03 KB

commandbuffer.md

File metadata and controls

35 lines (25 loc) · 2.03 KB
description
You have lots of plans, lots of orders for your subordinates but you can't carry them all out at once? How cool would it be if someone could do it for you?

CommandBuffer

It's often like this... we have a lot planned, but we can't do it all at once, we have to work through it piece by piece. The same applies to your world and entities, of course... and we have something for that here! The CommandBuffer is exactly for that. You can give it your commands, it saves them and executes them at a later time. Practical, especially for multithreading and if you want to postpone changes until later.

// Our dwarf
var dwarf = world.Create(new Dwarf(), new Position(), new Velocity());

// Buffering actions on entities to play them back later
var commandBuffer = new CommandBuffer();
commandBuffer.Add(dwarf, new Pickaxe();
commandBuffer.Set(dwarf, new Position(10,10);

// Buffering a whole entity
var nonExistingDwarf = commandBuffer.Create(new Signature(typeof(Dwarf), typeof(Position), typeof(Velocity));
commandBuffer.PlayBack(world, disposal = true);

{% hint style="info" %} Actions on entities can therefore be postponed and executed at a later time. This is sometimes more effective than executing them directly, all actions are thread-safe from theCommandBuffer and can also be executed in ParallelQuerys. {% endhint %}

And now we can record changes and play them back at any time, that's cool, isn't it?