Добавил фильтрацию по типу в GetActorsByTag
This commit is contained in:
@@ -31,10 +31,10 @@ public:
|
|||||||
void load(std::shared_ptr<SaveMap> save) override;
|
void load(std::shared_ptr<SaveMap> save) override;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
template<class T, class Container = std::vector<std::weak_ptr<T>>>
|
template<class T, template<class...> class Container = std::vector>
|
||||||
Container GetActorsByClass()
|
Container<std::weak_ptr<T>> GetActorsByClass()
|
||||||
{
|
{
|
||||||
Container list;
|
Container<std::weak_ptr<T>> list;
|
||||||
for (auto i = actors_map.cbegin(); i != actors_map.cend(); ++i)
|
for (auto i = actors_map.cbegin(); i != actors_map.cend(); ++i)
|
||||||
{
|
{
|
||||||
if (RTTI::dyn_cast<T, Actor>(i->second.get()))
|
if (RTTI::dyn_cast<T, Actor>(i->second.get()))
|
||||||
@@ -57,12 +57,14 @@ public:
|
|||||||
|
|
||||||
void DestroyActor(std::weak_ptr<Actor> ptr);
|
void DestroyActor(std::weak_ptr<Actor> ptr);
|
||||||
|
|
||||||
template<class T, class Container = std::vector<std::weak_ptr<T>>>
|
template<class T, template<class...> class Container = std::vector>
|
||||||
Container GetActorsByTag(std::string tag)
|
Container<std::weak_ptr<T>> GetActorsByTag(std::string tag)
|
||||||
{
|
{
|
||||||
Container container;
|
Container<std::weak_ptr<T>> container;
|
||||||
|
|
||||||
for (auto& i : actors_map)
|
for (auto& i : actors_map)
|
||||||
|
{
|
||||||
|
if (RTTI::dyn_cast<T, Actor>(i.second.get()))
|
||||||
{
|
{
|
||||||
const std::list<std::string>& tags = i.second->GetTags();
|
const std::list<std::string>& tags = i.second->GetTags();
|
||||||
for (auto& j : tags)
|
for (auto& j : tags)
|
||||||
@@ -71,6 +73,7 @@ public:
|
|||||||
container.push_back(i.second);
|
container.push_back(i.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ R"(
|
|||||||
CoreInstance tmp_core;
|
CoreInstance tmp_core;
|
||||||
|
|
||||||
// Test find by class
|
// Test find by class
|
||||||
std::vector<std::weak_ptr<TestActor>> test_actors = tmp_core.GetGameInstance()->GetWorld()->GetActorsByClass<TestActor>();
|
std::list<std::weak_ptr<TestActor>> test_actors = tmp_core.GetGameInstance()->GetWorld()->GetActorsByClass<TestActor, std::list>();
|
||||||
ASSERT_EQ(test_actors.size(), 1);
|
ASSERT_EQ(test_actors.size(), 1);
|
||||||
|
|
||||||
// Test find by tag
|
// Test find by tag
|
||||||
|
|||||||
Reference in New Issue
Block a user