mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-21 10:49:23 +00:00
Added rel/rso module dependencies to the script template format
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "CDependencyTree.h"
|
||||
#include "Core/Resource/Script/CMasterTemplate.h"
|
||||
#include "Core/Resource/Script/CScriptLayer.h"
|
||||
#include "Core/Resource/Script/CScriptObject.h"
|
||||
|
||||
@@ -370,3 +371,57 @@ CScriptInstanceDependencyTree* CAreaDependencyTree::ScriptInstanceByIndex(u32 In
|
||||
ASSERT(Index >= 0 && Index < mScriptInstances.size());
|
||||
return mScriptInstances[Index];
|
||||
}
|
||||
|
||||
void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector<TString>& rModuleDepsOut, std::vector<u32>& rModuleLayerOffsetsOut) const
|
||||
{
|
||||
CMasterTemplate *pMaster = CMasterTemplate::MasterForGame(Game);
|
||||
|
||||
// Output module list will be split per-script layer
|
||||
// The output offset list contains two offsets per layer - start index and end index
|
||||
for (u32 iLayer = 0; iLayer < mLayerOffsets.size(); iLayer++)
|
||||
{
|
||||
u32 StartIdx = mLayerOffsets[iLayer];
|
||||
u32 EndIdx = (iLayer == mLayerOffsets.size() - 1 ? mScriptInstances.size() : mLayerOffsets[iLayer + 1]);
|
||||
|
||||
u32 ModuleStartIdx = rModuleDepsOut.size();
|
||||
rModuleLayerOffsetsOut.push_back(ModuleStartIdx);
|
||||
|
||||
// Keep track of which types we've already checked on this layer to speed things up a little...
|
||||
std::set<u32> UsedObjectTypes;
|
||||
|
||||
for (u32 iInst = StartIdx; iInst < EndIdx; iInst++)
|
||||
{
|
||||
CScriptInstanceDependencyTree *pInst = mScriptInstances[iInst];
|
||||
u32 ObjType = pInst->ObjectType();
|
||||
|
||||
if (UsedObjectTypes.find(ObjType) == UsedObjectTypes.end())
|
||||
{
|
||||
// Get the module list for this object type and check whether any of them are new before adding them to the output list
|
||||
CScriptTemplate *pTemplate = pMaster->TemplateByID(ObjType);
|
||||
const std::vector<TString>& rkModules = pTemplate->RequiredModules();
|
||||
|
||||
for (u32 iMod = 0; iMod < rkModules.size(); iMod++)
|
||||
{
|
||||
TString ModuleName = rkModules[iMod];
|
||||
bool NewModule = true;
|
||||
|
||||
for (u32 iUsed = ModuleStartIdx; iUsed < rModuleDepsOut.size(); iUsed++)
|
||||
{
|
||||
if (rModuleDepsOut[iUsed] == ModuleName)
|
||||
{
|
||||
NewModule = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NewModule)
|
||||
rModuleDepsOut.push_back(ModuleName);
|
||||
}
|
||||
|
||||
UsedObjectTypes.insert(ObjType);
|
||||
}
|
||||
}
|
||||
|
||||
rModuleLayerOffsetsOut.push_back(rModuleDepsOut.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +162,7 @@ public:
|
||||
|
||||
void AddScriptLayer(CScriptLayer *pLayer);
|
||||
CScriptInstanceDependencyTree* ScriptInstanceByIndex(u32 Index) const;
|
||||
void GetModuleDependencies(EGame Game, std::vector<TString>& rModuleDepsOut, std::vector<u32>& rModuleLayerOffsetsOut) const;
|
||||
|
||||
// Accessors
|
||||
inline u32 NumScriptLayers() const { return mLayerOffsets.size(); }
|
||||
|
||||
@@ -244,6 +244,20 @@ void CTemplateWriter::SaveScriptTemplate(CScriptTemplate *pTemp)
|
||||
pName->SetText(*pTemp->Name());
|
||||
pRoot->LinkEndChild(pName);
|
||||
|
||||
// Write modules
|
||||
if (!pTemp->mModules.empty())
|
||||
{
|
||||
XMLElement *pModules = ScriptXML.NewElement("modules");
|
||||
pRoot->LinkEndChild(pModules);
|
||||
|
||||
for (u32 iMod = 0; iMod < pTemp->mModules.size(); iMod++)
|
||||
{
|
||||
XMLElement *pModule = ScriptXML.NewElement("module");
|
||||
pModule->SetText(*pTemp->mModules[iMod]);
|
||||
pModules->LinkEndChild(pModule);
|
||||
}
|
||||
}
|
||||
|
||||
// Write properties
|
||||
SaveProperties(&ScriptXML, pRoot, pTemp->mpBaseStruct);
|
||||
|
||||
|
||||
@@ -427,6 +427,20 @@ CScriptTemplate* CTemplateLoader::LoadScriptTemplate(XMLDocument *pDoc, const TS
|
||||
pScript->mpBaseStruct->SetName(pScript->mTemplateName);
|
||||
}
|
||||
|
||||
// Modules
|
||||
XMLElement *pModulesElem = pRoot->FirstChildElement("modules");
|
||||
|
||||
if (pModulesElem)
|
||||
{
|
||||
XMLElement *pModuleElem = pModulesElem->FirstChildElement("module");
|
||||
|
||||
while (pModuleElem)
|
||||
{
|
||||
pScript->mModules.push_back(pModuleElem->GetText());
|
||||
pModuleElem = pModuleElem->NextSiblingElement("module");
|
||||
}
|
||||
}
|
||||
|
||||
// Properties
|
||||
XMLElement *pPropsElem = pRoot->FirstChildElement("properties");
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ private:
|
||||
CStructTemplate *mpBaseStruct;
|
||||
std::list<CScriptObject*> mObjectList;
|
||||
TString mTemplateName;
|
||||
std::vector<TString> mModules;
|
||||
TString mSourceFile;
|
||||
u32 mObjectID;
|
||||
bool mVisible;
|
||||
@@ -116,27 +117,28 @@ public:
|
||||
CCollisionMeshGroup* FindCollision(CPropertyStruct *pProperties);
|
||||
|
||||
// Accessors
|
||||
inline CMasterTemplate* MasterTemplate() const { return mpMaster; }
|
||||
inline TString Name() const { return mTemplateName; }
|
||||
inline ERotationType RotationType() const { return mRotationType; }
|
||||
inline EScaleType ScaleType() const { return mScaleType; }
|
||||
inline float PreviewScale() const { return mPreviewScale; }
|
||||
inline u32 ObjectID() const { return mObjectID; }
|
||||
inline bool IsVisible() const { return mVisible; }
|
||||
inline TString SourceFile() const { return mSourceFile; }
|
||||
inline CStructTemplate* BaseStruct() const { return mpBaseStruct; }
|
||||
inline u32 NumAttachments() const { return mAttachments.size(); }
|
||||
const SAttachment& Attachment(u32 Index) const { return mAttachments[Index]; }
|
||||
inline CMasterTemplate* MasterTemplate() const { return mpMaster; }
|
||||
inline TString Name() const { return mTemplateName; }
|
||||
inline ERotationType RotationType() const { return mRotationType; }
|
||||
inline EScaleType ScaleType() const { return mScaleType; }
|
||||
inline float PreviewScale() const { return mPreviewScale; }
|
||||
inline u32 ObjectID() const { return mObjectID; }
|
||||
inline bool IsVisible() const { return mVisible; }
|
||||
inline TString SourceFile() const { return mSourceFile; }
|
||||
inline CStructTemplate* BaseStruct() const { return mpBaseStruct; }
|
||||
inline u32 NumAttachments() const { return mAttachments.size(); }
|
||||
const SAttachment& Attachment(u32 Index) const { return mAttachments[Index]; }
|
||||
const std::vector<TString>& RequiredModules() const { return mModules; }
|
||||
|
||||
inline bool HasName() const { return !mNameIDString.IsEmpty(); }
|
||||
inline bool HasPosition() const { return !mPositionIDString.IsEmpty(); }
|
||||
inline bool HasRotation() const { return !mRotationIDString.IsEmpty(); }
|
||||
inline bool HasScale() const { return !mScaleIDString.IsEmpty(); }
|
||||
inline bool HasActive() const { return !mActiveIDString.IsEmpty(); }
|
||||
inline bool HasName() const { return !mNameIDString.IsEmpty(); }
|
||||
inline bool HasPosition() const { return !mPositionIDString.IsEmpty(); }
|
||||
inline bool HasRotation() const { return !mRotationIDString.IsEmpty(); }
|
||||
inline bool HasScale() const { return !mScaleIDString.IsEmpty(); }
|
||||
inline bool HasActive() const { return !mActiveIDString.IsEmpty(); }
|
||||
|
||||
inline void SetVisible(bool Visible) { mVisible = Visible; }
|
||||
inline void SetVisible(bool Visible) { mVisible = Visible; }
|
||||
|
||||
inline void DebugPrintProperties() { mpBaseStruct->DebugPrintProperties(""); }
|
||||
inline void DebugPrintProperties() { mpBaseStruct->DebugPrintProperties(""); }
|
||||
|
||||
// Object Tracking
|
||||
u32 NumObjects() const;
|
||||
|
||||
Reference in New Issue
Block a user