Optimize actor search

This commit is contained in:
Mr. Capybara
2023-10-22 13:26:07 -04:00
parent 6c45141ef9
commit fff8a1e8a6
5 changed files with 41 additions and 26 deletions

View File

@@ -1359,14 +1359,16 @@ Actor* Actor::FindActor(const StringView& name) const
return result;
}
Actor* Actor::FindActor(const MClass* type) const
Actor* Actor::FindActor(const MClass* type, bool activeOnly) const
{
CHECK_RETURN(type, nullptr);
if (activeOnly && !_isActive)
return nullptr;
if (GetClass()->IsSubClassOf(type))
return const_cast<Actor*>(this);
for (auto child : Children)
{
const auto actor = child->FindActor(type);
const auto actor = child->FindActor(type, activeOnly);
if (actor)
return actor;
}
@@ -1387,14 +1389,16 @@ Actor* Actor::FindActor(const MClass* type, const StringView& name) const
return nullptr;
}
Actor* Actor::FindActor(const MClass* type, const Tag& tag) const
Actor* Actor::FindActor(const MClass* type, const Tag& tag, bool activeOnly) const
{
CHECK_RETURN(type, nullptr);
if (activeOnly && !_isActive)
return nullptr;
if (GetClass()->IsSubClassOf(type) && HasTag(tag))
return const_cast<Actor*>(this);
for (auto child : Children)
{
const auto actor = child->FindActor(type, tag);
const auto actor = child->FindActor(type, tag, activeOnly);
if (actor)
return actor;
}