From ecab7be63f37200b324aa9568355cfe8490ff7cc Mon Sep 17 00:00:00 2001 From: parax0 Date: Sat, 27 Feb 2016 02:16:29 -0700 Subject: [PATCH] Set up DKCR waypoints to draw using the color of their attached spline path --- resources/script/dkcr/Waypoint.cmdl | Bin 0 -> 1984 bytes src/Core/Core.pro | 6 +- src/Core/Resource/Cooker/CMaterialCooker.cpp | 2 +- src/Core/ScriptExtra/CScriptExtra.cpp | 7 ++ src/Core/ScriptExtra/CScriptExtra.h | 2 + src/Core/ScriptExtra/CSplinePathExtra.cpp | 84 ++++++++++++++++++ src/Core/ScriptExtra/CSplinePathExtra.h | 31 +++++++ src/Core/ScriptExtra/CWaypointExtra.cpp | 85 +++++++++++++++++-- src/Core/ScriptExtra/CWaypointExtra.h | 8 ++ templates/dkcr/Script/Waypoint.xml | 2 +- 10 files changed, 216 insertions(+), 11 deletions(-) create mode 100644 resources/script/dkcr/Waypoint.cmdl create mode 100644 src/Core/ScriptExtra/CSplinePathExtra.cpp create mode 100644 src/Core/ScriptExtra/CSplinePathExtra.h diff --git a/resources/script/dkcr/Waypoint.cmdl b/resources/script/dkcr/Waypoint.cmdl new file mode 100644 index 0000000000000000000000000000000000000000..6ff06f33ca369d4128cdd6cefc1221a5b67ef00f GIT binary patch literal 1984 zcmeHIJxE(o6h3K^nrN)H{iyX=B?Zq6Zvt zcVXq7oBK8DHEgU}pN^}o+-9To`9&9hOK?Ourg(DvI4w)85_KvrLf{Yf4ieSBE$h)b z|2uS!p7LDvevG2&ALU$-C`NRB?R%O3JNmya^rBCELH|~EB5zy;=k+-H*SefBTkLjx zllHj2j-0rMphxStAM6c!w61$YIa5pL3F`;E5&lJZ!jgy>IO7;=G;CA6DYt$V?G?;i<%VZ^8SUCzRXI_dd91zoph~+)|z}?yirQ zyvfd-d-U<768B!MUOC(|Je4^1+A2>NxBJe|?Bwte^4!KfHtVjNe%q|Ges0u2eh%z6b?&MzmkbVm2;?mY>ay;; ze7Re2W@+bQ;3ou!Xcw~?8NRnKOH0fB2WyVe^t?_T{xZTOptions() | (TexFlags << 16); + Flags |= (HasKonst ? 0x8 : 0x0) | (mpMat->Options() & ~0x8) | (TexFlags << 16); Out.WriteLong(Flags); diff --git a/src/Core/ScriptExtra/CScriptExtra.cpp b/src/Core/ScriptExtra/CScriptExtra.cpp index 11ecff79..dd49e4f5 100644 --- a/src/Core/ScriptExtra/CScriptExtra.cpp +++ b/src/Core/ScriptExtra/CScriptExtra.cpp @@ -6,6 +6,7 @@ #include "CPointOfInterestExtra.h" #include "CDoorExtra.h" #include "CRadiusSphereExtra.h" +#include "CSplinePathExtra.h" CScriptExtra* CScriptExtra::CreateExtra(CScriptNode *pNode) { @@ -50,6 +51,12 @@ CScriptExtra* CScriptExtra::CreateExtra(CScriptNode *pNode) case 0x52414444: // "RADD" RadialDamage (MP2/MP3/DKCR) pExtra = new CRadiusSphereExtra(pObj, pNode->Scene(), pNode); break; + + case 0x53505041: // SplinePath (DKCR) + case 0x5043544C: // PathControl (DKCR) + case 0x434C5043: // ClingPathControl (DKCR) + pExtra = new CSplinePathExtra(pObj, pNode->Scene(), pNode); + break; } } diff --git a/src/Core/ScriptExtra/CScriptExtra.h b/src/Core/ScriptExtra/CScriptExtra.h index 59520108..02345d10 100644 --- a/src/Core/ScriptExtra/CScriptExtra.h +++ b/src/Core/ScriptExtra/CScriptExtra.h @@ -27,6 +27,8 @@ public: } virtual ~CScriptExtra() {} + inline CScriptObject* Instance() const { return mpInstance; } + inline EGame Game() const { return mGame; } // Default implementations for CSceneNode virtual ENodeType NodeType() { return eScriptExtraNode; } diff --git a/src/Core/ScriptExtra/CSplinePathExtra.cpp b/src/Core/ScriptExtra/CSplinePathExtra.cpp new file mode 100644 index 00000000..ac60093a --- /dev/null +++ b/src/Core/ScriptExtra/CSplinePathExtra.cpp @@ -0,0 +1,84 @@ +#include "CSplinePathExtra.h" +#include "CWaypointExtra.h" +#include "Core/Scene/CScene.h" + +CSplinePathExtra::CSplinePathExtra(CScriptObject *pInstance, CScene *pScene, CSceneNode *pParent) + : CScriptExtra(pInstance, pScene, pParent) +{ + mpPathColor = TPropCast(pInstance->Properties()->PropertyByID(0x00DD86E2)); +} + +void CSplinePathExtra::PropertyModified(IProperty *pProperty) +{ + if (pProperty == mpPathColor) + { + for (auto it = mWaypoints.begin(); it != mWaypoints.end(); it++) + (*it)->CheckColor(); + } +} + +void CSplinePathExtra::PostLoad() +{ + AddWaypoints(); +} + +void CSplinePathExtra::FindAttachedWaypoints(std::set& rChecked, CWaypointExtra *pWaypoint) +{ + if (rChecked.find(pWaypoint) != rChecked.end()) + return; + + rChecked.insert(pWaypoint); + pWaypoint->AddToSplinePath(this); + mWaypoints.push_back(pWaypoint); + + std::list Attached; + pWaypoint->GetLinkedWaypoints(Attached); + + for (auto it = Attached.begin(); it != Attached.end(); it++) + FindAttachedWaypoints(rChecked, *it); +} + +void CSplinePathExtra::AddWaypoints() +{ + if (mGame != eReturns) + return; + + std::set CheckedWaypoints; + + for (u32 iLink = 0; iLink < mpInstance->NumOutLinks(); iLink++) + { + const SLink& rkLink = mpInstance->OutLink(iLink); + + if ( (rkLink.State == 0x49533030 && rkLink.Message == 0x41544348) || // InternalState00/Attach + (rkLink.State == 0x4D4F5450 && rkLink.Message == 0x41544348) ) // MotionPath/Attach + { + CScriptNode *pNode = mpScene->ScriptNodeByID(rkLink.ObjectID); + + if (pNode && pNode->Object()->ObjectTypeID() == 0x57415950) // Waypoint + { + CWaypointExtra *pWaypoint = static_cast(pNode->Extra()); + FindAttachedWaypoints(CheckedWaypoints, pWaypoint); + } + } + } +} + +void CSplinePathExtra::RemoveWaypoint(CWaypointExtra *pWaypoint) +{ + for (auto it = mWaypoints.begin(); it != mWaypoints.end(); it++) + { + if (*it == pWaypoint) + { + mWaypoints.erase(it); + break; + } + } +} + +void CSplinePathExtra::ClearWaypoints() +{ + for (auto it = mWaypoints.begin(); it != mWaypoints.end(); it++) + (*it)->RemoveFromSplinePath(this); + + mWaypoints.clear(); +} diff --git a/src/Core/ScriptExtra/CSplinePathExtra.h b/src/Core/ScriptExtra/CSplinePathExtra.h new file mode 100644 index 00000000..42cbae62 --- /dev/null +++ b/src/Core/ScriptExtra/CSplinePathExtra.h @@ -0,0 +1,31 @@ +#ifndef CSPLINEPATHEXTRA_H +#define CSPLINEPATHEXTRA_H + +#include "CScriptExtra.h" +#include +#include +#include + +class CWaypointExtra; + +class CSplinePathExtra : public CScriptExtra +{ + // Recolor waypoint paths to match the editor color parameter + TColorProperty *mpPathColor; + std::list mWaypoints; + +public: + explicit CSplinePathExtra(CScriptObject *pInstance, CScene *pScene, CSceneNode *pParent = 0); + ~CSplinePathExtra() { ClearWaypoints(); } + inline CColor PathColor() const { return (mpPathColor ? mpPathColor->Get() : CColor::skBlack); } + + void PostLoad(); + void PropertyModified(IProperty *pProperty); + + void FindAttachedWaypoints(std::set& rChecked, CWaypointExtra *pWaypoint); + void AddWaypoints(); + void RemoveWaypoint(CWaypointExtra *pWaypoint); + void ClearWaypoints(); +}; + +#endif // CSPLINEPATHEXTRA_H diff --git a/src/Core/ScriptExtra/CWaypointExtra.cpp b/src/Core/ScriptExtra/CWaypointExtra.cpp index f80ef2a5..cd366c8f 100644 --- a/src/Core/ScriptExtra/CWaypointExtra.cpp +++ b/src/Core/ScriptExtra/CWaypointExtra.cpp @@ -8,15 +8,69 @@ CWaypointExtra::CWaypointExtra(CScriptObject *pInstance, CScene *pScene, CSceneN , mColor(CColor::skBlack) , mLinksBuilt(false) { - // Fetch color from parent node's model - CScriptNode *pScript = static_cast(pParent); - CModel *pModel = pScript->ActiveModel(); + CheckColor(); +} - if (pModel && (pModel->GetMatSetCount() > 0) && (pModel->GetMatCount() > 0)) +CWaypointExtra::~CWaypointExtra() +{ + for (auto it = mPaths.begin(); it != mPaths.end(); it++) + (*it)->RemoveWaypoint(this); +} + +void CWaypointExtra::CheckColor() +{ + // Fetch color from attached SplinePath + if (!mPaths.empty()) { - CMaterial *pMat = pModel->GetMaterialByIndex(0, 0); - mColor = pMat->Konst(0); - mColor.a = 0; + CSplinePathExtra *pPath = mPaths.front(); + mColor = pPath->PathColor(); + } + + // Fetch color from parent node's model (MP1/2/3) + else if (mGame < eReturns) + { + CScriptNode *pScript = static_cast(mpParent); + CModel *pModel = pScript->ActiveModel(); + + if (pModel && (pModel->GetMatSetCount() > 0) && (pModel->GetMatCount() > 0)) + { + CMaterial *pMat = pModel->GetMaterialByIndex(0, 0); + mColor = pMat->Konst(0); + } + } + + // Use preset color (DKCR) + else + { + mColor = CColor::skCyan; + } + + mColor.a = 0; +} + +void CWaypointExtra::AddToSplinePath(CSplinePathExtra *pPath) +{ + for (auto it = mPaths.begin(); it != mPaths.end(); it++) + { + if (*it == pPath) + return; + } + + mPaths.push_back(pPath); + if (mPaths.size() == 1) + CheckColor(); +} + +void CWaypointExtra::RemoveFromSplinePath(CSplinePathExtra *pPath) +{ + for (auto it = mPaths.begin(); it != mPaths.end(); it++) + { + if (*it == pPath) + { + mPaths.erase(it); + CheckColor(); + break; + } } } @@ -71,6 +125,18 @@ bool CWaypointExtra::IsPathLink(const SLink& rkLink) return false; } +void CWaypointExtra::GetLinkedWaypoints(std::list& rOut) +{ + if (!mLinksBuilt) BuildLinks(); + + for (u32 iLink = 0; iLink < mLinks.size(); iLink++) + { + const SWaypointLink& rkLink = mLinks[iLink]; + CWaypointExtra *pExtra = static_cast(rkLink.pWaypoint->Extra()); + rOut.push_back(pExtra); + } +} + void CWaypointExtra::LinksModified() { BuildLinks(); @@ -104,3 +170,8 @@ void CWaypointExtra::Draw(FRenderOptions /*Options*/, int ComponentIndex, const CGraphics::UpdateMVPBlock(); CDrawUtil::DrawLine(mpParent->AABox().Center(), mLinks[ComponentIndex].pWaypoint->AABox().Center(), mColor); } + +CColor CWaypointExtra::TevColor() +{ + return (mGame < eReturns ? CColor::skWhite : mColor); +} diff --git a/src/Core/ScriptExtra/CWaypointExtra.h b/src/Core/ScriptExtra/CWaypointExtra.h index d5665c49..81fca9ac 100644 --- a/src/Core/ScriptExtra/CWaypointExtra.h +++ b/src/Core/ScriptExtra/CWaypointExtra.h @@ -2,6 +2,7 @@ #define CWAYPOINTEXTRA_H #include "CScriptExtra.h" +#include "CSplinePathExtra.h" #include class CWaypointExtra : public CScriptExtra @@ -9,6 +10,7 @@ class CWaypointExtra : public CScriptExtra // Draw waypoint paths formed by script connections CColor mColor; bool mLinksBuilt; + std::list mPaths; struct SWaypointLink { @@ -19,12 +21,18 @@ class CWaypointExtra : public CScriptExtra public: explicit CWaypointExtra(CScriptObject *pInstance, CScene *pScene, CSceneNode *pParent = 0); + ~CWaypointExtra(); + void CheckColor(); + void AddToSplinePath(CSplinePathExtra *pPath); + void RemoveFromSplinePath(CSplinePathExtra *pPath); void BuildLinks(); bool IsPathLink(const SLink& rkLink); + void GetLinkedWaypoints(std::list& rOut); void LinksModified(); void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); + CColor TevColor(); }; #endif // CWAYPOINTEXTRA_H diff --git a/templates/dkcr/Script/Waypoint.xml b/templates/dkcr/Script/Waypoint.xml index a3667954..4c596647 100644 --- a/templates/dkcr/Script/Waypoint.xml +++ b/templates/dkcr/Script/Waypoint.xml @@ -15,7 +15,7 @@ - script/common/Waypoint.cmdl + script/dkcr/Waypoint.cmdl enabled enabled