From 34ee3f0a6eaa5e401d28348e5855be2d64778081 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 19 Aug 2022 09:49:14 +0300 Subject: [PATCH] Support ecs behavior forbidden components that prevent applying it to a certain species --- libs/util/include/psemek/util/ecs.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libs/util/include/psemek/util/ecs.hpp b/libs/util/include/psemek/util/ecs.hpp index ce65fbd3..617b536a 100644 --- a/libs/util/include/psemek/util/ecs.hpp +++ b/libs/util/include/psemek/util/ecs.hpp @@ -89,6 +89,8 @@ namespace psemek::util template void apply(Behavior & behavior, Args const & ... args) { + if (!check_forbidden(behavior, 0)) + return; apply_impl(behavior, static_cast(nullptr), std::make_index_sequence>{}, args...); } @@ -103,6 +105,24 @@ namespace psemek::util std::string name_; species_handle id_; + template + bool check_forbidden(Behavior &, typename Behavior::forbidden_component_types * helper) + { + return check_forbidden_impl(helper); + } + + template + bool check_forbidden(Behavior &, ...) + { + return true; + } + + template + bool check_forbidden_impl(std::tuple *) + { + return (!get_species_component() && ...); + } + template void apply_impl(Behavior & behavior, std::tuple *, std::index_sequence, Args const & ... args) { @@ -395,6 +415,12 @@ namespace psemek::util friend auto operator <=> (entity_handle const &, entity_handle const &) = default; }; + template + struct without + { + using forbidden_component_types = std::tuple; + }; + template struct behavior {