https://github.com/weakknight/ecs
A tiny ECS library which mimics EnTT's API.
https://github.com/weakknight/ecs
Last synced: 3 months ago
JSON representation
A tiny ECS library which mimics EnTT's API.
- Host: GitHub
- URL: https://github.com/weakknight/ecs
- Owner: WeakKnight
- Created: 2022-08-09T07:35:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-25T15:24:03.000Z (over 2 years ago)
- Last Synced: 2025-01-17T20:40:41.085Z (4 months ago)
- Language: C++
- Homepage:
- Size: 22.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ECS
A tiny ECS library which mimics [EnTT](https://github.com/skypjack/entt)'s API.
``` cpp
#include "ECS.h"struct Position
{
COMPONENT_CTOR(float px, float py)
{
x = px;
y = py;
}float x;
float y;
};struct Velocity
{
COMPONENT_CTOR(float pdx, float pdy)
{
dx = pdx;
dy = pdy;
}float dx;
float dy;
};struct Movable
{
COMPONENT_CTOR()
{
}
};typedef ECS::Entity Entity;
int main()
{
ECS::Init();for (int i = 0; i < 100; i++)
{
Entity entity = Entity::Create();entity.AddComponent(i * 1.0f, i * 1.0f);
entity.AddComponent(i * 1.0f, i * 1.0f);if (i % 2 == 0)
{
entity.AddComponent(i * 1.0f, i * 1.0f);
if (i % 3 == 0)
{
auto movable = entity.AddComponent();
auto entityPrime = Entity::FromComponent(movable);
assert(entity == entityPrime);
}
}
}Entity::ForEach([](ECS::ComponentHandle position, ECS::ComponentHandle velocity, ECS::ComponentHandle) {
position->x += velocity->dx;
position->y += velocity->dy;
printf("[x: %f, y: %f]\n", position->x, position->y);
});ECS::Release();
return 0;
}
```