Moved selection handling code to CNodeSelection, implemented instance spawning, half-implemented instance deleting (this build is buggy/crash prone)

This commit is contained in:
parax0
2016-03-13 22:30:04 -06:00
parent b2699eb96f
commit f02f7ada0f
64 changed files with 1259 additions and 754 deletions

View File

@@ -52,8 +52,8 @@ public:
void SetSender(u32 NewSenderID, u32 Index = -1)
{
u32 OldSenderID = mSenderID;
CScriptObject *pOldSender = mpArea->GetInstanceByID(OldSenderID);
CScriptObject *pNewSender = mpArea->GetInstanceByID(NewSenderID);
CScriptObject *pOldSender = mpArea->InstanceByID(OldSenderID);
CScriptObject *pNewSender = mpArea->InstanceByID(NewSenderID);
mSenderID = NewSenderID;
pOldSender->RemoveLink(eOutgoing, this);
@@ -63,8 +63,8 @@ public:
void SetReceiver(u32 NewReceiverID, u32 Index = -1)
{
u32 OldReceiverID = mSenderID;
CScriptObject *pOldReceiver = mpArea->GetInstanceByID(OldReceiverID);
CScriptObject *pNewReceiver = mpArea->GetInstanceByID(NewReceiverID);
CScriptObject *pOldReceiver = mpArea->InstanceByID(OldReceiverID);
CScriptObject *pNewReceiver = mpArea->InstanceByID(NewReceiverID);
mReceiverID = NewReceiverID;
pOldReceiver->RemoveLink(eIncoming, this);
@@ -73,7 +73,7 @@ public:
u32 SenderIndex() const
{
CScriptObject *pSender = mpArea->GetInstanceByID(mSenderID);
CScriptObject *pSender = mpArea->InstanceByID(mSenderID);
for (u32 iLink = 0; iLink < pSender->NumLinks(eOutgoing); iLink++)
{
@@ -86,7 +86,7 @@ public:
u32 ReceiverIndex() const
{
CScriptObject *pReceiver = mpArea->GetInstanceByID(mReceiverID);
CScriptObject *pReceiver = mpArea->InstanceByID(mReceiverID);
for (u32 iLink = 0; iLink < pReceiver->NumLinks(eIncoming); iLink++)
{
@@ -117,8 +117,8 @@ public:
u32 Message() const { return mMessageID; }
u32 SenderID() const { return mSenderID; }
u32 ReceiverID() const { return mReceiverID; }
CScriptObject* Sender() const { return mpArea->GetInstanceByID(mSenderID); }
CScriptObject* Receiver() const { return mpArea->GetInstanceByID(mReceiverID); }
CScriptObject* Sender() const { return mpArea->InstanceByID(mSenderID); }
CScriptObject* Receiver() const { return mpArea->InstanceByID(mReceiverID); }
void SetState(u32 StateID) { mStateID = StateID; }
void SetMessage(u32 MessageID) { mMessageID = MessageID; }

View File

@@ -8,13 +8,15 @@
class CScriptLayer
{
CGameArea *mpArea;
TString mLayerName;
bool mActive;
bool mVisible;
std::vector<CScriptObject*> mInstances;
public:
CScriptLayer()
: mLayerName("New Layer")
CScriptLayer(CGameArea *pArea)
: mpArea(pArea)
, mLayerName("New Layer")
, mActive(true)
, mVisible(true)
{
@@ -27,9 +29,17 @@ public:
}
// Data Manipulation
void AddInstance(CScriptObject *pObject)
void AddInstance(CScriptObject *pObject, u32 Index = -1)
{
mInstances.push_back(pObject);
if (Index != -1 && Index < mInstances.size())
{
auto it = mInstances.begin();
std::advance(it, Index);
mInstances.insert(it, pObject);
}
else
mInstances.push_back(pObject);
}
void RemoveInstance(CScriptObject *pInstance)
@@ -67,6 +77,7 @@ public:
}
// Accessors
inline CGameArea* Area() const { return mpArea; }
inline TString Name() const { return mLayerName; }
inline bool IsActive() const { return mActive; }
inline bool IsVisible() const { return mVisible; }
@@ -88,6 +99,17 @@ public:
inline void SetActive(bool Active) { mActive = Active; }
inline void SetVisible(bool Visible) { mVisible = Visible; }
inline u32 AreaIndex() const
{
for (u32 iLyr = 0; iLyr < mpArea->GetScriptLayerCount(); iLyr++)
{
if (mpArea->GetScriptLayer(iLyr) == this)
return iLyr;
}
return -1;
}
// Operators
CScriptObject* operator[](u32 Index) { return InstanceByIndex(Index); }
};

View File

@@ -3,11 +3,12 @@
#include "CMasterTemplate.h"
#include "Core/Resource/CAnimSet.h"
CScriptObject::CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate)
CScriptObject::CScriptObject(u32 InstanceID, CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate)
: mpTemplate(pTemplate)
, mpArea(pArea)
, mpLayer(pLayer)
, mVersion(0)
, mInstanceID(InstanceID)
, mpDisplayModel(nullptr)
, mpCollision(nullptr)
, mHasInGameModel(false)
@@ -75,16 +76,27 @@ bool CScriptObject::IsEditorProperty(IProperty *pProp)
);
}
void CScriptObject::SetLayer(CScriptLayer *pLayer)
void CScriptObject::SetLayer(CScriptLayer *pLayer, u32 NewLayerIndex)
{
if (pLayer != mpLayer)
{
mpLayer->RemoveInstance(this);
mpLayer = pLayer;
mpLayer->AddInstance(this);
mpLayer->AddInstance(this, NewLayerIndex);
}
}
u32 CScriptObject::LayerIndex() const
{
for (u32 iInst = 0; iInst < mpLayer->NumInstances(); iInst++)
{
if (mpLayer->InstanceByIndex(iInst) == this)
return iInst;
}
return -1;
}
bool CScriptObject::HasNearVisibleActivation() const
{
/* This function is used to check whether an inactive DKCR object should render in game mode. DKCR deactivates a lot of
@@ -240,6 +252,26 @@ void CScriptObject::RemoveLink(ELinkType Type, CLink *pLink)
}
}
void CScriptObject::BreakAllLinks()
{
for (auto it = mInLinks.begin(); it != mInLinks.end(); it++)
{
CLink *pLink = *it;
pLink->Sender()->RemoveLink(eOutgoing, pLink);
delete pLink;
}
for (auto it = mOutLinks.begin(); it != mOutLinks.end(); it++)
{
CLink *pLink = *it;
pLink->Receiver()->RemoveLink(eIncoming, pLink);
delete pLink;
}
mInLinks.clear();
mOutLinks.clear();
}
TString CScriptObject::InstanceName() const
{
if (mpInstanceName)

View File

@@ -50,7 +50,7 @@ class CScriptObject
mutable bool mIsCheckingNearVisibleActivation;
public:
CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);
CScriptObject(u32 InstanceID, CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate);
~CScriptObject();
void EvaluateProperties();
@@ -59,7 +59,8 @@ public:
void EvaluateCollisionModel();
void EvaluateVolume();
bool IsEditorProperty(IProperty *pProp);
void SetLayer(CScriptLayer *pLayer);
void SetLayer(CScriptLayer *pLayer, u32 NewLayerIndex = -1);
u32 LayerIndex() const;
bool HasNearVisibleActivation() const;
CScriptTemplate* Template() const;
@@ -78,6 +79,7 @@ public:
CLink* Link(ELinkType Type, u32 Index) const;
void AddLink(ELinkType Type, CLink *pLink, u32 Index = -1);
void RemoveLink(ELinkType Type, CLink *pLink);
void BreakAllLinks();
CVector3f Position() const;
CVector3f Rotation() const;