sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.08k stars 1.11k forks source link

Code Generation: why do EntityIndex methods of Context are added as extensions methods and not as an interface + partial class #961

Closed itayalper closed 2 years ago

itayalper commented 3 years ago

Hi,

I have have question about entity index (es) as the title points out, I want to know if there is any issue with creating a custom code generator that creates EntityIndex methods as interface(d) methods.

To further explain my specific use case, I have 2 major contexts: frontend and backend, whom share a lot of the same systems - it could save me a lot of time if the EntityIndex methods were to be generated like that.

Cheers

sschmid commented 2 years ago

Entitas IContext has void AddEntityIndex(IEntityIndex entityIndex);

The generated code is just convenience and syntactic sugar

public static HashSet<TestEntity> GetEntitiesWithPosition(this GameContext context, IntVector2 position)
{
    return ((EntityIndex)(context.GetEntityIndex(Contexts.EntityIndex))).GetEntitiesWithPosition(position);
}

and can be changed to your needs.

In future versions of Entitas we will completely avoid partial class in favour of extension methods.

See https://github.com/sschmid/Entitas/issues/992#issuecomment-1227761712