Dropped support for transient resources; I am not using this functionality at all whatsoever and likely won't for a while, so why do I have it?

This commit is contained in:
Aruki 2017-05-07 20:29:33 -06:00
parent 283444cea4
commit f72f82d519
29 changed files with 156 additions and 330 deletions

View File

@ -33,11 +33,6 @@ CAssetID::CAssetID(u64 ID, EIDLength Length)
mID &= 0xFFFFFFFF; mID &= 0xFFFFFFFF;
} }
CAssetID::CAssetID(const char* pkID)
{
*this = CAssetID::FromString(pkID);
}
void CAssetID::Write(IOutputStream& rOutput) const void CAssetID::Write(IOutputStream& rOutput) const
{ {
if (mLength == e32Bit) if (mLength == e32Bit)

View File

@ -22,7 +22,6 @@ public:
CAssetID(); CAssetID();
CAssetID(u64 ID); CAssetID(u64 ID);
CAssetID(u64 ID, EIDLength Length); CAssetID(u64 ID, EIDLength Length);
CAssetID(const char* pkID);
CAssetID(IInputStream& rInput, EIDLength Length); CAssetID(IInputStream& rInput, EIDLength Length);
CAssetID(IInputStream& rInput, EGame Game); CAssetID(IInputStream& rInput, EGame Game);
void Write(IOutputStream& rOutput) const; void Write(IOutputStream& rOutput) const;
@ -31,7 +30,6 @@ public:
// Operators // Operators
inline void operator= (const u64& rkInput) { *this = CAssetID(rkInput); } inline void operator= (const u64& rkInput) { *this = CAssetID(rkInput); }
inline void operator= (const char *pkInput) { *this = CAssetID(pkInput); }
inline bool operator==(const CAssetID& rkOther) const { return mLength == rkOther.mLength && mID == rkOther.mID; } inline bool operator==(const CAssetID& rkOther) const { return mLength == rkOther.mLength && mID == rkOther.mID; }
inline bool operator!=(const CAssetID& rkOther) const { return mLength != rkOther.mLength || mID != rkOther.mID; } inline bool operator!=(const CAssetID& rkOther) const { return mLength != rkOther.mLength || mID != rkOther.mID; }
inline bool operator> (const CAssetID& rkOther) const { return mLength >= rkOther.mLength && mID > rkOther.mID; } inline bool operator> (const CAssetID& rkOther) const { return mLength >= rkOther.mLength && mID > rkOther.mID; }

View File

@ -47,13 +47,13 @@ CModel* CAreaAttributes::SkyModel() const
switch (mGame) switch (mGame)
{ {
case ePrime: case ePrime:
return (CModel*) gpResourceStore->LoadResource( static_cast<TAssetProperty*>(pBaseStruct->PropertyByIndex(7))->Get(), "CMDL" ); return gpResourceStore->LoadResource<CModel>( static_cast<TAssetProperty*>(pBaseStruct->PropertyByIndex(7))->Get() );
case eEchoesDemo: case eEchoesDemo:
case eEchoes: case eEchoes:
case eCorruptionProto: case eCorruptionProto:
case eCorruption: case eCorruption:
case eReturns: case eReturns:
return (CModel*) gpResourceStore->LoadResource( static_cast<TAssetProperty*>(pBaseStruct->PropertyByID(0xD208C9FA))->Get(), "CMDL" ); return gpResourceStore->LoadResource<CModel>( static_cast<TAssetProperty*>(pBaseStruct->PropertyByID(0xD208C9FA))->Get() );
default: default:
return nullptr; return nullptr;
} }

View File

@ -45,14 +45,14 @@ void CAudioManager::LoadAssets()
CAssetID AudioLookupID = mpProject->FindNamedResource(AudioLookupName); CAssetID AudioLookupID = mpProject->FindNamedResource(AudioLookupName);
if (AudioLookupID.IsValid()) if (AudioLookupID.IsValid())
mpAudioLookupTable = mpProject->ResourceStore()->LoadResource(AudioLookupID, "ATBL"); mpAudioLookupTable = mpProject->ResourceStore()->LoadResource<CAudioLookupTable>(AudioLookupID);
if (mpProject->Game() >= eEchoesDemo) if (mpProject->Game() >= eEchoesDemo)
{ {
CAssetID SfxNameListID = mpProject->FindNamedResource("audio_name_lookup_STLC"); CAssetID SfxNameListID = mpProject->FindNamedResource("audio_name_lookup_STLC");
if (SfxNameListID.IsValid()) if (SfxNameListID.IsValid())
mpSfxNameList = mpProject->ResourceStore()->LoadResource(SfxNameListID, "STLC"); mpSfxNameList = mpProject->ResourceStore()->LoadResource<CStringList>(SfxNameListID);
} }
} }

View File

