From 1c3d1b623db117631f93ce139759bd520fc71b94 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 25 Feb 2025 15:31:46 +0100 Subject: [PATCH] Optimize and cleanup some actor code --- Source/Engine/Level/Actor.cpp | 44 ++++++--------------- Source/Engine/Level/SceneObjectsFactory.cpp | 4 +- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index 1db13145d..a9e0ec9f2 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -99,7 +99,7 @@ void Actor::SetSceneInHierarchy(Scene* scene) for (int32 i = 0; i < Children.Count(); i++) { - Children[i]->SetSceneInHierarchy(scene); + Children.Get()[i]->SetSceneInHierarchy(scene); } } @@ -111,7 +111,7 @@ void Actor::OnEnableInHierarchy() for (int32 i = 0; i < Children.Count(); i++) { - Children[i]->OnEnableInHierarchy(); + Children.Get()[i]->OnEnableInHierarchy(); } } } @@ -122,7 +122,7 @@ void Actor::OnDisableInHierarchy() { for (int32 i = 0; i < Children.Count(); i++) { - Children[i]->OnDisableInHierarchy(); + Children.Get()[i]->OnDisableInHierarchy(); } OnDisable(); @@ -192,7 +192,7 @@ void Actor::OnDeleteObject() #endif for (int32 i = 0; i < Children.Count(); i++) { - auto e = Children[i]; + auto e = Children.Get()[i]; ASSERT(e->_parent == this); e->_parent = nullptr; e->DeleteObject(); @@ -208,7 +208,7 @@ void Actor::OnDeleteObject() #endif for (int32 i = 0; i < Scripts.Count(); i++) { - auto script = Scripts[i]; + auto script = Scripts.Get()[i]; ASSERT(script->_parent == this); if (script->_wasAwakeCalled) { @@ -370,8 +370,6 @@ void Actor::SetOrderInParent(int32 index) { if (!_parent) return; - - // Cache data auto& parentChildren = _parent->Children; const int32 currentIndex = parentChildren.Find(this); ASSERT(currentIndex != INVALID_INDEX); @@ -380,8 +378,6 @@ void Actor::SetOrderInParent(int32 index) if (currentIndex != index) { parentChildren.RemoveAtKeepOrder(currentIndex); - - // Check if index is invalid if (index < 0 || index >= parentChildren.Count()) { // Append at the end @@ -894,9 +890,7 @@ void Actor::BreakPrefabLink() void Actor::Initialize() { -#if ENABLE_ASSERTION - CHECK(!IsDuringPlay()); -#endif + CHECK_DEBUG(!IsDuringPlay()); // Cache if (_parent) @@ -910,9 +904,7 @@ void Actor::Initialize() void Actor::BeginPlay(SceneBeginData* data) { -#if ENABLE_ASSERTION - CHECK(!IsDuringPlay()); -#endif + CHECK_DEBUG(!IsDuringPlay()); // Set flag Flags |= ObjectFlags::IsDuringPlay; @@ -944,9 +936,7 @@ void Actor::BeginPlay(SceneBeginData* data) void Actor::EndPlay() { -#if ENABLE_ASSERTION - CHECK(IsDuringPlay()); -#endif + CHECK_DEBUG(IsDuringPlay()); // Fire event for scripting if (IsActiveInHierarchy() && GetScene()) @@ -1184,9 +1174,7 @@ void Actor::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) void Actor::OnEnable() { -#if ENABLE_ASSERTION - CHECK(!_isEnabled); -#endif + CHECK_DEBUG(!_isEnabled); _isEnabled = true; for (int32 i = 0; i < Scripts.Count(); i++) @@ -1206,9 +1194,7 @@ void Actor::OnEnable() void Actor::OnDisable() { -#if ENABLE_ASSERTION - CHECK(_isEnabled); -#endif + CHECK_DEBUG(_isEnabled); _isEnabled = false; for (int32 i = Scripts.Count() - 1; i >= 0; i--) @@ -1295,12 +1281,8 @@ void Actor::OnLayerChanged() BoundingBox Actor::GetBoxWithChildren() const { BoundingBox result = GetBox(); - for (int32 i = 0; i < Children.Count(); i++) - { - BoundingBox::Merge(result, Children[i]->GetBoxWithChildren(), result); - } - + BoundingBox::Merge(result, Children.Get()[i]->GetBoxWithChildren(), result); return result; } @@ -1315,9 +1297,7 @@ BoundingBox Actor::GetEditorBoxChildren() const { BoundingBox result = GetEditorBox(); for (int32 i = 0; i < Children.Count(); i++) - { - BoundingBox::Merge(result, Children[i]->GetEditorBoxChildren(), result); - } + BoundingBox::Merge(result, Children.Get()[i]->GetEditorBoxChildren(), result); return result; } diff --git a/Source/Engine/Level/SceneObjectsFactory.cpp b/Source/Engine/Level/SceneObjectsFactory.cpp index 520154b28..a53911361 100644 --- a/Source/Engine/Level/SceneObjectsFactory.cpp +++ b/Source/Engine/Level/SceneObjectsFactory.cpp @@ -244,9 +244,7 @@ SceneObject* SceneObjectsFactory::Spawn(Context& context, const ISerializable::D void SceneObjectsFactory::Deserialize(Context& context, SceneObject* obj, ISerializable::DeserializeStream& stream) { -#if ENABLE_ASSERTION - CHECK(obj); -#endif + CHECK_DEBUG(obj); ISerializeModifier* modifier = context.GetModifier(); LogContextScope logContext(obj->GetID());