Applied a bunch of fixes to get the current game exporter functionality working with the resource store system
This commit is contained in:
parent
2f2ec13ced
commit
24c5ad5cd7
|
@ -14,23 +14,25 @@
|
|||
#define EXPORT_COOKED 1
|
||||
|
||||
CGameExporter::CGameExporter(const TString& rkInputDir, const TString& rkOutputDir)
|
||||
: mStore(this)
|
||||
{
|
||||
mGameDir = FileUtil::MakeAbsolute(rkInputDir);
|
||||
mExportDir = FileUtil::MakeAbsolute(rkOutputDir);
|
||||
|
||||
mpProject = new CGameProject(mExportDir);
|
||||
mDiscDir = mpProject->DiscDir(true);
|
||||
mResDir = mpProject->ResourcesDir(true);
|
||||
mWorldsDir = mpProject->WorldsDir(true);
|
||||
mContentDir = mpProject->ContentDir(false);
|
||||
mCookedDir = mpProject->CookedDir(false);
|
||||
mCookedResDir = mpProject->CookedResourcesDir(true);
|
||||
mCookedWorldsDir = mpProject->CookedWorldsDir(true);
|
||||
mWorldsDirName = L"Worlds\\";
|
||||
mStore.SetActiveProject(mpProject);
|
||||
}
|
||||
|
||||
bool CGameExporter::Export()
|
||||
{
|
||||
SCOPED_TIMER(ExportGame);
|
||||
gResourceStore.SetGameExporter(this);
|
||||
|
||||
CResourceStore *pOldStore = gpResourceStore;
|
||||
gpResourceStore = &mStore;
|
||||
FileUtil::CreateDirectory(mExportDir);
|
||||
FileUtil::ClearDirectory(mExportDir);
|
||||
|
||||
|
@ -40,7 +42,7 @@ bool CGameExporter::Export()
|
|||
ExportWorlds();
|
||||
ExportCookedResources();
|
||||
|
||||
gResourceStore.SetGameExporter(nullptr);
|
||||
gpResourceStore = pOldStore;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -154,7 +156,7 @@ void CGameExporter::LoadAssetList()
|
|||
TString Name = pName ? pName->GetText() : "";
|
||||
|
||||
if (!Dir.EndsWith("/") && !Dir.EndsWith("\\")) Dir.Append("\\");
|
||||
SetResourcePath(ResourceID, mResDir + Dir.ToUTF16(), Name.ToUTF16());
|
||||
SetResourcePath(ResourceID, Dir.ToUTF16(), Name.ToUTF16());
|
||||
|
||||
pAsset = pAsset->NextSiblingElement("Asset");
|
||||
}
|
||||
|
@ -398,7 +400,6 @@ void CGameExporter::ExportWorlds()
|
|||
{
|
||||
#if EXPORT_WORLDS
|
||||
SCOPED_TIMER(ExportWorlds);
|
||||
//CResourceDatabase *pResDB = mpProject->ResourceDatabase();
|
||||
|
||||
for (u32 iPak = 0; iPak < mpProject->NumWorldPaks(); iPak++)
|
||||
{
|
||||
|
@ -418,7 +419,8 @@ void CGameExporter::ExportWorlds()
|
|||
|
||||
if (rkRes.Type == "MLVL" && !rkRes.Name.EndsWith("NODEPEND"))
|
||||
{
|
||||
TResPtr<CWorld> pWorld = (CWorld*) gResourceStore.LoadResource(rkRes.ID, rkRes.Type);
|
||||
// Load world
|
||||
CWorld *pWorld = (CWorld*) mStore.LoadResource(rkRes.ID, rkRes.Type);
|
||||
|
||||
if (!pWorld)
|
||||
{
|
||||
|
@ -428,7 +430,7 @@ void CGameExporter::ExportWorlds()
|
|||
|
||||
// Export world
|
||||
TWideString Name = rkRes.Name.ToUTF16();
|
||||
TWideString WorldDir = mWorldsDir + PakPath + FileUtil::SanitizeName(Name, true) + L"\\";
|
||||
TWideString WorldDir = mWorldsDirName + PakPath + FileUtil::SanitizeName(Name, true) + L"\\";
|
||||
FileUtil::CreateDirectory(mCookedDir + WorldDir);
|
||||
|
||||
SResourceInstance *pInst = FindResourceInstance(rkRes.ID);
|
||||
|
@ -442,7 +444,8 @@ void CGameExporter::ExportWorlds()
|
|||
{
|
||||
// Determine area names
|
||||
TWideString InternalAreaName = pWorld->AreaInternalName(iArea).ToUTF16();
|
||||
if (InternalAreaName.IsEmpty()) InternalAreaName = TWideString::FromInt32(iArea, 2, 10);
|
||||
bool HasInternalName = !InternalAreaName.IsEmpty();
|
||||
if (!HasInternalName) InternalAreaName = TWideString::FromInt32(iArea, 2, 10);
|
||||
|
||||
TWideString GameAreaName;
|
||||
CStringTable *pTable = pWorld->AreaName(iArea);
|
||||
|
@ -451,7 +454,7 @@ void CGameExporter::ExportWorlds()
|
|||
|
||||
// Load area
|
||||
CUniqueID AreaID = pWorld->AreaResourceID(iArea);
|
||||
CGameArea *pArea = (CGameArea*) gResourceStore.LoadResource(AreaID, "MREA");
|
||||
CGameArea *pArea = (CGameArea*) mStore.LoadResource(AreaID, "MREA");
|
||||
|
||||
if (!pArea)
|
||||
{
|
||||
|
@ -466,11 +469,11 @@ void CGameExporter::ExportWorlds()
|
|||
SResourceInstance *pInst = FindResourceInstance(AreaID);
|
||||
ASSERT(pInst != nullptr);
|
||||
|
||||
SetResourcePath(AreaID, AreaDir, InternalAreaName);
|
||||
SetResourcePath(AreaID, AreaDir, HasInternalName ? InternalAreaName : GameAreaName);
|
||||
ExportResource(*pInst);
|
||||
}
|
||||
|
||||
gResourceStore.DestroyUnreferencedResources();
|
||||
mStore.DestroyUnreferencedResources();
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -485,10 +488,9 @@ void CGameExporter::ExportWorlds()
|
|||
void CGameExporter::ExportCookedResources()
|
||||
{
|
||||
#if EXPORT_COOKED
|
||||
gResourceStore.CloseActiveProject();
|
||||
{
|
||||
SCOPED_TIMER(ExportCookedResources);
|
||||
FileUtil::CreateDirectory(mCookedDir + mResDir);
|
||||
FileUtil::CreateDirectory(mCookedDir);
|
||||
|
||||
for (auto It = mResourceMap.begin(); It != mResourceMap.end(); It++)
|
||||
{
|
||||
|
@ -498,7 +500,7 @@ void CGameExporter::ExportCookedResources()
|
|||
}
|
||||
{
|
||||
SCOPED_TIMER(SaveResourceDatabase);
|
||||
gResourceStore.SaveResourceDatabase(this->mExportDir.ToUTF8() + "ResourceDatabase.rdb");
|
||||
mStore.SaveResourceDatabase(this->mExportDir.ToUTF8() + "ResourceDatabase.rdb");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -512,27 +514,29 @@ void CGameExporter::ExportResource(SResourceInstance& rRes)
|
|||
|
||||
// Determine output path
|
||||
SResourcePath *pPath = FindResourcePath(rRes.ResourceID);
|
||||
TString OutName, OutDir;
|
||||
TWideString OutName, OutDir;
|
||||
|
||||
if (pPath)
|
||||
{
|
||||
OutName = pPath->Name.ToUTF8();
|
||||
OutDir = pPath->Dir.ToUTF8();
|
||||
OutName = pPath->Name;
|
||||
OutDir = pPath->Dir;
|
||||
}
|
||||
|
||||
if (OutName.IsEmpty()) OutName = rRes.ResourceID.ToString();
|
||||
if (OutDir.IsEmpty()) OutDir = mResDir;
|
||||
if (OutName.IsEmpty()) OutName = rRes.ResourceID.ToString().ToUTF16();
|
||||
if (OutDir.IsEmpty()) OutDir = L"Uncategorized\\";
|
||||
|
||||
// Write to file
|
||||
FileUtil::CreateDirectory(mCookedDir + OutDir.ToUTF16());
|
||||
TString OutPath = mCookedDir.ToUTF8() + OutDir + OutName + "." + rRes.ResourceType.ToString();
|
||||
CFileOutStream Out(OutPath.ToStdString(), IOUtil::eBigEndian);
|
||||
// Register resource and write to file
|
||||
CResourceEntry *pEntry = mStore.RegisterResource(rRes.ResourceID, CResource::ResTypeForExtension(rRes.ResourceType), OutDir, OutName);
|
||||
|
||||
// Cooked (todo: save raw)
|
||||
TWideString OutPath = pEntry->CookedAssetPath();
|
||||
FileUtil::CreateDirectory(OutPath.GetFileDirectory());
|
||||
CFileOutStream Out(OutPath.ToUTF8().ToStdString(), IOUtil::eBigEndian);
|
||||
|
||||
if (Out.IsValid())
|
||||
Out.WriteBytes(ResourceData.data(), ResourceData.size());
|
||||
|
||||
// Add to resource DB
|
||||
gResourceStore.RegisterResource(rRes.ResourceID, CResource::ResTypeForExtension(rRes.ResourceType), OutDir, OutName);
|
||||
rRes.Exported = true;
|
||||
ASSERT(pEntry->HasCookedVersion());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define CGAMEEXPORTER_H
|
||||
|
||||
#include "CGameProject.h"
|
||||
#include "CResourceStore.h"
|
||||
#include <Common/CUniqueID.h>
|
||||
#include <Common/Flags.h>
|
||||
#include <Common/TString.h>
|
||||
|
@ -12,16 +13,16 @@ class CGameExporter
|
|||
{
|
||||
// Project
|
||||
CGameProject *mpProject;
|
||||
CResourceStore mStore;
|
||||
|
||||
// Directories
|
||||
TWideString mGameDir;
|
||||
TWideString mExportDir;
|
||||
TWideString mDiscDir;
|
||||
TWideString mResDir;
|
||||
TWideString mWorldsDir;
|
||||
TWideString mContentDir;
|
||||
TWideString mCookedDir;
|
||||
TWideString mCookedResDir;
|
||||
TWideString mCookedWorldsDir;
|
||||
|
||||
TWideString mWorldsDirName;
|
||||
|
||||
// Resources
|
||||
TWideStringList mWorldPaks;
|
||||
|
|
|
@ -31,11 +31,8 @@ public:
|
|||
inline TWideString ProjectRoot() const { return mProjectRoot; }
|
||||
inline TWideString ResourceDBPath(bool Relative) const { return Relative ? mResourceDBPath : mProjectRoot + mResourceDBPath; }
|
||||
inline TWideString DiscDir(bool Relative) const { return Relative ? L"Disc\\" : mProjectRoot + L"Disc\\"; }
|
||||
inline TWideString ResourcesDir(bool Relative) const { return Relative ? L"Resources\\" : mProjectRoot + L"Resources\\"; }
|
||||
inline TWideString WorldsDir(bool Relative) const { return Relative ? L"Worlds\\" : mProjectRoot + L"Worlds\\"; }
|
||||
inline TWideString ContentDir(bool Relative) const { return Relative ? L"Content\\" : mProjectRoot + L"Content\\"; }
|
||||
inline TWideString CookedDir(bool Relative) const { return Relative ? L"Cooked\\" : mProjectRoot + L"Cooked\\"; }
|
||||
inline TWideString CookedResourcesDir(bool Relative) const { return CookedDir(Relative) + L"Resources\\"; }
|
||||
inline TWideString CookedWorldsDir(bool Relative) const { return CookedDir(Relative) + L"Worlds\\"; }
|
||||
|
||||
// Accessors
|
||||
inline void SetGame(EGame Game) { mGame = Game; }
|
||||
|
|
|
@ -29,7 +29,7 @@ CResourceEntry::CResourceEntry(CResourceStore *pStore, const CUniqueID& rkID,
|
|||
: mpStore(pStore)
|
||||
, mpResource(nullptr)
|
||||
, mID(rkID)
|
||||
, mFileName(rkFilename)
|
||||
, mName(rkFilename)
|
||||
, mType(Type)
|
||||
, mNeedsRecook(false)
|
||||
, mTransient(Transient)
|
||||
|
@ -58,16 +58,16 @@ TString CResourceEntry::RawAssetPath(bool Relative) const
|
|||
{
|
||||
TWideString Ext = GetResourceRawExtension(mType, mGame).ToUTF16();
|
||||
TWideString Path = mpDirectory ? mpDirectory->FullPath() : L"";
|
||||
TWideString Name = mFileName + L"." + Ext;
|
||||
return ((mTransient || Relative) ? Path + Name : mpStore->ActiveProject()->ResourcesDir(false) + Path + Name);
|
||||
TWideString Name = mName + L"." + Ext;
|
||||
return ((mTransient || Relative) ? Path + Name : mpStore->ActiveProject()->ContentDir(false) + Path + Name);
|
||||
}
|
||||
|
||||
TString CResourceEntry::CookedAssetPath(bool Relative) const
|
||||
{
|
||||
TWideString Ext = GetResourceCookedExtension(mType, mGame).ToUTF16();
|
||||
TWideString Path = mpDirectory ? mpDirectory->FullPath() : L"";
|
||||
TWideString Name = mFileName + L"." + Ext;
|
||||
return ((mTransient || Relative) ? Path + Name : mpStore->ActiveProject()->CookedResourcesDir(false) + Path + Name);
|
||||
TWideString Name = mName + L"." + Ext;
|
||||
return ((mTransient || Relative) ? Path + Name : mpStore->ActiveProject()->CookedDir(false) + Path + Name);
|
||||
}
|
||||
|
||||
bool CResourceEntry::NeedsRecook() const
|
||||
|
@ -147,3 +147,68 @@ bool CResourceEntry::Unload()
|
|||
mpResource = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CResourceEntry::Move(const TWideString& rkDir, const TWideString& rkName)
|
||||
{
|
||||
// Store old paths
|
||||
TString OldCookedPath = CookedAssetPath();
|
||||
TString OldRawPath = RawAssetPath();
|
||||
|
||||
// Set new directory and name
|
||||
bool HasDirectory = mpDirectory != nullptr;
|
||||
CVirtualDirectory *pNewDir = mpStore->GetVirtualDirectory(rkDir, mTransient, true);
|
||||
|
||||
if (pNewDir != mpDirectory)
|
||||
{
|
||||
if (mpDirectory)
|
||||
mpDirectory->RemoveChildResource(this);
|
||||
mpDirectory = pNewDir;
|
||||
}
|
||||
|
||||
if (mName != rkName)
|
||||
ASSERT(mpDirectory->FindChildResource(rkName) == nullptr);
|
||||
|
||||
mName = rkName;
|
||||
|
||||
// Move files
|
||||
if (HasDirectory)
|
||||
{
|
||||
TString CookedPath = CookedAssetPath();
|
||||
TString RawPath = RawAssetPath();
|
||||
|
||||
if (FileUtil::Exists(OldCookedPath) && CookedPath != OldCookedPath)
|
||||
FileUtil::MoveFile(OldCookedPath, CookedPath);
|
||||
|
||||
if (FileUtil::Exists(OldRawPath) && RawPath != OldRawPath)
|
||||
FileUtil::MoveFile(OldRawPath, RawPath);
|
||||
}
|
||||
}
|
||||
|
||||
void CResourceEntry::AddToProject(const TWideString& rkDir, const TWideString& rkName)
|
||||
{
|
||||
if (mTransient)
|
||||
{
|
||||
mTransient = false;
|
||||
Move(rkDir, rkName);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Log::Error("AddToProject called on non-transient resource entry: " + CookedAssetPath(true));
|
||||
}
|
||||
}
|
||||
|
||||
void CResourceEntry::RemoveFromProject()
|
||||
{
|
||||
if (!mTransient)
|
||||
{
|
||||
TString Dir = CookedAssetPath().GetFileDirectory();
|
||||
mTransient = true;
|
||||
Move(Dir, mName);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Log::Error("RemoveFromProject called on transient resource entry: " + CookedAssetPath(true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class CResourceEntry
|
|||
EResType mType;
|
||||
EGame mGame;
|
||||
CVirtualDirectory *mpDirectory;
|
||||
TWideString mFileName;
|
||||
TWideString mName;
|
||||
bool mNeedsRecook;
|
||||
bool mTransient;
|
||||
|
||||
|
@ -35,6 +35,9 @@ public:
|
|||
CResource* Load();
|
||||
CResource* Load(IInputStream& rInput);
|
||||
bool Unload();
|
||||
void Move(const TWideString& rkDir, const TWideString& rkName);
|
||||
void AddToProject(const TWideString& rkDir, const TWideString& rkName);
|
||||
void RemoveFromProject();
|
||||
|
||||
// Accessors
|
||||
void SetDirty() { mNeedsRecook = true; }
|
||||
|
@ -44,7 +47,7 @@ public:
|
|||
inline CUniqueID ID() const { return mID; }
|
||||
inline EGame Game() const { return mGame; }
|
||||
inline CVirtualDirectory* Directory() const { return mpDirectory; }
|
||||
inline TString FileName() const { return mFileName; }
|
||||
inline TWideString Name() const { return mName; }
|
||||
inline EResType ResourceType() const { return mType; }
|
||||
inline bool IsTransient() const { return mTransient; }
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <tinyxml2.h>
|
||||
|
||||
using namespace tinyxml2;
|
||||
CResourceStore gResourceStore;
|
||||
CResourceStore *gpResourceStore = new CResourceStore;
|
||||
|
||||
CResourceStore::CResourceStore()
|
||||
: mpProj(nullptr)
|
||||
|
@ -16,8 +16,21 @@ CResourceStore::CResourceStore()
|
|||
, mpExporter(nullptr)
|
||||
{}
|
||||
|
||||
CResourceStore::CResourceStore(CGameExporter *pExporter)
|
||||
: mpProj(nullptr)
|
||||
, mpProjectRoot(nullptr)
|
||||
, mpExporter(pExporter)
|
||||
{}
|
||||
|
||||
CResourceStore::~CResourceStore()
|
||||
{
|
||||
CloseActiveProject();
|
||||
|
||||
for (auto It = mResourceEntries.begin(); It != mResourceEntries.end(); It++)
|
||||
delete It->second;
|
||||
|
||||
for (auto It = mTransientRoots.begin(); It != mTransientRoots.end(); It++)
|
||||
delete *It;
|
||||
}
|
||||
|
||||
void CResourceStore::LoadResourceDatabase(const TString& rkPath)
|
||||
|
@ -122,7 +135,7 @@ void CResourceStore::SaveResourceDatabase(const TString& rkPath) const
|
|||
pRes->LinkEndChild(pDir);
|
||||
|
||||
XMLElement *pName = Doc.NewElement("FileName");
|
||||
pName->SetText(*pEntry->FileName());
|
||||
pName->SetText(*pEntry->Name().ToUTF8());
|
||||
pRes->LinkEndChild(pName);
|
||||
|
||||
XMLElement *pRecook = Doc.NewElement("NeedsRecook");
|
||||
|
@ -143,7 +156,9 @@ void CResourceStore::SetActiveProject(CGameProject *pProj)
|
|||
if (pProj)
|
||||
{
|
||||
mpProjectRoot = new CVirtualDirectory();
|
||||
LoadResourceDatabase(pProj->ResourceDBPath(false));
|
||||
|
||||
if (!mpExporter)
|
||||
LoadResourceDatabase(pProj->ResourceDBPath(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +172,7 @@ void CResourceStore::CloseActiveProject()
|
|||
{
|
||||
delete pEntry;
|
||||
It = mResourceEntries.erase(It);
|
||||
if (It == mResourceEntries.end()) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,33 +219,34 @@ CResourceEntry* CResourceStore::FindEntry(const CUniqueID& rkID) const
|
|||
else return Found->second;
|
||||
}
|
||||
|
||||
bool CResourceStore::RegisterResource(const CUniqueID& rkID, EResType Type, const TWideString& rkDir, const TWideString& rkFileName)
|
||||
bool CResourceStore::IsResourceRegistered(const CUniqueID& rkID) const
|
||||
{
|
||||
return FindEntry(rkID) == nullptr;
|
||||
}
|
||||
|
||||
CResourceEntry* CResourceStore::RegisterResource(const CUniqueID& rkID, EResType Type, const TWideString& rkDir, const TWideString& rkFileName)
|
||||
{
|
||||
CResourceEntry *pEntry = FindEntry(rkID);
|
||||
|
||||
if (pEntry)
|
||||
{
|
||||
Log::Error("Attempted to register resource that's already tracked in the database: " + rkID.ToString() + " / " + rkDir.ToUTF8() + " / " + rkFileName.ToUTF8());
|
||||
return false;
|
||||
if (pEntry->IsTransient())
|
||||
{
|
||||
ASSERT(pEntry->ResourceType() == Type);
|
||||
pEntry->AddToProject(rkDir, rkFileName);
|
||||
}
|
||||
|
||||
else
|
||||
Log::Error("Attempted to register resource that's already tracked in the database: " + rkID.ToString() + " / " + rkDir.ToUTF8() + " / " + rkFileName.ToUTF8());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
pEntry = new CResourceEntry(this, rkID, rkDir, rkFileName.GetFileName(false), Type);
|
||||
|
||||
if (!pEntry->HasCookedVersion() && !pEntry->HasRawVersion())
|
||||
{
|
||||
Log::Error("Attempted to register a resource that doesn't exist: " + rkID.ToString() + " | " + rkDir.ToUTF8() + " | " + rkFileName.ToUTF8());
|
||||
delete pEntry;
|
||||
return false;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mResourceEntries[rkID] = pEntry;
|
||||
return true;
|
||||
}
|
||||
mResourceEntries[rkID] = pEntry;
|
||||
}
|
||||
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
CResourceEntry* CResourceStore::RegisterTransientResource(EResType Type, const TWideString& rkDir /*= L""*/, const TWideString& rkFileName /*= L""*/)
|
||||
|
@ -241,8 +258,17 @@ CResourceEntry* CResourceStore::RegisterTransientResource(EResType Type, const T
|
|||
|
||||
CResourceEntry* CResourceStore::RegisterTransientResource(EResType Type, const CUniqueID& rkID, const TWideString& rkDir /*=L ""*/, const TWideString& rkFileName /*= L""*/)
|
||||
{
|
||||
CResourceEntry *pEntry = new CResourceEntry(this, rkID, rkDir, rkFileName, Type, true);
|
||||
mResourceEntries[rkID] = pEntry;
|
||||
CResourceEntry *pEntry = FindEntry(rkID);
|
||||
|
||||
if (pEntry)
|
||||
Log::Error("Attempted to register transient resource that already exists: " + rkID.ToString() + " / Dir: " + rkDir.ToUTF8() + " / Name: " + rkFileName.ToUTF8());
|
||||
|
||||
else
|
||||
{
|
||||
pEntry = new CResourceEntry(this, rkID, rkDir, rkFileName, Type, true);
|
||||
mResourceEntries[rkID] = pEntry;
|
||||
}
|
||||
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
|
@ -266,7 +292,12 @@ CResource* CResourceStore::LoadResource(const CUniqueID& rkID, const CFourCC& rk
|
|||
EResType Type = CResource::ResTypeForExtension(rkType);
|
||||
CResourceEntry *pEntry = RegisterTransientResource(Type, rkID);
|
||||
CResource *pRes = pEntry->Load(MemStream);
|
||||
if (pRes) mLoadedResources[rkID] = pEntry;
|
||||
|
||||
if (pRes)
|
||||
{
|
||||
mLoadedResources[rkID] = pEntry;
|
||||
}
|
||||
|
||||
return pRes;
|
||||
}
|
||||
|
||||
|
@ -292,6 +323,7 @@ CResource* CResourceStore::LoadResource(const CUniqueID& rkID, const CFourCC& rk
|
|||
CResource *pRes = pEntry->Load(File);
|
||||
|
||||
if (pRes) mLoadedResources[rkID] = pEntry;
|
||||
else DeleteResourceEntry(pEntry);
|
||||
return pRes;
|
||||
}
|
||||
|
||||
|
@ -341,6 +373,8 @@ CResource* CResourceStore::LoadResource(const TString& rkPath)
|
|||
CResource *pRes = pEntry->Load(File);
|
||||
|
||||
if (pRes) mLoadedResources[ID] = pEntry;
|
||||
else DeleteResourceEntry(pEntry);
|
||||
|
||||
mTransientLoadDir = OldTransientDir;
|
||||
|
||||
return pRes;
|
||||
|
@ -385,16 +419,16 @@ void CResourceStore::DestroyUnreferencedResources()
|
|||
{
|
||||
CResourceEntry *pEntry = It->second;
|
||||
|
||||
if (!pEntry->Resource()->IsReferenced())
|
||||
if (!pEntry->Resource()->IsReferenced() && pEntry->Unload())
|
||||
{
|
||||
bool Unloaded = pEntry->Unload();
|
||||
It = mLoadedResources.erase(It);
|
||||
NumDeleted++;
|
||||
|
||||
if (Unloaded)
|
||||
{
|
||||
It = mLoadedResources.erase(It);
|
||||
NumDeleted++;
|
||||
if (It == mLoadedResources.end()) break;
|
||||
}
|
||||
// Transient resources should have their entries cleared out when the resource is unloaded
|
||||
if (pEntry->IsTransient())
|
||||
DeleteResourceEntry(pEntry);
|
||||
|
||||
if (It == mLoadedResources.end()) break;
|
||||
}
|
||||
}
|
||||
} while (NumDeleted > 0);
|
||||
|
@ -414,6 +448,28 @@ void CResourceStore::DestroyUnreferencedResources()
|
|||
Log::Write(TString::FromInt32(mLoadedResources.size(), 0, 10) + " resources loaded");
|
||||
}
|
||||
|
||||
bool CResourceStore::DeleteResourceEntry(CResourceEntry *pEntry)
|
||||
{
|
||||
CUniqueID ID = pEntry->ID();
|
||||
|
||||
if (pEntry->IsLoaded())
|
||||
{
|
||||
if (!pEntry->Unload())
|
||||
return false;
|
||||
|
||||
auto It = mLoadedResources.find(ID);
|
||||
ASSERT(It != mLoadedResources.end());
|
||||
mLoadedResources.erase(It);
|
||||
}
|
||||
|
||||
auto It = mResourceEntries.find(ID);
|
||||
ASSERT(It != mResourceEntries.end());
|
||||
mResourceEntries.erase(It);
|
||||
|
||||
delete pEntry;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CResourceStore::SetTransientLoadDir(const TString& rkDir)
|
||||
{
|
||||
mTransientLoadDir = rkDir;
|
||||
|
|
|
@ -38,6 +38,7 @@ class CResourceStore
|
|||
|
||||
public:
|
||||
CResourceStore();
|
||||
CResourceStore(CGameExporter *pExporter);
|
||||
~CResourceStore();
|
||||
void LoadResourceDatabase(const TString& rkPath);
|
||||
void SaveResourceDatabase(const TString& rkPath) const;
|
||||
|
@ -45,7 +46,8 @@ public:
|
|||
void CloseActiveProject();
|
||||
CVirtualDirectory* GetVirtualDirectory(const TWideString& rkPath, bool Transient, bool AllowCreate);
|
||||
|
||||
bool RegisterResource(const CUniqueID& rkID, EResType Type, const TWideString& rkDir, const TWideString& rkFileName);
|
||||
bool IsResourceRegistered(const CUniqueID& rkID) const;
|
||||
CResourceEntry* RegisterResource(const CUniqueID& rkID, EResType Type, const TWideString& rkDir, const TWideString& rkFileName);
|
||||
CResourceEntry* FindEntry(const CUniqueID& rkID) const;
|
||||
CResourceEntry* RegisterTransientResource(EResType Type, const TWideString& rkDir = L"", const TWideString& rkFileName = L"");
|
||||
CResourceEntry* RegisterTransientResource(EResType Type, const CUniqueID& rkID, const TWideString& rkDir = L"", const TWideString& rkFileName = L"");
|
||||
|
@ -54,12 +56,13 @@ public:
|
|||
CResource* LoadResource(const TString& rkPath);
|
||||
CFourCC ResourceTypeByID(const CUniqueID& rkID, const TStringList& rkPossibleTypes) const;
|
||||
void DestroyUnreferencedResources();
|
||||
bool DeleteResourceEntry(CResourceEntry *pEntry);
|
||||
void SetTransientLoadDir(const TString& rkDir);
|
||||
|
||||
inline CGameProject* ActiveProject() const { return mpProj; }
|
||||
inline void SetGameExporter(CGameExporter *pExporter) { mpExporter = pExporter; }
|
||||
// Accessors
|
||||
inline CGameProject* ActiveProject() const { return mpProj; }
|
||||
};
|
||||
|
||||
extern CResourceStore gResourceStore;
|
||||
extern CResourceStore *gpResourceStore;
|
||||
|
||||
#endif // CRESOURCEDATABASE_H
|
||||
|
|
|
@ -54,8 +54,16 @@ CVirtualDirectory* CVirtualDirectory::FindChildDirectory(const TWideString& rkNa
|
|||
{
|
||||
if (SlashIdx == -1)
|
||||
return pChild;
|
||||
|
||||
else
|
||||
return pChild->FindChildDirectory( rkName.SubString(SlashIdx + 1, rkName.Size() - SlashIdx), AllowCreate );
|
||||
{
|
||||
TWideString Remaining = rkName.SubString(SlashIdx + 1, rkName.Size() - SlashIdx);
|
||||
|
||||
if (Remaining.IsEmpty())
|
||||
return pChild;
|
||||
else
|
||||
return pChild->FindChildDirectory(Remaining, AllowCreate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +78,17 @@ CVirtualDirectory* CVirtualDirectory::FindChildDirectory(const TWideString& rkNa
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
CResourceEntry* CVirtualDirectory::FindChildResource(const TWideString& rkName) const
|
||||
{
|
||||
for (u32 iRes = 0; iRes < mResources.size(); iRes++)
|
||||
{
|
||||
if (mResources[iRes]->Name() == rkName)
|
||||
return mResources[iRes];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CVirtualDirectory::AddChild(const TWideString &rkPath, CResourceEntry *pEntry)
|
||||
{
|
||||
if (rkPath.IsEmpty())
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
TWideString FullPath() const;
|
||||
CVirtualDirectory* GetRoot();
|
||||
CVirtualDirectory* FindChildDirectory(const TWideString& rkName, bool AllowCreate);
|
||||
CResourceEntry* FindChildResource(const TWideString& rkName) const;
|
||||
void AddChild(const TWideString& rkPath, CResourceEntry *pEntry);
|
||||
bool RemoveChildDirectory(CVirtualDirectory *pSubdir);
|
||||
bool RemoveChildResource(CResourceEntry *pEntry);
|
||||
|
|
|
@ -480,7 +480,7 @@ void CDrawUtil::InitLine()
|
|||
void CDrawUtil::InitCube()
|
||||
{
|
||||
Log::Write("Creating cube");
|
||||
mpCubeModel = gResourceStore.LoadResource("../resources/Cube.cmdl");
|
||||
mpCubeModel = gpResourceStore->LoadResource("../resources/Cube.cmdl");
|
||||
}
|
||||
|
||||
void CDrawUtil::InitWireCube()
|
||||
|
@ -518,14 +518,14 @@ void CDrawUtil::InitWireCube()
|
|||
void CDrawUtil::InitSphere()
|
||||
{
|
||||
Log::Write("Creating sphere");
|
||||
mpSphereModel = gResourceStore.LoadResource("../resources/Sphere.cmdl");
|
||||
mpDoubleSidedSphereModel = gResourceStore.LoadResource("../resources/SphereDoubleSided.cmdl");
|
||||
mpSphereModel = gpResourceStore->LoadResource("../resources/Sphere.cmdl");
|
||||
mpDoubleSidedSphereModel = gpResourceStore->LoadResource("../resources/SphereDoubleSided.cmdl");
|
||||
}
|
||||
|
||||
void CDrawUtil::InitWireSphere()
|
||||
{
|
||||
Log::Write("Creating wire sphere");
|
||||
mpWireSphereModel = gResourceStore.LoadResource("../resources/WireSphere.cmdl");
|
||||
mpWireSphereModel = gpResourceStore->LoadResource("../resources/WireSphere.cmdl");
|
||||
}
|
||||
|
||||
void CDrawUtil::InitShaders()
|
||||
|
@ -543,17 +543,17 @@ void CDrawUtil::InitShaders()
|
|||
void CDrawUtil::InitTextures()
|
||||
{
|
||||
Log::Write("Loading textures");
|
||||
mpCheckerTexture = gResourceStore.LoadResource("../resources/Checkerboard.txtr");
|
||||
mpCheckerTexture = gpResourceStore->LoadResource("../resources/Checkerboard.txtr");
|
||||
|
||||
mpLightTextures[0] = gResourceStore.LoadResource("../resources/LightAmbient.txtr");
|
||||
mpLightTextures[1] = gResourceStore.LoadResource("../resources/LightDirectional.txtr");
|
||||
mpLightTextures[2] = gResourceStore.LoadResource("../resources/LightCustom.txtr");
|
||||
mpLightTextures[3] = gResourceStore.LoadResource("../resources/LightSpot.txtr");
|
||||
mpLightTextures[0] = gpResourceStore->LoadResource("../resources/LightAmbient.txtr");
|
||||
mpLightTextures[1] = gpResourceStore->LoadResource("../resources/LightDirectional.txtr");
|
||||
mpLightTextures[2] = gpResourceStore->LoadResource("../resources/LightCustom.txtr");
|
||||
mpLightTextures[3] = gpResourceStore->LoadResource("../resources/LightSpot.txtr");
|
||||
|
||||
mpLightMasks[0] = gResourceStore.LoadResource("../resources/LightAmbientMask.txtr");
|
||||
mpLightMasks[1] = gResourceStore.LoadResource("../resources/LightDirectionalMask.txtr");
|
||||
mpLightMasks[2] = gResourceStore.LoadResource("../resources/LightCustomMask.txtr");
|
||||
mpLightMasks[3] = gResourceStore.LoadResource("../resources/LightSpotMask.txtr");
|
||||
mpLightMasks[0] = gpResourceStore->LoadResource("../resources/LightAmbientMask.txtr");
|
||||
mpLightMasks[1] = gpResourceStore->LoadResource("../resources/LightDirectionalMask.txtr");
|
||||
mpLightMasks[2] = gpResourceStore->LoadResource("../resources/LightCustomMask.txtr");
|
||||
mpLightMasks[3] = gpResourceStore->LoadResource("../resources/LightSpotMask.txtr");
|
||||
}
|
||||
|
||||
void CDrawUtil::Shutdown()
|
||||
|
|
|
@ -60,7 +60,6 @@ class CFont : public CResource
|
|||
public:
|
||||
CFont(CResourceEntry *pEntry = 0);
|
||||
~CFont();
|
||||
CResource* MakeCopy(CResCache *pCopyCache);
|
||||
CVector2f RenderString(const TString& rkString, CRenderer *pRenderer, float AspectRatio,
|
||||
CVector2f Position = CVector2f(0,0),
|
||||
CColor FillColor = CColor::skWhite, CColor StrokeColor = CColor::skBlack,
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
#include <Common/types.h>
|
||||
#include <Common/TString.h>
|
||||
|
||||
class CResCache;
|
||||
|
||||
// This macro creates functions that allow us to easily identify this resource type.
|
||||
// Must be included on every CResource subclass.
|
||||
#define DECLARE_RESOURCE_TYPE(ResTypeEnum) \
|
||||
|
@ -38,18 +36,17 @@ public:
|
|||
CResource(CResourceEntry *pEntry = 0)
|
||||
: mpEntry(pEntry), mRefCount(0)
|
||||
{
|
||||
if (!mpEntry) mpEntry = gResourceStore.RegisterTransientResource(Type());
|
||||
}
|
||||
|
||||
virtual ~CResource() {}
|
||||
|
||||
inline CResourceEntry* Entry() const { return mpEntry; }
|
||||
inline TString Source() const { return mpEntry->CookedAssetPath(true).GetFileName(); }
|
||||
inline TString FullSource() const { return mpEntry->CookedAssetPath(true); }
|
||||
inline CUniqueID ResID() const { return mpEntry->ID(); }
|
||||
inline EGame Game() const { return mpEntry->Game(); }
|
||||
inline TString Source() const { return mpEntry ? mpEntry->CookedAssetPath(true).GetFileName() : ""; }
|
||||
inline TString FullSource() const { return mpEntry ? mpEntry->CookedAssetPath(true) : ""; }
|
||||
inline CUniqueID ResID() const { return mpEntry ? mpEntry->ID() : CUniqueID::skInvalidID64; }
|
||||
inline EGame Game() const { return mpEntry ? mpEntry->Game() : eUnknownVersion; }
|
||||
inline bool IsReferenced() const { return mRefCount > 0; }
|
||||
inline void SetGame(EGame Game) { mpEntry->SetGame(Game); }
|
||||
inline void SetGame(EGame Game) { if (mpEntry) mpEntry->SetGame(Game); }
|
||||
inline void Lock() { mRefCount++; }
|
||||
inline void Release() { mRefCount--; }
|
||||
|
||||
|
|
|
@ -60,9 +60,9 @@ public:
|
|||
if (!IsValid())
|
||||
return nullptr;
|
||||
if (mIsPath)
|
||||
return gResourceStore.LoadResource(mPath);
|
||||
return gpResourceStore->LoadResource(mPath);
|
||||
else
|
||||
return gResourceStore.LoadResource(ID(), Type());
|
||||
return gpResourceStore->LoadResource(ID(), Type());
|
||||
}
|
||||
|
||||
inline bool IsValid() const
|
||||
|
|
|
@ -14,7 +14,7 @@ CAnimSet* CAnimSetLoader::LoadCorruptionCHAR(IInputStream& rCHAR)
|
|||
CAnimSet::SNode& node = pSet->mNodes[0];
|
||||
|
||||
node.Name = rCHAR.ReadString();
|
||||
node.pModel = gResourceStore.LoadResource(rCHAR.ReadLongLong(), "CMDL");
|
||||
node.pModel = gpResourceStore->LoadResource(rCHAR.ReadLongLong(), "CMDL");
|
||||
return pSet;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ CAnimSet* CAnimSetLoader::LoadReturnsCHAR(IInputStream& rCHAR)
|
|||
rNode.Name = rCHAR.ReadString();
|
||||
rCHAR.Seek(0x14, SEEK_CUR);
|
||||
rCHAR.ReadString();
|
||||
rNode.pModel = gResourceStore.LoadResource(rCHAR.ReadLongLong(), "CMDL");
|
||||
rNode.pModel = gpResourceStore->LoadResource(rCHAR.ReadLongLong(), "CMDL");
|
||||
return pSet;
|
||||
}
|
||||
|
||||
|
@ -238,9 +238,9 @@ CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& rANCS, CResourceEntry *pEntry)
|
|||
Loader.pSet->SetGame(Loader.mVersion);
|
||||
}
|
||||
pNode->Name = rANCS.ReadString();
|
||||
pNode->pModel = gResourceStore.LoadResource(rANCS.ReadLong(), "CMDL");
|
||||
pNode->pSkin = gResourceStore.LoadResource(rANCS.ReadLong(), "CSKR");
|
||||
pNode->pSkeleton = gResourceStore.LoadResource(rANCS.ReadLong(), "CINF");
|
||||
pNode->pModel = gpResourceStore->LoadResource(rANCS.ReadLong(), "CMDL");
|
||||
pNode->pSkin = gpResourceStore->LoadResource(rANCS.ReadLong(), "CSKR");
|
||||
pNode->pSkeleton = gpResourceStore->LoadResource(rANCS.ReadLong(), "CINF");
|
||||
if (pNode->pModel) pNode->pModel->SetSkin(pNode->pSkin);
|
||||
|
||||
// Unfortunately that's all that's actually supported at the moment. Hope to expand later.
|
||||
|
@ -349,7 +349,7 @@ CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& rANCS, CResourceEntry *pEntry)
|
|||
{
|
||||
CAnimSet::SAnimation Anim;
|
||||
Anim.Name = rPrim.Name;
|
||||
Anim.pAnim = gResourceStore.LoadResource(rPrim.AnimID, "ANIM");
|
||||
Anim.pAnim = gpResourceStore->LoadResource(rPrim.AnimID, "ANIM");
|
||||
Loader.pSet->mAnims.push_back(Anim);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
class CAnimSetLoader
|
||||
{
|
||||
TResPtr<CAnimSet> pSet;
|
||||
CResCache *mpResCache;
|
||||
EGame mVersion;
|
||||
|
||||
CAnimSetLoader();
|
||||
|
|
|
@ -603,7 +603,7 @@ void CAreaLoader::ReadEGMC()
|
|||
Log::FileWrite(mpMREA->GetSourceString(), "Reading EGMC");
|
||||
mpSectionMgr->ToSection(mEGMCBlockNum);
|
||||
CUniqueID EGMC(*mpMREA, (mVersion <= eEchoes ? e32Bit : e64Bit));
|
||||
mpArea->mpPoiToWorldMap = gResourceStore.LoadResource(EGMC, "EGMC");
|
||||
mpArea->mpPoiToWorldMap = gpResourceStore->LoadResource(EGMC, "EGMC");
|
||||
}
|
||||
|
||||
void CAreaLoader::SetUpObjects()
|
||||
|
|
|
@ -18,8 +18,8 @@ CFont* CFontLoader::LoadFont(IInputStream& rFONT)
|
|||
mpFont->mDefaultSize = rFONT.ReadLong();
|
||||
mpFont->mFontName = rFONT.ReadString();
|
||||
|
||||
if (mVersion <= eEchoes) mpFont->mpFontTexture = gResourceStore.LoadResource(rFONT.ReadLong(), "TXTR");
|
||||
else mpFont->mpFontTexture = gResourceStore.LoadResource(rFONT.ReadLongLong(), "TXTR");
|
||||
if (mVersion <= eEchoes) mpFont->mpFontTexture = gpResourceStore->LoadResource(rFONT.ReadLong(), "TXTR");
|
||||
else mpFont->mpFontTexture = gpResourceStore->LoadResource(rFONT.ReadLongLong(), "TXTR");
|
||||
|
||||
mpFont->mTextureFormat = rFONT.ReadLong();
|
||||
u32 NumGlyphs = rFONT.ReadLong();
|
||||
|
|
|
@ -50,7 +50,7 @@ void CMaterialLoader::ReadPrimeMatSet()
|
|||
for (u32 iTex = 0; iTex < NumTextures; iTex++)
|
||||
{
|
||||
u32 TextureID = mpFile->ReadLong();
|
||||
mTextures[iTex] = gResourceStore.LoadResource(TextureID, "TXTR");
|
||||
mTextures[iTex] = gpResourceStore->LoadResource(TextureID, "TXTR");
|
||||
}
|
||||
|
||||
// Materials
|
||||
|
@ -366,7 +366,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
|
|||
continue;
|
||||
}
|
||||
|
||||
pPass->mpTexture = gResourceStore.LoadResource(TextureID, "TXTR");
|
||||
pPass->mpTexture = gpResourceStore->LoadResource(TextureID, "TXTR");
|
||||
|
||||
pPass->mTexCoordSource = 4 + (u8) mpFile->ReadLong();
|
||||
u32 AnimSize = mpFile->ReadLong();
|
||||
|
|
|
@ -10,7 +10,7 @@ CScan* CScanLoader::LoadScanMP1(IInputStream& rSCAN)
|
|||
{
|
||||
// Basic support at the moment - don't read animation/scan image data
|
||||
rSCAN.Seek(0x4, SEEK_CUR); // Skip FRME ID
|
||||
mpScan->mpStringTable = gResourceStore.LoadResource(rSCAN.ReadLong(), "STRG");
|
||||
mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLong(), "STRG");
|
||||
mpScan->mIsSlow = (rSCAN.ReadLong() != 0);
|
||||
mpScan->mCategory = (CScan::ELogbookCategory) rSCAN.ReadLong();
|
||||
mpScan->mIsImportant = (rSCAN.ReadByte() == 1);
|
||||
|
@ -88,7 +88,7 @@ void CScanLoader::LoadParamsMP2(IInputStream& rSCAN)
|
|||
switch (PropertyID)
|
||||
{
|
||||
case 0x2F5B6423:
|
||||
mpScan->mpStringTable = gResourceStore.LoadResource(rSCAN.ReadLong(), "STRG");
|
||||
mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLong(), "STRG");
|
||||
break;
|
||||
|
||||
case 0xC308A322:
|
||||
|
@ -121,7 +121,7 @@ void CScanLoader::LoadParamsMP3(IInputStream& rSCAN)
|
|||
switch (PropertyID)
|
||||
{
|
||||
case 0x2F5B6423:
|
||||
mpScan->mpStringTable = gResourceStore.LoadResource(rSCAN.ReadLongLong(), "STRG");
|
||||
mpScan->mpStringTable = gpResourceStore->LoadResource(rSCAN.ReadLongLong(), "STRG");
|
||||
break;
|
||||
|
||||
case 0xC308A322:
|
||||
|
|
|
@ -117,7 +117,7 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY
|
|||
|
||||
if (ResID.IsValid())
|
||||
{
|
||||
CFourCC Type = gResourceStore.ResourceTypeByID(ResID, rkExtensions);
|
||||
CFourCC Type = gpResourceStore->ResourceTypeByID(ResID, rkExtensions);
|
||||
Info = CResourceInfo(ResID, Type);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,19 +15,19 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
|
|||
// Header
|
||||
if (mVersion < eCorruptionProto)
|
||||
{
|
||||
mpWorld->mpWorldName = gResourceStore.LoadResource(rMLVL.ReadLong(), "STRG");
|
||||
if (mVersion == eEchoes) mpWorld->mpDarkWorldName = gResourceStore.LoadResource(rMLVL.ReadLong(), "STRG");
|
||||
mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLong(), "STRG");
|
||||
if (mVersion == eEchoes) mpWorld->mpDarkWorldName = gpResourceStore->LoadResource(rMLVL.ReadLong(), "STRG");
|
||||
if (mVersion >= eEchoes) mpWorld->mUnknown1 = rMLVL.ReadLong();
|
||||
if (mVersion >= ePrime) mpWorld->mpSaveWorld = gResourceStore.LoadResource(rMLVL.ReadLong(), "SAVW");
|
||||
mpWorld->mpDefaultSkybox = gResourceStore.LoadResource(rMLVL.ReadLong(), "CMDL");
|
||||
if (mVersion >= ePrime) mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLong(), "SAVW");
|
||||
mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLong(), "CMDL");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mpWorld->mpWorldName = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
rMLVL.Seek(0x4, SEEK_CUR); // Skipping unknown value
|
||||
mpWorld->mpSaveWorld = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "SAVW");
|
||||
mpWorld->mpDefaultSkybox = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "CMDL");
|
||||
mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "SAVW");
|
||||
mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "CMDL");
|
||||
}
|
||||
|
||||
// Memory relays - only in MP1
|
||||
|
@ -58,9 +58,9 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
|
|||
CWorld::SArea *pArea = &mpWorld->mAreas[iArea];
|
||||
|
||||
if (mVersion < eCorruptionProto)
|
||||
pArea->pAreaName = gResourceStore.LoadResource(rMLVL.ReadLong(), "STRG");
|
||||
pArea->pAreaName = gpResourceStore->LoadResource(rMLVL.ReadLong(), "STRG");
|
||||
else
|
||||
pArea->pAreaName = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
pArea->pAreaName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
|
||||
pArea->Transform = CTransform4f(rMLVL);
|
||||
pArea->AetherBox = CAABox(rMLVL);
|
||||
|
@ -169,9 +169,9 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
|
|||
|
||||
// MapWorld
|
||||
if (mVersion < eCorruptionProto)
|
||||
mpWorld->mpMapWorld = gResourceStore.LoadResource(rMLVL.ReadLong(), "MAPW");
|
||||
mpWorld->mpMapWorld = gpResourceStore->LoadResource(rMLVL.ReadLong(), "MAPW");
|
||||
else
|
||||
mpWorld->mpMapWorld = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "MAPW");
|
||||
mpWorld->mpMapWorld = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "MAPW");
|
||||
rMLVL.Seek(0x5, SEEK_CUR); // Unknown values which are always 0
|
||||
|
||||
// AudioGrps
|
||||
|
@ -221,7 +221,7 @@ void CWorldLoader::LoadPrimeMLVL(IInputStream& rMLVL)
|
|||
|
||||
void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL)
|
||||
{
|
||||
mpWorld->mpWorldName = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
mpWorld->mpWorldName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
|
||||
bool Check = (rMLVL.ReadByte() != 0);
|
||||
if (Check)
|
||||
|
@ -230,8 +230,8 @@ void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL)
|
|||
rMLVL.Seek(0x10, SEEK_CUR);
|
||||
}
|
||||
|
||||
mpWorld->mpSaveWorld = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "SAVW");
|
||||
mpWorld->mpDefaultSkybox = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "CMDL");
|
||||
mpWorld->mpSaveWorld = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "SAVW");
|
||||
mpWorld->mpDefaultSkybox = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "CMDL");
|
||||
|
||||
// Areas
|
||||
u32 NumAreas = rMLVL.ReadLong();
|
||||
|
@ -242,7 +242,7 @@ void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL)
|
|||
// Area header
|
||||
CWorld::SArea *pArea = &mpWorld->mAreas[iArea];
|
||||
|
||||
pArea->pAreaName = gResourceStore.LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
pArea->pAreaName = gpResourceStore->LoadResource(rMLVL.ReadLongLong(), "STRG");
|
||||
pArea->Transform = CTransform4f(rMLVL);
|
||||
pArea->AetherBox = CAABox(rMLVL);
|
||||
pArea->FileID = rMLVL.ReadLongLong();
|
||||
|
|
|
@ -166,7 +166,7 @@ CResource* CScriptTemplate::FindDisplayAsset(CPropertyStruct *pProperties, u32&
|
|||
if (it->AssetSource == SEditorAsset::eFile)
|
||||
{
|
||||
TString Path = "../resources/" + it->AssetLocation;
|
||||
pRes = gResourceStore.LoadResource(Path);
|
||||
pRes = gpResourceStore->LoadResource(Path);
|
||||
}
|
||||
|
||||
// Property
|
||||
|
@ -216,7 +216,7 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties
|
|||
if (it->AssetSource == SEditorAsset::eFile)
|
||||
{
|
||||
TString path = "../resources/" + it->AssetLocation;
|
||||
pRes = gResourceStore.LoadResource(path);
|
||||
pRes = gpResourceStore->LoadResource(path);
|
||||
}
|
||||
|
||||
// Property
|
||||
|
|
|
@ -258,7 +258,7 @@ void CSceneNode::DrawBoundingBox() const
|
|||
|
||||
void CSceneNode::DrawRotationArrow() const
|
||||
{
|
||||
static TResPtr<CModel> spArrowModel = gResourceStore.LoadResource("../resources/RotationArrow.cmdl");
|
||||
static TResPtr<CModel> spArrowModel = gpResourceStore->LoadResource("../resources/RotationArrow.cmdl");
|
||||
spArrowModel->Draw(eNoRenderOptions, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -535,15 +535,15 @@ void CScriptNode::UpdatePreviewVolume()
|
|||
{
|
||||
case eAxisAlignedBoxShape:
|
||||
case eBoxShape:
|
||||
pVolumeModel = gResourceStore.LoadResource("../resources/VolumeBox.cmdl");
|
||||
pVolumeModel = gpResourceStore->LoadResource("../resources/VolumeBox.cmdl");
|
||||
break;
|
||||
|
||||
case eEllipsoidShape:
|
||||
pVolumeModel = gResourceStore.LoadResource("../resources/VolumeSphere.cmdl");
|
||||
pVolumeModel = gpResourceStore->LoadResource("../resources/VolumeSphere.cmdl");
|
||||
break;
|
||||
|
||||
case eCylinderShape:
|
||||
pVolumeModel = gResourceStore.LoadResource("../resources/VolumeCylinder.cmdl");
|
||||
pVolumeModel = gpResourceStore->LoadResource("../resources/VolumeCylinder.cmdl");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -543,32 +543,32 @@ void CGizmo::LoadModels()
|
|||
{
|
||||
Log::Write("Loading transform gizmo models");
|
||||
|
||||
smTranslateModels[CGIZMO_TRANSLATE_X] = SModelPart(eX, true, false, gResourceStore.LoadResource("../resources/editor/TranslateX.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_Y] = SModelPart(eY, true, false, gResourceStore.LoadResource("../resources/editor/TranslateY.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_Z] = SModelPart(eZ, true, false, gResourceStore.LoadResource("../resources/editor/TranslateZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_LINES_XY] = SModelPart(eXY, true, false, gResourceStore.LoadResource("../resources/editor/TranslateLinesXY.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_LINES_XZ] = SModelPart(eXZ, true, false, gResourceStore.LoadResource("../resources/editor/TranslateLinesXZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_LINES_YZ] = SModelPart(eYZ, true, false, gResourceStore.LoadResource("../resources/editor/TranslateLinesYZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_POLY_XY] = SModelPart(eXY, false, false, gResourceStore.LoadResource("../resources/editor/TranslatePolyXY.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_POLY_XZ] = SModelPart(eXZ, false, false, gResourceStore.LoadResource("../resources/editor/TranslatePolyXZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_POLY_YZ] = SModelPart(eYZ, false, false, gResourceStore.LoadResource("../resources/editor/TranslatePolyYZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_X] = SModelPart(eX, true, false, gpResourceStore->LoadResource("../resources/editor/TranslateX.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_Y] = SModelPart(eY, true, false, gpResourceStore->LoadResource("../resources/editor/TranslateY.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_Z] = SModelPart(eZ, true, false, gpResourceStore->LoadResource("../resources/editor/TranslateZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_LINES_XY] = SModelPart(eXY, true, false, gpResourceStore->LoadResource("../resources/editor/TranslateLinesXY.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_LINES_XZ] = SModelPart(eXZ, true, false, gpResourceStore->LoadResource("../resources/editor/TranslateLinesXZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_LINES_YZ] = SModelPart(eYZ, true, false, gpResourceStore->LoadResource("../resources/editor/TranslateLinesYZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_POLY_XY] = SModelPart(eXY, false, false, gpResourceStore->LoadResource("../resources/editor/TranslatePolyXY.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_POLY_XZ] = SModelPart(eXZ, false, false, gpResourceStore->LoadResource("../resources/editor/TranslatePolyXZ.CMDL"));
|
||||
smTranslateModels[CGIZMO_TRANSLATE_POLY_YZ] = SModelPart(eYZ, false, false, gpResourceStore->LoadResource("../resources/editor/TranslatePolyYZ.CMDL"));
|
||||
|
||||
smRotateModels[CGIZMO_ROTATE_OUTLINE] = SModelPart(eNone, true, true, gResourceStore.LoadResource("../resources/editor/RotateClipOutline.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_X] = SModelPart(eX, true, false, gResourceStore.LoadResource("../resources/editor/RotateX.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_Y] = SModelPart(eY, true, false, gResourceStore.LoadResource("../resources/editor/RotateY.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_Z] = SModelPart(eZ, true, false, gResourceStore.LoadResource("../resources/editor/RotateZ.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_XYZ] = SModelPart(eXYZ, false, false, gResourceStore.LoadResource("../resources/editor/RotateXYZ.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_OUTLINE] = SModelPart(eNone, true, true, gpResourceStore->LoadResource("../resources/editor/RotateClipOutline.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_X] = SModelPart(eX, true, false, gpResourceStore->LoadResource("../resources/editor/RotateX.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_Y] = SModelPart(eY, true, false, gpResourceStore->LoadResource("../resources/editor/RotateY.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_Z] = SModelPart(eZ, true, false, gpResourceStore->LoadResource("../resources/editor/RotateZ.CMDL"));
|
||||
smRotateModels[CGIZMO_ROTATE_XYZ] = SModelPart(eXYZ, false, false, gpResourceStore->LoadResource("../resources/editor/RotateXYZ.CMDL"));
|
||||
|
||||
smScaleModels[CGIZMO_SCALE_X] = SModelPart(eX, true, false, gResourceStore.LoadResource("../resources/editor/ScaleX.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_Y] = SModelPart(eY, true, false, gResourceStore.LoadResource("../resources/editor/ScaleY.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_Z] = SModelPart(eZ, true, false, gResourceStore.LoadResource("../resources/editor/ScaleZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_LINES_XY] = SModelPart(eXY, true, false, gResourceStore.LoadResource("../resources/editor/ScaleLinesXY.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_LINES_XZ] = SModelPart(eXZ, true, false, gResourceStore.LoadResource("../resources/editor/ScaleLinesXZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_LINES_YZ] = SModelPart(eYZ, true, false, gResourceStore.LoadResource("../resources/editor/ScaleLinesYZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_POLY_XY] = SModelPart(eXY, true, false, gResourceStore.LoadResource("../resources/editor/ScalePolyXY.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_POLY_XZ] = SModelPart(eXZ, true, false, gResourceStore.LoadResource("../resources/editor/ScalePolyXZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_POLY_YZ] = SModelPart(eYZ, true, false, gResourceStore.LoadResource("../resources/editor/ScalePolyYZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_XYZ] = SModelPart(eXYZ, true, false, gResourceStore.LoadResource("../resources/editor/ScaleXYZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_X] = SModelPart(eX, true, false, gpResourceStore->LoadResource("../resources/editor/ScaleX.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_Y] = SModelPart(eY, true, false, gpResourceStore->LoadResource("../resources/editor/ScaleY.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_Z] = SModelPart(eZ, true, false, gpResourceStore->LoadResource("../resources/editor/ScaleZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_LINES_XY] = SModelPart(eXY, true, false, gpResourceStore->LoadResource("../resources/editor/ScaleLinesXY.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_LINES_XZ] = SModelPart(eXZ, true, false, gpResourceStore->LoadResource("../resources/editor/ScaleLinesXZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_LINES_YZ] = SModelPart(eYZ, true, false, gpResourceStore->LoadResource("../resources/editor/ScaleLinesYZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_POLY_XY] = SModelPart(eXY, true, false, gpResourceStore->LoadResource("../resources/editor/ScalePolyXY.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_POLY_XZ] = SModelPart(eXZ, true, false, gpResourceStore->LoadResource("../resources/editor/ScalePolyXZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_POLY_YZ] = SModelPart(eYZ, true, false, gpResourceStore->LoadResource("../resources/editor/ScalePolyYZ.CMDL"));
|
||||
smScaleModels[CGIZMO_SCALE_XYZ] = SModelPart(eXYZ, true, false, gpResourceStore->LoadResource("../resources/editor/ScaleXYZ.CMDL"));
|
||||
|
||||
smModelsLoaded = true;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ void CStartWindow::on_actionOpen_MLVL_triggered()
|
|||
if (mpWorldEditor->close())
|
||||
{
|
||||
TString Dir = TO_TSTRING(WorldFile).GetFileDirectory();
|
||||
gResourceStore.SetTransientLoadDir(Dir);
|
||||
mpWorld = gResourceStore.LoadResource(WorldFile.toStdString());
|
||||
gpResourceStore->SetTransientLoadDir(Dir);
|
||||
mpWorld = gpResourceStore->LoadResource(WorldFile.toStdString());
|
||||
|
||||
QString QStrDir = TO_QSTRING(Dir);
|
||||
mpWorldEditor->SetWorldDir(QStrDir);
|
||||
|
@ -194,7 +194,7 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
|||
|
||||
CUniqueID AreaID = mpWorld->AreaResourceID(mSelectedAreaIndex);
|
||||
TString AreaPath = mpWorld->Entry()->CookedAssetPath().GetFileDirectory() + AreaID.ToString() + ".MREA";
|
||||
TResPtr<CGameArea> pArea = gResourceStore.LoadResource(AreaPath);
|
||||
TResPtr<CGameArea> pArea = gpResourceStore->LoadResource(AreaPath);
|
||||
|
||||
if (!pArea)
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
|||
pArea->SetWorldIndex(mSelectedAreaIndex);
|
||||
mpWorld->SetAreaLayerInfo(pArea);
|
||||
mpWorldEditor->SetArea(mpWorld, pArea);
|
||||
gResourceStore.DestroyUnreferencedResources();
|
||||
gpResourceStore->DestroyUnreferencedResources();
|
||||
|
||||
mpWorldEditor->setWindowModality(Qt::WindowModal);
|
||||
mpWorldEditor->showMaximized();
|
||||
|
|
|
@ -191,7 +191,7 @@ void CCharacterEditor::Open()
|
|||
QString CharFilename = QFileDialog::getOpenFileName(this, "Open Character", "", "Animation Character Set (*.ANCS)");
|
||||
if (CharFilename.isEmpty()) return;
|
||||
|
||||
CAnimSet *pSet = (CAnimSet*) gResourceStore.LoadResource(CharFilename.toStdString());
|
||||
CAnimSet *pSet = (CAnimSet*) gpResourceStore->LoadResource(CharFilename.toStdString());
|
||||
|
||||
if (pSet)
|
||||
{
|
||||
|
@ -242,7 +242,7 @@ void CCharacterEditor::Open()
|
|||
QMessageBox::warning(this, "Error", "Couldn't load file: " + CharFilename);
|
||||
}
|
||||
|
||||
gResourceStore.DestroyUnreferencedResources();
|
||||
gpResourceStore->DestroyUnreferencedResources();
|
||||
}
|
||||
|
||||
void CCharacterEditor::ToggleGrid(bool Enable)
|
||||
|
|
|
@ -580,7 +580,7 @@ void CModelEditorWindow::UpdateMaterial(QString Value)
|
|||
if (mIgnoreSignals) return;
|
||||
|
||||
EModelEditorWidget Widget = (EModelEditorWidget) sender()->property("ModelEditorWidgetType").toInt();
|
||||
TResPtr<CTexture> pTex = gResourceStore.LoadResource(TO_TSTRING(Value));
|
||||
TResPtr<CTexture> pTex = gpResourceStore->LoadResource(TO_TSTRING(Value));
|
||||
if (pTex->Type() != eTexture) pTex = nullptr;
|
||||
|
||||
switch (Widget)
|
||||
|
@ -722,7 +722,7 @@ void CModelEditorWindow::Open()
|
|||
QString ModelFilename = QFileDialog::getOpenFileName(this, "Save model", "", "Retro Model (*.CMDL)");
|
||||
if (ModelFilename.isEmpty()) return;
|
||||
|
||||
TResPtr<CModel> pModel = gResourceStore.LoadResource(ModelFilename.toStdString());
|
||||
TResPtr<CModel> pModel = gpResourceStore->LoadResource(ModelFilename.toStdString());
|
||||
if (pModel)
|
||||
{
|
||||
SetActiveModel(pModel);
|
||||
|
@ -730,7 +730,7 @@ void CModelEditorWindow::Open()
|
|||
mOutputFilename = TO_QSTRING(pModel->FullSource());
|
||||
}
|
||||
|
||||
gResourceStore.DestroyUnreferencedResources();
|
||||
gpResourceStore->DestroyUnreferencedResources();
|
||||
}
|
||||
|
||||
void CModelEditorWindow::Import()
|
||||
|
@ -773,7 +773,7 @@ void CModelEditorWindow::Import()
|
|||
SetActiveModel(pModel);
|
||||
SET_WINDOWTITLE_APPVARS("%APP_FULL_NAME% - Model Editor: Untitled");
|
||||
mOutputFilename = "";
|
||||
gResourceStore.DestroyUnreferencedResources();
|
||||
gpResourceStore->DestroyUnreferencedResources();
|
||||
}
|
||||
|
||||
void CModelEditorWindow::Save()
|
||||
|
@ -809,7 +809,7 @@ void CModelEditorWindow::ConvertToDDS()
|
|||
if (Input.isEmpty()) return;
|
||||
|
||||
TString TexFilename = Input.toStdString();
|
||||
TResPtr<CTexture> pTex = gResourceStore.LoadResource(TexFilename);
|
||||
TResPtr<CTexture> pTex = gpResourceStore->LoadResource(TexFilename);
|
||||
TString OutName = TexFilename.GetFilePathWithoutExtension() + ".dds";
|
||||
|
||||
CFileOutStream Out(OutName.ToStdString(), IOUtil::eLittleEndian);
|
||||
|
|
Loading…
Reference in New Issue