HatchitGame
ht_component.h
1 
25 #pragma once
26 
27 #include <cstdint>
28 #include <type_traits>
29 #include <ht_transform.h>
30 #include <ht_guid.h>
31 #include <ht_jsonhelper.h>
32 
33 
34 namespace Hatchit {
35 
36  namespace Game {
37 
38  class GameObject;
39 
40  using JSON = Core::JSON;
41 
42  class HT_API Component
43  {
44  public:
50  template <typename T>
51  static Core::Guid GetComponentId(void);
52 
53  Component(void) = default;
54  virtual ~Component(void) = default;
55  Component(const Component& rhs) = default;
56  Component(Component&& rhs) = default;
57  Component& operator=(const Component& rhs) = default;
58  Component& operator=(Component&& rhs) = default;
59 
60  virtual Core::JSON VSerialize(void) = 0;
61  virtual bool VDeserialize(const Core::JSON& jsonObject) = 0;
62 
63 
68  GameObject* GetOwner(void);
69 
74  bool GetEnabled(void);
75 
80  void SetEnabled(bool value);
81 
82 
86  virtual void VOnInit(void) = 0;
87 
92  virtual void VOnUpdate(void) = 0;
93 
94 
100  virtual void VOnDestroy(void) = 0;
101 
106  virtual Component* VClone(void) const = 0;
107 
108  virtual Core::Guid VGetComponentId(void) const = 0;
109 
114  void SetOwner(GameObject *owner);
115 
116  protected:
121  virtual void VOnEnabled(void) = 0;
122 
128  virtual void VOnDisabled(void) = 0;
129 
130  bool m_enabled{true};
132  };
133 
134  template <typename T>
135  Core::Guid Component::GetComponentId(void)
136  {
137  static_assert(std::is_base_of<Component, T>::value && !std::is_same<Component, T>::value, "Must be a sub-class of Hatchit::Game::Component!");
138  static Core::Guid id = Core::Guid();
139  return id;
140  }
141  }
142 }
Definition: ht_component.h:42
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_glfwkeyboard.h:21
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_gameobject.h:48
static Core::Guid GetComponentId(void)
Returns the unique id associated with a Component of type T.
Definition: ht_component.h:135
GameObject * m_owner
The GameObject to which this Component is attached.
Definition: ht_component.h:131