mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-19 01:46:27 +00:00
Loading SCLY file properties into a new class CResourceInfo instead of loading it as a CResource
This commit is contained in:
@@ -46,12 +46,12 @@ CModel* CAreaAttributes::SkyModel() const
|
||||
switch (mGame)
|
||||
{
|
||||
case ePrime:
|
||||
return (CModel*) static_cast<TFileProperty*>(pBaseStruct->PropertyByIndex(7))->Get().RawPointer();
|
||||
return (CModel*) static_cast<TFileProperty*>(pBaseStruct->PropertyByIndex(7))->Get().Load();
|
||||
case eEchoesDemo:
|
||||
case eEchoes:
|
||||
case eCorruptionProto:
|
||||
case eCorruption:
|
||||
return (CModel*) static_cast<TFileProperty*>(pBaseStruct->PropertyByID(0xD208C9FA))->Get().RawPointer();
|
||||
return (CModel*) static_cast<TFileProperty*>(pBaseStruct->PropertyByID(0xD208C9FA))->Get().Load();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,8 @@ HEADERS += \
|
||||
Render/FRenderOptions.h \
|
||||
Scene/FShowFlags.h \
|
||||
Scene/CScene.h \
|
||||
Scene/CSceneIterator.h
|
||||
Scene/CSceneIterator.h \
|
||||
Resource/CResourceInfo.h
|
||||
|
||||
# Source Files
|
||||
SOURCES += \
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <Common/TString.h>
|
||||
#include <FileIO/FileIO.h>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
CResCache::CResCache()
|
||||
{
|
||||
@@ -208,6 +209,41 @@ CResource* CResCache::GetResource(const TString& ResPath)
|
||||
return Res;
|
||||
}
|
||||
|
||||
CFourCC CResCache::FindResourceType(CUniqueID ResID, const TStringList& rkPossibleTypes)
|
||||
{
|
||||
// If we only have one type then there's only one possibility.
|
||||
if (rkPossibleTypes.size() == 1)
|
||||
return CFourCC(rkPossibleTypes.front());
|
||||
|
||||
// Determine extension from pak
|
||||
if (mResSource.Source == SResSource::PakFile)
|
||||
{
|
||||
for (auto it = rkPossibleTypes.begin(); it != rkPossibleTypes.end(); it++)
|
||||
{
|
||||
SResInfo ResInfo = mpPak->getResourceInfo(ResID.ToLongLong(), CFourCC(*it));
|
||||
|
||||
if (ResInfo.resType != "NULL")
|
||||
return CFourCC(*it);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine extension from filesystem - try every extension until we find one that works
|
||||
else
|
||||
{
|
||||
TString PathBase = mResSource.Path + ResID.ToString() + ".";
|
||||
|
||||
for (auto it = rkPossibleTypes.begin(); it != rkPossibleTypes.end(); it++)
|
||||
{
|
||||
TString NewPath = PathBase + *it;
|
||||
|
||||
if (boost::filesystem::exists(NewPath.ToStdString()))
|
||||
return CFourCC(*it);
|
||||
}
|
||||
}
|
||||
|
||||
return "UNKN";
|
||||
}
|
||||
|
||||
void CResCache::CacheResource(CResource *pRes)
|
||||
{
|
||||
u64 ID = pRes->ResID().ToLongLong();
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
TString GetSourcePath();
|
||||
CResource* GetResource(CUniqueID ResID, CFourCC type);
|
||||
CResource* GetResource(const TString& ResPath);
|
||||
CFourCC FindResourceType(CUniqueID ResID, const TStringList& rkPossibleTypes);
|
||||
void CacheResource(CResource *pRes);
|
||||
void DeleteResource(CUniqueID ResID);
|
||||
};
|
||||
|
||||
70
src/Core/Resource/CResourceInfo.h
Normal file
70
src/Core/Resource/CResourceInfo.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef CRESOURCEINFO
|
||||
#define CRESOURCEINFO
|
||||
|
||||
#include "CResource.h"
|
||||
#include "CResCache.h"
|
||||
#include <Common/CUniqueID.h>
|
||||
#include <Common/CFourCC.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
class CResourceInfo
|
||||
{
|
||||
TString mPath;
|
||||
bool mIsPath;
|
||||
bool mIsValidPath;
|
||||
|
||||
public:
|
||||
CResourceInfo()
|
||||
: mPath(""), mIsPath(false), mIsValidPath(false) {}
|
||||
|
||||
CResourceInfo(const TString& rkPath)
|
||||
: mPath(rkPath), mIsPath(true)
|
||||
{
|
||||
mIsValidPath = boost::filesystem::exists(rkPath.ToStdString());
|
||||
}
|
||||
|
||||
CResourceInfo(const CUniqueID& rkID, CFourCC Type)
|
||||
: mIsPath(false), mIsValidPath(false)
|
||||
{
|
||||
mPath = rkID.ToString() + "." + Type.ToString();
|
||||
}
|
||||
|
||||
inline CUniqueID ID() const
|
||||
{
|
||||
if (!mIsPath)
|
||||
return CUniqueID::FromString(mPath.GetFileName());
|
||||
else
|
||||
return CUniqueID::skInvalidID64;
|
||||
}
|
||||
|
||||
inline CFourCC Type() const
|
||||
{
|
||||
return mPath.GetFileExtension();
|
||||
}
|
||||
|
||||
inline TString ToString() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
inline CResource* Load() const
|
||||
{
|
||||
if (!IsValid())
|
||||
return nullptr;
|
||||
if (mIsPath)
|
||||
return gResCache.GetResource(mPath);
|
||||
else
|
||||
return gResCache.GetResource(ID(), Type());
|
||||
}
|
||||
|
||||
inline bool IsValid() const
|
||||
{
|
||||
if (!mIsPath)
|
||||
return ID().IsValid();
|
||||
else
|
||||
return mIsValidPath;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRESOURCEINFO
|
||||
|
||||
@@ -97,43 +97,17 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& SCLY)
|
||||
TFileProperty *pFileCast = static_cast<TFileProperty*>(pProp);
|
||||
|
||||
CUniqueID ResID = (mVersion < eCorruptionProto ? SCLY.ReadLong() : SCLY.ReadLongLong());
|
||||
const TStringList& Extensions = static_cast<CFileTemplate*>(pTemp)->Extensions();
|
||||
const TStringList& rkExtensions = static_cast<CFileTemplate*>(pTemp)->Extensions();
|
||||
|
||||
CResource *pRes = nullptr;
|
||||
|
||||
// Check for each extension individually until we find a match
|
||||
// This could be done better with a function to fetch the extension given the resource ID
|
||||
// and a "does resource exist" function, but this will do for now
|
||||
bool hasIgnoredExt = false;
|
||||
CResourceInfo Info(ResID, "UNKN");
|
||||
|
||||
if (ResID.IsValid())
|
||||
{
|
||||
for (auto it = Extensions.begin(); it != Extensions.end(); it++)
|
||||
{
|
||||
const TString& ext = *it;
|
||||
|
||||
if ((ext != "MREA") && (ext != "MLVL")) {
|
||||
pRes = gResCache.GetResource(ResID, ext);
|
||||
if (pRes) break;
|
||||
}
|
||||
|
||||
else
|
||||
hasIgnoredExt = true;
|
||||
}
|
||||
CFourCC Type = gResCache.FindResourceType(ResID, rkExtensions);
|
||||
Info = CResourceInfo(ResID, Type);
|
||||
}
|
||||
|
||||
// Property may have an incorrect extension listed - print error
|
||||
if ((!pRes) && (CUniqueID(ResID).IsValid()) && (!hasIgnoredExt))
|
||||
{
|
||||
TString ExtList;
|
||||
for (auto it = Extensions.begin(); it != Extensions.end(); it++)
|
||||
{
|
||||
if (it != Extensions.begin()) ExtList += "/";
|
||||
ExtList += *it;
|
||||
}
|
||||
}
|
||||
|
||||
pFileCast->Set(pRes);
|
||||
pFileCast->Set(Info);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ struct SResInfo
|
||||
u64 resID;
|
||||
u32 offset;
|
||||
u32 size;
|
||||
|
||||
SResInfo()
|
||||
: compressed(false), resType("NULL"), resID(0), offset(0), size(0) {}
|
||||
};
|
||||
|
||||
#endif // SRESINFO_H
|
||||
|
||||
@@ -228,7 +228,7 @@ CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties)
|
||||
if (pProp->Type() == eFileProperty)
|
||||
{
|
||||
TFileProperty *pFile = static_cast<TFileProperty*>(pProp);
|
||||
pRes = pFile->Get();
|
||||
pRes = pFile->Get().Load();
|
||||
}
|
||||
|
||||
else if (pProp->Type() == eCharacterProperty)
|
||||
@@ -268,7 +268,7 @@ CTexture* CScriptTemplate::FindBillboardTexture(CPropertyStruct *pProperties)
|
||||
if (pProp->Type() == eFileProperty)
|
||||
{
|
||||
TFileProperty *pFile = static_cast<TFileProperty*>(pProp);
|
||||
pRes = pFile->Get();
|
||||
pRes = pFile->Get().Load();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties
|
||||
if (pProp->Type() == eFileProperty)
|
||||
{
|
||||
TFileProperty *pFile = static_cast<TFileProperty*>(pProp);
|
||||
pRes = pFile->Get();
|
||||
pRes = pFile->Get().Load();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ bool CScriptTemplate::HasInGameModel(CPropertyStruct *pProperties)
|
||||
if (pProp->Type() == eFileProperty)
|
||||
{
|
||||
TFileProperty *pFile = static_cast<TFileProperty*>(pProp);
|
||||
pRes = pFile->Get();
|
||||
pRes = pFile->Get().Load();
|
||||
}
|
||||
|
||||
else if (pProp->Type() == eCharacterProperty)
|
||||
|
||||
@@ -67,7 +67,7 @@ typedef TTypedProperty<float, eFloatProperty, CFloatValue>
|
||||
typedef TTypedProperty<TString, eStringProperty, CStringValue> TStringProperty;
|
||||
typedef TTypedProperty<CVector3f, eVector3Property, CVector3Value> TVector3Property;
|
||||
typedef TTypedProperty<CColor, eColorProperty, CColorValue> TColorProperty;
|
||||
typedef TTypedProperty<TResPtr<CResource>, eFileProperty, CFileValue> TFileProperty;
|
||||
typedef TTypedProperty<CResourceInfo, eFileProperty, CFileValue> TFileProperty;
|
||||
typedef TTypedProperty<CAnimationParameters, eCharacterProperty, CCharacterValue> TAnimParamsProperty;
|
||||
typedef TTypedProperty<std::vector<u8>, eUnknownProperty, CUnknownValue> TUnknownProperty;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Core/Log.h"
|
||||
#include "Core/Resource/CAnimationParameters.h"
|
||||
#include "Core/Resource/CResource.h"
|
||||
#include "Core/Resource/CResourceInfo.h"
|
||||
#include "Core/Resource/TResPtr.h"
|
||||
|
||||
#include <Common/CColor.h>
|
||||
@@ -253,11 +254,11 @@ public:
|
||||
void FromString(const TString&) { }
|
||||
};
|
||||
|
||||
class CFileValue : public TTypedPropertyValue<TResPtr<CResource>>
|
||||
class CFileValue : public TTypedPropertyValue<CResourceInfo>
|
||||
{
|
||||
public:
|
||||
CFileValue() {}
|
||||
CFileValue(CResource *pRes) { mValue = pRes; }
|
||||
CFileValue(const CResourceInfo& rkInfo) { mValue = rkInfo; }
|
||||
|
||||
TString ToString() const { return ""; }
|
||||
void FromString(const TString&) { }
|
||||
|
||||
@@ -167,7 +167,7 @@ void CDamageableTriggerExtra::PropertyModified(IProperty *pProperty)
|
||||
{
|
||||
if (pProperty == mpTextureProps[iTex])
|
||||
{
|
||||
mpTextures[iTex] = mpTextureProps[iTex]->Get();
|
||||
mpTextures[iTex] = mpTextureProps[iTex]->Get().Load();
|
||||
|
||||
if (mpTextures[iTex] && mpTextures[iTex]->Type() != eTexture)
|
||||
mpTextures[iTex] = nullptr;
|
||||
|
||||
@@ -41,7 +41,7 @@ void CDoorExtra::PropertyModified(IProperty *pProperty)
|
||||
{
|
||||
if (pProperty == mpShieldModelProp)
|
||||
{
|
||||
mpShieldModel = mpShieldModelProp->Get();
|
||||
mpShieldModel = mpShieldModelProp->Get().Load();
|
||||
|
||||
if (mpShieldModel)
|
||||
mLocalAABox = mpShieldModel->AABox();
|
||||
|
||||
@@ -42,7 +42,7 @@ CPointOfInterestExtra::CPointOfInterestExtra(CScriptObject *pInstance, CScene *p
|
||||
void CPointOfInterestExtra::PropertyModified(IProperty* pProperty)
|
||||
{
|
||||
if (mpScanProperty == pProperty)
|
||||
mpScanData = mpScanProperty->Get();
|
||||
mpScanData = mpScanProperty->Get().Load();
|
||||
}
|
||||
|
||||
void CPointOfInterestExtra::ModifyTintColor(CColor& Color)
|
||||
|
||||
Reference in New Issue
Block a user