You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 line
2.3 KiB

  1. #pragma once
  2. #include <ecs/config.h>
  3. beg_namespace_ecs_system_execution_adapter
  4. {
  5. namespace __impl
  6. {
  7. template<typename T_predicate>
  8. struct predicate_holder
  9. {
  10. private:
  11. using predicate_type = T_predicate;
  12. template<typename T_instance>
  13. using predicate_result_type = decltype(
  14. std::declval<predicate_type>()(
  15. std::declval<core::mp::decay_t<T_instance>>().system()));
  16. template<typename T_predicate_result>
  17. using enabler = std::enable_if_t<T_predicate_result { }, void>;
  18. public:
  19. template<typename T_func>
  20. constexpr decltype(auto) detailed_instance(T_func&& func) noexcept
  21. {
  22. return [f = std::forward<T_func>(func)](auto& instance, auto& executor)
  23. -> enabler<predicate_result_type<decltype(instance)>>
  24. {
  25. f(instance, executor);
  26. };
  27. }
  28. template<typename T_func>
  29. constexpr decltype(auto) detailed(T_func&& func) noexcept
  30. {
  31. return detailed_instance([f = std::forward<T_func>(func)](auto& instance, auto& executor) {
  32. f(instance.system(), executor);
  33. });
  34. }
  35. template<typename T_func>
  36. constexpr decltype(auto) for_subtasks(T_func&& func) noexcept
  37. {
  38. return detailed([f = std::forward<T_func>(func)](auto& system, auto& executor){
  39. executor.for_subtasks([&system, &f](auto& data){
  40. f(system, data);
  41. });
  42. });
  43. }
  44. };
  45. }
  46. template<typename T_func>
  47. constexpr decltype(auto) matching(T_func) noexcept
  48. {
  49. return __impl::predicate_holder<T_func> { };
  50. }
  51. constexpr decltype(auto) all() noexcept
  52. {
  53. return matching(hana::always(hana::true_c));
  54. }
  55. template<typename... T_system_tags>
  56. constexpr decltype(auto) tags(T_system_tags... tags) noexcept
  57. {
  58. auto tag_set = hana::make_set(tags...);
  59. return matching([tag_set](auto& system) {
  60. auto tag = tag::system::make(system);
  61. return hana::contains(tag_set, tag);
  62. });
  63. }
  64. }
  65. end_namespace_ecs_system_execution_adapter