Giter Club home page Giter Club logo

enttsharp's Introduction

EnTT Sharp is a C# port of EnTT for C++. EnTT is a lightweight entity-component-system library with a focus on performance and cache friendliness.

This C# port roughly matches version 2.8 of the C++ EnTT library. It does not contain many of the C++ specific helper functions (like type information systems or sane events, etc) which are part of the .NET runtime or can be easily added via external libraries. Referencing libraries is not as painful in C# as it apparently is in C++.

Table of Contents

Introduction

The entity-component-system (also known as ECS) is an architectural pattern used mostly in game development. For further details:

The EnTT wiki contains helpful

This project is a faithful port of the C++ version of EnTT without any of the C++ specific helper systems needed in the original version. The EnTT system allows you to define abstract entities, assign tags and components to those entities and finally to iterate the entity and component pools in a fast and cache friendly way.

EnTTSharp has the following features:

  • An incredibly fast entity-component system based on sparse sets, with its own pay for what you use policy to adjust performance and memory usage according to the users' requirements.
  • Works on POCO objects, no need to pollute your code with library interfaces.
  • Optional, attribute-based automatic registration of components and serializers
  • 64-Bit Entity Keys, 2^31 entities per registry and 24 bits of additional data per key to allow partitioned key-spaces in distributed systems.
  • Snapshop and state serialization support
  • Compatible with .NET-Framework 4.7, .NET Core 2.0 (and later) and Unity's C# dialect.

Code Example

    public readonly struct Position
    {
        public readonly double X;
        public readonly double Y;

        public Position(double x, double y)
        {
            X = x;
            Y = y;
        }
    }

    public readonly struct Velocity
    {
        public readonly double DeltaX;
        public readonly double DeltaY;

        public Velocity(double deltaX, double deltaY)
        {
            DeltaX = deltaX;
            DeltaY = deltaY;
        }
    }

    public static void UpdatePosition(EntityRegistry registry, TimeSpan deltaTime)
    {
        // view contains all the entities that have both a position and a velocty component ...
        var view = registry.View<Velocity, Position>();
        foreach (var entity in view)
        {
            if (view.GetComponent(entity, out Position pos) &&
                view.GetComponent(entity, out Velocity velocity))
            {
                var posChanged = new Position(pos.X + velocity.DeltaX * deltaTime.TotalSeconds,
                                              pos.Y + velocity.DeltaY * deltaTime.TotalSeconds);
                registry.AssignComponent(entity, in posChanged);
            }
        }
    }

    public static void ClearVelocity(EntityRegistry registry)
    {
        var view = registry.View<Velocity>();
        foreach (var entity in view)
        {
            registry.AssignComponent(entity, new Velocity(0,0));
        }
    }

    public static void Main(string [] args)
    {
        var random = new Random();
        var registry = new EntityRegistry();
        registry.Register<Velocity>();
        registry.Register<Position>();

        for (int x = 0; x < 10; x += 1)
        {
            var entity = registry.Create();
            registry.AssignComponent<Position>(entity);
            if ((x % 2) == 0)
            {
                registry.AssignComponent(entity, new Velocity(random.NextDouble(), random.NextDouble()));
            }
        }

        UpdatePosition(registry, TimeSpan.FromSeconds(0.24));
        ClearVelocity(registry);
    }

Motivation

I ported EnTT-Sharp after looking though many of the existing C# based ECS libraries. The existing libraries (Entidas, SharpECS) are sadly not written with garbage-collector or cache friendliness in mind and proceed to define components and entities mandatorily as reference types.

I do not want to be forced to pay the 20-bytes garbage collector enablement tax the .NET framework imposes on reference types. Unity's ECS system seems to have the right ideas, but after years of working against Unity's bugs I have little trust left to bind myself exclusively to a Unity provided implementation.

I ported EnTT to provide me with a fast way of defining entities and component systems to enable me to work in a more data driven way. The library is intentionally not bound to any game library. The ECS architecture splits the update loop in distinct phases that are small enough to be easily understood and can be individually debugged.

