Implemented initial version of resource browser

This commit is contained in:
parax0
2016-07-10 06:58:23 -06:00
parent 08dcfe5e5a
commit 6f98ae5bb8
17 changed files with 716 additions and 7 deletions

View File

@@ -171,6 +171,7 @@ void CGameExporter::LoadPaks()
for (auto It = mPaks.begin(); It != mPaks.end(); It++)
{
TWideString PakPath = *It;
TWideString PakName = PakPath.GetFileName(false);
TString CharPak = PakPath.ToUTF8();
CFileInStream Pak(CharPak.ToStdString(), IOUtil::eBigEndian);
@@ -203,6 +204,7 @@ void CGameExporter::LoadPaks()
u32 NameLen = Pak.ReadLong();
TString Name = Pak.ReadString(NameLen);
pCollection->AddResource(Name, ResID, ResType);
SetResourcePath(ResID.ToLongLong(), PakName + L"\\", Name.ToUTF16());
}
u32 NumResources = Pak.ReadLong();
@@ -261,6 +263,7 @@ void CGameExporter::LoadPaks()
CFourCC ResType = Pak.ReadLong();
CUniqueID ResID(Pak, IDLength);
pCollection->AddResource(Name, ResID, ResType);
SetResourcePath(ResID.ToLongLong(), PakName + L"\\", Name.ToUTF16());
}
}

View File

@@ -33,6 +33,8 @@ CResourceEntry::CResourceEntry(CResourceStore *pStore, const CUniqueID& rkID,
, mType(Type)
, mNeedsRecook(false)
, mTransient(Transient)
, mCachedSize(-1)
, mCachedUppercaseName(rkFilename.ToUpper())
{
mpDirectory = mpStore->GetVirtualDirectory(rkDir, Transient, true);
if (mpDirectory) mpDirectory->AddChild(L"", this);
@@ -70,6 +72,32 @@ TString CResourceEntry::CookedAssetPath(bool Relative) const
return ((mTransient || Relative) ? Path + Name : mpStore->ActiveProject()->CookedDir(false) + Path + Name);
}
bool CResourceEntry::IsInDirectory(CVirtualDirectory *pDir) const
{
CVirtualDirectory *pParentDir = mpDirectory;
while (pParentDir)
{
if (pParentDir == pDir) return true;
pParentDir = pParentDir->Parent();
}
return false;
}
u64 CResourceEntry::Size() const
{
if (mCachedSize == -1)
{
if (HasCookedVersion())
mCachedSize = FileUtil::FileSize(CookedAssetPath());
else
return 0;
}
return mCachedSize;
}
bool CResourceEntry::NeedsRecook() const
{
// Assets that do not have a raw version can't be recooked since they will always just be saved cooked to begin with.
@@ -170,6 +198,7 @@ void CResourceEntry::Move(const TWideString& rkDir, const TWideString& rkName)
ASSERT(mpDirectory->FindChildResource(rkName) == nullptr);
mName = rkName;
mCachedUppercaseName = rkName.ToUpper();
// Move files
if (HasDirectory)

View File

@@ -21,6 +21,9 @@ class CResourceEntry
bool mNeedsRecook;
bool mTransient;
mutable u64 mCachedSize;
mutable TWideString mCachedUppercaseName; // This is used to speed up case-insensitive sorting.
public:
CResourceEntry(CResourceStore *pStore, const CUniqueID& rkID,
const TWideString& rkDir, const TWideString& rkFilename,
@@ -30,6 +33,8 @@ public:
bool HasCookedVersion() const;
TString RawAssetPath(bool Relative = false) const;
TString CookedAssetPath(bool Relative = false) const;
bool IsInDirectory(CVirtualDirectory *pDir) const;
u64 Size() const;
bool NeedsRecook() const;
void SetGame(EGame NewGame);
CResource* Load();
@@ -48,6 +53,7 @@ public:
inline EGame Game() const { return mGame; }
inline CVirtualDirectory* Directory() const { return mpDirectory; }
inline TWideString Name() const { return mName; }
inline TWideString UppercaseName() const { return mCachedUppercaseName; }
inline EResType ResourceType() const { return mType; }
inline bool IsTransient() const { return mTransient; }

View File

@@ -0,0 +1,69 @@
#ifndef CRESOURCEITERATOR
#define CRESOURCEITERATOR
#include <Core/GameProject/CResourceEntry.h>
#include <Core/GameProject/CResourceStore.h>
class CResourceIterator
{
CResourceStore *mpStore;
std::map<CUniqueID, CResourceEntry*>::iterator mIter;
CResourceEntry *mpCurEntry;
public:
CResourceIterator(CResourceStore *pStore)
: mpStore(pStore)
, mpCurEntry(nullptr)
{
mIter = mpStore->mResourceEntries.begin();
Next();
}
inline CResourceEntry* Next()
{
if (mIter != mpStore->mResourceEntries.end())
{
mpCurEntry = mIter->second;
mIter++;
}
else mpCurEntry = nullptr;
return mpCurEntry;
}
inline bool DoneIterating() const
{
return mpCurEntry == nullptr;
}
inline operator bool() const
{
return !DoneIterating();
}
inline CResourceEntry* operator*() const
{
return mpCurEntry;
}
inline CResourceEntry* operator->() const
{
return mpCurEntry;
}
inline CResourceIterator& operator++()
{
Next();
return *this;
}
inline CResourceIterator operator++(int)
{
CResourceIterator Copy = *this;
Next();
return Copy;
}
};
#endif // CRESOURCEITERATOR

View File

@@ -16,6 +16,8 @@ class CResource;
class CResourceStore
{
friend class CResourceIterator;
CGameProject *mpProj;
CVirtualDirectory *mpProjectRoot;
std::vector<CVirtualDirectory*> mTransientRoots;
@@ -61,7 +63,8 @@ public:
void SetTransientLoadDir(const TString& rkDir);
// Accessors
inline CGameProject* ActiveProject() const { return mpProj; }
inline CGameProject* ActiveProject() const { return mpProj; }
inline CVirtualDirectory* RootDirectory() const { return mpProjectRoot; }
};
extern CResourceStore *gpResourceStore;