From 29e325efdcaae6a6653451c7773fed7d0f0f5704 Mon Sep 17 00:00:00 2001
From: D-AIRY <admin@ds-servers.com>
Date: Tue, 15 Dec 2020 22:37:49 +0300
Subject: [PATCH] Fixed parented entities handling in editor

---
 source/game/BaseEntity.cpp   | 14 +++++++++++++-
 source/game/EditorObject.cpp | 18 ++++++++++++++++++
 source/game/EditorObject.h   | 11 +++--------
 3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/source/game/BaseEntity.cpp b/source/game/BaseEntity.cpp
index 5bca9322a..65a8f2ac5 100644
--- a/source/game/BaseEntity.cpp
+++ b/source/game/BaseEntity.cpp
@@ -153,6 +153,12 @@ void CBaseEntity::getSphere(float3 * center, float * radius)
 
 void CBaseEntity::setPos(const float3 & pos)
 {
+	CBaseEntity *pParent = NULL;
+	if(m_pParent)
+	{
+		pParent = m_pParent;
+		setParent(NULL);
+	}
 	m_vPosition = pos;
 
 	if(m_pEditorRigidBody)
@@ -160,6 +166,11 @@ void CBaseEntity::setPos(const float3 & pos)
 		m_pEditorRigidBody->getWorldTransform().setOrigin(F3_BTVEC(m_vPosition));
 		SPhysics_GetDynWorld()->updateSingleAabb(m_pEditorRigidBody);
 	}
+
+	if(pParent)
+	{
+		setParent(pParent, m_iParentAttachment);
+	}
 }
 
 float3 CBaseEntity::getPos()
@@ -619,6 +630,8 @@ CBaseEntity* CBaseEntity::getParent()
 
 void CBaseEntity::onSync()
 {
+	m_bSynced = true;
+
 	if(m_pParent)
 	{
 		if(!m_pParent->m_bSynced)
@@ -647,7 +660,6 @@ void CBaseEntity::onSync()
 	//	m_vOrientation = m_pPhysObj->getOrient();
 	//}
 
-	m_bSynced = true;
 }
 
 void CBaseEntity::onPostLoad()
diff --git a/source/game/EditorObject.cpp b/source/game/EditorObject.cpp
index 9a71d4df8..9bb29d110 100644
--- a/source/game/EditorObject.cpp
+++ b/source/game/EditorObject.cpp
@@ -146,6 +146,24 @@ void XMETHODCALLTYPE CEditorObject::setOrient(const SMQuaternion &orient)
 	m_qRot = orient;
 }
 
+float3_t XMETHODCALLTYPE CEditorObject::getPos()
+{
+	if(m_pEntity)
+	{
+		m_vPos = m_pEntity->getPos();
+	}
+	return(m_vPos);
+}
+
+SMQuaternion XMETHODCALLTYPE CEditorObject::getOrient()
+{
+	if(m_pEntity)
+	{
+		m_qRot = m_pEntity->getOrient();
+	}
+	return(m_qRot);
+}
+
 void XMETHODCALLTYPE CEditorObject::getBound(float3 *pvMin, float3 *pvMax)
 {
 	*pvMin = *pvMax = float3();
diff --git a/source/game/EditorObject.h b/source/game/EditorObject.h
index dea578214..e9bab6d37 100644
--- a/source/game/EditorObject.h
+++ b/source/game/EditorObject.h
@@ -42,15 +42,10 @@ public:
 
 
 
-	float3_t XMETHODCALLTYPE getPos() override
-	{
-		return(m_vPos);
-	}
+	float3_t XMETHODCALLTYPE getPos() override;
+
+	SMQuaternion XMETHODCALLTYPE getOrient() override;
 
-	SMQuaternion XMETHODCALLTYPE getOrient() override
-	{
-		return(m_qRot);
-	}
 	float3_t XMETHODCALLTYPE getScale() override
 	{
 		return(m_vScale);
-- 
GitLab