|
1 |
| -#pragma once |
2 |
| - |
3 |
| -#include <type_traits> |
4 |
| -#include "ecsact/runtime/core.h" |
5 |
| - |
6 |
| -namespace ecsact::entt::detail { |
7 |
| - |
8 |
| -struct execution_events_collector { |
9 |
| - const ecsact_execution_events_collector* target; |
10 |
| - |
11 |
| - inline bool has_init_callback() const { |
12 |
| - return target->init_callback != nullptr; |
13 |
| - } |
14 |
| - |
15 |
| - inline bool has_update_callback() const { |
16 |
| - return target->update_callback != nullptr; |
17 |
| - } |
18 |
| - |
19 |
| - inline bool has_remove_callback() const { |
20 |
| - return target->remove_callback != nullptr; |
21 |
| - } |
22 |
| - |
23 |
| - inline bool has_entity_created_callback() const { |
24 |
| - return target->entity_created_callback != nullptr; |
25 |
| - } |
26 |
| - |
27 |
| - inline bool has_entity_destroyed_callback() const { |
28 |
| - return target->entity_destroyed_callback != nullptr; |
29 |
| - } |
30 |
| - |
31 |
| - template<typename C> |
32 |
| - requires(!std::is_empty_v<C>) |
33 |
| - void invoke_init_callback(ecsact_entity_id entity, const C& component) { |
34 |
| - target->init_callback( |
35 |
| - ECSACT_EVENT_INIT_COMPONENT, |
36 |
| - static_cast<ecsact_entity_id>(entity), |
37 |
| - static_cast<ecsact_component_id>(C::id), |
38 |
| - static_cast<const void*>(&component), |
39 |
| - target->init_callback_user_data |
40 |
| - ); |
41 |
| - } |
42 |
| - |
43 |
| - template<typename C> |
44 |
| - requires(std::is_empty_v<C>) |
45 |
| - void invoke_init_callback(ecsact_entity_id entity) { |
46 |
| - target->init_callback( |
47 |
| - ECSACT_EVENT_INIT_COMPONENT, |
48 |
| - static_cast<ecsact_entity_id>(entity), |
49 |
| - static_cast<ecsact_component_id>(C::id), |
50 |
| - nullptr, |
51 |
| - target->init_callback_user_data |
52 |
| - ); |
53 |
| - } |
54 |
| - |
55 |
| - template<typename C> |
56 |
| - requires(!std::is_empty_v<C>) |
57 |
| - void invoke_update_callback(ecsact_entity_id entity, const C& component) { |
58 |
| - target->update_callback( |
59 |
| - ECSACT_EVENT_UPDATE_COMPONENT, |
60 |
| - static_cast<ecsact_entity_id>(entity), |
61 |
| - static_cast<ecsact_component_id>(C::id), |
62 |
| - static_cast<const void*>(&component), |
63 |
| - target->update_callback_user_data |
64 |
| - ); |
65 |
| - } |
66 |
| - |
67 |
| - template<typename C> |
68 |
| - requires(std::is_empty_v<C>) |
69 |
| - void invoke_update_callback(ecsact_entity_id entity) { |
70 |
| - target->update_callback( |
71 |
| - ECSACT_EVENT_UPDATE_COMPONENT, |
72 |
| - static_cast<ecsact_entity_id>(entity), |
73 |
| - static_cast<ecsact_component_id>(C::id), |
74 |
| - nullptr, |
75 |
| - target->update_callback_user_data |
76 |
| - ); |
77 |
| - } |
78 |
| - |
79 |
| - template<typename C> |
80 |
| - requires(!std::is_empty_v<C>) |
81 |
| - void invoke_remove_callback(ecsact_entity_id entity, const C& component) { |
82 |
| - target->remove_callback( |
83 |
| - ECSACT_EVENT_REMOVE_COMPONENT, |
84 |
| - static_cast<ecsact_entity_id>(entity), |
85 |
| - static_cast<ecsact_component_id>(C::id), |
86 |
| - static_cast<const void*>(&component), |
87 |
| - target->remove_callback_user_data |
88 |
| - ); |
89 |
| - } |
90 |
| - |
91 |
| - template<typename C> |
92 |
| - requires(std::is_empty_v<C>) |
93 |
| - void invoke_remove_callback(ecsact_entity_id entity) { |
94 |
| - target->remove_callback( |
95 |
| - ECSACT_EVENT_REMOVE_COMPONENT, |
96 |
| - static_cast<ecsact_entity_id>(entity), |
97 |
| - static_cast<ecsact_component_id>(C::id), |
98 |
| - nullptr, |
99 |
| - target->remove_callback_user_data |
100 |
| - ); |
101 |
| - } |
102 |
| - |
103 |
| - void invoke_entity_created_callback( |
104 |
| - ecsact_entity_id entity, |
105 |
| - ecsact_placeholder_entity_id placeholder_entity_id |
106 |
| - ) { |
107 |
| - target->entity_created_callback( |
108 |
| - ECSACT_EVENT_CREATE_ENTITY, |
109 |
| - entity, |
110 |
| - placeholder_entity_id, |
111 |
| - target->entity_created_callback_user_data |
112 |
| - ); |
113 |
| - } |
114 |
| - |
115 |
| - void invoke_entity_destroyed_callback(ecsact_entity_id entity) { |
116 |
| - target->entity_destroyed_callback( |
117 |
| - ECSACT_EVENT_DESTROY_ENTITY, |
118 |
| - entity, |
119 |
| - // This value doesn't matter for the destroy callback |
120 |
| - static_cast<ecsact_placeholder_entity_id>(entity), |
121 |
| - target->entity_destroyed_callback_user_data |
122 |
| - ); |
123 |
| - } |
124 |
| -}; |
125 |
| - |
126 |
| -} // namespace ecsact::entt::detail |
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <type_traits> |
| 4 | +#include "ecsact/runtime/core.h" |
| 5 | + |
| 6 | +namespace ecsact::entt::detail { |
| 7 | + |
| 8 | +struct execution_events_collector { |
| 9 | + const ecsact_execution_events_collector* target; |
| 10 | + |
| 11 | + inline bool has_init_callback() const { |
| 12 | + return target->init_callback != nullptr; |
| 13 | + } |
| 14 | + |
| 15 | + inline bool has_update_callback() const { |
| 16 | + return target->update_callback != nullptr; |
| 17 | + } |
| 18 | + |
| 19 | + inline bool has_remove_callback() const { |
| 20 | + return target->remove_callback != nullptr; |
| 21 | + } |
| 22 | + |
| 23 | + inline bool has_entity_created_callback() const { |
| 24 | + return target->entity_created_callback != nullptr; |
| 25 | + } |
| 26 | + |
| 27 | + inline bool has_entity_destroyed_callback() const { |
| 28 | + return target->entity_destroyed_callback != nullptr; |
| 29 | + } |
| 30 | + |
| 31 | + template<typename C> |
| 32 | + requires(!std::is_empty_v<C>) |
| 33 | + void invoke_init_callback(ecsact_entity_id entity, const C& component) { |
| 34 | + target->init_callback( |
| 35 | + ECSACT_EVENT_INIT_COMPONENT, |
| 36 | + static_cast<ecsact_entity_id>(entity), |
| 37 | + static_cast<ecsact_component_id>(C::id), |
| 38 | + static_cast<const void*>(&component), |
| 39 | + target->init_callback_user_data |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + template<typename C> |
| 44 | + requires(std::is_empty_v<C>) |
| 45 | + void invoke_init_callback(ecsact_entity_id entity) { |
| 46 | + target->init_callback( |
| 47 | + ECSACT_EVENT_INIT_COMPONENT, |
| 48 | + static_cast<ecsact_entity_id>(entity), |
| 49 | + static_cast<ecsact_component_id>(C::id), |
| 50 | + nullptr, |
| 51 | + target->init_callback_user_data |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + template<typename C> |
| 56 | + requires(!std::is_empty_v<C>) |
| 57 | + void invoke_update_callback(ecsact_entity_id entity, const C& component) { |
| 58 | + target->update_callback( |
| 59 | + ECSACT_EVENT_UPDATE_COMPONENT, |
| 60 | + static_cast<ecsact_entity_id>(entity), |
| 61 | + static_cast<ecsact_component_id>(C::id), |
| 62 | + static_cast<const void*>(&component), |
| 63 | + target->update_callback_user_data |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + template<typename C> |
| 68 | + requires(std::is_empty_v<C>) |
| 69 | + void invoke_update_callback(ecsact_entity_id entity) { |
| 70 | + target->update_callback( |
| 71 | + ECSACT_EVENT_UPDATE_COMPONENT, |
| 72 | + static_cast<ecsact_entity_id>(entity), |
| 73 | + static_cast<ecsact_component_id>(C::id), |
| 74 | + nullptr, |
| 75 | + target->update_callback_user_data |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + template<typename C> |
| 80 | + requires(!std::is_empty_v<C>) |
| 81 | + void invoke_remove_callback(ecsact_entity_id entity, const C& component) { |
| 82 | + target->remove_callback( |
| 83 | + ECSACT_EVENT_REMOVE_COMPONENT, |
| 84 | + static_cast<ecsact_entity_id>(entity), |
| 85 | + static_cast<ecsact_component_id>(C::id), |
| 86 | + static_cast<const void*>(&component), |
| 87 | + target->remove_callback_user_data |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + template<typename C> |
| 92 | + requires(std::is_empty_v<C>) |
| 93 | + void invoke_remove_callback(ecsact_entity_id entity) { |
| 94 | + target->remove_callback( |
| 95 | + ECSACT_EVENT_REMOVE_COMPONENT, |
| 96 | + static_cast<ecsact_entity_id>(entity), |
| 97 | + static_cast<ecsact_component_id>(C::id), |
| 98 | + nullptr, |
| 99 | + target->remove_callback_user_data |
| 100 | + ); |
| 101 | + } |
| 102 | + |
| 103 | + void invoke_entity_created_callback( |
| 104 | + ecsact_entity_id entity, |
| 105 | + ecsact_placeholder_entity_id placeholder_entity_id |
| 106 | + ) { |
| 107 | + target->entity_created_callback( |
| 108 | + ECSACT_EVENT_CREATE_ENTITY, |
| 109 | + entity, |
| 110 | + placeholder_entity_id, |
| 111 | + target->entity_created_callback_user_data |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + void invoke_entity_destroyed_callback(ecsact_entity_id entity) { |
| 116 | + target->entity_destroyed_callback( |
| 117 | + ECSACT_EVENT_DESTROY_ENTITY, |
| 118 | + entity, |
| 119 | + // This value doesn't matter for the destroy callback |
| 120 | + static_cast<ecsact_placeholder_entity_id>(entity), |
| 121 | + target->entity_destroyed_callback_user_data |
| 122 | + ); |
| 123 | + } |
| 124 | +}; |
| 125 | + |
| 126 | +} // namespace ecsact::entt::detail |
0 commit comments