diff --git a/seika/ecs/ec_system.c b/seika/ecs/ec_system.c index e850cb1..42889b7 100644 --- a/seika/ecs/ec_system.c +++ b/seika/ecs/ec_system.c @@ -3,6 +3,7 @@ #include "seika/utils/se_string_util.h" #include "seika/data_structures/se_queue.h" #include "seika/memory/se_mem.h" +#include "seika/utils/flag_util.h" #include "seika/utils/logger.h" #include "seika/utils/se_assert.h" @@ -125,7 +126,7 @@ void ska_ecs_system_register(SkaECSSystem* system) { void ska_ecs_system_update_entity_signature_with_systems(SkaEntity entity) { const SkaComponentType entityComponentSignature = ska_ecs_component_manager_get_component_signature(entity); for (size_t i = 0; i < entitySystemData.entity_systems_count; i++) { - if ((entityComponentSignature & entitySystemData.entity_systems[i]->component_signature) == entitySystemData.entity_systems[i]->component_signature) { + if (SKA_FLAG_CONTAINS(entityComponentSignature, entitySystemData.entity_systems[i]->component_signature)) { ska_ecs_system_insert_entity_into_system(entity, entitySystemData.entity_systems[i]); } else { ska_ecs_system_remove_entity_from_system(entity, entitySystemData.entity_systems[i]); @@ -136,7 +137,7 @@ void ska_ecs_system_update_entity_signature_with_systems(SkaEntity entity) { void ska_ecs_system_event_entity_start(SkaEntity entity) { const SkaComponentType entityComponentSignature = ska_ecs_component_manager_get_component_signature(entity); for (size_t i = 0; i < entitySystemData.on_entity_start_systems_count; i++) { - if ((entityComponentSignature & entitySystemData.on_entity_start_systems[i]->component_signature) == entitySystemData.on_entity_start_systems[i]->component_signature) { + if (SKA_FLAG_CONTAINS(entityComponentSignature, entitySystemData.on_entity_start_systems[i]->component_signature)) { entitySystemData.on_entity_start_systems[i]->on_entity_start_func(entity); } } @@ -147,7 +148,7 @@ void ska_ecs_system_event_entity_end(SkaEntity entity) { // TODO: Consider hooks for components instead of direct node component references const SkaComponentType entityComponentSignature = ska_ecs_component_manager_get_component_signature(entity); for (size_t i = 0; i < entitySystemData.on_entity_end_systems_count; i++) { - if ((entityComponentSignature & entitySystemData.on_entity_end_systems[i]->component_signature) == entitySystemData.on_entity_end_systems[i]->component_signature) { + if (SKA_FLAG_CONTAINS(entityComponentSignature, entitySystemData.on_entity_end_systems[i]->component_signature)) { entitySystemData.on_entity_end_systems[i]->on_entity_end_func(entity); } } @@ -170,7 +171,7 @@ void ska_ecs_system_event_entity_entered_scene(SkaEntity entity) { // } const SkaComponentType entityComponentSignature = ska_ecs_component_manager_get_component_signature(entity); for (size_t i = 0; i < entitySystemData.on_entity_entered_scene_systems_count; i++) { - if ((entityComponentSignature & entitySystemData.on_entity_entered_scene_systems[i]->component_signature) == entitySystemData.on_entity_entered_scene_systems[i]->component_signature) { + if (SKA_FLAG_CONTAINS(entityComponentSignature, entitySystemData.on_entity_entered_scene_systems[i]->component_signature)) { entitySystemData.on_entity_entered_scene_systems[i]->on_entity_entered_scene_func(entity); } } diff --git a/seika/utils/flag_util.h b/seika/utils/flag_util.h new file mode 100644 index 0000000..cf19264 --- /dev/null +++ b/seika/utils/flag_util.h @@ -0,0 +1,18 @@ +#pragma once + +// Contains flag macros... + +// Check if 'FLAGS' contains all the flags specified in 'REQUIRED_FLAGS' +#define SKA_FLAG_CONTAINS(FLAGS, REQUIRED_FLAGS) (((FLAGS) & (REQUIRED_FLAGS)) == (REQUIRED_FLAGS)) + +// Check if 'FLAGS' contains any of the flags specified in 'REQUIRED_FLAGS' +#define HAS_ANY_FLAG(FLAGS, REQUIRED_FLAGS) ((FLAGS) & (REQUIRED_FLAGS)) + +// Check if 'FLAGS' contains none of the flags specified in 'FORBIDDEN_FLAGS' +#define HAS_NO_FLAG(FLAGS, FORBIDDEN_FLAGS) (((FLAGS) & (FORBIDDEN_FLAGS)) == 0) + +// Check if 'FLAGS' contains exactly one of the flags specified in 'REQUIRED_FLAGS' +#define HAS_EXACTLY_ONE_FLAG(FLAGS, REQUIRED_FLAGS) (HAS_ALL_FLAGS(FLAGS, REQUIRED_FLAGS) && ((FLAGS) != 0)) + +// Check if 'FLAGS' contains none of the flags specified in 'REQUIRED_FLAGS' +#define HAS_NONE_OF_FLAGS(FLAGS, REQUIRED_FLAGS) (((FLAGS) & (REQUIRED_FLAGS)) == 0) diff --git a/vcpkg.json b/vcpkg.json index 2532d70..16afc3c 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "seika", - "version": "0.0.29", + "version": "0.0.30", "dependencies": [ { "name": "sdl2",