Skip to content

Instantly share code, notes, and snippets.

@wackoisgod
Created October 17, 2022 22:36
Show Gist options
  • Save wackoisgod/6f93589a4ac38338bbce2d7a23237ba7 to your computer and use it in GitHub Desktop.
Save wackoisgod/6f93589a4ac38338bbce2d7a23237ba7 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <flecs.h>
typedef struct Position {
float x;
float y;
} Position;
int main(int argc, char *argv[]) {
ecs_world_t *ecs = ecs_init_w_args(argc, argv);
ECS_COMPONENT_DEFINE(ecs, Position);
ecs_singleton_add(ecs, Position);
ecs_singleton_set(ecs, Position, {1, 1});
ecs_snapshot_t* snap = ecs_snapshot_take(ecs);
Position* p = ecs_singleton_get_mut(ecs, Position);
p->x = 2;
p->y = 2;
ecs_snapshot_restore(ecs, snap);
Position* p2 = ecs_singleton_get(ecs, Position);
printf("x: %f, y: %f\n", p2->x, p2->y);
return ecs_fini(ecs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment