From 9c93828976e37cf1bfcb916e5e0df34f9bc116d7 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 3 Jun 2023 11:51:24 -0400 Subject: [PATCH 1/3] add search actor by parent tag --- Source/Engine/Level/Level.cpp | 46 ++++++++++++++++++++++++++++++++++- Source/Engine/Level/Level.h | 3 +++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index 4fa37c80d..b1c5ede2b 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -783,6 +783,20 @@ void FindActorsRecursive(Actor* node, const Tag& tag, Array& result) FindActorsRecursive(child, tag, result); } +void FindActorsRecursiveByParentTags(Actor* node, const Array& tags, Array& result) +{ + for (Tag tag : tags) + { + if (node->HasTag(tag)) { + result.Add(node); + break; + } + } + + for (Actor* child : node->Children) + FindActorsRecursiveByParentTags(child, tags, result); +} + Actor* Level::FindActor(const Tag& tag, Actor* root) { PROFILE_CPU(); @@ -822,6 +836,36 @@ Array Level::FindActors(const Tag& tag, Actor* root) return result; } +API_FUNCTION()Array Level::FindActorsByParentTag(const Tag& parentTag, Actor* root) +{ + PROFILE_CPU(); + Array result; + const Array subTags = Tags::GetSubTags(parentTag); + + if (subTags.Count() == 0) + { + return result; + } + + if (subTags.Count() == 1) + { + result = FindActors(subTags[0], root); + return result; + } + + if (root) + { + FindActorsRecursiveByParentTags(root, subTags, result); + } + else + { + for (Scene* scene : Scenes) + FindActorsRecursiveByParentTags(scene, subTags, result); + } + + return result; +} + void Level::callActorEvent(ActorEventType eventType, Actor* a, Actor* b) { PROFILE_CPU(); @@ -1301,7 +1345,7 @@ bool Level::SaveSceneToBytes(Scene* scene, rapidjson_flax::StringBuffer& outData } // Info - LOG(Info, "Scene saved! Time {0} ms", Math::CeilToInt(static_cast((DateTime::NowUTC()- startTime).GetTotalMilliseconds()))); + LOG(Info, "Scene saved! Time {0} ms", Math::CeilToInt(static_cast((DateTime::NowUTC() - startTime).GetTotalMilliseconds()))); // Fire event CallSceneEvent(SceneEventType::OnSceneSaved, scene, scene->GetID()); diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index ed2efe485..20c2f8e90 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -397,6 +397,7 @@ public: /// Found actors list. API_FUNCTION() static Array GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type); + /// /// Finds all the scripts of the given type in all the loaded scenes. /// @@ -479,6 +480,8 @@ public: /// Found actors or empty if none. API_FUNCTION() static Array FindActors(const Tag& tag, Actor* root = nullptr); + API_FUNCTION() static Array FindActorsByParentTag(const Tag& tag, Actor* root = nullptr); + private: // Actor API enum class ActorEventType From 88a5e07f2e5a1374c3b4213017dd9a68640e2e2a Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 3 Jun 2023 11:59:18 -0400 Subject: [PATCH 2/3] add docs --- Source/Engine/Level/Level.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index 20c2f8e90..e578d8090 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -465,22 +465,28 @@ public: public: /// - /// Tries to find the actor with the given tag (returns the first one found). + /// Tries to find the actor with the given parentTag (returns the first one found). /// - /// The tag of the actor to search for. + /// The parentTag of the actor to search for. /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. /// Found actor or null. API_FUNCTION() static Actor* FindActor(const Tag& tag, Actor* root = nullptr); /// - /// Tries to find the actors with the given tag (returns all found). + /// Tries to find the actors with the given parentTag (returns all found). /// - /// The tag of the actor to search for. + /// The parentTag of the actor to search for. /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. /// Found actors or empty if none. API_FUNCTION() static Array FindActors(const Tag& tag, Actor* root = nullptr); - API_FUNCTION() static Array FindActorsByParentTag(const Tag& tag, Actor* root = nullptr); + /// + /// Search actors using a parent parentTag. + /// + /// The tag to search actors with subtags belonging to this tag + /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. + /// Returns all actors that have subtags belonging to the given parent parentTag + API_FUNCTION() static Array FindActorsByParentTag(const Tag& parentTag, Actor* root = nullptr); private: // Actor API From 50639e2378b2614169f6f7c259f55ea86c8b317c Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 3 Jun 2023 12:03:21 -0400 Subject: [PATCH 3/3] fix doc --- Source/Engine/Level/Level.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index e578d8090..203930bac 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -465,17 +465,17 @@ public: public: /// - /// Tries to find the actor with the given parentTag (returns the first one found). + /// Tries to find the actor with the given tag (returns the first one found). /// - /// The parentTag of the actor to search for. + /// The tag of the actor to search for. /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. /// Found actor or null. API_FUNCTION() static Actor* FindActor(const Tag& tag, Actor* root = nullptr); /// - /// Tries to find the actors with the given parentTag (returns all found). + /// Tries to find the actors with the given tag (returns all found). /// - /// The parentTag of the actor to search for. + /// The tag of the actor to search for. /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. /// Found actors or empty if none. API_FUNCTION() static Array FindActors(const Tag& tag, Actor* root = nullptr);