CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
ActionManager.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
11
12#include "Action.hpp"
13
15
18
19#include <type_traits>
20
21namespace CeresEngine {
22
24 using EntityActionID = unsigned int;
25
27 private:
30
31 public:
33
38
40
41 public:
49 template<CEntityAction Action, typename... Args>
50 [[nodiscard]] bool canAct(Entity entity, Args&&... args) noexcept(std::is_nothrow_constructible_v<Action, Args...>);
51
58 template<CEntityAction Action> [[nodiscard]] bool canAct(Entity entity, const Action& action) noexcept;
59
66 template<CEntityAction Action, typename... Args> typename Action::ReturnType act(Entity entity, Args&&... args);
67
73 template<CEntityAction Action> typename Action::ReturnType act(Entity entity, const Action& action);
74
75 public:
79 template<CEntityAction A> void add(EntityActionHandler<A>& actionHandler) { add(A::actionID, actionHandler); }
80
85 void add(EntityActionID actionID, AbstractActionHandler& actionHandler);
86
90 template<CEntityAction A> void remove(EntityActionHandler<A>& actionHandler) { remove(A::actionID, actionHandler); }
91
96 void remove(EntityActionID actionID, AbstractActionHandler& actionHandler);
97 };
98
99} // namespace CeresEngine
100
101#include "ActionManager.inl"
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Definition ActionHandler.hpp:17
Definition ActionHandler.hpp:23
Definition ActionManager.hpp:26
void remove(EntityActionID actionID, AbstractActionHandler &actionHandler)
Adds a new action handler.
Action::ReturnType act(Entity entity, const Action &action)
Dispatches an action to a handler.
EntityActionManager(const EntityActionManager &)=delete
bool canAct(Entity entity, const Action &action) noexcept
Checks if the action manager has an action handler that can handle the given action.
bool canAct(Entity entity, Args &&... args) noexcept(std::is_nothrow_constructible_v< Action, Args... >)
Checks if the action manager has an action handler that can handle the given action.
HashMap< EntityActionID, Vector< AbstractActionHandler * > > mActionHandlers
The map of action handlers.
Definition ActionManager.hpp:29
EntityActionManager(EntityActionManager &&)=delete
void add(EntityActionID actionID, AbstractActionHandler &actionHandler)
Adds a new action handler.
EntityActionManager & operator=(EntityActionManager &&)=delete
void add(EntityActionHandler< A > &actionHandler)
Adds a new action handler.
Definition ActionManager.hpp:79
EntityActionManager & operator=(const EntityActionManager &)=delete
Action::ReturnType act(Entity entity, Args &&... args)
Dispatches an action to a handler.
void remove(EntityActionHandler< A > &actionHandler)
Removes an existing action handler.
Definition ActionManager.hpp:90
The base entity class.
Definition Entity.hpp:41
Definition Action.hpp:69
Definition Application.hpp:19
unsigned int EntityActionID
A numeric type that represents a action.
Definition Action.hpp:19
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25