Each system function works on a limited set of data and can be trivially unit tested. EnTT's design cleanly separates the game logic from the library.

I have used this library successfully in both Unity and MonoGame projects. Testing its support for Godot is on the roadmap, I suspect it will work out of the box.

Build instructions

This library can be built via the standard build command

 dotnet build

The core EnTTSharp library has no external dependencies. A NuGet package can be created via

 dotnet pack

Todo: Add release scripts.

Documentation

Todo

Tests

Todo

Packaging Tools

ToDo. EnTT Sharp will be available via NuGet once it has some better tests and documentation.

Contributors

EnTTSharp was written initially as a faster alternative to other well known and open source entity-component systems. Requests for features, PR, suggestions and feedback are highly appreciated.

If you find you can help me and want to contribute to the project with your experience or you do want to get part of the project for some other reasons, feel free to contact me directly (you can find the mail in the profile).
I can't promise that each and every contribution will be accepted, but I can assure that I'll do my best to take them all seriously.

If you decide to participate, please see the guidelines for contributing before to create issues or pull requests.
Take also a look at the contributors list to know who has participated so far.

License

C# code and documentation Copyright(c) 2020 Thomas Morgner
Original code and documentation Copyright (c) 2017-2020 Michele Caini.

Code released under the MIT license. Documentation released under CC BY 4.0.
Logo released under CC BY-SA 4.0.

enttsharp's People

Contributors

tmorgner avatar

Stargazers

Happy Pixels avatar Geun-Hee Park avatar Vladislav Kantaev avatar angelofb avatar Roger Winright avatar  avatar Michael Comperda avatar Julio Labarca avatar aeonic avatar Annas avatar EEEEEEEEEEEEX avatar Urada avatar  avatar William Dekker avatar Amber avatar Valery Arugin avatar Brett M avatar Travis Johnsen avatar  avatar Oli Garrett avatar  avatar  avatar David avatar eunjin avatar Vitor Henrique avatar  avatar youchao.woo avatar Light avatar  avatar  avatar harun seng avatar Enrico Speranza avatar 西风逍遥游 avatar Guillaume Delevoye avatar Emanuele Manzione avatar Michele Caini avatar  avatar Luiz André avatar Light0457 avatar Felix Strauß avatar Artem Saikin avatar Simple Boy avatar  avatar Wave Walnut avatar bmbcrckr avatar SanSan avatar  avatar Nuno Silva avatar Ricky avatar Rogerio Cruz avatar Julio Litwin avatar

Watchers

James Cloos avatar Gytis avatar  avatar  avatar

enttsharp's Issues

First of all, thank you for porting EnTT to C#

I never imagined anyone would ever think of doing this so I didn't bother searching before... but it looks like I was wrong.

The thing I'm most interested in is performance. Obviously it would be better than most ECS systems in C# that don't take GC or cache into consideration. However, I was wondering how close to native performance one can get to C++ when one would write an entire program out of EnTT with no object references.

I somewhat religiously depend on ECS for everything in C++ such that I almost never use native pointers for nearly anything. To my understanding, the only reason C# can be potentially slower than C++ is its GC and cache-unfriendly logistics. If we can bypass that with EnTT, would the performance technically be similar to native code?

I just needed to make sure, and know what really is going under the hood that can potentially be different from its C++ counterpart. But if what you promised is correct, this just about solves nearly all problems for me.

p.s. I would very much like at least a very simple prototype of documentation. On how to properly or partially serialize a component, for example, or marking it for automatic registration using attributes (does it work the same as Unity? SerializeField and such). And other stuff available in the original entt.

Readme has wrong .Net Standard version

The readme states this builds for .Net Standard 2.0+ (which works with many of the .Net Frameworks and Unity 2018.1+) but as of commit 3c7a39b (Sept 27 2022), this can only be built to Standard 2.1 due to (in particular) null-state analysis attributes.

hello

Can you give me a nuget package

Questions.

Hey ~

  • Is ready for production or still under development?
  • Comparing performance with leoecs, defaultecs and others, how does EnTTSharp behave?

Thanks,
Cheers.

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.