GitWither / SharpActors

A simple C# Entity Component System

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SharpActors

A simple C# Entity Component System. This library aims to simplify and speed up the implementation of ECS in C# games and engines.

Key Features

  • Actors (entities) are integers and hold no data
  • Components are simple structs and are stored in contiguous memory
  • A view system that allows you to query actors during runtime
  • A System implementation that allows you to process entities based on their components

Usage

It's very easy to start using this library. Simply add it as a reference to your project. To start using it in code, you have to initialize an ActorRegistry:

const int maxActors = 10000;
ActorRegistry actorRegistry = new ActorRegistry(maxActors);

Creating Actors

int actor = actorRegistry.CreateActor();

Managing Components

struct CoolComponent {
  public int coolness;
}

actorRegistry.RegisterComponent<CoolComponent>();

actorRegistry.AddComponent<CoolComponent>(actor);
bool isCool = actorRegistry.HasComponent<CoolComponent>(actor);
actorRegistry.RemoveComponent<CoolComponent>(actor);

Views

ActorView coolView = actorRegistry.CreateView<CoolComponent>();
Console.WriteLine(coolView.Count);

Systems

A System can be any class that inherits from ActorSystem

public RenderSystem : ActorSystem {
  void CoolFunc() {
    //Access actors with //this.Actors
  }
}

RenderSystem renderSystem = actorRegistry.RegisterSystem<CoolComponent, RenderingComponent>()

You can find more examples in the Unit Tests

About

A simple C# Entity Component System


Languages

Language:C# 100.0%