https://github.com/andreakarasho/tinyecs
A tiny archetype-style ECS library for dotnet
https://github.com/andreakarasho/tinyecs
csharp data-oriented-design dotnet ecs entity-component-system
Last synced: 10 months ago
JSON representation
A tiny archetype-style ECS library for dotnet
- Host: GitHub
- URL: https://github.com/andreakarasho/tinyecs
- Owner: andreakarasho
- License: mit
- Created: 2022-12-30T08:12:38.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-27T21:48:16.000Z (almost 2 years ago)
- Last Synced: 2024-05-02T04:15:10.452Z (almost 2 years ago)
- Topics: csharp, data-oriented-design, dotnet, ecs, entity-component-system
- Language: C#
- Homepage:
- Size: 916 KB
- Stars: 45
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TinyEcs
[](https://www.nuget.org/packages/TinyEcs.Main)
TinyEcs: a reflection-free dotnet ECS library, born to meet your needs.
## Key Features
- Fast
- Reflection-free design
- NativeAOT & bflat support
- Zero runtime allocations
- Relationships support
- `Bevy systems` concept
## Requirements
- `net9.0`
## Status
🚧 Early development stage: Expect breaking changes! 🚧
## Run the pepe game!
```bash
cd samples/TinyEcsGame
dotnet run -c Release
```
## Sample code
This is a very basic example which doens't show the whole features set of this library.
```csharp
using var world = new World();
var scheduler = new Scheduler(world);
// create the Time variable accessible globally by any system which stays fixed at 60fps
scheduler.AddResource(new Time() { FrameTime = 1000.0f / 60.0f });
scheduler.AddResource(new AssetManager());
var setupSysFn = Setup;
scheduler.AddSystem(setupSysFn, Stages.Startup);
var moveSysFn = MoveEntities;
scheduler.AddSystem(moveSysFn);
var countSomethingSysFn = CountSomething;
scheduler.AddSystem(countSomethingSysFn);
while (true)
scheduler.Run();
void Setup(World world, Res assets)
{
// spawn an entity and attach some components to it
world.Entity()
.Set(new Position() { X = 20f, Y = 9f })
.Set(new Velocity() { X = 1f, Y = 1.3f });
var texture = new Texture(0, 2, 2);
texture.SetData(new byte[] { 0, 0, 0, 0 });
assets.Register("image.png", texture);
}
void MoveEntities(Query> query, Res
void CountSomething(Local localCounter, Res
struct Position { public float X, Y; }
struct Velocity { public float X, Y; }
class Time
{
public float FrameTime;
}
class Texture
{
public Texture(int id, int width, int height)
{
Id = id;
Width = width;
Height = height;
}
public int Id { get; }
public int Width { get; }
public int Height { get; }
public void SetData(byte[] data)
{
// ...
}
}
class AssetManager
{
private readonly Dictionary _assets = new ();
public void Register(string name, Texture texture)
{
_assets[name] = texture;
}
public Texture? Get(string name)
{
_assets.TryGetValue(name, out var texture);
return texture;
}
}
```
## Bechmarks
- [friflo - ECS.CSharp.Benchmark-common-use-cases](https://github.com/friflo/ECS.CSharp.Benchmark-common-use-cases/tree/main?tab=readme-ov-file#feature-matrix)
## Credits
Inspired by:
- [entity-component-system](https://github.com/jasonliang-dev/entity-component-system)
- [flecs](https://github.com/SanderMertens/flecs)
- [bevy](https://github.com/bevyengine/bevy)
## Cool Design Reference
- [flecs Manual](https://github.com/SanderMertens/flecs/blob/master/docs/Manual.md)