Browse Source

Improve entity weak_ptr expiration check

master
Riyyi 4 years ago
parent
commit
1580794521
  1. 3
      inferno/src/inferno/scene/entity.cpp
  2. 5
      inferno/src/inferno/scene/entity.h

3
inferno/src/inferno/scene/entity.cpp

@ -32,7 +32,8 @@ namespace Inferno {
void Entity::valid() const void Entity::valid() const
{ {
ASSERT(m_registry.lock()->valid(m_entity)); expired();
ASSERT(m_registry.lock()->valid(m_entity), "Entity is not valid");
} }
// ---------------------------------------- // ----------------------------------------

5
inferno/src/inferno/scene/entity.h

@ -23,7 +23,6 @@ namespace Inferno {
template<typename... T> template<typename... T>
[[nodiscard]] bool has() const [[nodiscard]] bool has() const
{ {
expired();
valid(); valid();
return m_registry.lock()->has<T...>(m_entity); return m_registry.lock()->has<T...>(m_entity);
} }
@ -31,7 +30,6 @@ namespace Inferno {
template<typename... T> template<typename... T>
[[nodiscard]] bool any() const [[nodiscard]] bool any() const
{ {
expired();
valid(); valid();
return m_registry.lock()->any<T...>(m_entity); return m_registry.lock()->any<T...>(m_entity);
} }
@ -39,7 +37,6 @@ namespace Inferno {
template<typename T, typename... P> template<typename T, typename... P>
T& add(P&&... parameters) const T& add(P&&... parameters) const
{ {
expired();
valid(); valid();
return m_registry.lock()->emplace_or_replace<T>(m_entity, std::forward<P>(parameters)...); return m_registry.lock()->emplace_or_replace<T>(m_entity, std::forward<P>(parameters)...);
}; };
@ -47,7 +44,6 @@ namespace Inferno {
template<typename T> template<typename T>
size_t remove() const size_t remove() const
{ {
expired();
valid(); valid();
return m_registry.lock()->remove_if_exists<T>(m_entity); return m_registry.lock()->remove_if_exists<T>(m_entity);
} }
@ -55,7 +51,6 @@ namespace Inferno {
template<typename T, typename... P> template<typename T, typename... P>
T& get(P&&... parameters) const T& get(P&&... parameters) const
{ {
expired();
valid(); valid();
return m_registry.lock()->get_or_emplace<T>(m_entity, std::forward<P>(parameters)...); return m_registry.lock()->get_or_emplace<T>(m_entity, std::forward<P>(parameters)...);
} }

Loading…
Cancel
Save