commit 3d3d4d89e5a3cf96fc92664cdfbd8df224c09317
parent e24168ead002e3729dc9a51d11f9b33434e017ef
Author: bsandro <email@bsandro.tech>
Date: Mon, 7 Sep 2026 23:00:19 +0300
action/turn end clauses
Diffstat:
4 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/core/world.c b/core/world.c
@@ -14,8 +14,10 @@ void World_addSystem(World *w, System *s) {
arrput(w->systems, *s);
}
-void World_runSystems(World *w) {
+bool World_runSystems(World *w) {
+ bool ret = true;
for (int i=0;i<arrlen(w->systems);++i) {
- w->systems[i].run(w);
+ ret &= w->systems[i].run(w);
}
+ return ret;
}
diff --git a/core/world.h b/core/world.h
@@ -1,5 +1,6 @@
#pragma once
+#include <stdbool.h>
#include "map.h"
#include "core/ecs/entity.h"
#include "core/ecs/system.h"
@@ -13,4 +14,4 @@ typedef struct World {
World * World_init();
void World_addEntity(World *w, Entity *e);
void World_addSystem(World *w, System *s);
-void World_runSystems(World *w);
+bool World_runSystems(World *w);
diff --git a/main.c b/main.c
@@ -25,10 +25,12 @@ int main(int argc, char **argv) {
}
puts("unknown command");
return 1;
-fin:
- World_runSystems(&w);
- puts("world systems run ok");
+fin:
+ int turn = 0;
+ while (World_runSystems(&w)) {
+ printf("[turn %3d] world systems run ok\n", turn++);
+ }
puts("ok");
return 0;
diff --git a/systems/actions.c b/systems/actions.c
@@ -6,14 +6,20 @@
bool actions_run(World *w) {
printf("actions_run world %p\n", (void *)w);
+ bool ret = false;
for (int i=0;i<arrlen(w->entities);++i) {
for (int j=0;j<arrlen(w->entities[i].components);++j) {
+ // @todo wrap the component finder in macros or function
if (w->entities[i].components[j].type==COMPONENT_ACTIONS) {
for (int k=0;k<arrlen(w->entities[i].components[j].actions.items);++k) {
- w->entities[i].components[j].actions.items[k].run(&w->entities[i], w);
+ if (w->entities[i].components[j].actions.items[k].run(&w->entities[i], w)) {
+ ret = true;
+ break;
+ }
}
+ break;
}
}
}
- return true;
+ return ret;
}