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.

96 line
2.8 KiB

  1. #pragma once
  2. #include <ecs/core/system/data_proxy/multi.h>
  3. namespace ecs {
  4. namespace core {
  5. namespace system {
  6. namespace data_proxy {
  7. /* multi */
  8. template<typename T_context, typename T_instance>
  9. inline multi<T_context, T_instance>
  10. ::multi(context_type& p_context, instance_type& p_instance, size_t p_index, size_t p_begin, size_t p_end)
  11. : base_type (p_context, p_instance)
  12. , _index (p_index)
  13. , _begin (p_begin)
  14. , _end (p_end)
  15. { }
  16. template<typename T_context, typename T_instance>
  17. template<typename T_func>
  18. inline void multi<T_context, T_instance>
  19. ::for_entities(T_func&& func) const
  20. {
  21. for (size_t i = _begin; i < _end; ++i)
  22. {
  23. std::forward<T_func>(func)(this->instance.subscribed()[i]);
  24. }
  25. }
  26. template<typename T_context, typename T_instance>
  27. template<typename T_func>
  28. inline void multi<T_context, T_instance>
  29. ::for_other_entities(T_func&& func) const
  30. {
  31. auto& subscribed = this->instance.subscribed();
  32. auto total_count = this->instance.subscribed_count();
  33. for (size_t i = 0; i < _begin; ++i)
  34. {
  35. std::forward<T_func>(func)(subscribed()[i]);
  36. }
  37. for (size_t i = _end; i < total_count; ++i)
  38. {
  39. std::forward<T_func>(func)(subscribed()[i]);
  40. }
  41. }
  42. template<typename T_context, typename T_instance>
  43. template<typename T_func>
  44. inline void multi<T_context, T_instance>
  45. ::for_all_entities(T_func&& func) const
  46. {
  47. for (auto& e : this->instance.subscribed())
  48. {
  49. std::forward<T_func>(func)(e);
  50. }
  51. }
  52. template<typename T_context, typename T_instance>
  53. inline size_t multi<T_context, T_instance>
  54. ::entity_count() const
  55. {
  56. return _end - _begin;
  57. }
  58. template<typename T_context, typename T_instance>
  59. inline size_t multi<T_context, T_instance>
  60. ::other_entity_count() const
  61. {
  62. return all_entity_count() - entity_count();
  63. }
  64. template<typename T_context, typename T_instance>
  65. inline size_t multi<T_context, T_instance>
  66. ::all_entity_count() const
  67. {
  68. return this->instance.subscribed_count();
  69. }
  70. /* make_multi */
  71. template<typename T_context, typename T_instance>
  72. constexpr decltype(auto) make_multi(T_context&& context, T_instance&& instance, size_t index, size_t begin, size_t end)
  73. {
  74. using context_type = mp::decay_t<T_context>;
  75. using instance_type = mp::decay_t<T_instance>;
  76. return multi<context_type, instance_type>(
  77. std::forward<T_context>(context),
  78. std::forward<T_instance>(instance),
  79. index,
  80. begin,
  81. end);
  82. }
  83. } } } }