GameKit  0.0.1a
C++ gamedev tools
BehaviourComponent.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: BehaviourComponent.hpp
5  *
6  * Description:
7  *
8  * Created: 17/01/2018 19:45:23
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_BEHAVIOURCOMPONENT_HPP_
15 #define GK_BEHAVIOURCOMPONENT_HPP_
16 
17 #include <unordered_map>
18 
20 
21 namespace gk {
22 
24  public:
25  template<typename T, typename... Args>
26  T &addBehaviour(const char *name, Args &&...args) {
27  T *t = new T(std::forward<Args>(args)...);
28  m_behaviours.emplace(name, t);
29  return *t;
30  }
31 
32  void update(SceneObject &object) {
33  for (auto &it : m_behaviours) {
34  it.second->update(object);
35  }
36  }
37 
38  private:
39  std::unordered_map<std::string, std::unique_ptr<Behaviour>> m_behaviours;
40 };
41 
42 } // namespace gk
43 
44 #endif // GK_BEHAVIOURCOMPONENT_HPP_
T & addBehaviour(const char *name, Args &&...args)
void update(SceneObject &object)
std::unordered_map< std::string, std::unique_ptr< Behaviour > > m_behaviours