@ -32,7 +32,7 @@ void ApplyGeneratedName(CResourceEntry *pEntry, const TString& rkDir, const TStr
if (pEntry->Game() >= eCorruptionProto) if (pEntry->Game() >= eCorruptionProto)
SanitizedDir = SanitizedDir.ToLower(); SanitizedDir = SanitizedDir.ToLower();
CVirtualDirectory *pNewDir = pEntry->ResourceStore()->GetVirtualDirectory(SanitizedDir, false, true); CVirtualDirectory *pNewDir = pEntry->ResourceStore()->GetVirtualDirectory(SanitizedDir, true);
if (pEntry->Directory() == pNewDir && pEntry->Name() == SanitizedName) return; if (pEntry->Directory() == pNewDir && pEntry->Name() == SanitizedName) return;
TString Name = SanitizedName; TString Name = SanitizedName;

View File

@ -468,35 +468,32 @@ void CGameExporter::ExportResourceEditorData()
// should really be doing this by dependency order instead of by ID order. // should really be doing this by dependency order instead of by ID order.
for (CResourceIterator It(mpStore); It; ++It) for (CResourceIterator It(mpStore); It; ++It)
{ {
if (!It->IsTransient()) // Worlds need some info we can only get from the pak at export time; namely, which areas can
// have duplicates, as well as the world's internal name.
if (It->ResourceType() == eWorld)
{ {
// Worlds need some info we can only get from the pak at export time; namely, which areas can CWorld *pWorld = (CWorld*) It->Load();
// have duplicates, as well as the world's internal name.
if (It->ResourceType() == eWorld) // Set area duplicate flags
for (u32 iArea = 0; iArea < pWorld->NumAreas(); iArea++)
{ {
CWorld *pWorld = (CWorld*) It->Load(); CAssetID AreaID = pWorld->AreaResourceID(iArea);
auto Find = mAreaDuplicateMap.find(AreaID);
// Set area duplicate flags if (Find != mAreaDuplicateMap.end())
for (u32 iArea = 0; iArea < pWorld->NumAreas(); iArea++) pWorld->SetAreaAllowsPakDuplicates(iArea, Find->second);
{
CAssetID AreaID = pWorld->AreaResourceID(iArea);
auto Find = mAreaDuplicateMap.find(AreaID);
if (Find != mAreaDuplicateMap.end())
pWorld->SetAreaAllowsPakDuplicates(iArea, Find->second);
}
// Set world name
TString WorldName = MakeWorldName(pWorld->ID());
pWorld->SetName(WorldName);
} }
// Save raw resource + generate dependencies // Set world name
if (It->TypeInfo()->CanBeSerialized()) TString WorldName = MakeWorldName(pWorld->ID());
It->Save(true); pWorld->SetName(WorldName);
else
It->UpdateDependencies();
} }
// Save raw resource + generate dependencies
if (It->TypeInfo()->CanBeSerialized())
It->Save(true);
else
It->UpdateDependencies();
} }
} }
{ {

View File

@ -12,7 +12,7 @@
CResourceEntry::CResourceEntry(CResourceStore *pStore, const CAssetID& rkID, CResourceEntry::CResourceEntry(CResourceStore *pStore, const CAssetID& rkID,
const TString& rkDir, const TString& rkFilename, const TString& rkDir, const TString& rkFilename,
EResType Type, bool Transient /*= false*/) EResType Type)
: mpResource(nullptr) : mpResource(nullptr)
, mpStore(pStore) , mpStore(pStore)
, mpDependencies(nullptr) , mpDependencies(nullptr)
@ -25,9 +25,7 @@ CResourceEntry::CResourceEntry(CResourceStore *pStore, const CAssetID& rkID,
mpTypeInfo = CResTypeInfo::FindTypeInfo(Type); mpTypeInfo = CResTypeInfo::FindTypeInfo(Type);
ASSERT(mpTypeInfo); ASSERT(mpTypeInfo);
if (Transient) mFlags |= eREF_Transient; mpDirectory = mpStore->GetVirtualDirectory(rkDir, true);
mpDirectory = mpStore->GetVirtualDirectory(rkDir, Transient, true);
if (mpDirectory) mpDirectory->AddChild("", this); if (mpDirectory) mpDirectory->AddChild("", this);
} }
@ -39,8 +37,6 @@ CResourceEntry::~CResourceEntry()
void CResourceEntry::SerializeCacheData(IArchive& rArc) void CResourceEntry::SerializeCacheData(IArchive& rArc)
{ {
ASSERT(!IsTransient());
u32 Flags = mFlags & eREF_SavedFlags; u32 Flags = mFlags & eREF_SavedFlags;
rArc << SERIAL_AUTO(Flags); rArc << SERIAL_AUTO(Flags);
if (rArc.IsReader()) mFlags = Flags & eREF_SavedFlags; if (rArc.IsReader()) mFlags = Flags & eREF_SavedFlags;
@ -99,7 +95,7 @@ TString CResourceEntry::RawAssetPath(bool Relative) const
TString Ext = RawExtension(); TString Ext = RawExtension();
TString Path = mpDirectory ? mpDirectory->FullPath() : ""; TString Path = mpDirectory ? mpDirectory->FullPath() : "";
TString Name = mName + "." + Ext; TString Name = mName + "." + Ext;
return ((IsTransient() || Relative) ? Path + Name : mpStore->RawDir(false) + Path + Name); return Relative ? Path + Name : mpStore->RawDir(false) + Path + Name;
} }
TString CResourceEntry::RawExtension() const TString CResourceEntry::RawExtension() const
@ -112,7 +108,7 @@ TString CResourceEntry::CookedAssetPath(bool Relative) const
TString Ext = CookedExtension().ToString(); TString Ext = CookedExtension().ToString();
TString Path = mpDirectory ? mpDirectory->FullPath() : ""; TString Path = mpDirectory ? mpDirectory->FullPath() : "";
TString Name = mName + "." + Ext; TString Name = mName + "." + Ext;
return ((IsTransient() || Relative) ? Path + Name : mpStore->CookedDir(false) + Path + Name); return Relative ? Path + Name : mpStore->CookedDir(false) + Path + Name;
} }
CFourCC CResourceEntry::CookedExtension() const CFourCC CResourceEntry::CookedExtension() const
@ -267,11 +263,12 @@ bool CResourceEntry::Cook()
CResource* CResourceEntry::Load() CResource* CResourceEntry::Load()
{ {
// If the asset is already loaded then just return it immediately
if (mpResource) return mpResource;
// Always try to load raw version as the raw version contains extra editor-only data. // Always try to load raw version as the raw version contains extra editor-only data.
// If there is no raw version (which will be the case for resource types that don't // If there is no raw version (which will be the case for resource types that don't
// support serialization yet) then load the cooked version as a backup. // support serialization yet) then load the cooked version as a backup.
if (mpResource) return mpResource;
if (HasRawVersion()) if (HasRawVersion())
{ {
mpResource = CResourceFactory::SpawnResource(this); mpResource = CResourceFactory::SpawnResource(this);
@ -353,14 +350,11 @@ bool CResourceEntry::Unload()
bool CResourceEntry::CanMoveTo(const TString& rkDir, const TString& rkName) bool CResourceEntry::CanMoveTo(const TString& rkDir, const TString& rkName)
{ {
// Transient resources can't be moved
if (IsTransient()) return false;
// Validate that the path/name are valid // Validate that the path/name are valid
if (!mpStore->IsValidResourcePath(rkDir, rkName)) return false; if (!mpStore->IsValidResourcePath(rkDir, rkName)) return false;
// We need to validate the path isn't taken already - either the directory doesn't exist, or doesn't have a resource by this name // We need to validate the path isn't taken already - either the directory doesn't exist, or doesn't have a resource by this name
CVirtualDirectory *pDir = mpStore->GetVirtualDirectory(rkDir, false, false); CVirtualDirectory *pDir = mpStore->GetVirtualDirectory(rkDir, false);
if (pDir && pDir->FindChildResource(rkName, ResourceType())) return false; if (pDir && pDir->FindChildResource(rkName, ResourceType())) return false;
// All checks are true // All checks are true
@ -378,7 +372,7 @@ bool CResourceEntry::Move(const TString& rkDir, const TString& rkName)
TString OldRawPath = RawAssetPath(); TString OldRawPath = RawAssetPath();
// Set new directory and name // Set new directory and name
CVirtualDirectory *pNewDir = mpStore->GetVirtualDirectory(rkDir, IsTransient(), true); CVirtualDirectory *pNewDir = mpStore->GetVirtualDirectory(rkDir, true);
if (pNewDir == mpDirectory && rkName == mName) return false; if (pNewDir == mpDirectory && rkName == mName) return false;
// Check if we can legally move to this spot // Check if we can legally move to this spot
@ -459,35 +453,6 @@ bool CResourceEntry::Move(const TString& rkDir, const TString& rkName)
} }
} }
void CResourceEntry::AddToProject(const TString& rkDir, const TString& rkName)
{
if (mFlags.HasFlag(eREF_Transient))
{
mFlags.ClearFlag(eREF_Transient);
Move(rkDir, rkName);
}
else
{
Log::Error("AddToProject called on non-transient resource entry: " + CookedAssetPath(true));
}
}
void CResourceEntry::RemoveFromProject()
{
if (!mFlags.HasFlag(eREF_Transient))
{
TString Dir = CookedAssetPath().GetFileDirectory();
mFlags.SetFlag(eREF_Transient);
Move(Dir, mName);
}
else
{
Log::Error("RemoveFromProject called on transient resource entry: " + CookedAssetPath(true));
}
}
CGameProject* CResourceEntry::Project() const CGameProject* CResourceEntry::Project() const
{ {
return mpStore ? mpStore->Project() : nullptr; return mpStore ? mpStore->Project() : nullptr;

View File

@ -17,7 +17,7 @@ class CDependencyTree;
enum EResEntryFlag enum EResEntryFlag
{ {
eREF_NeedsRecook = 0x00000001, // Resource has been updated but not recooked eREF_NeedsRecook = 0x00000001, // Resource has been updated but not recooked
eREF_Transient = 0x00000002, // Resource is transient (not part of a game project resource DB) // UNUSED = 0x00000002,
eREF_Hidden = 0x00000004, // Resource is hidden, doesn't show up in resource browser eREF_Hidden = 0x00000004, // Resource is hidden, doesn't show up in resource browser
eREF_HasBeenModified = 0x00000008, // Resource has been modified and resaved by the user eREF_HasBeenModified = 0x00000008, // Resource has been modified and resaved by the user
eREF_IsUserResource = 0x00000010, // Resource was created by the user (i.e. isn't a Retro Studios asset) eREF_IsUserResource = 0x00000010, // Resource was created by the user (i.e. isn't a Retro Studios asset)
@ -43,7 +43,7 @@ class CResourceEntry
public: public:
CResourceEntry(CResourceStore *pStore, const CAssetID& rkID, CResourceEntry(CResourceStore *pStore, const CAssetID& rkID,
const TString& rkDir, const TString& rkFilename, const TString& rkDir, const TString& rkFilename,
EResType Type, bool Transient = false); EResType Type);
~CResourceEntry(); ~CResourceEntry();
void SerializeCacheData(IArchive& rArc); void SerializeCacheData(IArchive& rArc);
@ -65,8 +65,6 @@ public:
bool Unload(); bool Unload();
bool CanMoveTo(const TString& rkDir, const TString& rkName); bool CanMoveTo(const TString& rkDir, const TString& rkName);
bool Move(const TString& rkDir, const TString& rkName); bool Move(const TString& rkDir, const TString& rkName);
void AddToProject(const TString& rkDir, const TString& rkName);
void RemoveFromProject();
CGameProject* Project() const; CGameProject* Project() const;
EGame Game() const; EGame Game() const;
@ -87,7 +85,6 @@ public:
inline TString Name() const { return mName; } inline TString Name() const { return mName; }
inline const TString& UppercaseName() const { return mCachedUppercaseName; } inline const TString& UppercaseName() const { return mCachedUppercaseName; }
inline EResType ResourceType() const { return mpTypeInfo->Type(); } inline EResType ResourceType() const { return mpTypeInfo->Type(); }
inline bool IsTransient() const { return mFlags.HasFlag(eREF_Transient); }
inline bool IsHidden() const { return mFlags.HasFlag(eREF_Hidden); } inline bool IsHidden() const { return mFlags.HasFlag(eREF_Hidden); }
protected: protected:

View File

@ -56,9 +56,6 @@ CResourceStore::~CResourceStore()
for (auto It = mResourceEntries.begin(); It != mResourceEntries.end(); It++) for (auto It = mResourceEntries.begin(); It != mResourceEntries.end(); It++)
delete It->second; delete It->second;
for (auto It = mTransientRoots.begin(); It != mTransientRoots.end(); It++)
delete *It;
} }
void CResourceStore::SerializeResourceDatabase(IArchive& rArc) void CResourceStore::SerializeResourceDatabase(IArchive& rArc)
@ -83,10 +80,7 @@ void CResourceStore::SerializeResourceDatabase(IArchive& rArc)
Resources.reserve(mResourceEntries.size()); Resources.reserve(mResourceEntries.size());
for (CResourceIterator It(this); It; ++It) for (CResourceIterator It(this); It; ++It)
{ Resources.push_back( SDatabaseResource { It->ID(), It->TypeInfo(), It->Directory()->FullPath(), It->Name() } );
if (!It->IsTransient())
Resources.push_back( SDatabaseResource { It->ID(), It->TypeInfo(), It->Directory()->FullPath(), It->Name() } );
}
} }
// Serialize // Serialize
@ -175,7 +169,7 @@ bool CResourceStore::LoadCacheFile()
CResourceEntry *pEntry = FindEntry(ID); CResourceEntry *pEntry = FindEntry(ID);
if (pEntry && !pEntry->IsTransient()) if (pEntry)
{ {
CBasicBinaryReader Reader(&CacheFile, Version); CBasicBinaryReader Reader(&CacheFile, Version);
@ -215,26 +209,23 @@ bool CResourceStore::SaveCacheFile()
// Structure: Entry Asset ID -> Entry Cache Size -> Serialized Entry Cache Data // Structure: Entry Asset ID -> Entry Cache Size -> Serialized Entry Cache Data
for (CResourceIterator It(this); It; ++It) for (CResourceIterator It(this); It; ++It)
{ {
if (!It->IsTransient()) ResCount++;
It->ID().Write(CacheFile);
u32 SizeOffset = CacheFile.Tell();
CacheFile.WriteLong(0);
CBasicBinaryWriter Writer(&CacheFile, Version.FileVersion(), Version.Game());
if (Writer.ParamBegin("EntryCache"))
{ {
ResCount++; It->SerializeCacheData(Writer);
It->ID().Write(CacheFile); Writer.ParamEnd();
u32 SizeOffset = CacheFile.Tell();
CacheFile.WriteLong(0);
CBasicBinaryWriter Writer(&CacheFile, Version.FileVersion(), Version.Game());
if (Writer.ParamBegin("EntryCache"))
{
It->SerializeCacheData(Writer);
Writer.ParamEnd();
}
u32 EntryCacheEnd = CacheFile.Tell();
CacheFile.Seek(SizeOffset, SEEK_SET);
CacheFile.WriteLong(EntryCacheEnd - SizeOffset - 4);
CacheFile.Seek(EntryCacheEnd, SEEK_SET);
} }
u32 EntryCacheEnd = CacheFile.Tell();
CacheFile.Seek(SizeOffset, SEEK_SET);
CacheFile.WriteLong(EntryCacheEnd - SizeOffset - 4);
CacheFile.Seek(EntryCacheEnd, SEEK_SET);
} }
CacheFile.Seek(ResCountOffset, SEEK_SET); CacheFile.Seek(ResCountOffset, SEEK_SET);
@ -294,16 +285,8 @@ void CResourceStore::CloseProject()
while (It != mResourceEntries.end()) while (It != mResourceEntries.end())
{ {
CResourceEntry *pEntry = It->second; delete It->second;
It = mResourceEntries.erase(It);
if (!pEntry->IsTransient())
{
delete pEntry;
It = mResourceEntries.erase(It);
}
else
It++;
} }
delete mpDatabaseRoot; delete mpDatabaseRoot;
@ -312,34 +295,14 @@ void CResourceStore::CloseProject()
mGame = eUnknownGame; mGame = eUnknownGame;
} }
CVirtualDirectory* CResourceStore::GetVirtualDirectory(const TString& rkPath, bool Transient, bool AllowCreate) CVirtualDirectory* CResourceStore::GetVirtualDirectory(const TString& rkPath, bool AllowCreate)
{ {
if (rkPath.IsEmpty()) return mpDatabaseRoot; if (rkPath.IsEmpty())
return mpDatabaseRoot;
else if (Transient)
{
for (u32 iTrans = 0; iTrans < mTransientRoots.size(); iTrans++)
{
if (mTransientRoots[iTrans]->Name() == rkPath)
return mTransientRoots[iTrans];
}
if (AllowCreate)
{
CVirtualDirectory *pDir = new CVirtualDirectory(rkPath, this);
mTransientRoots.push_back(pDir);
return pDir;
}
else return nullptr;
}
else if (mpDatabaseRoot) else if (mpDatabaseRoot)
{
return mpDatabaseRoot->FindChildDirectory(rkPath, AllowCreate); return mpDatabaseRoot->FindChildDirectory(rkPath, AllowCreate);
} else
return nullptr;
else return nullptr;
} }
void CResourceStore::ConditionalDeleteDirectory(CVirtualDirectory *pDir) void CResourceStore::ConditionalDeleteDirectory(CVirtualDirectory *pDir)
@ -382,16 +345,7 @@ CResourceEntry* CResourceStore::RegisterResource(const CAssetID& rkID, EResType
CResourceEntry *pEntry = FindEntry(rkID); CResourceEntry *pEntry = FindEntry(rkID);
if (pEntry) if (pEntry)
{ Log::Error("Attempted to register resource that's already tracked in the database: " + rkID.ToString() + " / " + rkDir + " / " + rkName);
if (pEntry->IsTransient())
{
ASSERT(pEntry->ResourceType() == Type);
pEntry->AddToProject(rkDir, rkName);
}
else
Log::Error("Attempted to register resource that's already tracked in the database: " + rkID.ToString() + " / " + rkDir + " / " + rkName);
}
else else
{ {
@ -409,133 +363,74 @@ CResourceEntry* CResourceStore::RegisterResource(const CAssetID& rkID, EResType
return pEntry; return pEntry;
} }
CResourceEntry* CResourceStore::RegisterTransientResource(EResType Type, const TString& rkDir /*= ""*/, const TString& rkFileName /*= ""*/) CResource* CResourceStore::LoadResource(const CAssetID& rkID)
{
CResourceEntry *pEntry = new CResourceEntry(this, CAssetID::RandomID(), rkDir, rkFileName, Type, true);
mResourceEntries[pEntry->ID()] = pEntry;
return pEntry;
}
CResourceEntry* CResourceStore::RegisterTransientResource(EResType Type, const CAssetID& rkID, const TString& rkDir /*=L ""*/, const TString& rkFileName /*= ""*/)
{
CResourceEntry *pEntry = FindEntry(rkID);
if (!pEntry)
{
pEntry = new CResourceEntry(this, rkID, rkDir, rkFileName, Type, true);
mResourceEntries[rkID] = pEntry;
}
return pEntry;
}
CResource* CResourceStore::LoadResource(const CAssetID& rkID, const CFourCC& rkType)
{ {
if (!rkID.IsValid()) return nullptr; if (!rkID.IsValid()) return nullptr;
// Check if resource is already loaded
auto Find = mLoadedResources.find(rkID);
if (Find != mLoadedResources.end())
return Find->second->Resource();
// Check for resource in store
CResourceEntry *pEntry = FindEntry(rkID); CResourceEntry *pEntry = FindEntry(rkID);
if (pEntry) return pEntry->Load();
// Check in transient load directory - this only works for cooked if (pEntry)
EResType Type = CResTypeInfo::TypeForCookedExtension(mGame, rkType)->Type(); return pEntry->Load();
if (Type != eInvalidResType)
{
// Note the entry may not be able to find the resource on its own (due to not knowing what game
// it is) so we will attempt to open the file stream ourselves and pass it to the entry instead.
TString Name = rkID.ToString();
CResourceEntry *pEntry = RegisterTransientResource(Type, mTransientLoadDir, Name);
TString Path = mTransientLoadDir + Name + "." + rkType.ToString();
CFileInStream File(Path, IOUtil::eBigEndian);
CResource *pRes = pEntry->LoadCooked(File);
if (!pRes) DeleteResourceEntry(pEntry);
return pRes;
}
else else
{ {
Log::Error("Can't load requested resource with ID \"" + rkID.ToString() + "\"; can't locate resource. Note: Loading raw assets from an arbitrary directory is unsupported.");; // Resource doesn't seem to exist
Log::Error("Can't find requested resource with ID \"" + rkID.ToString() + "\".");;
return nullptr; return nullptr;
} }
} }
CResource* CResourceStore::LoadResource(const CAssetID& rkID, EResType Type)
{
CResource *pRes = LoadResource(rkID);
if (pRes)
{
if (pRes->Type() == Type)
{
return pRes;
}
else
{
CResTypeInfo *pExpectedType = CResTypeInfo::FindTypeInfo(Type);
CResTypeInfo *pGotType = pRes->TypeInfo();
ASSERT(pExpectedType && pGotType);
Log::Error("Resource with ID \"" + rkID.ToString() + "\" requested with the wrong type; expected " + pExpectedType->TypeName() + " asset, got " + pGotType->TypeName() + " asset");
return nullptr;
}
}
else
return nullptr;
}
CResource* CResourceStore::LoadResource(const TString& rkPath) CResource* CResourceStore::LoadResource(const TString& rkPath)
{ {
// If this is a relative path then load via the resource DB // If this is a relative path then load via the resource DB
if (!FileUtil::IsAbsolute(rkPath)) CResourceEntry *pEntry = FindEntry(rkPath);
if (pEntry)
{ {
CResourceEntry *pEntry = FindEntry(rkPath); // Verify extension matches the entry + load resource
TString Ext = rkPath.GetFileExtension();
if (pEntry) if (!Ext.IsEmpty())
{ {
// Verify extension matches the entry + load resource if (Ext.Length() == 4)
TString Ext = rkPath.GetFileExtension();
if (!Ext.IsEmpty())
{ {
if (Ext.Length() == 4) ASSERT(Ext.CaseInsensitiveCompare(pEntry->CookedExtension().ToString()));
{ }
ASSERT(Ext.CaseInsensitiveCompare(pEntry->CookedExtension().ToString())); else
} {
else ASSERT(Ext.CaseInsensitiveCompare(pEntry->RawExtension()));
{
ASSERT(Ext.CaseInsensitiveCompare(pEntry->RawExtension()));
}
} }
return pEntry->Load();
} }
else return nullptr; return pEntry->Load();
} }
// Otherwise create transient entry; construct ID from string, check if resource is loaded already else return nullptr;
TString Dir = FileUtil::MakeAbsolute(rkPath.GetFileDirectory());
TString Name = rkPath.GetFileName(false);
CAssetID ID = (Name.IsHexString() ? Name.ToInt64() : rkPath.Hash64());
auto Find = mLoadedResources.find(ID);
if (Find != mLoadedResources.end())
return Find->second->Resource();
// Determine type
TString Extension = rkPath.GetFileExtension().ToUpper();
EResType Type = CResTypeInfo::TypeForCookedExtension(mGame, Extension)->Type();
if (Type == eInvalidResType)
{
Log::Error("Unable to load resource " + rkPath + "; unrecognized extension: " + Extension);
return nullptr;
}
// Open file
CFileInStream File(rkPath, IOUtil::eBigEndian);
if (!File.IsValid())
{
Log::Error("Unable to load resource; couldn't open file: " + rkPath);
return nullptr;
}
// Load resource
TString OldTransientDir = mTransientLoadDir;
mTransientLoadDir = Dir;
CResourceEntry *pEntry = RegisterTransientResource(Type, ID, Dir, Name);
CResource *pRes = pEntry->LoadCooked(File);
if (!pRes) DeleteResourceEntry(pEntry);
mTransientLoadDir = OldTransientDir;
return pRes;
} }
void CResourceStore::TrackLoadedResource(CResourceEntry *pEntry) void CResourceStore::TrackLoadedResource(CResourceEntry *pEntry)
@ -563,27 +458,11 @@ void CResourceStore::DestroyUnreferencedResources()
{ {
It = mLoadedResources.erase(It); It = mLoadedResources.erase(It);
NumDeleted++; NumDeleted++;
// Transient resources should have their entries cleared out when the resource is unloaded
if (pEntry->IsTransient())
DeleteResourceEntry(pEntry);
} }
else It++; else It++;
} }
} while (NumDeleted > 0); } while (NumDeleted > 0);
// Destroy empty virtual directories
for (auto DirIt = mTransientRoots.begin(); DirIt != mTransientRoots.end(); DirIt++)
{
CVirtualDirectory *pRoot = *DirIt;
if (pRoot->IsEmpty())
{
delete pRoot;
DirIt = mTransientRoots.erase(DirIt);
}
}
} }
bool CResourceStore::DeleteResourceEntry(CResourceEntry *pEntry) bool CResourceStore::DeleteResourceEntry(CResourceEntry *pEntry)
@ -611,13 +490,6 @@ bool CResourceStore::DeleteResourceEntry(CResourceEntry *pEntry)
return true; return true;
} }
void CResourceStore::SetTransientLoadDir(const TString& rkDir)
{
mTransientLoadDir = rkDir;
mTransientLoadDir.EnsureEndsWith('/');
Log::Write("Set resource directory: " + rkDir);
}
void CResourceStore::ImportNamesFromPakContentsTxt(const TString& rkTxtPath, bool UnnamedOnly) void CResourceStore::ImportNamesFromPakContentsTxt(const TString& rkTxtPath, bool UnnamedOnly)
{ {
// Read file contents -first- then move assets -after-; this // Read file contents -first- then move assets -after-; this

View File

@ -22,7 +22,6 @@ class CResourceStore
CGameProject *mpProj; CGameProject *mpProj;
EGame mGame; EGame mGame;
CVirtualDirectory *mpDatabaseRoot; CVirtualDirectory *mpDatabaseRoot;
std::vector<CVirtualDirectory*> mTransientRoots;
std::map<CAssetID, CResourceEntry*> mResourceEntries; std::map<CAssetID, CResourceEntry*> mResourceEntries;
std::map<CAssetID, CResourceEntry*> mLoadedResources; std::map<CAssetID, CResourceEntry*> mLoadedResources;
bool mDatabaseDirty; bool mDatabaseDirty;
@ -33,7 +32,6 @@ class CResourceStore
TString mDatabaseName; TString mDatabaseName;
TString mRawDir; TString mRawDir;
TString mCookedDir; TString mCookedDir;
TString mTransientLoadDir;
enum EDatabaseVersion enum EDatabaseVersion
{ {
@ -56,22 +54,21 @@ public:
void ConditionalSaveStore(); void ConditionalSaveStore();
void SetProject(CGameProject *pProj); void SetProject(CGameProject *pProj);
void CloseProject(); void CloseProject();
CVirtualDirectory* GetVirtualDirectory(const TString& rkPath, bool Transient, bool AllowCreate); CVirtualDirectory* GetVirtualDirectory(const TString& rkPath, bool AllowCreate);
void ConditionalDeleteDirectory(CVirtualDirectory *pDir); void ConditionalDeleteDirectory(CVirtualDirectory *pDir);
bool IsResourceRegistered(const CAssetID& rkID) const; bool IsResourceRegistered(const CAssetID& rkID) const;
CResourceEntry* RegisterResource(const CAssetID& rkID, EResType Type, const TString& rkDir, const TString& rkName); CResourceEntry* RegisterResource(const CAssetID& rkID, EResType Type, const TString& rkDir, const TString& rkName);
CResourceEntry* FindEntry(const CAssetID& rkID) const; CResourceEntry* FindEntry(const CAssetID& rkID) const;
CResourceEntry* FindEntry(const TString& rkPath) const; CResourceEntry* FindEntry(const TString& rkPath) const;
CResourceEntry* RegisterTransientResource(EResType Type, const TString& rkDir = "", const TString& rkFileName = "");
CResourceEntry* RegisterTransientResource(EResType Type, const CAssetID& rkID, const TString& rkDir = "", const TString& rkFileName = "");
CResource* LoadResource(const CAssetID& rkID, const CFourCC& rkType); template<typename ResType> ResType* LoadResource(const CAssetID& rkID) { return static_cast<ResType*>(LoadResource(rkID, ResType::StaticType())); }
CResource* LoadResource(const CAssetID& rkID);
CResource* LoadResource(const CAssetID& rkID, EResType Type);
CResource* LoadResource(const TString& rkPath); CResource* LoadResource(const TString& rkPath);
void TrackLoadedResource(CResourceEntry *pEntry); void TrackLoadedResource(CResourceEntry *pEntry);
void DestroyUnreferencedResources(); void DestroyUnreferencedResources();
bool DeleteResourceEntry(CResourceEntry *pEntry); bool DeleteResourceEntry(CResourceEntry *pEntry);
void SetTransientLoadDir(const TString& rkDir);
void ImportNamesFromPakContentsTxt(const TString& rkTxtPath, bool UnnamedOnly); void ImportNamesFromPakContentsTxt(const TString& rkTxtPath, bool UnnamedOnly);

View File

@ -98,7 +98,7 @@ void CCharacterUsageMap::DebugPrintContents()
{ {
CAssetID ID = Iter->first; CAssetID ID = Iter->first;
std::vector<bool>& rUsedList = Iter->second; std::vector<bool>& rUsedList = Iter->second;
CAnimSet *pSet = (CAnimSet*) mpStore->LoadResource(ID, "ANCS"); CAnimSet *pSet = mpStore->LoadResource<CAnimSet>(ID);
for (u32 iChar = 0; iChar < pSet->NumCharacters(); iChar++) for (u32 iChar = 0; iChar < pSet->NumCharacters(); iChar++)
{ {

View File

@ -161,7 +161,7 @@ public:
rkAnim.pMetaAnim->GetUniquePrimitives(PrimitiveSet); rkAnim.pMetaAnim->GetUniquePrimitives(PrimitiveSet);
} }
CSourceAnimData *pAnimData = (CSourceAnimData*) gpResourceStore->LoadResource(rkChar.AnimDataID, "SAND"); CSourceAnimData *pAnimData = gpResourceStore->LoadResource<CSourceAnimData>(rkChar.AnimDataID);
if (pAnimData) if (pAnimData)
pAnimData->AddTransitionDependencies(pTree); pAnimData->AddTransitionDependencies(pTree);

View File

@ -28,7 +28,7 @@ public:
// Accessors // Accessors
inline EGame Version() const { return mGame; } inline EGame Version() const { return mGame; }
inline CAssetID ID() const { return mCharacterID; } inline CAssetID ID() const { return mCharacterID; }
inline CAnimSet* AnimSet() const { return (CAnimSet*) gpResourceStore->LoadResource(mCharacterID, (mGame < eCorruptionProto ? "ANCS" : "CHAR")); } inline CAnimSet* AnimSet() const { return (CAnimSet*) gpResourceStore->LoadResource(mCharacterID); }
inline u32 CharacterIndex() const { return mCharIndex; } inline u32 CharacterIndex() const { return mCharIndex; }
inline u32 AnimIndex() const { return mAnimIndex; } inline u32 AnimIndex() const { return mAnimIndex; }
inline void SetCharIndex(u32 Index) { mCharIndex = Index; } inline void SetCharIndex(u32 Index) { mCharIndex = Index; }

View File

@ -34,7 +34,7 @@ public:
CAnimPrimitive(IInputStream& rInput, EGame Game) CAnimPrimitive(IInputStream& rInput, EGame Game)
{ {
mpAnim = gpResourceStore->LoadResource( CAssetID(rInput, Game), "ANIM" ); mpAnim = gpResourceStore->LoadResource( CAssetID(rInput, Game) );
mID = rInput.ReadLong(); mID = rInput.ReadLong();
mName = rInput.ReadString(); mName = rInput.ReadString();
} }

View File

@ -26,6 +26,11 @@ public: \
return ResTypeEnum; \ return ResTypeEnum; \
} \ } \
\ \
static CResTypeInfo* StaticTypeInfo() \
{ \
return CResTypeInfo::FindTypeInfo(StaticType()); \
} \
\
private: \ private: \
class CResource class CResource

View File

@ -166,7 +166,7 @@ bool CWorldCooker::CookMLVL(CWorld *pWorld, IOutputStream& rMLVL)
for (auto It = AudioGroups.begin(); It != AudioGroups.end(); It++) for (auto It = AudioGroups.begin(); It != AudioGroups.end(); It++)
{ {
CAudioGroup *pGroup = (CAudioGroup*) gpResourceStore->LoadResource(*It, "AGSC"); CAudioGroup *pGroup = gpResourceStore->LoadResource<CAudioGroup>(*It);
ASSERT(pGroup); ASSERT(pGroup);
SortedAudioGroups.push_back(pGroup); SortedAudioGroups.push_back(pGroup);
} }

View File

@ -15,8 +15,8 @@ CAnimSet* CAnimSetLoader::LoadCorruptionCHAR(IInputStream& rCHAR)
// Character Header // Character Header
rChar.ID = rCHAR.ReadByte(); rChar.ID = rCHAR.ReadByte();
rChar.Name = rCHAR.ReadString(); rChar.Name = rCHAR.ReadString();
rChar.pModel = gpResourceStore->LoadResource(rCHAR.ReadLongLong(), "CMDL"); rChar.pModel = gpResourceStore->LoadResource<CModel>(rCHAR.ReadLongLong());
rChar.pSkin = gpResourceStore->LoadResource(rCHAR.ReadLongLong(), "CSKR"); rChar.pSkin = gpResourceStore->LoadResource<CSkin>(rCHAR.ReadLongLong());
u32 NumOverlays = rCHAR.ReadLong(); u32 NumOverlays = rCHAR.ReadLong();
@ -29,7 +29,7 @@ CAnimSet* CAnimSetLoader::LoadCorruptionCHAR(IInputStream& rCHAR)
rChar.OverlayModels.push_back(Overlay); rChar.OverlayModels.push_back(Overlay);
} }
rChar.pSkeleton = gpResourceStore->LoadResource(rCHAR.ReadLongLong(), "CINF"); rChar.pSkeleton = gpResourceStore->LoadResource<CSkeleton>(rCHAR.ReadLongLong());
rChar.AnimDataID = CAssetID(rCHAR, e64Bit); rChar.AnimDataID = CAssetID(rCHAR, e64Bit);
// PAS Database // PAS Database
@ -108,7 +108,7 @@ CAnimSet* CAnimSetLoader::LoadReturnsCHAR(IInputStream& rCHAR)
rChar.Name = rCHAR.ReadString(); rChar.Name = rCHAR.ReadString();
rCHAR.Seek(0x14, SEEK_CUR); rCHAR.Seek(0x14, SEEK_CUR);
rCHAR.ReadString(); rCHAR.ReadString();
rChar.pModel = gpResourceStore->LoadResource(rCHAR.ReadLongLong(), "CMDL"); rChar.pModel = gpResourceStore->LoadResource<CModel>(rCHAR.ReadLongLong());
return pSet; return pSet;
} }
@ -285,7 +285,7 @@ void CAnimSetLoader::ProcessPrimitives()
if (mGame == eCorruptionProto || mGame == eCorruption) if (mGame == eCorruptionProto || mGame == eCorruption)
{ {
CSourceAnimData *pAnimData = (CSourceAnimData*) gpResourceStore->LoadResource( pSet->mCharacters[0].AnimDataID, "SAND" ); CSourceAnimData *pAnimData = gpResourceStore->LoadResource<CSourceAnimData>( pSet->mCharacters[0].AnimDataID );
if (pAnimData) if (pAnimData)
pAnimData->GetUniquePrimitives(UniquePrimitives); pAnimData->GetUniquePrimitives(UniquePrimitives);
@ -415,9 +415,9 @@ CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& rANCS, CResourceEntry *pEntry)
Loader.mGame = (CharVersion == 0xA) ? eEchoes : ePrime; Loader.mGame = (CharVersion == 0xA) ? eEchoes : ePrime;
} }
pChar->Name = rANCS.ReadString(); pChar->Name = rANCS.ReadString();
pChar->pModel = gpResourceStore->LoadResource(rANCS.ReadLong(), "CMDL"); pChar->pModel = gpResourceStore->LoadResource<CModel>(rANCS.ReadLong());
pChar->pSkin = gpResourceStore->LoadResource(rANCS.ReadLong(), "CSKR"); pChar->pSkin = gpResourceStore->LoadResource<CSkin>(rANCS.ReadLong());
pChar->pSkeleton = gpResourceStore->LoadResource(rANCS.ReadLong(), "CINF"); pChar->pSkeleton = gpResourceStore->LoadResource<CSkeleton>(rANCS.ReadLong());
if (pChar->pModel) pChar->pModel->SetSkin(pChar->pSkin); if (pChar->pModel) pChar->pModel->SetSkin(pChar->pSkin);
// Unfortunately that's all that's actually supported at the moment. Hope to expand later. // Unfortunately that's all that's actually supported at the moment. Hope to expand later.

