Thrive
component.h
1 
4 #pragma once
5 
6 #include "engine/typedefs.h"
7 
8 #include <memory>
9 #include <string>
10 #include <unordered_map>
11 
12 namespace luabind {
13 class scope;
14 }
15 
16 namespace thrive {
17 
18 class StorageContainer;
19 
31 class Component {
32 
33 public:
34 
46  static luabind::scope
47  luaBindings();
48 
52  virtual ~Component() = 0;
53 
59  bool
60  isVolatile() const;
61 
67  virtual void
68  load(
70  ) = 0;
71 
79  EntityId
80  owner() const {
81  return m_owner;
82  }
83 
91  void
93  bool isVolatile
94  );
95 
96 
104  void
106  EntityId owner
107  ) {
108  m_owner = owner;
109  }
110 
116  virtual StorageContainer
117  storage() const = 0;
118 
122  virtual ComponentTypeId
123  typeId() const = 0;
124 
128  virtual std::string
129  typeName() const = 0;
130 
131 protected:
132 
133 private:
134 
135  bool m_isVolatile = false;
136 
137  EntityId m_owner = NULL_ENTITY;
138 
139 };
140 
141 }
142 
169 #define COMPONENT(name) \
170  public: \
171  \
172  static const ComponentTypeId TYPE_ID; \
173  \
174  ComponentTypeId typeId() const override { \
175  return TYPE_ID; \
176  } \
177  \
178  static const std::string& TYPE_NAME() { \
179  static std::string string(#name); \
180  return string; \
181  } \
182  \
183  std::string typeName() const override { \
184  return TYPE_NAME(); \
185  } \
186  \
187  private: \
188 
189 
virtual ComponentTypeId typeId() const =0
The component's type id.
virtual std::string typeName() const =0
The component's type name.
static luabind::scope luaBindings()
Lua bindings.
Definition: component.cpp:87
Base class for components.
Definition: component.h:31
EntityId owner() const
The entity this component belongs to.
Definition: component.h:80
Definition: bullet_to_ogre_system.h:5
Definition: bullet_ogre_conversion.h:6
virtual StorageContainer storage() const =0
Serializes the component.
Definition: component.cpp:127
void setOwner(EntityId owner)
Sets the component's owner.
Definition: component.h:105
virtual void load(const StorageContainer &storage)=0
Loads the component.
Definition: component.cpp:111
virtual ~Component()=0
Destructor.
Definition: component.cpp:101
bool isVolatile() const
A volatile component is not serialized during a save.
Definition: component.cpp:105
A key-value storage for serialization.
Definition: serialization.h:36
void setVolatile(bool isVolatile)
Sets the volatile flag.
Definition: component.cpp:119