https://github.com/simmsb/simple-ecs
A simple Entity Component System written in C
https://github.com/simmsb/simple-ecs
Last synced: 12 months ago
JSON representation
A simple Entity Component System written in C
- Host: GitHub
- URL: https://github.com/simmsb/simple-ecs
- Owner: simmsb
- License: mit
- Created: 2019-05-19T04:33:31.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-01T06:11:25.000Z (about 7 years ago)
- Last Synced: 2025-04-22T00:03:18.231Z (about 1 year ago)
- Language: C
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple ECS
This is a simple ECS framework for C
# Example
```c
#include
#include
#include "entity.h"
#include "component.h"
#include "system.h"
struct position_storage {
int32_t x, y;
};
DEFINE_COMPONENT(position, struct position_storage);
REGISTER_COMPONENT(position, struct position_storage);
struct velocity_storage {
int32_t dx, dy;
};
DEFINE_COMPONENT(velocity, struct velocity_storage);
REGISTER_COMPONENT(velocity, struct velocity_storage);
REGISTER_SYSTEM(update_velocity_values, {
FOR_JOIN_COMPONENT_2(position, velocity, d, {
d.position->x += d.velocity->dx;
d.position->y += d.velocity->dy;
});
});
int main() {
uint32_t test_entity = new_entity_id();
position.add_value(test_entity, (struct position_storage){.x = 0, .y = 0});
velocity.add_value(test_entity, (struct velocity_storage){.dx = 1, .dy = 2});
while (true) {
run_systems();
}
}
```