Added support for script instance copy/paste in the World Editor

This commit is contained in:
parax0
2016-03-20 06:31:23 -06:00
parent d961545309
commit 5009c08c87
21 changed files with 463 additions and 46 deletions

View File

@@ -64,5 +64,6 @@ SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& ViewInfo)
}
}
if (Result.Hit) Result.HitPoint = mRay.PointOnRay(Result.Distance);
return Result;
}

View File

@@ -127,6 +127,22 @@ CScriptObject* CGameArea::InstanceByID(u32 InstanceID)
else return nullptr;
}
u32 CGameArea::FindUnusedInstanceID(CScriptLayer *pLayer) const
{
u32 InstanceID = (pLayer->AreaIndex() << 26) | (mWorldIndex << 16) | 1;
while (true)
{
auto it = mObjectMap.find(InstanceID);
if (it == mObjectMap.end())
break;
else
InstanceID++;
}
return InstanceID;
}
CScriptObject* CGameArea::SpawnInstance(CScriptTemplate *pTemplate,
CScriptLayer *pLayer,
@@ -167,17 +183,7 @@ CScriptObject* CGameArea::SpawnInstance(CScriptTemplate *pTemplate,
}
// Look for a valid instance ID
InstanceID = (LayerIndex << 26) | (mWorldIndex << 16) | 1;
while (true)
{
auto it = mObjectMap.find(InstanceID);
if (it == mObjectMap.end())
break;
else
InstanceID++;
}
InstanceID = FindUnusedInstanceID(pLayer);
}
// Spawn instance

View File

@@ -69,6 +69,7 @@ public:
void ClearScriptLayers();
u32 TotalInstanceCount() const;
CScriptObject* InstanceByID(u32 InstanceID);
u32 FindUnusedInstanceID(CScriptLayer *pLayer) const;
CScriptObject* SpawnInstance(CScriptTemplate *pTemplate, CScriptLayer *pLayer,
const CVector3f& rkPosition = CVector3f::skZero,
const CQuaternion& rkRotation = CQuaternion::skIdentity,

View File

@@ -215,6 +215,7 @@ CScriptObject* CScriptLoader::LoadObjectMP1(IInputStream& rSCLY)
}
u32 InstanceID = rSCLY.ReadLong();
if (InstanceID == -1) InstanceID = mpArea->FindUnusedInstanceID(mpLayer);
mpObj = new CScriptObject(InstanceID, mpArea, mpLayer, pTemp);
// Load connections
@@ -328,6 +329,7 @@ CScriptObject* CScriptLoader::LoadObjectMP2(IInputStream& rSCLY)
}
u32 InstanceID = rSCLY.ReadLong();
if (InstanceID == -1) InstanceID = mpArea->FindUnusedInstanceID(mpLayer);
mpObj = new CScriptObject(InstanceID, mpArea, mpLayer, pTemplate);
// Load connections

View File

@@ -56,7 +56,7 @@ public:
CScriptObject *pNewSender = mpArea->InstanceByID(NewSenderID);
mSenderID = NewSenderID;
pOldSender->RemoveLink(eOutgoing, this);
if (pOldSender) pOldSender->RemoveLink(eOutgoing, this);
pNewSender->AddLink(eOutgoing, this, Index);
}
@@ -67,7 +67,7 @@ public:
CScriptObject *pNewReceiver = mpArea->InstanceByID(NewReceiverID);
mReceiverID = NewReceiverID;
pOldReceiver->RemoveLink(eIncoming, this);
if (pOldReceiver) pOldReceiver->RemoveLink(eIncoming, this);
pNewReceiver->AddLink(eIncoming, this, Index);
}