Native extension for Leopotam ecslite
An extension for Leopotam ecslite framework with full per entity operations support from Unity Job system side
System example:
class ExampleSystem : BaseGameJobSystem<TJob>
{
// Or you can provide operations service that has been created in DI container
public override INativeOperationsService ProvideNativeOperationsService()
=> new NativeOperationsService();
public override int GetChunkSize(EcsSystems systems)
=> 10;
public override EcsFilter GetFilter(EcsWorld world)
{
return world.Filter<Component1>().Inc<Component2>().End();
}
// Here you should set entities pool
public override void SetData(EcsSystems systems, ref TJob job)
{
var world = systems.GetWorld();
var filter = GetFilter()
job.Filter = GetFilterWrapper(filter);
job.Component1Operations = OperationsService
.GetReadOnlyOperations<Component1>(systems);
job.Component2Operations = OperationsService
.GetReadOnlyOperations<Component2>(systems);
job.Component3Operations = OperationsService
.GetReadWriteOperations<Component3>(systems);
}
}
Components example:
struct Component1
{
int a;
}
struct Component2
{
int b;
}
struct Component3
{
int c;
}
Job example:
[BurstCompile]
public struct SummAndWriteJob : IJobParallelFor
{
public NativeFilterWrapper Filter;
public ReadOnlyNativeEntityOperations<Component1> Component1Operations;
public ReadWriteNativeEntityOperations<Component2> Component2Operations;
public ReadWriteNativeEntityOperations<Component3> Component3Operations;
public void Execute(int index)
{
var entity = Filter.Entity(index);
var component1Value = Component1Operations.Get(entity);
var component2Value = Component2Operations.Get(entity);
ref var component3Value = ref Component3Operations.Add(entity);
component3Value = component1Value + component2Value;
Component2Operations.Del(entity);
}
}
And that's all! All you need is to operate over entity values.
You also can use this mechanism outside ecs system, for example in some kind of service, in this sutuation you need to call ApplyOperations(EcsSystems systems)
on NativeOperationsService
by yourself
- No AutoReset
- No internal arrays resizing. Be careful or specify pool arrays size in EcsWorld.Config
- No way to create entity inside Job
- Not true entity deletion in Job
- Entity creation in Job
- True entity deletion in Job
- Find ways to resize internal managed arrays in Job that has been wrapped to NativeArray
- Add AutoReset