diff --git a/distr/flecs.c b/distr/flecs.c index 143d8d9508..082e6d1b22 100644 --- a/distr/flecs.c +++ b/distr/flecs.c @@ -14284,7 +14284,7 @@ void flecs_observer_invoke( bool match_this = query->flags & EcsQueryMatchThis; if (match_this) { callback(it); - query->eval_count ++; + ecs_os_inc(&query->eval_count); } else { ecs_entity_t observer_src = ECS_TERM_REF_ID(&term->src); if (observer_src && !(term->src.id & EcsIsEntity)) { @@ -14300,7 +14300,7 @@ void flecs_observer_invoke( it->entities = &e; if (!observer_src) { callback(it); - query->eval_count ++; + ecs_os_inc(&query->eval_count); } else if (observer_src == e) { ecs_entity_t dummy = 0; it->entities = &dummy; @@ -14309,7 +14309,7 @@ void flecs_observer_invoke( } callback(it); - query->eval_count ++; + ecs_os_inc(&query->eval_count); it->sources[0] = src; break; } @@ -52131,9 +52131,11 @@ int32_t flecs_run_pipeline_ops( ecs_system_t* sys = (ecs_system_t*)poly->poly; /* 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; + * know from where to resume the schedule in case the schedule + * changes during a merge. */ + if (stage_index == 0) { + sys->last_frame = world->info.frame_count_total + 1; + } ecs_stage_t* s = NULL; if (!op->immediate) { @@ -52145,7 +52147,7 @@ int32_t flecs_run_pipeline_ops( flecs_run_intern(world, s, system, sys, stage_index, stage_count, delta_time, NULL); - world->info.systems_ran_frame++; + ecs_os_linc(&world->info.systems_ran_frame); ran_since_merge++; if (ran_since_merge == op->count) { @@ -69889,7 +69891,7 @@ ecs_iter_t ecs_query_iter( } /* Ok, only for stats */ - ECS_CONST_CAST(ecs_query_t*, q)->eval_count ++; + ecs_os_linc(&ECS_CONST_CAST(ecs_query_t*, q)->eval_count); ecs_query_impl_t *impl = flecs_query_impl(q); ecs_query_cache_t *cache = impl->cache; diff --git a/distr/flecs.h b/distr/flecs.h index 908542f3e1..d18eef7f51 100644 --- a/distr/flecs.h +++ b/distr/flecs.h @@ -73,6 +73,13 @@ */ // #define FLECS_ACCURATE_COUNTERS +/** @def FLECS_DISABLE_COUNTERS + * Disables counters used for statistics. Improves performance, but + * will prevent some features that rely on statistics from working, + * like the statistics pages in the explorer. + */ +// #define FLECS_DISABLE_COUNTERS + /* Make sure provided configuration is valid */ #if defined(FLECS_DEBUG) && defined(FLECS_NDEBUG) #error "invalid configuration: cannot both define FLECS_DEBUG and FLECS_NDEBUG" @@ -2707,6 +2714,7 @@ void ecs_os_set_api_defaults(void); #define ecs_os_now() ecs_os_api.now_() #define ecs_os_get_time(time_out) ecs_os_api.get_time_(time_out) +#ifndef FLECS_DISABLE_COUNTERS #ifdef FLECS_ACCURATE_COUNTERS #define ecs_os_inc(v) (ecs_os_ainc(v)) #define ecs_os_linc(v) (ecs_os_lainc(v)) @@ -2718,6 +2726,13 @@ void ecs_os_set_api_defaults(void); #define ecs_os_dec(v) (--(*v)) #define ecs_os_ldec(v) (--(*v)) #endif +#else +#define ecs_os_inc(v) +#define ecs_os_linc(v) +#define ecs_os_dec(v) +#define ecs_os_ldec(v) +#endif + #ifdef ECS_TARGET_MINGW /* mingw bug: without this a conversion error is thrown, but isnan/isinf should diff --git a/include/flecs.h b/include/flecs.h index 16ab64c354..031f93c4b7 100644 --- a/include/flecs.h +++ b/include/flecs.h @@ -71,6 +71,13 @@ */ // #define FLECS_ACCURATE_COUNTERS +/** @def FLECS_DISABLE_COUNTERS + * Disables counters used for statistics. Improves performance, but + * will prevent some features that rely on statistics from working, + * like the statistics pages in the explorer. + */ +// #define FLECS_DISABLE_COUNTERS + /* Make sure provided configuration is valid */ #if defined(FLECS_DEBUG) && defined(FLECS_NDEBUG) #error "invalid configuration: cannot both define FLECS_DEBUG and FLECS_NDEBUG" diff --git a/include/flecs/os_api.h b/include/flecs/os_api.h index c6dad4578a..2d2cb42bdb 100644 --- a/include/flecs/os_api.h +++ b/include/flecs/os_api.h @@ -517,6 +517,7 @@ void ecs_os_set_api_defaults(void); #define ecs_os_now() ecs_os_api.now_() #define ecs_os_get_time(time_out) ecs_os_api.get_time_(time_out) +#ifndef FLECS_DISABLE_COUNTERS #ifdef FLECS_ACCURATE_COUNTERS #define ecs_os_inc(v) (ecs_os_ainc(v)) #define ecs_os_linc(v) (ecs_os_lainc(v)) @@ -528,6 +529,13 @@ void ecs_os_set_api_defaults(void); #define ecs_os_dec(v) (--(*v)) #define ecs_os_ldec(v) (--(*v)) #endif +#else +#define ecs_os_inc(v) +#define ecs_os_linc(v) +#define ecs_os_dec(v) +#define ecs_os_ldec(v) +#endif + #ifdef ECS_TARGET_MINGW /* mingw bug: without this a conversion error is thrown, but isnan/isinf should diff --git a/src/addons/pipeline/pipeline.c b/src/addons/pipeline/pipeline.c index 102a4750ec..f28fafc19d 100644 --- a/src/addons/pipeline/pipeline.c +++ b/src/addons/pipeline/pipeline.c @@ -560,9 +560,11 @@ int32_t flecs_run_pipeline_ops( ecs_system_t* sys = (ecs_system_t*)poly->poly; /* 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; + * know from where to resume the schedule in case the schedule + * changes during a merge. */ + if (stage_index == 0) { + sys->last_frame = world->info.frame_count_total + 1; + } ecs_stage_t* s = NULL; if (!op->immediate) { @@ -574,7 +576,7 @@ int32_t flecs_run_pipeline_ops( flecs_run_intern(world, s, system, sys, stage_index, stage_count, delta_time, NULL); - world->info.systems_ran_frame++; + ecs_os_linc(&world->info.systems_ran_frame); ran_since_merge++; if (ran_since_merge == op->count) { diff --git a/src/observer.c b/src/observer.c index d073ccad6b..05a0d04b55 100644 --- a/src/observer.c +++ b/src/observer.c @@ -314,7 +314,7 @@ void flecs_observer_invoke( bool match_this = query->flags & EcsQueryMatchThis; if (match_this) { callback(it); - query->eval_count ++; + ecs_os_inc(&query->eval_count); } else { ecs_entity_t observer_src = ECS_TERM_REF_ID(&term->src); if (observer_src && !(term->src.id & EcsIsEntity)) { @@ -330,7 +330,7 @@ void flecs_observer_invoke( it->entities = &e; if (!observer_src) { callback(it); - query->eval_count ++; + ecs_os_inc(&query->eval_count); } else if (observer_src == e) { ecs_entity_t dummy = 0; it->entities = &dummy; @@ -339,7 +339,7 @@ void flecs_observer_invoke( } callback(it); - query->eval_count ++; + ecs_os_inc(&query->eval_count); it->sources[0] = src; break; } diff --git a/src/query/engine/eval_iter.c b/src/query/engine/eval_iter.c index 1c128fe93e..052955dda1 100644 --- a/src/query/engine/eval_iter.c +++ b/src/query/engine/eval_iter.c @@ -372,7 +372,7 @@ ecs_iter_t ecs_query_iter( } /* Ok, only for stats */ - ECS_CONST_CAST(ecs_query_t*, q)->eval_count ++; + ecs_os_linc(&ECS_CONST_CAST(ecs_query_t*, q)->eval_count); ecs_query_impl_t *impl = flecs_query_impl(q); ecs_query_cache_t *cache = impl->cache;