ECSTASY
All in the name
Loading...
Searching...
No Matches
PollActions.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_INTEGRATIONS_USER_ACTION_POLLACTIONS_HPP_
13#define ECSTASY_INTEGRATIONS_USER_ACTION_POLLACTIONS_HPP_
14
15#include <utility>
16#include "Action.hpp"
17#include "ActionListener.hpp"
18#include "PendingActions.hpp"
21
23{
32 template <typename Actions>
34
43 template <Action::Id... Actions>
44 class PollActions<std::integer_sequence<Action::Id, Actions...>> : public ecstasy::ISystem {
45 public:
47 void run(Registry &registry) override final
48 {
49 if (!registry.hasResource<PendingActions>()) [[unlikely]]
50 return;
51 RR<PendingActions> pendingActions = registry.getResource<PendingActions>();
52 while (!pendingActions.get()->empty()) {
53 std::ignore = std::make_tuple((callListeners<Actions>(registry, pendingActions.get()->front()), 0)...);
54 pendingActions.get()->pop();
55 }
56 }
57
58 private:
60 template <Action::Id A>
61 void callListeners(Registry &registry, Action action)
62 {
63 if (action.id != A && A != Action::All)
64 return;
65
66 for (auto [entity, listener] : registry.query<ecstasy::Entities, ActionIdListener<A>>())
67 listener.listener(registry, entity, action);
68 }
69 };
70} // namespace ecstasy::integration::user_action
71
72#endif /* !ECSTASY_INTEGRATIONS_USER_ACTION_POLLACTIONS_HPP_ */
System interface, base class of all systems.
Registry class definition.
Resource holding all the Registry entities.
Definition Entities.hpp:30
System interface, base class of all systems.
Definition ISystem.hpp:28
Basic object wrapper as a resource.
Base of an ECS architecture.
Definition Registry.hpp:82
RegistrySelectStackQuery< thread::AUTO_LOCK_DEFAULT, queryable_type_t< C >, queryable_type_t< Cs >... > query()
Construct a query for the given components.
Primary template of PollActions to unpack the action parameter pack.
T make_tuple(T... args)
User action integration.
Definition Action.hpp:18
ResourceReference< R, AutoLock > RR
ResourceReference alias
Definition Registry.hpp:66
Describe an action changed event.
Definition Action.hpp:25
static constexpr Id All
Constant id matching any action ID.
Definition Action.hpp:30
size_t Id
Action identifier type.
Definition Action.hpp:27
Action listener component templated with the target action id.