Closed WEREMSOFT closed 4 years ago
I was doing it wrong. This code is the correct one:
#include <stdio.h>
#include <flecs.h>
void system_evens(ecs_rows_t *rows) {
printf("evens\n");
ECS_COLUMN_COMPONENT(rows, tag_to_remove, 1);
ECS_COLUMN_COMPONENT(rows, tag_to_add, 2);
for (int i = 0; i < rows->count; i++) {
ecs_remove(rows->world, rows->entities[i], tag_to_remove);
ecs_add(rows->world, rows->entities[i], tag_to_add);
}
}
void system_odds(ecs_rows_t *rows) {
printf("ods\n");
ECS_COLUMN_COMPONENT(rows, tag_to_remove, 1);
ECS_COLUMN_COMPONENT(rows, tag_to_add, 2);
for (int i = 0; i < rows->count; i++) {
ecs_remove(rows->world, rows->entities[i], tag_to_remove);
ecs_add(rows->world, rows->entities[i], tag_to_add);
}
}
void system_test_update(ecs_rows_t *rows) {
printf("updating\n");
}
int main(int argc, char *argv[]) {
ecs_world_t *world = ecs_init_w_args(argc, argv);
ECS_TAG(world, tag_evens);
ECS_TAG(world, tag_odds);
ECS_SYSTEM(world, system_test_update, EcsOnUpdate, 0);
ECS_SYSTEM(world, system_evens, EcsOnUpdate, tag_evens, .tag_odds);
ECS_SYSTEM(world, system_odds, EcsOnUpdate, tag_odds, .tag_evens);
int break_condition = 100;
ECS_TYPE(world, Dummy, tag_evens);
ecs_new_w_count(world, Dummy, 1);
while (ecs_progress(world, 0) && break_condition--);
ecs_fini(world);
}
Describe the bug I'm trying to remove and add tags to entities in order to process them by different systems. The idea is using tags to implement a finite state machine, being the tags handled as states.
I tried to send the reference to the tag in two ways to the system: As a context and with the nothing operator. But the program crash with this stack trace:
To Reproduce Run the code and try to change the systems where the objects are being processed to the other system.
Expected behavior The program should print "Even" and "Odd" while the systems have entities to process.
Actual Behavior The program crash.
Aditional Context You can see the full code in the following github https://github.com/WEREMSOFT/FlecsTests/blob/merge_systems/src/main.c