Skip to content

Commit

Permalink
Added flag macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Feb 9, 2024
1 parent 2b3d67d commit eba8041
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 5 additions & 4 deletions seika/ecs/ec_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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]);
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
18 changes: 18 additions & 0 deletions seika/utils/flag_util.h
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seika",
"version": "0.0.29",
"version": "0.0.30",
"dependencies": [
{
"name": "sdl2",
Expand Down

0 comments on commit eba8041

Please sign in to comment.