158 ComponentArray componentArray = {};
160 ComponentBitSet componentBitSet;
161 GroupBitSet groupBitSet;
164 std::optional<ComponentArray> nodeComponentArray;
165 std::optional<ComponentBitSet> nodeComponentBitSet;
169 std::vector<EmptyEntity*> children;
171 void setId(
unsigned int m_id) {
id = m_id; }
172 unsigned int getId() {
return id; }
186 std::vector<std::unique_ptr<BaseComponent>> components;
191 virtual void update(
float deltaTime)
194 for (
auto& c : components) {
195 c->update(deltaTime);
199 virtual void cellUpdate() {};
201 virtual Cell* getOwnerCell()
const {
return nullptr; };
205 for (
auto& c : components) {
206 c->draw(e_index, batch, window);
211 for (
auto& c : components) {
212 c->draw(e_index, batch, window);
217 for (
auto& c : components) {
218 c->draw(e_index, batch, window);
223 for (
auto& c : components) {
224 c->draw(e_index, batch, window);
227 bool isActive() {
return active; }
228 virtual void destroy() { active =
false;
231 bool hasGroup(Group mGroup)
233 return groupBitSet[mGroup];
236 virtual void addGroup(Group mGroup);
237 void removeGroup(Group mGroup);
239 template <
typename T>
bool hasComponent()
const
241 if constexpr (std::is_base_of_v<LinkComponent, T>) {
242 return this && componentBitSet[GetLinkComponentTypeID<T>()];
244 else if constexpr (std::is_base_of_v<NodeComponent, T>) {
245 return this && nodeComponentBitSet.has_value() && (*nodeComponentBitSet)[GetNodeComponentTypeID<T>()];
247 return this && componentBitSet[GetComponentTypeID<T>()];
250 template <
typename T,
typename... TArgs>
253 T* c(
new T(std::forward<TArgs>(mArgs)...));
254 if constexpr (std::is_base_of_v<LinkComponent, T>) {
255 std::unique_ptr<LinkComponent> uPtr{ c };
256 components.emplace_back(std::move(uPtr));
258 setComponentEntity(c);
259 componentArray[GetLinkComponentTypeID<T>()] = c;
260 componentBitSet[GetLinkComponentTypeID<T>()] =
true;
262 c->id = GetLinkComponentTypeID<T>();
267 else if constexpr (std::is_base_of_v<NodeComponent, T>) {
268 std::unique_ptr<NodeComponent> uPtr{ c };
269 components.emplace_back(std::move(uPtr));
271 setComponentEntity(c);
272 (*nodeComponentArray)[GetNodeComponentTypeID<T>()] = c;
273 (*nodeComponentBitSet)[GetNodeComponentTypeID<T>()] =
true;
275 c->id = GetNodeComponentTypeID<T>();
281 std::unique_ptr<Component> uPtr{ c };
282 components.emplace_back(std::move(uPtr));
284 setComponentEntity(c);
285 componentArray[GetComponentTypeID<T>()] = c;
286 componentBitSet[GetComponentTypeID<T>()] =
true;
288 c->id = GetComponentTypeID<T>();
297 template <
typename T>
298 void removeComponent()
300 if constexpr (std::is_base_of_v<LinkComponent, T>)
302 size_t id = GetLinkComponentTypeID<T>();
303 auto it = std::remove_if(components.begin(), components.end(),
304 [
id](
const std::unique_ptr<BaseComponent>& comp) {
305 return typeid(*comp).hash_code() == typeid(T).hash_code();
308 if (it != components.end())
310 components.erase(it, components.end());
311 componentArray[id] =
nullptr;
312 componentBitSet[id] =
false;
315 else if constexpr (std::is_base_of_v<NodeComponent, T>)
317 size_t id = GetNodeComponentTypeID<T>();
318 auto it = std::remove_if(components.begin(), components.end(),
319 [
id](
const std::unique_ptr<BaseComponent>& comp) {
320 return typeid(*comp).hash_code() == typeid(T).hash_code();
323 if (it != components.end())
325 components.erase(it, components.end());
326 (*nodeComponentArray)[id] =
nullptr;
327 (*nodeComponentBitSet)[id] =
false;
332 size_t id = GetComponentTypeID<T>();
333 auto it = std::remove_if(components.begin(), components.end(),
334 [
id](
const std::unique_ptr<BaseComponent>& comp) {
335 return typeid(*comp).hash_code() == typeid(T).hash_code();
338 if (it != components.end())
340 components.erase(it, components.end());
341 componentArray[id] =
nullptr;
342 componentBitSet[id] =
false;
347 virtual void setComponentEntity(
Component* c) {
357 template<
typename T> T& GetComponent()
const
359 if constexpr (std::is_base_of_v<LinkComponent, T>) {
360 auto ptr(componentArray[GetLinkComponentTypeID<T>()]);
361 return *
static_cast<T*
>(ptr);
363 else if constexpr (std::is_base_of_v<NodeComponent, T>) {
364 auto ptr((*nodeComponentArray)[GetNodeComponentTypeID<T>()]);
365 return *
static_cast<T*
>(ptr);
368 auto ptr(componentArray[GetComponentTypeID<T>()]);
369 return *
static_cast<T*
>(ptr);
373 bool hasComponentByName(
const std::string& componentName) {
374 for (
auto& component : components) {
376 component->GetComponentName() == componentName) {
390 virtual void addMessage(std::string mMessage) {}
393 virtual Entity* getParentEntity() {
397 virtual void setParentEntity(
Entity* pEntity) {}
399 virtual void imgui_print() {}
401 virtual void imgui_display() {}
403 virtual void removeEntity() {}