Code Monkey home page Code Monkey logo

native-ecslite's Introduction

Native extension for Leopotam ecslite

An extension for Leopotam ecslite framework with full per entity operations support from Unity Job system side

Badges

MIT License Downloads

Documentation

Usage/Examples

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

FAQ

Know problems

  1. No AutoReset
  2. No internal arrays resizing. Be careful or specify pool arrays size in EcsWorld.Config
  3. No way to create entity inside Job
  4. Not true entity deletion in Job

Future plans

  1. Entity creation in Job
  2. True entity deletion in Job
  3. Find ways to resize internal managed arrays in Job that has been wrapped to NativeArray
  4. Add AutoReset

native-ecslite's People

Contributors

antontidev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.