thelinuxlich/artemis_CSharp — pull request #55 by Maximusya (2013-12-14 13:51:54+00:00)
Title: Add component from pool to entity after running init code

Problem
------------
Since Entity is automatically refreshed after adding a Component, the respective Systems run their `OnAdded(Entity entity)` methods during `entity.AddComponent` call.
It's all good when you first create a component, initialize all the required data - and only then *AddComponent*.
But `Entity.AddComponentFromPool()` does not allow you to 1) get component from pool; 2) set component's data; 3) add component to entity. It just adds a newly created or (possibly) cleaned-up Component to Entity. Thus Systems may get an Entity with inconsistent Component data in `EnitySystem.OnAdded(Entity entity)` method.

Remember issue #49 where `EntitySystem.OnRemoved` was expected to unload some resource - that was supposed to be previousely loaded in OnAdded event.

Solution
-----------
```csharp
public void AddComponentFromPool(global::System.Action init) where T : ComponentPoolable
{
Debug.Assert(init != null, "Init delegate must not be null.");

T component = this.entityWorld.GetComponentFromPool();
init(component);
this.entityManager.AddComponent(this, component);
}
```

Example:
```csharp
entity.AddComponentFromPool(c => c.Power = 100);
```