Optimize and cleanup some actor code
This commit is contained in:
@@ -99,7 +99,7 @@ void Actor::SetSceneInHierarchy(Scene* scene)
|
|||||||
|
|
||||||
for (int32 i = 0; i < Children.Count(); i++)
|
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++)
|
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++)
|
for (int32 i = 0; i < Children.Count(); i++)
|
||||||
{
|
{
|
||||||
Children[i]->OnDisableInHierarchy();
|
Children.Get()[i]->OnDisableInHierarchy();
|
||||||
}
|
}
|
||||||
|
|
||||||
OnDisable();
|
OnDisable();
|
||||||
@@ -192,7 +192,7 @@ void Actor::OnDeleteObject()
|
|||||||
#endif
|
#endif
|
||||||
for (int32 i = 0; i < Children.Count(); i++)
|
for (int32 i = 0; i < Children.Count(); i++)
|
||||||
{
|
{
|
||||||
auto e = Children[i];
|
auto e = Children.Get()[i];
|
||||||
ASSERT(e->_parent == this);
|
ASSERT(e->_parent == this);
|
||||||
e->_parent = nullptr;
|
e->_parent = nullptr;
|
||||||
e->DeleteObject();
|
e->DeleteObject();
|
||||||
@@ -208,7 +208,7 @@ void Actor::OnDeleteObject()
|
|||||||
#endif
|
#endif
|
||||||
for (int32 i = 0; i < Scripts.Count(); i++)
|
for (int32 i = 0; i < Scripts.Count(); i++)
|
||||||
{
|
{
|
||||||
auto script = Scripts[i];
|
auto script = Scripts.Get()[i];
|
||||||
ASSERT(script->_parent == this);
|
ASSERT(script->_parent == this);
|
||||||
if (script->_wasAwakeCalled)
|
if (script->_wasAwakeCalled)
|
||||||
{
|
{
|
||||||
@@ -370,8 +370,6 @@ void Actor::SetOrderInParent(int32 index)
|
|||||||
{
|
{
|
||||||
if (!_parent)
|
if (!_parent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Cache data
|
|
||||||
auto& parentChildren = _parent->Children;
|
auto& parentChildren = _parent->Children;
|
||||||
const int32 currentIndex = parentChildren.Find(this);
|
const int32 currentIndex = parentChildren.Find(this);
|
||||||
ASSERT(currentIndex != INVALID_INDEX);
|
ASSERT(currentIndex != INVALID_INDEX);
|
||||||
@@ -380,8 +378,6 @@ void Actor::SetOrderInParent(int32 index)
|
|||||||
if (currentIndex != index)
|
if (currentIndex != index)
|
||||||
{
|
{
|
||||||
parentChildren.RemoveAtKeepOrder(currentIndex);
|
parentChildren.RemoveAtKeepOrder(currentIndex);
|
||||||
|
|
||||||
// Check if index is invalid
|
|
||||||
if (index < 0 || index >= parentChildren.Count())
|
if (index < 0 || index >= parentChildren.Count())
|
||||||
{
|
{
|
||||||
// Append at the end
|
// Append at the end
|
||||||
@@ -894,9 +890,7 @@ void Actor::BreakPrefabLink()
|
|||||||
|
|
||||||
void Actor::Initialize()
|
void Actor::Initialize()
|
||||||
{
|
{
|
||||||
#if ENABLE_ASSERTION
|
CHECK_DEBUG(!IsDuringPlay());
|
||||||
CHECK(!IsDuringPlay());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
if (_parent)
|
if (_parent)
|
||||||
@@ -910,9 +904,7 @@ void Actor::Initialize()
|
|||||||
|
|
||||||
void Actor::BeginPlay(SceneBeginData* data)
|
void Actor::BeginPlay(SceneBeginData* data)
|
||||||
{
|
{
|
||||||
#if ENABLE_ASSERTION
|
CHECK_DEBUG(!IsDuringPlay());
|
||||||
CHECK(!IsDuringPlay());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set flag
|
// Set flag
|
||||||
Flags |= ObjectFlags::IsDuringPlay;
|
Flags |= ObjectFlags::IsDuringPlay;
|
||||||
@@ -944,9 +936,7 @@ void Actor::BeginPlay(SceneBeginData* data)
|
|||||||
|
|
||||||
void Actor::EndPlay()
|
void Actor::EndPlay()
|
||||||
{
|
{
|
||||||
#if ENABLE_ASSERTION
|
CHECK_DEBUG(IsDuringPlay());
|
||||||
CHECK(IsDuringPlay());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Fire event for scripting
|
// Fire event for scripting
|
||||||
if (IsActiveInHierarchy() && GetScene())
|
if (IsActiveInHierarchy() && GetScene())
|
||||||
@@ -1184,9 +1174,7 @@ void Actor::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
|
|||||||
|
|
||||||
void Actor::OnEnable()
|
void Actor::OnEnable()
|
||||||
{
|
{
|
||||||
#if ENABLE_ASSERTION
|
CHECK_DEBUG(!_isEnabled);
|
||||||
CHECK(!_isEnabled);
|
|
||||||
#endif
|
|
||||||
_isEnabled = true;
|
_isEnabled = true;
|
||||||
|
|
||||||
for (int32 i = 0; i < Scripts.Count(); i++)
|
for (int32 i = 0; i < Scripts.Count(); i++)
|
||||||
@@ -1206,9 +1194,7 @@ void Actor::OnEnable()
|
|||||||
|
|
||||||
void Actor::OnDisable()
|
void Actor::OnDisable()
|
||||||
{
|
{
|
||||||
#if ENABLE_ASSERTION
|
CHECK_DEBUG(_isEnabled);
|
||||||
CHECK(_isEnabled);
|
|
||||||
#endif
|
|
||||||
_isEnabled = false;
|
_isEnabled = false;
|
||||||
|
|
||||||
for (int32 i = Scripts.Count() - 1; i >= 0; i--)
|
for (int32 i = Scripts.Count() - 1; i >= 0; i--)
|
||||||
@@ -1295,12 +1281,8 @@ void Actor::OnLayerChanged()
|
|||||||
BoundingBox Actor::GetBoxWithChildren() const
|
BoundingBox Actor::GetBoxWithChildren() const
|
||||||
{
|
{
|
||||||
BoundingBox result = GetBox();
|
BoundingBox result = GetBox();
|
||||||
|
|
||||||
for (int32 i = 0; i < Children.Count(); i++)
|
for (int32 i = 0; i < Children.Count(); i++)
|
||||||
{
|
BoundingBox::Merge(result, Children.Get()[i]->GetBoxWithChildren(), result);
|
||||||
BoundingBox::Merge(result, Children[i]->GetBoxWithChildren(), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1315,9 +1297,7 @@ BoundingBox Actor::GetEditorBoxChildren() const
|
|||||||
{
|
{
|
||||||
BoundingBox result = GetEditorBox();
|
BoundingBox result = GetEditorBox();
|
||||||
for (int32 i = 0; i < Children.Count(); i++)
|
for (int32 i = 0; i < Children.Count(); i++)
|
||||||
{
|
BoundingBox::Merge(result, Children.Get()[i]->GetEditorBoxChildren(), result);
|
||||||
BoundingBox::Merge(result, Children[i]->GetEditorBoxChildren(), result);
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -244,9 +244,7 @@ SceneObject* SceneObjectsFactory::Spawn(Context& context, const ISerializable::D
|
|||||||
|
|
||||||
void SceneObjectsFactory::Deserialize(Context& context, SceneObject* obj, ISerializable::DeserializeStream& stream)
|
void SceneObjectsFactory::Deserialize(Context& context, SceneObject* obj, ISerializable::DeserializeStream& stream)
|
||||||
{
|
{
|
||||||
#if ENABLE_ASSERTION
|
CHECK_DEBUG(obj);
|
||||||
CHECK(obj);
|
|
||||||
#endif
|
|
||||||
ISerializeModifier* modifier = context.GetModifier();
|
ISerializeModifier* modifier = context.GetModifier();
|
||||||
LogContextScope logContext(obj->GetID());
|
LogContextScope logContext(obj->GetID());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user