An open API service indexing awesome lists of open source software.

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.

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;
}
```