Skip to content

Commit

Permalink
#124 don't prefix entity constants for builtin tags
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 20, 2020
1 parent 157e280 commit fabfe90
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 104 deletions.
14 changes: 7 additions & 7 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,16 @@ extern ecs_type_t
#define FLECS__EEcsTrigger (3)
#define FLECS__EEcsType (4)
#define FLECS__EEcsModule (5)
#define FLECS__EEcsPrefab (6)
#define EcsPrefab (6)
#define FLECS__EEcsSystem (7)
#define FLECS__EEcsColSystem (8)
#define FLECS__EEcsName (9)
#define FLECS__EEcsHidden (10)
#define FLECS__EEcsDisabled (11)
#define FLECS__EEcsDisabledIntern (12)
#define FLECS__EEcsInactive (13)
#define FLECS__EEcsOnDemand (14)
#define FLECS__EEcsMonitor (15)
#define EcsHidden (10)
#define EcsDisabled (11)
#define EcsDisabledIntern (12)
#define EcsInactive (13)
#define EcsOnDemand (14)
#define EcsMonitor (15)
#define FLECS__EEcsPipeline (17)
#define FLECS__EEcsPipelineQuery (18)
#define FLECS__EEcsTimer (19)
Expand Down
4 changes: 2 additions & 2 deletions src/api_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ ecs_entity_t ecs_new_prefab(

ecs_entity_t result = lookup(world, name, type.normalized);
if (!result) {
result = ecs_new_w_entity(world, ecs_entity(EcsPrefab));
result = ecs_new_w_entity(world, EcsPrefab);
ecs_add_type(world, result, type.normalized);
ecs_set(world, result, EcsName, {name});
} else {
if (!ecs_has(world, result, EcsPrefab)) {
if (!ecs_has_entity(world, result, EcsPrefab)) {
ecs_abort(ECS_ALREADY_DEFINED, name);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void ecs_colsystem_dtor(
}

/* Invoke Disabled action for enabled systems */
if (!ecs_has_entity(world, e, ecs_entity(EcsDisabled)) &&
!ecs_has_entity(world, e, ecs_entity(EcsDisabledIntern)))
if (!ecs_has_entity(world, e, EcsDisabled) &&
!ecs_has_entity(world, e, EcsDisabledIntern))
{
ecs_invoke_status_action(world, e, ptr, EcsSystemDisabled);
}
Expand Down
2 changes: 1 addition & 1 deletion src/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int ecs_dbg_col_system(
*dbg_out = (ecs_dbg_col_system_t){.system = system};
dbg_out->active_table_count = ecs_vector_count(system_data->query->tables);
dbg_out->inactive_table_count = ecs_vector_count(system_data->query->inactive_tables);
dbg_out->enabled = !ecs_has(world, system, EcsDisabled);
dbg_out->enabled = !ecs_has_entity(world, system, EcsDisabled);

ecs_matched_table_t *mt = ecs_vector_first(system_data->query->tables);
int32_t i, count = ecs_vector_count(system_data->query->tables);
Expand Down
4 changes: 2 additions & 2 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void instantiate_children(
ecs_entity_t c = type_array[i];

/* Make sure instances don't have EcsPrefab */
if (c == ecs_entity(EcsPrefab)) {
if (c == EcsPrefab) {
continue;
}

Expand Down Expand Up @@ -1778,7 +1778,7 @@ const void* ecs_get_ptr_w_entity(

ptr = get_component(&info, component);
if (!ptr) {
if (component != ecs_entity(EcsName) && component != ecs_entity(EcsPrefab)) {
if (component != ecs_entity(EcsName) && component != EcsPrefab) {
ptr = get_base_component(
world, stage, entity, &info, 0, component);
}
Expand Down
9 changes: 5 additions & 4 deletions src/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void build_pipeline(
}

bool needs_merge = false;
bool is_active = !ecs_has(world, rows->entities[i], EcsInactive);
bool is_active = !ecs_has_entity(
world, rows->entities[i], EcsInactive);

ecs_vector_each(q->sig.columns, ecs_sig_column_t, column, {
needs_merge |= check_column(column, is_active, write_state);
Expand Down Expand Up @@ -301,8 +302,8 @@ void EcsOnAddPipeline(
* the regular query matching */
ecs_sig_add(&sig, EcsFromSelf, EcsOperAnd, EcsIn, ecs_entity(EcsColSystem), 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperAnd, EcsIn, ECS_XOR | pipeline, 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperNot, EcsIn, ecs_entity(EcsInactive), 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperNot, EcsIn, ecs_entity(EcsDisabledIntern), 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperNot, EcsIn, EcsInactive, 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperNot, EcsIn, EcsDisabledIntern, 0);

/* Create the query. Sort the query by system id and phase */
ecs_query_t *query = ecs_query_new_w_sig(world, 0, &sig);
Expand All @@ -315,7 +316,7 @@ void EcsOnAddPipeline(
* operations need to be put in place. */
ecs_sig_add(&sig, EcsFromSelf, EcsOperAnd, EcsIn, ecs_entity(EcsColSystem), 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperAnd, EcsIn, ECS_XOR | pipeline, 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperNot, EcsIn, ecs_entity(EcsDisabledIntern), 0);
ecs_sig_add(&sig, EcsFromSelf, EcsOperNot, EcsIn, EcsDisabledIntern, 0);

/* Use the same sorting functions for the build query */
ecs_query_t *build_query = ecs_query_new_w_sig(world, 0, &sig);
Expand Down
16 changes: 8 additions & 8 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,15 @@ bool match_table(

/* Don't match disabled entities */
if (!query->match_disabled && ecs_type_has_owned_entity(
world, table_type, ecs_entity(EcsDisabled), true))
world, table_type, EcsDisabled, true))
{
failure_info->reason = EcsMatchEntityIsDisabled;
return false;
}

/* Don't match prefab entities */
if (!query->match_prefab && ecs_type_has_owned_entity(
world, table_type, ecs_entity(EcsPrefab), true))
world, table_type, EcsPrefab, true))
{
failure_info->reason = EcsMatchEntityIsPrefab;
return false;
Expand Down Expand Up @@ -1027,12 +1027,12 @@ void process_signature(
* signal that disabled entities should be matched. By default,
* disabled entities are not matched. */
if (ecs_type_has_owned_entity(
world, column->is.type, ecs_entity(EcsDisabled), true))
world, column->is.type, EcsDisabled, true))
{
query->match_disabled = true;
}
} else if (op == EcsOperAnd || op == EcsOperOptional) {
if (column->is.component == ecs_entity(EcsDisabled)) {
if (column->is.component == EcsDisabled) {
query->match_disabled = true;
}
}
Expand All @@ -1044,12 +1044,12 @@ void process_signature(
* signal that disabled entities should be matched. By default,
* prefab entities are not matched. */
if (ecs_type_has_owned_entity(
world, column->is.type, ecs_entity(EcsPrefab), true))
world, column->is.type, EcsPrefab, true))
{
query->match_prefab = true;
}
} else if (op == EcsOperAnd || op == EcsOperOptional) {
if (column->is.component == ecs_entity(EcsPrefab)) {
if (column->is.component == EcsPrefab) {
query->match_prefab = true;
}
}
Expand Down Expand Up @@ -1193,9 +1193,9 @@ void ecs_query_rematch(
* already dis/enabled this operation has no side effects. */
if (query->system) {
if (ecs_sig_check_constraints(world, &query->sig)) {
ecs_remove(world, query->system, EcsDisabledIntern);
ecs_remove_entity(world, query->system, EcsDisabledIntern);
} else {
ecs_add(world, query->system, EcsDisabledIntern);
ecs_add_entity(world, query->system, EcsDisabledIntern);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ void StatsCollectSystemStats(ecs_rows_t *rows) {
stats[i].period_seconds = ecs_get_interval(rows->world, system[i].tick_source);
stats[i].seconds_total = system[i].time_spent;
stats[i].invoke_count_total = system[i].invoke_count;
stats[i].is_enabled = !ecs_has(rows->world, entity, EcsDisabled);
stats[i].is_enabled = !ecs_has_entity(rows->world, entity, EcsDisabled);
stats[i].is_active = ecs_vector_count(system[i].query->tables) != 0;
stats[i].is_hidden = ecs_has(rows->world, entity, EcsHidden);
stats[i].is_hidden = ecs_has_entity(rows->world, entity, EcsHidden);
}
}

Expand Down Expand Up @@ -549,7 +549,7 @@ void StatsCollectTypeStats(ecs_rows_t *rows) {
stats[i].entity = rows->entities[i];
stats[i].type = type_component[i].type;
stats[i].normalized_type = type_component[i].normalized;
stats[i].is_hidden = ecs_has(world, rows->entities[i], EcsHidden);
stats[i].is_hidden = ecs_has_entity(world, rows->entities[i], EcsHidden);
stats[i].entities_count = 0;
stats[i].entities_childof_count = 0;
stats[i].entities_instanceof_count = 0;
Expand Down
24 changes: 12 additions & 12 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ void activate_in_columns(
/* If this is the first out column that is requested from
* the OnDemand system, enable it */
if (activate && out[s]->count == 1) {
ecs_remove(world, out[s]->system, EcsDisabledIntern);
ecs_remove_entity(world, out[s]->system, EcsDisabledIntern);
} else if (!activate && !out[s]->count) {
ecs_add(world, out[s]->system, EcsDisabledIntern);
ecs_add_entity(world, out[s]->system, EcsDisabledIntern);
}
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ void ecs_system_activate(
ecs_assert(!world->in_progress, ECS_INTERNAL_ERROR, NULL);

if (activate) {
ecs_remove(world, system, EcsInactive);
ecs_remove_entity(world, system, EcsInactive);
}

const EcsColSystem *system_data = ecs_get_ptr(world, system, EcsColSystem);
Expand Down Expand Up @@ -209,7 +209,7 @@ void ecs_init_system(
ecs_trace_push();

/* All systems start out inactive */
ecs_add(world, system, EcsInactive);
ecs_add_entity(world, system, EcsInactive);

/* Create the query for the system */
ecs_query_t *query = ecs_query_new_w_sig(world, system, &sig);
Expand Down Expand Up @@ -243,7 +243,7 @@ void ecs_init_system(
/* Check if all non-table column constraints are met. If not, disable
* system (system will be enabled once constraints are met) */
if (!ecs_sig_check_constraints(world, &query->sig)) {
ecs_add(world, system, EcsDisabledIntern);
ecs_add_entity(world, system, EcsDisabledIntern);
}

/* If system has FromSystem columns, add components to the system entity */
Expand All @@ -254,7 +254,7 @@ void ecs_init_system(
});

/* If the query has a OnDemand system tag, register its [out] columns */
if (ecs_has(world, system, EcsOnDemand)) {
if (ecs_has_entity(world, system, EcsOnDemand)) {
sptr = ecs_get_mut(world, system, EcsColSystem, NULL);

register_out_columns(world, system, sptr);
Expand All @@ -263,11 +263,11 @@ void ecs_init_system(
/* If there are no systems currently interested in any of the [out]
* columns of the on demand system, disable it */
if (!sptr->on_demand->count) {
ecs_add(world, system, EcsDisabledIntern);
ecs_add_entity(world, system, EcsDisabledIntern);
}
}

if (ecs_has(world, system, EcsMonitor)) {
if (ecs_has_entity(world, system, EcsMonitor)) {
ecs_query_set_monitor(world, query, true);
}

Expand Down Expand Up @@ -312,9 +312,9 @@ void ecs_enable(
});
} else {
if (enabled) {
ecs_remove(world, entity, EcsDisabled);
ecs_remove_entity(world, entity, EcsDisabled);
} else {
ecs_add(world, entity, EcsDisabled);
ecs_add_entity(world, entity, EcsDisabled);
}
}
}
Expand All @@ -331,7 +331,7 @@ void ecs_set_system_status_action(
system_data->status_action = action;
system_data->status_ctx = (void*)ctx;

if (!ecs_has(world, system, EcsDisabled)) {
if (!ecs_has_entity(world, system, EcsDisabled)) {
/* If system is already enabled, generate enable status. The API
* should guarantee that it exactly matches enable-disable
* notifications and activate-deactivate notifications. */
Expand Down Expand Up @@ -502,7 +502,7 @@ bool ecs_is_enabled(
ecs_world_t *world,
ecs_entity_t system)
{
return !ecs_has(world, system, EcsDisabled);
return !ecs_has_entity(world, system, EcsDisabled);
}

void ecs_set_system_context(
Expand Down
4 changes: 2 additions & 2 deletions src/table_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ void init_edges(
table->flags |= EcsTableHasBuiltins;
}

if (e == ecs_entity(EcsPrefab)) {
if (e == EcsPrefab) {
table->flags |= EcsTableIsPrefab;
table->flags |= EcsTableIsDisabled;
}

if (e == ecs_entity(EcsDisabled)) {
if (e == EcsDisabled) {
table->flags |= EcsTableIsDisabled;
}

Expand Down
6 changes: 3 additions & 3 deletions src/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ ecs_entity_t ecs_type_contains(
if (e1 != e2) {
if (match_prefab && e2 !=
ecs_entity(EcsName) && e2 !=
ecs_entity(EcsPrefab) && e2 !=
ecs_entity(EcsDisabled))
EcsPrefab && e2 !=
EcsDisabled)
{
if (ecs_find_entity_in_prefabs(world, 0, type_1, e2, 0)) {
e1 = e2;
Expand Down Expand Up @@ -284,7 +284,7 @@ bool ecs_type_has_entity(
return true;
}

if (e & ECS_INSTANCEOF) {
if (e & ECS_INSTANCEOF && entity != EcsPrefab && entity != EcsDisabled){
ecs_entity_t base = e & ECS_ENTITY_MASK;
if (ecs_has_entity(world, base, entity)) {
return true;
Expand Down
28 changes: 14 additions & 14 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ void bootstrap_types(
ecs_type(EcsTrigger) = bootstrap_type(world, ecs_entity(EcsTrigger));
ecs_type(EcsType) = bootstrap_type(world, ecs_entity(EcsType));
ecs_type(EcsModule) = bootstrap_type(world, ecs_entity(EcsModule));
ecs_type(EcsPrefab) = bootstrap_type(world, ecs_entity(EcsPrefab));
ecs_type(EcsPrefab) = bootstrap_type(world, EcsPrefab);
ecs_type(EcsColSystem) = bootstrap_type(world, ecs_entity(EcsColSystem));
ecs_type(EcsName) = bootstrap_type(world, ecs_entity(EcsName));
ecs_type(EcsHidden) = bootstrap_type(world, ecs_entity(EcsHidden));
ecs_type(EcsDisabled) = bootstrap_type(world, ecs_entity(EcsDisabled));
ecs_type(EcsDisabledIntern) = bootstrap_type(world, ecs_entity(EcsDisabledIntern));
ecs_type(EcsInactive) = bootstrap_type(world, ecs_entity(EcsInactive));
ecs_type(EcsOnDemand) = bootstrap_type(world, ecs_entity(EcsOnDemand));
ecs_type(EcsMonitor) = bootstrap_type(world, ecs_entity(EcsMonitor));
ecs_type(EcsHidden) = bootstrap_type(world, EcsHidden);
ecs_type(EcsDisabled) = bootstrap_type(world, EcsDisabled);
ecs_type(EcsDisabledIntern) = bootstrap_type(world, EcsDisabledIntern);
ecs_type(EcsInactive) = bootstrap_type(world, EcsInactive);
ecs_type(EcsOnDemand) = bootstrap_type(world, EcsOnDemand);
ecs_type(EcsMonitor) = bootstrap_type(world, EcsMonitor);
ecs_type(EcsPipeline) = bootstrap_type(world, ecs_entity(EcsPipeline));
ecs_type(EcsPipelineQuery) = bootstrap_type(world, ecs_entity(EcsPipelineQuery));
ecs_type(EcsTimer) = bootstrap_type(world, ecs_entity(EcsTimer));
Expand Down Expand Up @@ -395,16 +395,16 @@ ecs_world_t *ecs_init(void) {
bootstrap_component(world, table, ecs_entity(EcsTrigger), ECS_COMPONENT_TRIGGER_NAME, sizeof(EcsTrigger));
bootstrap_component(world, table, ecs_entity(EcsType), ECS_TYPE_NAME, sizeof(EcsType));
bootstrap_component(world, table, ecs_entity(EcsModule), ECS_MODULE_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsPrefab), ECS_PREFAB_NAME, 0);
bootstrap_component(world, table, EcsPrefab, ECS_PREFAB_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsSystem), ECS_SYSTEM_NAME, sizeof(EcsSystem));
bootstrap_component(world, table, ecs_entity(EcsColSystem), ECS_COL_SYSTEM_NAME, sizeof(EcsColSystem));
bootstrap_component(world, table, ecs_entity(EcsName), ECS_NAME_NAME, sizeof(EcsName));
bootstrap_component(world, table, ecs_entity(EcsHidden), ECS_HIDDEN_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsDisabled), ECS_DISABLED_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsDisabledIntern), ECS_DISABLED_INTERN_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsInactive), ECS_INACTIVE_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsOnDemand), ECS_ON_DEMAND_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsMonitor), ECS_MONITOR_NAME, 0);
bootstrap_component(world, table, EcsHidden, ECS_HIDDEN_NAME, 0);
bootstrap_component(world, table, EcsDisabled, ECS_DISABLED_NAME, 0);
bootstrap_component(world, table, EcsDisabledIntern, ECS_DISABLED_INTERN_NAME, 0);
bootstrap_component(world, table, EcsInactive, ECS_INACTIVE_NAME, 0);
bootstrap_component(world, table, EcsOnDemand, ECS_ON_DEMAND_NAME, 0);
bootstrap_component(world, table, EcsMonitor, ECS_MONITOR_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsPipeline), ECS_PIPELINE_NAME, 0);
bootstrap_component(world, table, ecs_entity(EcsPipelineQuery), ECS_PIPELINE_QUERY_NAME, sizeof(EcsPipelineQuery));
bootstrap_component(world, table, ecs_entity(EcsTimer), ECS_TIMER_NAME, sizeof(EcsTimer));
Expand Down
Loading

0 comments on commit fabfe90

Please sign in to comment.