Skip to content

Commit

Permalink
Add ecs_quit to signal that application should stop progressing world
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jan 7, 2019
1 parent bb75176 commit 5bbf50d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
*.o
*.dylib
1 change: 1 addition & 0 deletions include/private/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ struct EcsWorld {
bool auto_merge; /* Are stages auto-merged by ecs_progress */
bool measure_frame_time; /* Time spent on each frame */
bool measure_system_time; /* Time spent by each system */
bool should_quit; /* Did a system signal that app should quit */
};

extern const EcsArrayParams handle_arr_params;
Expand Down
13 changes: 12 additions & 1 deletion include/reflecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ REFLECS_EXPORT
EcsResult ecs_fini(
EcsWorld *world);

/** Signal exit
* This operation signals that the application should quit. It will cause
* ecs_progress to return false.
*
* @time-complexity: O(1)
* @param world The world to quit.
*/
REFLECS_EXPORT
void ecs_quit(
EcsWorld *world);

/** Import a reflecs module.
* Reflecs modules enable reusing components and systems across projects. To
* use a module, a project needs to link with its library and include its header
Expand Down Expand Up @@ -239,7 +250,7 @@ void ecs_import(
* @param delta_time The time passed since the last frame.
*/
REFLECS_EXPORT
void ecs_progress(
bool ecs_progress(
EcsWorld *world,
float delta_time);

Expand Down
11 changes: 10 additions & 1 deletion src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ EcsWorld *ecs_init(void) {
world->measure_frame_time = false;
world->measure_system_time = false;
world->last_handle = 0;
world->should_quit = false;

ut_time_get(&world->frame_start);
world->frame_time = 0;
Expand Down Expand Up @@ -618,7 +619,7 @@ EcsHandle ecs_lookup(
return 0;
}

void ecs_progress(
bool ecs_progress(
EcsWorld *world,
float delta_time)
{
Expand Down Expand Up @@ -704,6 +705,14 @@ void ecs_progress(
ut_sleepf(sleep);
}
}

return !world->should_quit;
}

void ecs_quit(
EcsWorld *world)
{
world->should_quit = true;
}

void ecs_merge(
Expand Down

0 comments on commit 5bbf50d

Please sign in to comment.