Skip to content

Commit

Permalink
Change ecs_owns_id from macro to function
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 15, 2023
1 parent 9ee83ca commit 830be77
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
8 changes: 8 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8879,6 +8879,14 @@ bool ecs_has_id(
return false;
}

bool ecs_owns_id(
const ecs_world_t *world,
ecs_entity_t entity,
ecs_id_t id)
{
return (ecs_search(world, ecs_get_table(world, entity), id, 0) != -1);
}

ecs_entity_t ecs_get_target(
const ecs_world_t *world,
ecs_entity_t entity,
Expand Down
25 changes: 18 additions & 7 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5562,21 +5562,35 @@ char* ecs_entity_str(
const ecs_world_t *world,
ecs_entity_t entity);

/** Test if an entity has an entity.
* This operation returns true if the entity has the provided entity in its
* type.
/** Test if an entity has an id.
* This operation returns true if the entity has or inherits the specified id.
*
* @param world The world.
* @param entity The entity.
* @param id The id to test for.
* @return True if the entity has the entity, false if not.
* @return True if the entity has the id, false if not.
*/
FLECS_API
bool ecs_has_id(
const ecs_world_t *world,
ecs_entity_t entity,
ecs_id_t id);

/** Test if an entity owns an id.
* This operation returns true if the entity has the specified id. Other than
* ecs_has_id this operation will not return true if the id is inherited.
*
* @param world The world.
* @param entity The entity.
* @param id The id to test for.
* @return True if the entity has the id, false if not.
*/
FLECS_API
bool ecs_owns_id(
const ecs_world_t *world,
ecs_entity_t entity,
ecs_id_t id);

/** Get the target of a relationship.
* This will return a target (second element of a pair) of the entity for the
* specified relationship. The index allows for iterating through the targets, if a
Expand Down Expand Up @@ -8506,9 +8520,6 @@ int ecs_value_move_ctor(
#define ecs_has_pair(world, entity, first, second)\
ecs_has_id(world, entity, ecs_pair(first, second))

#define ecs_owns_id(world, entity, id)\
(ecs_search(world, ecs_get_table(world, entity), id, 0) != -1)

#define ecs_owns_pair(world, entity, first, second)\
ecs_owns_id(world, entity, ecs_pair(first, second))

Expand Down
22 changes: 18 additions & 4 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2888,21 +2888,35 @@ char* ecs_entity_str(
const ecs_world_t *world,
ecs_entity_t entity);

/** Test if an entity has an entity.
* This operation returns true if the entity has the provided entity in its
* type.
/** Test if an entity has an id.
* This operation returns true if the entity has or inherits the specified id.
*
* @param world The world.
* @param entity The entity.
* @param id The id to test for.
* @return True if the entity has the entity, false if not.
* @return True if the entity has the id, false if not.
*/
FLECS_API
bool ecs_has_id(
const ecs_world_t *world,
ecs_entity_t entity,
ecs_id_t id);

/** Test if an entity owns an id.
* This operation returns true if the entity has the specified id. Other than
* ecs_has_id this operation will not return true if the id is inherited.
*
* @param world The world.
* @param entity The entity.
* @param id The id to test for.
* @return True if the entity has the id, false if not.
*/
FLECS_API
bool ecs_owns_id(
const ecs_world_t *world,
ecs_entity_t entity,
ecs_id_t id);

/** Get the target of a relationship.
* This will return a target (second element of a pair) of the entity for the
* specified relationship. The index allows for iterating through the targets, if a
Expand Down
3 changes: 0 additions & 3 deletions include/flecs/addons/flecs_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,6 @@
#define ecs_has_pair(world, entity, first, second)\
ecs_has_id(world, entity, ecs_pair(first, second))

#define ecs_owns_id(world, entity, id)\
(ecs_search(world, ecs_get_table(world, entity), id, 0) != -1)

#define ecs_owns_pair(world, entity, first, second)\
ecs_owns_id(world, entity, ecs_pair(first, second))

Expand Down
8 changes: 8 additions & 0 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,14 @@ bool ecs_has_id(
return false;
}

bool ecs_owns_id(
const ecs_world_t *world,
ecs_entity_t entity,
ecs_id_t id)
{
return (ecs_search(world, ecs_get_table(world, entity), id, 0) != -1);
}

ecs_entity_t ecs_get_target(
const ecs_world_t *world,
ecs_entity_t entity,
Expand Down

0 comments on commit 830be77

Please sign in to comment.