146 ComponentArray componentArray = {};
148 ComponentBitSet componentBitSet;
149 GroupBitSet groupBitSet;
152 std::optional<ComponentArray> nodeComponentArray;
153 std::optional<ComponentBitSet> nodeComponentBitSet;
157 std::unordered_map<std::string,EmptyEntity*> children;
159 void setId(
unsigned int m_id) {
id = m_id; }
160 unsigned int getId() {
return id; }
174 std::vector<std::unique_ptr<BaseComponent>> components;
179 virtual void update(
float deltaTime)
182 for (
auto& c : components) {
183 c->update(deltaTime);
187 virtual void cellUpdate() {};
189 virtual Cell* getOwnerCell()
const {
return nullptr; };
193 for (
auto& c : components) {
194 c->draw(e_index, batch, window);
199 for (
auto& c : components) {
200 c->draw(e_index, batch, window);
205 for (
auto& c : components) {
206 c->draw(e_index, batch, window);
211 for (
auto& c : components) {
212 c->draw(e_index, batch, window);
215 bool isActive() {
return active; }
216 virtual void destroy() { active =
false;
219 bool hasGroup(Group mGroup)
221 return groupBitSet[mGroup];
224 virtual void addGroup(Group mGroup);
225 void removeGroup(Group mGroup);
227 template <
typename T>
bool hasComponent()
const
229 if constexpr (std::is_base_of_v<LinkComponent, T>) {
230 return this && componentBitSet[GetLinkComponentTypeID<T>()];
232 else if constexpr (std::is_base_of_v<NodeComponent, T>) {
233 return this && nodeComponentBitSet.has_value() && (*nodeComponentBitSet)[GetNodeComponentTypeID<T>()];
235 return this && componentBitSet[GetComponentTypeID<T>()];
238 template <
typename T,
typename... TArgs>
241 T* c(
new T(std::forward<TArgs>(mArgs)...));
242 if constexpr (std::is_base_of_v<LinkComponent, T>) {
243 std::unique_ptr<LinkComponent> uPtr{ c };
244 components.emplace_back(std::move(uPtr));
246 setComponentEntity(c);
247 componentArray[GetLinkComponentTypeID<T>()] = c;
248 componentBitSet[GetLinkComponentTypeID<T>()] =
true;
250 c->id = GetLinkComponentTypeID<T>();
255 else if constexpr (std::is_base_of_v<NodeComponent, T>) {
256 std::unique_ptr<NodeComponent> uPtr{ c };
257 components.emplace_back(std::move(uPtr));
259 setComponentEntity(c);
260 (*nodeComponentArray)[GetNodeComponentTypeID<T>()] = c;
261 (*nodeComponentBitSet)[GetNodeComponentTypeID<T>()] =
true;
263 c->id = GetNodeComponentTypeID<T>();
269 std::unique_ptr<Component> uPtr{ c };
270 components.emplace_back(std::move(uPtr));
272 setComponentEntity(c);
273 componentArray[GetComponentTypeID<T>()] = c;
274 componentBitSet[GetComponentTypeID<T>()] =
true;
276 c->id = GetComponentTypeID<T>();
285 template <
typename T>
286 void removeComponent()
288 if constexpr (std::is_base_of_v<LinkComponent, T>)
290 size_t id = GetLinkComponentTypeID<T>();
291 auto it = std::remove_if(components.begin(), components.end(),
292 [
id](
const std::unique_ptr<BaseComponent>& comp) {
293 return typeid(*comp).hash_code() == typeid(T).hash_code();
296 if (it != components.end())
298 components.erase(it, components.end());
299 componentArray[id] =
nullptr;
300 componentBitSet[id] =
false;
303 else if constexpr (std::is_base_of_v<NodeComponent, T>)
305 size_t id = GetNodeComponentTypeID<T>();
306 auto it = std::remove_if(components.begin(), components.end(),
307 [
id](
const std::unique_ptr<BaseComponent>& comp) {
308 return typeid(*comp).hash_code() == typeid(T).hash_code();
311 if (it != components.end())
313 components.erase(it, components.end());
314 (*nodeComponentArray)[id] =
nullptr;
315 (*nodeComponentBitSet)[id] =
false;
320 size_t id = GetComponentTypeID<T>();
321 auto it = std::remove_if(components.begin(), components.end(),
322 [
id](
const std::unique_ptr<BaseComponent>& comp) {
323 return typeid(*comp).hash_code() == typeid(T).hash_code();
326 if (it != components.end())
328 components.erase(it, components.end());
329 componentArray[id] =
nullptr;
330 componentBitSet[id] =
false;
335 virtual void setComponentEntity(
Component* c) {
345 template<
typename T> T& GetComponent()
const
347 if constexpr (std::is_base_of_v<LinkComponent, T>) {
348 auto ptr(componentArray[GetLinkComponentTypeID<T>()]);
349 return *
static_cast<T*
>(ptr);
351 else if constexpr (std::is_base_of_v<NodeComponent, T>) {
352 auto ptr((*nodeComponentArray)[GetNodeComponentTypeID<T>()]);
353 return *
static_cast<T*
>(ptr);
356 auto ptr(componentArray[GetComponentTypeID<T>()]);
357 return *
static_cast<T*
>(ptr);
361 bool hasComponentByName(
const std::string& componentName) {
362 for (
auto& component : components) {
364 component->GetComponentName() == componentName) {
378 virtual void addMessage(std::string mMessage) {}
381 virtual Entity* getParentEntity() {
385 virtual void setParentEntity(
Entity* pEntity) {}
387 virtual void imgui_print() {}
389 virtual void imgui_display() {}
391 virtual void removeEntity() {}