View File

@ -199,7 +199,7 @@ void CAnimationLoader::ReadUncompressedANIM()
if (mGame == ePrime) if (mGame == ePrime)
{ {
mpAnim->mpEventData = gpResourceStore->LoadResource(mpInput->ReadLong(), "EVNT"); mpAnim->mpEventData = gpResourceStore->LoadResource<CAnimEventData>(mpInput->ReadLong());
} }
} }
@ -213,7 +213,7 @@ void CAnimationLoader::ReadCompressedANIM()
if (mGame == ePrime) if (mGame == ePrime)
{ {
mpAnim->mpEventData = gpResourceStore->LoadResource(mpInput->ReadLong(), "EVNT"); mpAnim->mpEventData = gpResourceStore->LoadResource<CAnimEventData>(mpInput->ReadLong());
mpInput->Seek(0x4, SEEK_CUR); // Skip unknown mpInput->Seek(0x4, SEEK_CUR); // Skip unknown
} }
else mpInput->Seek(0x2, SEEK_CUR); // Skip unknowns else mpInput->Seek(0x2, SEEK_CUR); // Skip unknowns

View File

@ -603,7 +603,7 @@ void CAreaLoader::ReadEGMC()
{ {
mpSectionMgr->ToSection(mEGMCBlockNum); mpSectionMgr->ToSection(mEGMCBlockNum);
CAssetID EGMC(*mpMREA, mVersion); CAssetID EGMC(*mpMREA, mVersion);
mpArea->mpPoiToWorldMap = gpResourceStore->LoadResource(EGMC, "EGMC"); mpArea->mpPoiToWorldMap = gpResourceStore->LoadResource(EGMC, eStaticGeometryMap);
} }
void CAreaLoader::MergeGeneratedLayer(CScriptLayer *pLayer) void CAreaLoader::MergeGeneratedLayer(CScriptLayer *pLayer)

View File

@ -18,8 +18,8 @@ CFont* CFontLoader::LoadFont(IInputStream& rFONT)
mpFont->mDefaultSize = rFONT.ReadLong(); mpFont->mDefaultSize = rFONT.ReadLong();
mpFont->mFontName = rFONT.ReadString(); mpFont->mFontName = rFONT.ReadString();
if (mVersion <= eEchoes) mpFont->mpFontTexture = gpResourceStore->LoadResource(rFONT.ReadLong(), "TXTR"); if (mVersion <= eEchoes) mpFont->mpFontTexture = gpResourceStore->LoadResource(rFONT.ReadLong(), eTexture);
else mpFont->mpFontTexture = gpResourceStore->LoadResource(rFONT.ReadLongLong(), "TXTR"); else mpFont->mpFontTexture = gpResourceStore->LoadResource(rFONT.ReadLongLong(), eTexture);
mpFont->mTextureFormat = rFONT.ReadLong(); mpFont->mTextureFormat = rFONT.ReadLong();
u32 NumGlyphs = rFONT.ReadLong(); u32 NumGlyphs = rFONT.ReadLong();

View File

@ -50,7 +50,7 @@ void CMaterialLoader::ReadPrimeMatSet()
for (u32 iTex = 0; iTex < NumTextures; iTex++) for (u32 iTex = 0; iTex < NumTextures; iTex++)
{ {
u32 TextureID = mpFile->ReadLong(); u32 TextureID = mpFile->ReadLong();
mTextures[iTex] = gpResourceStore->LoadResource(TextureID, "TXTR"); mTextures[iTex] = gpResourceStore->LoadResource<CTexture>(TextureID);
} }
// Materials // Materials
@ -367,7 +367,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
continue; continue;
} }
pPass->mpTexture = gpResourceStore->LoadResource(TextureID, "TXTR"); pPass->mpTexture = gpResourceStore->LoadResource<CTexture>(TextureID);
pPass->mTexCoordSource = 4 + (u8) mpFile->ReadLong(); pPass->mTexCoordSource = 4 + (u8) mpFile->ReadLong();
u32 AnimSize = mpFile->ReadLong(); u32 AnimSize = mpFile->ReadLong();

View File

@ -10,7 +10,7 @@ CScan* CScanLoader::LoadScanMP1(IInputStream& rSCAN)
{ {
// Basic support at the moment - don't read animation/scan image data // Basic support at the moment - don't read animation/scan image data
mpScan->mFrameID = CAssetID(rSCAN, e32Bit); mpScan->mFrameID = CAssetID(rSCAN, e32Bit);
mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLong(), "STRG"); mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLong(), eStringTable);
mpScan->mIsSlow = (rSCAN.ReadLong() != 0); mpScan->mIsSlow = (rSCAN.ReadLong() != 0);
mpScan->mCategory = (CScan::ELogbookCategory) rSCAN.ReadLong(); mpScan->mCategory = (CScan::ELogbookCategory) rSCAN.ReadLong();
mpScan->mIsImportant = (rSCAN.ReadByte() == 1); mpScan->mIsImportant = (rSCAN.ReadByte() == 1);
@ -112,7 +112,7 @@ void CScanLoader::LoadParamsMP2(IInputStream& rSCAN, u16 NumProperties)
switch (PropertyID) switch (PropertyID)
{ {
case 0x2F5B6423: case 0x2F5B6423:
mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLong(), "STRG"); mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLong(), eStringTable);
break; break;
case 0xC308A322: case 0xC308A322:
@ -210,7 +210,7 @@ void CScanLoader::LoadParamsMP3(IInputStream& rSCAN, u16 NumProperties)
switch (PropertyID) switch (PropertyID)
{ {
case 0x2F5B6423: case 0x2F5B6423:
mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLongLong(), "STRG"); mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLongLong(), eStringTable);
break; break;
case 0xC308A322: case 0xC308A322:

