Created
May 21, 2022 10:00
-
-
Save Hexlord/d29946654c6758b2cf27e88daf1e2e5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static double accum = 0.0; | |
static ecs_time_t last_time; | |
static int counter = 0; | |
int ecs_term_finalize( | |
const ecs_world_t *world, | |
const char *name, | |
ecs_term_t *term) | |
{ | |
static bool initialized = false; | |
if(!initialized) { | |
ecs_os_get_time(&last_time); | |
initialized = true; | |
} | |
ecs_time_t start; | |
ecs_os_get_time(&start); | |
if (finalize_term_vars(world, term, name)) { | |
return -1; | |
} | |
if (!term->id) { | |
if (finalize_term_id(world, term, name)) { | |
return -1; | |
} | |
} else { | |
if (populate_from_term_id(world, term, name)) { | |
return -1; | |
} | |
} | |
if (finalize_term_identifiers(world, term, name)) { | |
return -1; | |
} | |
if (!term_can_inherit(term)) { | |
if (term->subj.set.relation == EcsIsA) { | |
term->subj.set.relation = 0; | |
term->subj.set.mask = EcsSelf; | |
} | |
} | |
if (term->role == ECS_AND || term->role == ECS_OR || term->role == ECS_NOT){ | |
/* AND/OR terms match >1 component, which is only valid as filter */ | |
if (term->inout != EcsInOutDefault && term->inout != EcsInOutFilter) { | |
term_error(world, term, name, "AND/OR terms must be filters"); | |
return -1; | |
} | |
term->inout = EcsInOutFilter; | |
/* Translate role to operator */ | |
if (term->role == ECS_AND) { | |
term->oper = EcsAndFrom; | |
} else | |
if (term->role == ECS_OR) { | |
term->oper = EcsOrFrom; | |
} else | |
if (term->role == ECS_NOT) { | |
term->oper = EcsNotFrom; | |
} | |
/* Zero out role & strip from id */ | |
term->id &= ECS_COMPONENT_MASK; | |
term->role = 0; | |
} | |
if (verify_term_consistency(world, term, name)) { | |
return -1; | |
} | |
ecs_time_t current; | |
ecs_os_get_time(¤t); | |
double delta = ecs_time_to_double(ecs_time_sub(current, start)); | |
accum += delta; | |
++counter; | |
if(ecs_time_to_double(ecs_time_sub(current, last_time)) >= 1.0) { | |
printf("ecs_term_finalize during last second: %d calls taking %f seconds\n", counter, accum); | |
counter = 0; | |
accum = 0.0; | |
last_time = current; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment