mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-18 09:25:31 +00:00
Implemented functionality for editing, creating, and deleting script object links
This commit is contained in:
@@ -186,7 +186,7 @@ HEADERS += \
|
||||
Resource/Factory/CSectionMgrIn.h \
|
||||
Resource/Cooker/CScriptCooker.h \
|
||||
ScriptExtra/CSplinePathExtra.h \
|
||||
Resource/Script/SLink.h
|
||||
Resource/Script/CLink.h
|
||||
|
||||
# Source Files
|
||||
SOURCES += \
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "CScriptCooker.h"
|
||||
#include "Core/Resource/Script/CLink.h"
|
||||
|
||||
void CScriptCooker::WriteProperty(IProperty *pProp, bool InSingleStruct)
|
||||
{
|
||||
@@ -211,14 +212,14 @@ void CScriptCooker::WriteInstanceMP1(CScriptObject *pInstance)
|
||||
u32 InstanceStart = mpSCLY->Tell();
|
||||
|
||||
mpSCLY->WriteLong(pInstance->InstanceID());
|
||||
mpSCLY->WriteLong(pInstance->NumOutLinks());
|
||||
mpSCLY->WriteLong(pInstance->NumLinks(eOutgoing));
|
||||
|
||||
for (u32 iLink = 0; iLink < pInstance->NumOutLinks(); iLink++)
|
||||
for (u32 iLink = 0; iLink < pInstance->NumLinks(eOutgoing); iLink++)
|
||||
{
|
||||
const SLink& rkLink = pInstance->OutLink(iLink);
|
||||
mpSCLY->WriteLong(rkLink.State);
|
||||
mpSCLY->WriteLong(rkLink.Message);
|
||||
mpSCLY->WriteLong(rkLink.ObjectID);
|
||||
CLink *pLink = pInstance->Link(eOutgoing, iLink);
|
||||
mpSCLY->WriteLong(pLink->State());
|
||||
mpSCLY->WriteLong(pLink->Message());
|
||||
mpSCLY->WriteLong(pLink->ReceiverID());
|
||||
}
|
||||
|
||||
WriteProperty(pInstance->Properties(), false);
|
||||
@@ -261,14 +262,14 @@ void CScriptCooker::WriteInstanceMP2(CScriptObject *pInstance)
|
||||
u32 InstanceStart = mpSCLY->Tell();
|
||||
|
||||
mpSCLY->WriteLong(pInstance->InstanceID());
|
||||
mpSCLY->WriteShort((u16) pInstance->NumOutLinks());
|
||||
mpSCLY->WriteShort((u16) pInstance->NumLinks(eOutgoing));
|
||||
|
||||
for (u32 iLink = 0; iLink < pInstance->NumOutLinks(); iLink++)
|
||||
for (u32 iLink = 0; iLink < pInstance->NumLinks(eOutgoing); iLink++)
|
||||
{
|
||||
const SLink& rkLink = pInstance->OutLink(iLink);
|
||||
mpSCLY->WriteLong(rkLink.State);
|
||||
mpSCLY->WriteLong(rkLink.Message);
|
||||
mpSCLY->WriteLong(rkLink.ObjectID);
|
||||
CLink *pLink = pInstance->Link(eOutgoing, iLink);
|
||||
mpSCLY->WriteLong(pLink->State());
|
||||
mpSCLY->WriteLong(pLink->Message());
|
||||
mpSCLY->WriteLong(pLink->ReceiverID());
|
||||
}
|
||||
|
||||
WriteProperty(pInstance->Properties(), false);
|
||||
|
||||
@@ -627,15 +627,10 @@ void CAreaLoader::SetUpObjects()
|
||||
mpArea->mObjectMap[pObj->InstanceID()] = pObj;
|
||||
|
||||
// Store outgoing connections
|
||||
for (u32 iCon = 0; iCon < pObj->NumOutLinks(); iCon++)
|
||||
for (u32 iCon = 0; iCon < pObj->NumLinks(eOutgoing); iCon++)
|
||||
{
|
||||
SLink Connection = pObj->OutLink(iCon);
|
||||
|
||||
SLink NewConnection;
|
||||
NewConnection.State = Connection.State;
|
||||
NewConnection.Message = Connection.Message;
|
||||
NewConnection.ObjectID = pObj->InstanceID();
|
||||
mConnectionMap[Connection.ObjectID].push_back(NewConnection);
|
||||
CLink *pLink = pObj->Link(eOutgoing, iCon);
|
||||
mConnectionMap[pLink->ReceiverID()].push_back(pLink);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -649,7 +644,7 @@ void CAreaLoader::SetUpObjects()
|
||||
if (iConMap != mConnectionMap.end())
|
||||
{
|
||||
CScriptObject *pObj = mpArea->GetInstanceByID(InstanceID);
|
||||
pObj->mInConnections = iConMap->second;
|
||||
pObj->mInLinks = iConMap->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CAREALOADER_H
|
||||
|
||||
#include "CSectionMgrIn.h"
|
||||
#include "Core/Resource/Script/SLink.h"
|
||||
#include "Core/Resource/Script/CLink.h"
|
||||
#include "Core/Resource/CGameArea.h"
|
||||
#include "Core/Resource/EGame.h"
|
||||
#include "Core/Resource/CResCache.h"
|
||||
@@ -22,7 +22,7 @@ class CAreaLoader
|
||||
u32 mNumLayers;
|
||||
|
||||
// Object connections
|
||||
std::unordered_map<u32, std::vector<SLink>> mConnectionMap;
|
||||
std::unordered_map<u32, std::vector<CLink*>> mConnectionMap;
|
||||
|
||||
// Compression
|
||||
u8 *mDecmpBuffer;
|
||||
|
||||
@@ -219,15 +219,16 @@ CScriptObject* CScriptLoader::LoadObjectMP1(IInputStream& SCLY)
|
||||
|
||||
// Load connections
|
||||
u32 NumLinks = SCLY.ReadLong();
|
||||
mpObj->mOutConnections.reserve(NumLinks);
|
||||
mpObj->mOutLinks.reserve(NumLinks);
|
||||
|
||||
for (u32 iLink = 0; iLink < NumLinks; iLink++)
|
||||
{
|
||||
SLink Link;
|
||||
Link.State = SCLY.ReadLong();
|
||||
Link.Message = SCLY.ReadLong();
|
||||
Link.ObjectID = SCLY.ReadLong();
|
||||
mpObj->mOutConnections.push_back(Link);
|
||||
u32 State = SCLY.ReadLong();
|
||||
u32 Message = SCLY.ReadLong();
|
||||
u32 ReceiverID = SCLY.ReadLong();
|
||||
|
||||
CLink *pLink = new CLink(mpArea, State, Message, mpObj->mInstanceID, ReceiverID);
|
||||
mpObj->mOutLinks.push_back(pLink);
|
||||
}
|
||||
|
||||
// Load object...
|
||||
@@ -331,15 +332,16 @@ CScriptObject* CScriptLoader::LoadObjectMP2(IInputStream& SCLY)
|
||||
|
||||
// Load connections
|
||||
u32 NumConnections = SCLY.ReadShort();
|
||||
mpObj->mOutConnections.reserve(NumConnections);
|
||||
mpObj->mOutLinks.reserve(NumConnections);
|
||||
|
||||
for (u32 iCon = 0; iCon < NumConnections; iCon++)
|
||||
{
|
||||
SLink Link;
|
||||
Link.State = SCLY.ReadLong();
|
||||
Link.Message = SCLY.ReadLong();
|
||||
Link.ObjectID = SCLY.ReadLong();
|
||||
mpObj->mOutConnections.push_back(Link);
|
||||
u32 State = SCLY.ReadLong();
|
||||
u32 Message = SCLY.ReadLong();
|
||||
u32 ReceiverID = SCLY.ReadLong();
|
||||
|
||||
CLink *pLink = new CLink(mpArea, State, Message, mpObj->mInstanceID, ReceiverID);
|
||||
mpObj->mOutLinks.push_back(pLink);
|
||||
}
|
||||
|
||||
// Load object
|
||||
|
||||
128
src/Core/Resource/Script/CLink.h
Normal file
128
src/Core/Resource/Script/CLink.h
Normal file
@@ -0,0 +1,128 @@
|
||||
#ifndef CLINK_H
|
||||
#define CLINK_H
|
||||
|
||||
#include "CScriptObject.h"
|
||||
#include "Core/Resource/CGameArea.h"
|
||||
#include <Common/TString.h>
|
||||
#include <Common/types.h>
|
||||
|
||||
struct SState
|
||||
{
|
||||
u32 ID;
|
||||
TString Name;
|
||||
|
||||
SState() {}
|
||||
SState(u32 _ID, const TString& rkName) : ID(_ID), Name(rkName) {}
|
||||
};
|
||||
|
||||
struct SMessage
|
||||
{
|
||||
u32 ID;
|
||||
TString Name;
|
||||
|
||||
SMessage() {}
|
||||
SMessage(u32 _ID, const TString& rkName) : ID(_ID), Name(rkName) {}
|
||||
};
|
||||
|
||||
class CLink
|
||||
{
|
||||
CGameArea *mpArea;
|
||||
u32 mStateID;
|
||||
u32 mMessageID;
|
||||
u32 mSenderID;
|
||||
u32 mReceiverID;
|
||||
|
||||
public:
|
||||
CLink(CGameArea *pArea)
|
||||
: mpArea(pArea)
|
||||
, mStateID(-1)
|
||||
, mMessageID(-1)
|
||||
, mSenderID(-1)
|
||||
, mReceiverID(-1)
|
||||
{}
|
||||
|
||||
CLink(CGameArea *pArea, u32 StateID, u32 MessageID, u32 SenderID, u32 ReceiverID)
|
||||
: mpArea(pArea)
|
||||
, mStateID(StateID)
|
||||
, mMessageID(MessageID)
|
||||
, mSenderID(SenderID)
|
||||
, mReceiverID(ReceiverID)
|
||||
{}
|
||||
|
||||
void SetSender(u32 NewSenderID, u32 Index = -1)
|
||||
{
|
||||
u32 OldSenderID = mSenderID;
|
||||
CScriptObject *pOldSender = mpArea->GetInstanceByID(OldSenderID);
|
||||
CScriptObject *pNewSender = mpArea->GetInstanceByID(NewSenderID);
|
||||
|
||||
mSenderID = NewSenderID;
|
||||
pOldSender->RemoveLink(eOutgoing, this);
|
||||
pNewSender->AddLink(eOutgoing, this, Index);
|
||||
}
|
||||
|
||||
void SetReceiver(u32 NewReceiverID, u32 Index = -1)
|
||||
{
|
||||
u32 OldReceiverID = mSenderID;
|
||||
CScriptObject *pOldReceiver = mpArea->GetInstanceByID(OldReceiverID);
|
||||
CScriptObject *pNewReceiver = mpArea->GetInstanceByID(NewReceiverID);
|
||||
|
||||
mReceiverID = NewReceiverID;
|
||||
pOldReceiver->RemoveLink(eIncoming, this);
|
||||
pNewReceiver->AddLink(eIncoming, this, Index);
|
||||
}
|
||||
|
||||
u32 SenderIndex() const
|
||||
{
|
||||
CScriptObject *pSender = mpArea->GetInstanceByID(mSenderID);
|
||||
|
||||
for (u32 iLink = 0; iLink < pSender->NumLinks(eOutgoing); iLink++)
|
||||
{
|
||||
if (pSender->Link(eOutgoing, iLink) == this)
|
||||
return iLink;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
u32 ReceiverIndex() const
|
||||
{
|
||||
CScriptObject *pReceiver = mpArea->GetInstanceByID(mReceiverID);
|
||||
|
||||
for (u32 iLink = 0; iLink < pReceiver->NumLinks(eIncoming); iLink++)
|
||||
{
|
||||
if (pReceiver->Link(eIncoming, iLink) == this)
|
||||
return iLink;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Operators
|
||||
bool operator==(const CLink& rkOther)
|
||||
{
|
||||
return ( (mpArea == rkOther.mpArea) &&
|
||||
(mStateID == rkOther.mStateID) &&
|
||||
(mMessageID == rkOther.mMessageID) &&
|
||||
(mSenderID == rkOther.mSenderID) &&
|
||||
(mReceiverID == rkOther.mReceiverID) );
|
||||
}
|
||||
|
||||
bool operator!=(const CLink& rkOther)
|
||||
{
|
||||
return (!(*this == rkOther));
|
||||
}
|
||||
|
||||
// Accessors
|
||||
u32 State() const { return mStateID; }
|
||||
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); }
|
||||
|
||||
void SetState(u32 StateID) { mStateID = StateID; }
|
||||
void SetMessage(u32 MessageID) { mMessageID = MessageID; }
|
||||
};
|
||||
|
||||
|
||||
#endif // CLINK_H
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CMASTERTEMPLATE_H
|
||||
|
||||
#include "CScriptTemplate.h"
|
||||
#include "SLink.h"
|
||||
#include "CLink.h"
|
||||
#include "Core/Resource/EGame.h"
|
||||
#include <Common/types.h>
|
||||
#include <map>
|
||||
|
||||
@@ -21,6 +21,10 @@ CScriptObject::~CScriptObject()
|
||||
{
|
||||
if (mpProperties) delete mpProperties;
|
||||
mpTemplate->RemoveObject(this);
|
||||
|
||||
// Note: Incoming links will be deleted by the sender.
|
||||
for (u32 iLink = 0; iLink < mOutLinks.size(); iLink++)
|
||||
delete mOutLinks[iLink];
|
||||
}
|
||||
|
||||
// ************ DATA MANIPULATION ************
|
||||
@@ -94,17 +98,17 @@ bool CScriptObject::HasNearVisibleActivation() const
|
||||
if (mIsCheckingNearVisibleActivation) return false;
|
||||
mIsCheckingNearVisibleActivation = true;
|
||||
|
||||
for (u32 iLink = 0; iLink < mInConnections.size(); iLink++)
|
||||
for (u32 iLink = 0; iLink < mInLinks.size(); iLink++)
|
||||
{
|
||||
const SLink& rkLink = mInConnections[iLink];
|
||||
CLink *pLink = mInLinks[iLink];
|
||||
|
||||
// Check for trigger activation
|
||||
if (rkLink.State == 0x49533034 || rkLink.State == 0x49533035 || rkLink.State == 0x49533036) // "IS04", "IS05", or "IS06"
|
||||
if (pLink->State() == 0x49533034 || pLink->State() == 0x49533035 || pLink->State() == 0x49533036) // "IS04", "IS05", or "IS06"
|
||||
{
|
||||
if ( (!IsRelay && rkLink.Message == 0x41435456) || // "ACTV"
|
||||
(IsRelay && rkLink.Message == 0x4143544E) ) // "ACTN"
|
||||
if ( (!IsRelay && pLink->Message() == 0x41435456) || // "ACTV"
|
||||
(IsRelay && pLink->Message() == 0x4143544E) ) // "ACTN"
|
||||
{
|
||||
CScriptObject *pObj = mpArea->GetInstanceByID(rkLink.ObjectID);
|
||||
CScriptObject *pObj = pLink->Sender();
|
||||
|
||||
if (pObj->ObjectTypeID() == 0x54524752) // "TRGR"
|
||||
{
|
||||
@@ -115,12 +119,12 @@ bool CScriptObject::HasNearVisibleActivation() const
|
||||
}
|
||||
|
||||
// Check for relay activation
|
||||
else if (rkLink.State == 0x524C4159) // "RLAY"
|
||||
else if (pLink->State() == 0x524C4159) // "RLAY"
|
||||
{
|
||||
if ( (!IsRelay && rkLink.Message == 0x41435456) || // "ACTV"
|
||||
(IsRelay && rkLink.Message == 0x4143544E) ) // "ACTN"
|
||||
if ( (!IsRelay && pLink->Message() == 0x41435456) || // "ACTV"
|
||||
(IsRelay && pLink->Message() == 0x4143544E) ) // "ACTN"
|
||||
{
|
||||
CScriptObject *pObj = mpArea->GetInstanceByID(rkLink.ObjectID);
|
||||
CScriptObject *pObj = pLink->Sender();
|
||||
|
||||
if (pObj->ObjectTypeID() == 0x53524C59) // "SRLY"
|
||||
Relays.push_back(pObj);
|
||||
@@ -198,24 +202,42 @@ u32 CScriptObject::InstanceID() const
|
||||
return mInstanceID;
|
||||
}
|
||||
|
||||
u32 CScriptObject::NumInLinks() const
|
||||
u32 CScriptObject::NumLinks(ELinkType Type) const
|
||||
{
|
||||
return mInConnections.size();
|
||||
return (Type == eIncoming ? mInLinks.size() : mOutLinks.size());
|
||||
}
|
||||
|
||||
u32 CScriptObject::NumOutLinks() const
|
||||
CLink* CScriptObject::Link(ELinkType Type, u32 Index) const
|
||||
{
|
||||
return mOutConnections.size();
|
||||
return (Type == eIncoming ? mInLinks[Index] : mOutLinks[Index]);
|
||||
}
|
||||
|
||||
const SLink& CScriptObject::InLink(u32 index) const
|
||||
void CScriptObject::AddLink(ELinkType Type, CLink *pLink, u32 Index /*= -1*/)
|
||||
{
|
||||
return mInConnections[index];
|
||||
std::vector<CLink*> *pLinkVec = (Type == eIncoming ? &mInLinks : &mOutLinks);
|
||||
|
||||
if (Index == -1 || Index == pLinkVec->size())
|
||||
pLinkVec->push_back(pLink);
|
||||
else
|
||||
{
|
||||
auto it = pLinkVec->begin();
|
||||
std::advance(it, Index);
|
||||
pLinkVec->insert(it, pLink);
|
||||
}
|
||||
}
|
||||
|
||||
const SLink& CScriptObject::OutLink(u32 index) const
|
||||
void CScriptObject::RemoveLink(ELinkType Type, CLink *pLink)
|
||||
{
|
||||
return mOutConnections[index];
|
||||
std::vector<CLink*> *pLinkVec = (Type == eIncoming ? &mInLinks : &mOutLinks);
|
||||
|
||||
for (auto it = pLinkVec->begin(); it != pLinkVec->end(); it++)
|
||||
{
|
||||
if (*it == pLink)
|
||||
{
|
||||
pLinkVec->erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TString CScriptObject::InstanceName() const
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef CSCRIPTOBJECT_H
|
||||
#define CSCRIPTOBJECT_H
|
||||
|
||||
#include "SLink.h"
|
||||
#include "IProperty.h"
|
||||
#include "IPropertyTemplate.h"
|
||||
#include "CScriptTemplate.h"
|
||||
@@ -10,6 +9,13 @@
|
||||
#include "Core/Resource/CGameArea.h"
|
||||
|
||||
class CScriptLayer;
|
||||
class CLink;
|
||||
|
||||
enum ELinkType
|
||||
{
|
||||
eIncoming,
|
||||
eOutgoing
|
||||
};
|
||||
|
||||
class CScriptObject
|
||||
{
|
||||
@@ -22,8 +28,8 @@ class CScriptObject
|
||||
u32 mVersion;
|
||||
|
||||
u32 mInstanceID;
|
||||
std::vector<SLink> mOutConnections;
|
||||
std::vector<SLink> mInConnections;
|
||||
std::vector<CLink*> mOutLinks;
|
||||
std::vector<CLink*> mInLinks;
|
||||
CPropertyStruct *mpProperties;
|
||||
|
||||
TStringProperty *mpInstanceName;
|
||||
@@ -67,10 +73,11 @@ public:
|
||||
IProperty* PropertyByIDString(const TIDString& str) const;
|
||||
u32 ObjectTypeID() const;
|
||||
u32 InstanceID() const;
|
||||
u32 NumInLinks() const;
|
||||
u32 NumOutLinks() const;
|
||||
const SLink& InLink(u32 index) const;
|
||||
const SLink& OutLink(u32 index) const;
|
||||
|
||||
u32 NumLinks(ELinkType Type) const;
|
||||
CLink* Link(ELinkType Type, u32 Index) const;
|
||||
void AddLink(ELinkType Type, CLink *pLink, u32 Index = -1);
|
||||
void RemoveLink(ELinkType Type, CLink *pLink);
|
||||
|
||||
CVector3f Position() const;
|
||||
CVector3f Rotation() const;
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef SLINK_H
|
||||
#define SLINK_H
|
||||
|
||||
#include <Common/TString.h>
|
||||
#include <Common/types.h>
|
||||
|
||||
struct SState
|
||||
{
|
||||
u32 ID;
|
||||
TString Name;
|
||||
|
||||
SState() {}
|
||||
SState(u32 _ID, const TString& rkName) : ID(_ID), Name(rkName) {}
|
||||
};
|
||||
|
||||
struct SMessage
|
||||
{
|
||||
u32 ID;
|
||||
TString Name;
|
||||
|
||||
SMessage() {}
|
||||
SMessage(u32 _ID, const TString& rkName) : ID(_ID), Name(rkName) {}
|
||||
};
|
||||
|
||||
struct SLink
|
||||
{
|
||||
u32 State;
|
||||
u32 Message;
|
||||
u32 ObjectID; // not a pointer because it can refer to objects outside the current area
|
||||
};
|
||||
|
||||
#endif // SLINK_H
|
||||
@@ -255,18 +255,18 @@ void CScriptNode::DrawSelection()
|
||||
CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity;
|
||||
CGraphics::UpdateMVPBlock();
|
||||
|
||||
for (u32 iIn = 0; iIn < mpInstance->NumInLinks(); iIn++)
|
||||
for (u32 iIn = 0; iIn < mpInstance->NumLinks(eIncoming); iIn++)
|
||||
{
|
||||
// Don't draw in links if the other object is selected.
|
||||
const SLink& con = mpInstance->InLink(iIn);
|
||||
CScriptNode *pLinkNode = mpScene->ScriptNodeByID(con.ObjectID);
|
||||
CLink *pLink = mpInstance->Link(eIncoming, iIn);
|
||||
CScriptNode *pLinkNode = mpScene->ScriptNodeByID(pLink->SenderID());
|
||||
if (pLinkNode && !pLinkNode->IsSelected()) CDrawUtil::DrawLine(CenterPoint(), pLinkNode->CenterPoint(), CColor::skTransparentRed);
|
||||
}
|
||||
|
||||
for (u32 iOut = 0; iOut < mpInstance->NumOutLinks(); iOut++)
|
||||
for (u32 iOut = 0; iOut < mpInstance->NumLinks(eOutgoing); iOut++)
|
||||
{
|
||||
const SLink& con = mpInstance->OutLink(iOut);
|
||||
CScriptNode *pLinkNode = mpScene->ScriptNodeByID(con.ObjectID);
|
||||
CLink *pLink = mpInstance->Link(eOutgoing, iOut);
|
||||
CScriptNode *pLinkNode = mpScene->ScriptNodeByID(pLink->ReceiverID());
|
||||
if (pLinkNode) CDrawUtil::DrawLine(CenterPoint(), pLinkNode->CenterPoint(), CColor::skTransparentGreen);
|
||||
}
|
||||
}
|
||||
@@ -429,6 +429,11 @@ CColor CScriptNode::TintColor(const SViewInfo &ViewInfo) const
|
||||
return BaseColor;
|
||||
}
|
||||
|
||||
void CScriptNode::LinksModified()
|
||||
{
|
||||
if (mpExtra) mpExtra->LinksModified();
|
||||
}
|
||||
|
||||
void CScriptNode::PropertyModified(IProperty *pProp)
|
||||
{
|
||||
// Update volume
|
||||
@@ -534,13 +539,13 @@ void CScriptNode::GeneratePosition()
|
||||
|
||||
// Ideal way to generate the position is to find a spot close to where it's being used.
|
||||
// To do this I check the location of the objects that this one is linked to.
|
||||
u32 NumLinks = mpInstance->NumInLinks() + mpInstance->NumOutLinks();
|
||||
u32 NumLinks = mpInstance->NumLinks(eIncoming) + mpInstance->NumLinks(eOutgoing);
|
||||
|
||||
// In the case of one link, apply an offset so the new position isn't the same place as the object it's linked to
|
||||
if (NumLinks == 1)
|
||||
{
|
||||
const SLink& link = (mpInstance->NumInLinks() > 0 ? mpInstance->InLink(0) : mpInstance->OutLink(0));
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(link.ObjectID);
|
||||
u32 LinkedID = (mpInstance->NumLinks(eIncoming) > 0 ? mpInstance->Link(eIncoming, 0)->SenderID() : mpInstance->Link(eOutgoing, 0)->ReceiverID());
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(LinkedID);
|
||||
pNode->GeneratePosition();
|
||||
mPosition = pNode->AbsolutePosition();
|
||||
mPosition.z += (pNode->AABox().Size().z / 2.f);
|
||||
@@ -553,9 +558,9 @@ void CScriptNode::GeneratePosition()
|
||||
{
|
||||
CVector3f NewPos = CVector3f::skZero;
|
||||
|
||||
for (u32 iIn = 0; iIn < mpInstance->NumInLinks(); iIn++)
|
||||
for (u32 iIn = 0; iIn < mpInstance->NumLinks(eIncoming); iIn++)
|
||||
{
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(mpInstance->InLink(iIn).ObjectID);
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(mpInstance->Link(eIncoming, iIn)->SenderID());
|
||||
|
||||
if (pNode)
|
||||
{
|
||||
@@ -564,9 +569,9 @@ void CScriptNode::GeneratePosition()
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 iOut = 0; iOut < mpInstance->NumOutLinks(); iOut++)
|
||||
for (u32 iOut = 0; iOut < mpInstance->NumLinks(eOutgoing); iOut++)
|
||||
{
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(mpInstance->OutLink(iOut).ObjectID);
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(mpInstance->Link(eOutgoing, iOut)->ReceiverID());
|
||||
|
||||
if (pNode)
|
||||
{
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
CColor TintColor(const SViewInfo &ViewInfo) const;
|
||||
CColor WireframeColor() const;
|
||||
|
||||
void LinksModified();
|
||||
void PropertyModified(IProperty *pProp);
|
||||
void UpdatePreviewVolume();
|
||||
void GeneratePosition();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "CSplinePathExtra.h"
|
||||
#include "CWaypointExtra.h"
|
||||
#include "Core/Resource/Script/CLink.h"
|
||||
#include "Core/Scene/CScene.h"
|
||||
|
||||
CSplinePathExtra::CSplinePathExtra(CScriptObject *pInstance, CScene *pScene, CSceneNode *pParent)
|
||||
@@ -45,14 +46,14 @@ void CSplinePathExtra::AddWaypoints()
|
||||
|
||||
std::set<CWaypointExtra*> CheckedWaypoints;
|
||||
|
||||
for (u32 iLink = 0; iLink < mpInstance->NumOutLinks(); iLink++)
|
||||
for (u32 iLink = 0; iLink < mpInstance->NumLinks(eOutgoing); iLink++)
|
||||
{
|
||||
const SLink& rkLink = mpInstance->OutLink(iLink);
|
||||
CLink *pLink = mpInstance->Link(eOutgoing, iLink);
|
||||
|
||||
if ( (rkLink.State == 0x49533030 && rkLink.Message == 0x41544348) || // InternalState00/Attach
|
||||
(rkLink.State == 0x4D4F5450 && rkLink.Message == 0x41544348) ) // MotionPath/Attach
|
||||
if ( (pLink->State() == 0x49533030 && pLink->Message() == 0x41544348) || // InternalState00/Attach
|
||||
(pLink->State() == 0x4D4F5450 && pLink->Message() == 0x41544348) ) // MotionPath/Attach
|
||||
{
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(rkLink.ObjectID);
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(pLink->ReceiverID());
|
||||
|
||||
if (pNode && pNode->Object()->ObjectTypeID() == 0x57415950) // Waypoint
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "CWaypointExtra.h"
|
||||
#include "Core/Resource/Script/CLink.h"
|
||||
#include "Core/Render/CDrawUtil.h"
|
||||
#include "Core/Render/CRenderer.h"
|
||||
#include "Core/Scene/CScene.h"
|
||||
@@ -78,13 +79,13 @@ void CWaypointExtra::BuildLinks()
|
||||
{
|
||||
mLinks.clear();
|
||||
|
||||
for (u32 iLink = 0; iLink < mpInstance->NumOutLinks(); iLink++)
|
||||
for (u32 iLink = 0; iLink < mpInstance->NumLinks(eOutgoing); iLink++)
|
||||
{
|
||||
const SLink& rkLink = mpInstance->OutLink(iLink);
|
||||
CLink *pLink = mpInstance->Link(eOutgoing, iLink);
|
||||
|
||||
if (IsPathLink(rkLink))
|
||||
if (IsPathLink(pLink))
|
||||
{
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(rkLink.ObjectID);
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(pLink->ReceiverID());
|
||||
|
||||
SWaypointLink Link;
|
||||
Link.pWaypoint = pNode;
|
||||
@@ -97,26 +98,26 @@ void CWaypointExtra::BuildLinks()
|
||||
mLinksBuilt = true;
|
||||
}
|
||||
|
||||
bool CWaypointExtra::IsPathLink(const SLink& rkLink)
|
||||
bool CWaypointExtra::IsPathLink(CLink *pLink)
|
||||
{
|
||||
bool Valid = false;
|
||||
|
||||
if (rkLink.State < 0xFF)
|
||||
if (pLink->State() < 0xFF)
|
||||
{
|
||||
if (rkLink.State == 0x1 && rkLink.Message == 0x8) Valid = true; // Arrived / Next (MP1)
|
||||
if (pLink->State() == 0x1 && pLink->Message() == 0x8) Valid = true; // Arrived / Next (MP1)
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
CFourCC State(rkLink.State);
|
||||
CFourCC Message(rkLink.Message);
|
||||
CFourCC State(pLink->State());
|
||||
CFourCC Message(pLink->Message());
|
||||
if (State == "ARRV" && Message == "NEXT") Valid = true; // Arrived / Next (MP2)
|
||||
if (State == "NEXT" && Message == "ATCH") Valid = true; // Next / Attach (MP3/DKCR)
|
||||
}
|
||||
|
||||
if (Valid)
|
||||
{
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(rkLink.ObjectID);
|
||||
CScriptNode *pNode = mpScene->ScriptNodeByID(pLink->ReceiverID());
|
||||
|
||||
if (pNode)
|
||||
return pNode->Object()->ObjectTypeID() == mpInstance->ObjectTypeID();
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
void AddToSplinePath(CSplinePathExtra *pPath);
|
||||
void RemoveFromSplinePath(CSplinePathExtra *pPath);
|
||||
void BuildLinks();
|
||||
bool IsPathLink(const SLink& rkLink);
|
||||
bool IsPathLink(CLink *pLink);
|
||||
void GetLinkedWaypoints(std::list<CWaypointExtra*>& rOut);
|
||||
|
||||
void LinksModified();
|
||||
|
||||
Reference in New Issue
Block a user