View File

@ -16,19 +16,19 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
// Header // Header
if (mVersion < eCorruptionProto) if (mVersion < eCorruptionProto)
{ {
mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLong(), "STRG"); mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLong(), eStringTable);
if (mVersion == eEchoes) mpWorld->mpDarkWorldName = gpResourceStore->LoadResource(rMLVL.ReadLong(), "STRG"); if (mVersion == eEchoes) mpWorld->mpDarkWorldName = gpResourceStore->LoadResource(rMLVL.ReadLong(), eStringTable);
if (mVersion >= eEchoes) mpWorld->mTempleKeyWorldIndex = rMLVL.ReadLong(); if (mVersion >= eEchoes) mpWorld->mTempleKeyWorldIndex = rMLVL.ReadLong();
if (mVersion >= ePrime) mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLong(), "SAVW"); if (mVersion >= ePrime) mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLong(), eSaveWorld);
mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLong(), "CMDL"); mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLong(), eModel);
} }
else else
{ {
mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "STRG"); mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), eStringTable);
rMLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value rMLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value
mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "SAVW"); mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), eStringTable);
mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "CMDL"); mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), eModel);
} }
// Memory relays - only in MP1 // Memory relays - only in MP1
@ -57,7 +57,7 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
{ {
// Area header // Area header
CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; CWorld::SArea *pArea = &mpWorld->mAreas[iArea];
pArea->pAreaName = gpResourceStore->LoadResource( CAssetID(rMLVL, mVersion), "STRG" ); pArea->pAreaName = gpResourceStore->LoadResource<CStringTable>( CAssetID(rMLVL, mVersion) );
pArea->Transform = CTransform4f(rMLVL); pArea->Transform = CTransform4f(rMLVL);
pArea->AetherBox = CAABox(rMLVL); pArea->AetherBox = CAABox(rMLVL);
pArea->AreaResID = CAssetID(rMLVL, mVersion); pArea->AreaResID = CAssetID(rMLVL, mVersion);
@ -132,7 +132,7 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
} }
// MapWorld // MapWorld
mpWorld->mpMapWorld = gpResourceStore->LoadResource( CAssetID(rMLVL, mVersion), "MAPW" ); mpWorld->mpMapWorld = gpResourceStore->LoadResource( CAssetID(rMLVL, mVersion), eMapWorld );
rMLVL.Seek(0x5, SEEK_CUR); // Unknown values which are always 0 rMLVL.Seek(0x5, SEEK_CUR); // Unknown values which are always 0
// Audio Groups - we don't need this info as we regenerate it on cook // Audio Groups - we don't need this info as we regenerate it on cook
@ -173,7 +173,7 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL) void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL)
{ {
mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "STRG"); mpWorld->mpWorldName = gpResourceStore->LoadResource<CStringTable>(rMLVL.ReadLongLong());
bool Check = (rMLVL.ReadByte() != 0); bool Check = (rMLVL.ReadByte() != 0);
if (Check) if (Check)
@ -182,8 +182,8 @@ void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL)
rMLVL.Seek(0x10, SEEK_CUR); rMLVL.Seek(0x10, SEEK_CUR);
} }
mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "SAVW"); mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), eSaveWorld);
mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "CMDL"); mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource<CModel>(rMLVL.ReadLongLong());
// Areas // Areas
u32 NumAreas = rMLVL.ReadLong(); u32 NumAreas = rMLVL.ReadLong();
@ -194,7 +194,7 @@ void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL)
// Area header // Area header
CWorld::SArea *pArea = &mpWorld->mAreas[iArea]; CWorld::SArea *pArea = &mpWorld->mAreas[iArea];
pArea->pAreaName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "STRG"); pArea->pAreaName = gpResourceStore->LoadResource<CStringTable>(rMLVL.ReadLongLong());
pArea->Transform = CTransform4f(rMLVL); pArea->Transform = CTransform4f(rMLVL);
pArea->AetherBox = CAABox(rMLVL); pArea->AetherBox = CAABox(rMLVL);
pArea->AreaResID = rMLVL.ReadLongLong(); pArea->AreaResID = rMLVL.ReadLongLong();

