Skip to content

Commit

Permalink
#1005 Remove unneeded if and main_thread param from flecs_run_pipelin…
Browse files Browse the repository at this point in the history
…e_ops

* Remove unneeded if and main_thread param from flecs_run_pipeline_ops

* Fix double semicolon's
  • Loading branch information
ZeroErrors authored Jul 19, 2023
1 parent b5241cc commit 2879e12
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 62 deletions.
54 changes: 24 additions & 30 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -11416,7 +11416,7 @@ ecs_page_t* flecs_sparse_get_page(
if (page_index >= ecs_vec_count(&sparse->pages)) {
return NULL;
}
return ecs_vec_get_t(&sparse->pages, ecs_page_t, page_index);;
return ecs_vec_get_t(&sparse->pages, ecs_page_t, page_index);
}

static
Expand Down Expand Up @@ -16886,8 +16886,7 @@ int32_t flecs_run_pipeline_ops(
ecs_stage_t* stage,
int32_t stage_index,
int32_t stage_count,
ecs_ftime_t delta_time,
bool main_thread);
ecs_ftime_t delta_time);

////////////////////////////////////////////////////////////////////////////////
//// Worker API
Expand Down Expand Up @@ -16960,7 +16959,7 @@ void* flecs_worker(void *arg) {
ecs_entity_t old_scope = ecs_set_scope((ecs_world_t*)stage, 0);

ecs_dbg_3("worker %d: run", stage->id);
flecs_run_pipeline_ops(world, stage, stage->id, world->stage_count, world->info.delta_time, false);
flecs_run_pipeline_ops(world, stage, stage->id, world->stage_count, world->info.delta_time);

ecs_set_scope((ecs_world_t*)stage, old_scope);

Expand Down Expand Up @@ -17756,44 +17755,39 @@ int32_t flecs_run_pipeline_ops(
ecs_stage_t* stage,
int32_t stage_index,
int32_t stage_count,
ecs_ftime_t delta_time,
bool main_thread)
ecs_ftime_t delta_time)
{
ecs_pipeline_state_t* pq = world->pq;
ecs_pipeline_op_t* op = pq->cur_op;
int32_t i = pq->cur_i;

ecs_assert(!stage_index || op->multi_threaded, ECS_INTERNAL_ERROR, NULL);

int32_t count = ecs_vec_count(&pq->systems);
ecs_entity_t* systems = ecs_vec_first_t(&pq->systems, ecs_entity_t);
int32_t ran_since_merge = i - op->offset;

for (; i < count; i++) {
/* Run system if:
* - this is the main thread, or if
* - the system is multithreaded
*/
if (main_thread || op->multi_threaded) {
ecs_entity_t system = systems[i];
const EcsPoly* poly = ecs_get_pair(world, system, EcsPoly, EcsSystem);
ecs_assert(poly != NULL, ECS_INTERNAL_ERROR, NULL);
ecs_system_t* sys = ecs_poly(poly->poly, ecs_system_t);
ecs_entity_t system = systems[i];
const EcsPoly* poly = ecs_get_pair(world, system, EcsPoly, EcsSystem);
ecs_assert(poly != NULL, ECS_INTERNAL_ERROR, NULL);
ecs_system_t* sys = ecs_poly(poly->poly, ecs_system_t);

/* Keep track of the last frame for which the system has ran, so we
* know from where to resume the schedule in case the schedule
* changes during a merge. */
sys->last_frame = world->info.frame_count_total + 1;
/* Keep track of the last frame for which the system has ran, so we
* know from where to resume the schedule in case the schedule
* changes during a merge. */
sys->last_frame = world->info.frame_count_total + 1;

ecs_stage_t* s = NULL;
if (!op->no_readonly) {
/* If system is no_readonly it operates on the actual world, not
* the stage. Only pass stage to system if it's readonly. */
s = stage;
}

ecs_run_intern(world, s, system, sys, stage_index,
stage_count, delta_time, 0, 0, NULL);
ecs_stage_t* s = NULL;
if (!op->no_readonly) {
/* If system is no_readonly it operates on the actual world, not
* the stage. Only pass stage to system if it's readonly. */
s = stage;
}

ecs_run_intern(world, s, system, sys, stage_index,
stage_count, delta_time, 0, 0, NULL);

world->info.systems_ran_frame++;
ran_since_merge++;

Expand Down Expand Up @@ -17822,7 +17816,7 @@ void flecs_run_pipeline(

ecs_assert(!stage_index, ECS_INVALID_OPERATION, NULL);

bool multi_threaded = ecs_get_stage_count(world) > 1;;
bool multi_threaded = ecs_get_stage_count(world) > 1;

// Update the pipeline the workers will execute
world->pq = pq;
Expand Down Expand Up @@ -17860,7 +17854,7 @@ void flecs_run_pipeline(
ecs_time_measure(&st);
}

const int32_t i = flecs_run_pipeline_ops(world, stage, stage_index, stage_count, delta_time, true);
const int32_t i = flecs_run_pipeline_ops(world, stage, stage_index, stage_count, delta_time);

if (measure_time) {
/* Don't include merge time in system time */
Expand Down
51 changes: 23 additions & 28 deletions src/addons/pipeline/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,44 +529,39 @@ int32_t flecs_run_pipeline_ops(
ecs_stage_t* stage,
int32_t stage_index,
int32_t stage_count,
ecs_ftime_t delta_time,
bool main_thread)
ecs_ftime_t delta_time)
{
ecs_pipeline_state_t* pq = world->pq;
ecs_pipeline_op_t* op = pq->cur_op;
int32_t i = pq->cur_i;

ecs_assert(!stage_index || op->multi_threaded, ECS_INTERNAL_ERROR, NULL);

int32_t count = ecs_vec_count(&pq->systems);
ecs_entity_t* systems = ecs_vec_first_t(&pq->systems, ecs_entity_t);
int32_t ran_since_merge = i - op->offset;

for (; i < count; i++) {
/* Run system if:
* - this is the main thread, or if
* - the system is multithreaded
*/
if (main_thread || op->multi_threaded) {
ecs_entity_t system = systems[i];
const EcsPoly* poly = ecs_get_pair(world, system, EcsPoly, EcsSystem);
ecs_assert(poly != NULL, ECS_INTERNAL_ERROR, NULL);
ecs_system_t* sys = ecs_poly(poly->poly, ecs_system_t);

/* Keep track of the last frame for which the system has ran, so we
* know from where to resume the schedule in case the schedule
* changes during a merge. */
sys->last_frame = world->info.frame_count_total + 1;

ecs_stage_t* s = NULL;
if (!op->no_readonly) {
/* If system is no_readonly it operates on the actual world, not
* the stage. Only pass stage to system if it's readonly. */
s = stage;
}

ecs_run_intern(world, s, system, sys, stage_index,
stage_count, delta_time, 0, 0, NULL);
ecs_entity_t system = systems[i];
const EcsPoly* poly = ecs_get_pair(world, system, EcsPoly, EcsSystem);
ecs_assert(poly != NULL, ECS_INTERNAL_ERROR, NULL);
ecs_system_t* sys = ecs_poly(poly->poly, ecs_system_t);

/* Keep track of the last frame for which the system has ran, so we
* know from where to resume the schedule in case the schedule
* changes during a merge. */
sys->last_frame = world->info.frame_count_total + 1;

ecs_stage_t* s = NULL;
if (!op->no_readonly) {
/* If system is no_readonly it operates on the actual world, not
* the stage. Only pass stage to system if it's readonly. */
s = stage;
}

ecs_run_intern(world, s, system, sys, stage_index,
stage_count, delta_time, 0, 0, NULL);

world->info.systems_ran_frame++;
ran_since_merge++;

Expand Down Expand Up @@ -595,7 +590,7 @@ void flecs_run_pipeline(

ecs_assert(!stage_index, ECS_INVALID_OPERATION, NULL);

bool multi_threaded = ecs_get_stage_count(world) > 1;;
bool multi_threaded = ecs_get_stage_count(world) > 1;

// Update the pipeline the workers will execute
world->pq = pq;
Expand Down Expand Up @@ -633,7 +628,7 @@ void flecs_run_pipeline(
ecs_time_measure(&st);
}

const int32_t i = flecs_run_pipeline_ops(world, stage, stage_index, stage_count, delta_time, true);
const int32_t i = flecs_run_pipeline_ops(world, stage, stage_index, stage_count, delta_time);

if (measure_time) {
/* Don't include merge time in system time */
Expand Down
3 changes: 1 addition & 2 deletions src/addons/pipeline/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ int32_t flecs_run_pipeline_ops(
ecs_stage_t* stage,
int32_t stage_index,
int32_t stage_count,
ecs_ftime_t delta_time,
bool main_thread);
ecs_ftime_t delta_time);

////////////////////////////////////////////////////////////////////////////////
//// Worker API
Expand Down
2 changes: 1 addition & 1 deletion src/addons/pipeline/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void* flecs_worker(void *arg) {
ecs_entity_t old_scope = ecs_set_scope((ecs_world_t*)stage, 0);

ecs_dbg_3("worker %d: run", stage->id);
flecs_run_pipeline_ops(world, stage, stage->id, world->stage_count, world->info.delta_time, false);
flecs_run_pipeline_ops(world, stage, stage->id, world->stage_count, world->info.delta_time);

ecs_set_scope((ecs_world_t*)stage, old_scope);

Expand Down
2 changes: 1 addition & 1 deletion src/datastructures/sparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ecs_page_t* flecs_sparse_get_page(
if (page_index >= ecs_vec_count(&sparse->pages)) {
return NULL;
}
return ecs_vec_get_t(&sparse->pages, ecs_page_t, page_index);;
return ecs_vec_get_t(&sparse->pages, ecs_page_t, page_index);
}

static
Expand Down

0 comments on commit 2879e12

Please sign in to comment.