View File

@ -224,7 +224,7 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties
if (pProp->Type() == eAssetProperty) if (pProp->Type() == eAssetProperty)
{ {
TAssetProperty *pAsset = static_cast<TAssetProperty*>(pProp); TAssetProperty *pAsset = static_cast<TAssetProperty*>(pProp);
pRes = gpResourceStore->LoadResource( pAsset->Get(), "DCLN" ); pRes = gpResourceStore->LoadResource( pAsset->Get(), eDynamicCollision );
} }
} }

View File

@ -22,7 +22,7 @@ void CScriptAttachNode::AttachPropertyModified()
if (mpAttachAssetProp) if (mpAttachAssetProp)
{ {
if (mpAttachAssetProp->Type() == eAssetProperty) if (mpAttachAssetProp->Type() == eAssetProperty)
mpAttachAsset = gpResourceStore->LoadResource( TPropCast<TAssetProperty>(mpAttachAssetProp)->Get(), "CMDL" ); mpAttachAsset = gpResourceStore->LoadResource<CModel>( TPropCast<TAssetProperty>(mpAttachAssetProp)->Get() );
else if (mpAttachAssetProp->Type() == eCharacterProperty) else if (mpAttachAssetProp->Type() == eCharacterProperty)
mpAttachAsset = TPropCast<TCharacterProperty>(mpAttachAssetProp)->Get().AnimSet(); mpAttachAsset = TPropCast<TCharacterProperty>(mpAttachAssetProp)->Get().AnimSet();

View File

@ -200,7 +200,7 @@ void CDamageableTriggerExtra::PropertyModified(IProperty *pProperty)
{ {
if (pProperty == mpTextureProps[iTex]) if (pProperty == mpTextureProps[iTex])
{ {
mpTextures[iTex] = gpResourceStore->LoadResource( mpTextureProps[iTex]->Get(), "TXTR" ); mpTextures[iTex] = gpResourceStore->LoadResource<CTexture>( mpTextureProps[iTex]->Get() );
if (mpTextures[iTex] && mpTextures[iTex]->Type() != eTexture) if (mpTextures[iTex] && mpTextures[iTex]->Type() != eTexture)
mpTextures[iTex] = nullptr; mpTextures[iTex] = nullptr;

View File

@ -29,7 +29,7 @@ void CDoorExtra::PropertyModified(IProperty *pProperty)
{ {
if (pProperty == mpShieldModelProp) if (pProperty == mpShieldModelProp)
{ {
mpShieldModel = gpResourceStore->LoadResource( mpShieldModelProp->Get(), "CMDL" ); mpShieldModel = gpResourceStore->LoadResource<CModel>( mpShieldModelProp->Get() );
if (mpShieldModel) if (mpShieldModel)
mLocalAABox = mpShieldModel->AABox(); mLocalAABox = mpShieldModel->AABox();

View File

@ -19,7 +19,7 @@ CPointOfInterestExtra::CPointOfInterestExtra(CScriptObject *pInstance, CScene *p
void CPointOfInterestExtra::PropertyModified(IProperty* pProperty) void CPointOfInterestExtra::PropertyModified(IProperty* pProperty)
{ {
if (mpScanProperty == pProperty) if (mpScanProperty == pProperty)
mpScanData = gpResourceStore->LoadResource( mpScanProperty->Get(), "SCAN" ); mpScanData = gpResourceStore->LoadResource<CScan>( mpScanProperty->Get() );
} }
void CPointOfInterestExtra::ModifyTintColor(CColor& Color) void CPointOfInterestExtra::ModifyTintColor(CColor& Color)

View File

@ -705,7 +705,7 @@ void CWorldEditor::UpdateOpenRecentActions()
// Remove projects that don't exist anymore // Remove projects that don't exist anymore
foreach (const QString& rkProj, RecentProjectsList) foreach (const QString& rkProj, RecentProjectsList)
{ {
if (!FileUtil::Exists( TO_TSTRING(rkProj) )) if (!FileUtil::Exists( TO_TSTRING(rkProj) ) || rkProj.contains('\\') )
RecentProjectsList.removeAll(rkProj); RecentProjectsList.removeAll(rkProj);
} }