From 1195bd72cd5cc988674d768778e17c66edbc178b Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:54:29 +0100 Subject: [PATCH] More renames and cleanup Make the code more understandable. --- src/logic/pakfile.cpp | 72 +++++++++++++++++++++---------------------- src/logic/pakfile.h | 34 ++++++++++---------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/logic/pakfile.cpp b/src/logic/pakfile.cpp index 513ec99..6a824bf 100644 --- a/src/logic/pakfile.cpp +++ b/src/logic/pakfile.cpp @@ -232,7 +232,7 @@ void CPakFileBuilder::WriteHeader(BinaryIO& io) //----------------------------------------------------------------------------- void CPakFileBuilder::WriteAssetDescriptors(BinaryIO& io) { - for (PakAsset_t& it : m_Assets) + for (PakAsset_t& it : m_assets) { io.Write(it.guid); io.Write(it.unk0); @@ -261,9 +261,9 @@ void CPakFileBuilder::WriteAssetDescriptors(BinaryIO& io) it.SetPublicData(nullptr); } - assert(m_Assets.size() <= UINT32_MAX); + assert(m_assets.size() <= UINT32_MAX); // update header asset count with the assets we've just written - this->m_Header.assetCount = static_cast(m_Assets.size()); + this->m_Header.assetCount = static_cast(m_assets.size()); } //----------------------------------------------------------------------------- @@ -291,7 +291,7 @@ void CPakFileBuilder::WritePagePointers(BinaryIO& out) void CPakFileBuilder::WriteAssetUses(BinaryIO& out) { - for (const PakAsset_t& it : m_Assets) + for (const PakAsset_t& it : m_assets) { for (const PakGuidRef_s& ref : it._uses) out.Write(ref.ptr); @@ -300,7 +300,7 @@ void CPakFileBuilder::WriteAssetUses(BinaryIO& out) void CPakFileBuilder::WriteAssetDependents(BinaryIO& out) { - for (const PakAsset_t& it : m_Assets) + for (const PakAsset_t& it : m_assets) { for (const unsigned int dependent : it._dependents) out.Write(dependent); @@ -313,9 +313,9 @@ void CPakFileBuilder::WriteAssetDependents(BinaryIO& out) //----------------------------------------------------------------------------- void CPakFileBuilder::GenerateInternalDependencies() { - for (size_t i = 0; i < m_Assets.size(); i++) + for (size_t i = 0; i < m_assets.size(); i++) { - PakAsset_t& it = m_Assets[i]; + PakAsset_t& it = m_assets[i]; std::set processed; for (const PakGuidRef_s& ref : it._uses) @@ -343,7 +343,7 @@ void CPakFileBuilder::GenerateAssetUses() { size_t totalUsesCount = 0; - for (PakAsset_t& it : m_Assets) + for (PakAsset_t& it : m_assets) { const size_t numUses = it._uses.size(); @@ -370,7 +370,7 @@ void CPakFileBuilder::GenerateAssetDependents() { size_t totalDependentsCount = 0; - for (PakAsset_t& it : m_Assets) + for (PakAsset_t& it : m_assets) { const size_t numDependents = it._dependents.size(); @@ -400,7 +400,7 @@ PakPageLump_s CPakFileBuilder::CreatePageLump(const size_t size, const int flags PakAsset_t* CPakFileBuilder::GetAssetByGuid(const PakGuid_t guid, uint32_t* const idx /*= nullptr*/, const bool silent /*= false*/) { uint32_t i = 0; - for (PakAsset_t& it : m_Assets) + for (PakAsset_t& it : m_assets) { if (it.guid == guid) { @@ -566,7 +566,7 @@ static bool Pak_StreamToStreamEncode(BinaryIO& inStream, BinaryIO& outStream, co size_t CPakFileBuilder::EncodeStreamAndSwap(BinaryIO& io, const int compressLevel, const int workerCount) { BinaryIO outCompressed; - const std::string outCompressedPath = m_Path + "_encoded"; + const std::string outCompressedPath = m_pakFilePath + "_encoded"; if (!outCompressed.Open(outCompressedPath, BinaryIO::Mode_e::Write)) { @@ -585,29 +585,29 @@ size_t CPakFileBuilder::EncodeStreamAndSwap(BinaryIO& io, const int compressLeve // note(amos): we must reopen the file in ReadWrite mode as otherwise // the file gets truncated. - if (!std::filesystem::remove(m_Path)) + if (!std::filesystem::remove(m_pakFilePath)) { Warning("Failed to remove uncompressed pak file \"%s\" for swap.\n", outCompressedPath.c_str()); // reopen and continue uncompressed. - if (io.Open(m_Path, BinaryIO::Mode_e::ReadWrite)) - Error("Failed to reopen pak file \"%s\".\n", m_Path.c_str()); + if (io.Open(m_pakFilePath, BinaryIO::Mode_e::ReadWrite)) + Error("Failed to reopen pak file \"%s\".\n", m_pakFilePath.c_str()); return 0; } - std::filesystem::rename(outCompressedPath, m_Path); + std::filesystem::rename(outCompressedPath, m_pakFilePath); // either the rename failed or something holds an open handle to the // newly renamed compressed file, irrecoverable. - if (!io.Open(m_Path, BinaryIO::Mode_e::ReadWrite)) - Error("Failed to reopen pak file \"%s\".\n", m_Path.c_str()); + if (!io.Open(m_pakFilePath, BinaryIO::Mode_e::ReadWrite)) + Error("Failed to reopen pak file \"%s\".\n", m_pakFilePath.c_str()); const size_t reopenedPakSize = io.GetSize(); if (reopenedPakSize != compressedSize) Error("Reopened pak file \"%s\" appears truncated or corrupt; compressed size: %zu expected: %zu.\n", - m_Path.c_str(), reopenedPakSize, compressedSize); + m_pakFilePath.c_str(), reopenedPakSize, compressedSize); // set the header flags indicating this pak is compressed. m_Header.flags |= (PAK_HEADER_FLAGS_COMPRESSED | PAK_HEADER_FLAGS_ZSTREAM_ENCODED); @@ -630,7 +630,7 @@ void CPakFileBuilder::CreateStreamFileStream(const char* const streamFilePath, c else streamFileName += 1; // advance from '/' to start of filename. - const std::string fullFilePath = m_OutputPath + streamFileName; + const std::string fullFilePath = m_outputPath + streamFileName; if (!out.Open(fullFilePath, BinaryIO::Mode_e::Write)) Error("Failed to open %s streaming file \"%s\".\n", Pak_StreamSetToName(set), fullFilePath.c_str()); @@ -694,40 +694,40 @@ void CPakFileBuilder::BuildFromMap(const string& mapPath) { Warning("No \"assetsDir\" field provided; assuming that everything is relative to the working directory.\n"); if (inputPath.has_parent_path()) - m_AssetPath = inputPath.parent_path().string(); + m_assetPath = inputPath.parent_path().string(); else - m_AssetPath = ".\\"; + m_assetPath = ".\\"; } else { const fs::path assetsDirPath(assetDir); if (assetsDirPath.is_relative() && inputPath.has_parent_path()) - m_AssetPath = std::filesystem::canonical(inputPath.parent_path() / assetsDirPath).string(); + m_assetPath = std::filesystem::canonical(inputPath.parent_path() / assetsDirPath).string(); else - m_AssetPath = assetsDirPath.string(); + m_assetPath = assetsDirPath.string(); // ensure that the path has a slash at the end - Utils::AppendSlash(m_AssetPath); + Utils::AppendSlash(m_assetPath); } // determine final build path from map file - if (JSON_GetValue(doc, "outputDir", m_OutputPath)) + if (JSON_GetValue(doc, "outputDir", m_outputPath)) { fs::path outputDirPath(doc["outputDir"].GetString()); if (outputDirPath.is_relative() && inputPath.has_parent_path()) - m_OutputPath = fs::canonical(inputPath.parent_path() / outputDirPath).string(); + m_outputPath = fs::canonical(inputPath.parent_path() / outputDirPath).string(); else - m_OutputPath = outputDirPath.string(); + m_outputPath = outputDirPath.string(); // ensure that the path has a slash at the end - Utils::AppendSlash(m_OutputPath); + Utils::AppendSlash(m_outputPath); } else - m_OutputPath = DEFAULT_RPAK_PATH; + m_outputPath = DEFAULT_RPAK_PATH; // create output directory if it does not exist yet. - fs::create_directories(m_OutputPath); + fs::create_directories(m_outputPath); const int pakVersion = JSON_GetValueOrDefault(doc, "version", -1); @@ -741,11 +741,11 @@ void CPakFileBuilder::BuildFromMap(const string& mapPath) Log("build settings:\n"); Log("version: %i\n", GetVersion()); Log("fileName: %s.rpak\n", pakName); - Log("assetsDir: %s\n", m_AssetPath.c_str()); - Log("outputDir: %s\n\n", m_OutputPath.c_str()); + Log("assetsDir: %s\n", m_assetPath.c_str()); + Log("outputDir: %s\n\n", m_outputPath.c_str()); // set build path - SetPath(m_OutputPath + pakName + ".rpak"); + SetPath(m_outputPath + pakName + ".rpak"); // should dev-only data be kept - e.g. texture asset names, uimg texture names if (JSON_GetValueOrDefault(doc, "keepDevOnly", false)) @@ -759,8 +759,8 @@ void CPakFileBuilder::BuildFromMap(const string& mapPath) // create file stream from path created above BinaryIO out; - if (!out.Open(m_Path, BinaryIO::Mode_e::ReadWriteCreate)) - Error("Failed to open output pak file \"%s\".\n", m_Path.c_str()); + if (!out.Open(m_pakFilePath, BinaryIO::Mode_e::ReadWriteCreate)) + Error("Failed to open output pak file \"%s\".\n", m_pakFilePath.c_str()); // write a placeholder header so we can come back and complete it // when we have all the info @@ -867,7 +867,7 @@ void CPakFileBuilder::BuildFromMap(const string& mapPath) const ssize_t totalPakSize = out.GetSize(); Log("Written pak file \"%s\" with %zu assets, totaling %zd bytes.\n", - m_Path.c_str(), GetAssetCount(), totalPakSize); + m_pakFilePath.c_str(), GetAssetCount(), totalPakSize); // if we had pages which we ended up padding out to match the alignment, // then we need to seek back to the end of the file; SeekPut only writes diff --git a/src/logic/pakfile.h b/src/logic/pakfile.h index b85ec25..f0df7dd 100644 --- a/src/logic/pakfile.h +++ b/src/logic/pakfile.h @@ -30,9 +30,9 @@ class CPakFileBuilder //---------------------------------------------------------------------------- // inlines //---------------------------------------------------------------------------- - inline bool IsFlagSet(int flag) const { return m_Flags & flag; }; + inline bool IsFlagSet(int flag) const { return m_buildFlags & flag; }; - inline size_t GetAssetCount() const { return m_Assets.size(); }; + inline size_t GetAssetCount() const { return m_assets.size(); }; inline size_t GetMandatoryStreamingAssetCount() const { return m_mandatoryStreamingDataBlocks.size(); }; inline size_t GetOptionalStreamingAssetCount() const { return m_optionalStreamingDataBlocks.size(); }; @@ -55,11 +55,11 @@ class CPakFileBuilder m_Header.optStarpakPathsSize = optLen; } - inline std::string GetPath() const { return m_Path; } - inline void SetPath(const std::string& path) { m_Path = path; } + inline std::string GetPath() const { return m_pakFilePath; } + inline void SetPath(const std::string& path) { m_pakFilePath = path; } - inline std::string GetAssetPath() const { return m_AssetPath; } - inline void SetAssetPath(const std::string& assetPath) { m_AssetPath = assetPath; } + inline std::string GetAssetPath() const { return m_assetPath; } + inline void SetAssetPath(const std::string& assetPath) { m_assetPath = assetPath; } inline size_t GetNumStarpakPaths() const { return m_mandatoryStreamFilePaths.size(); } @@ -72,8 +72,8 @@ class CPakFileBuilder inline FILETIME GetFileTime() const { return m_Header.fileTime; } inline void SetFileTime(FILETIME fileTime) { m_Header.fileTime = fileTime; } - inline void AddFlags(int flags) { m_Flags |= flags; } - inline void RemoveFlags(int flags) { m_Flags &= ~flags; } + inline void AddFlags(int flags) { m_buildFlags |= flags; } + inline void RemoveFlags(int flags) { m_buildFlags &= ~flags; } //---------------------------------------------------------------------------- // rpak @@ -105,7 +105,7 @@ class CPakFileBuilder Error("Attempted to create asset with a non-unique GUID.\n" "Assets at index %u (%s) and %u (%s) have the same GUID (%llx).\n", assetIdx, match->name.c_str(), - static_cast(m_Assets.size()), asset.name.c_str(), + static_cast(m_assets.size()), asset.name.c_str(), asset.guid ); } @@ -114,7 +114,7 @@ class CPakFileBuilder FORCEINLINE void PushAsset(const PakAsset_t& asset) { RequireUniqueAssetGUID(asset); - m_Assets.push_back(asset); + m_assets.push_back(asset); }; void CreateStreamFileStream(const char* const path, const PakStreamSet_e set); @@ -125,18 +125,18 @@ class CPakFileBuilder private: friend class CPakPage; - int m_Flags = 0; + int m_buildFlags = 0; PakHdr_t m_Header; - std::string m_Path; - std::string m_AssetPath; - std::string m_OutputPath; + std::string m_pakFilePath; + std::string m_assetPath; + std::string m_outputPath; - CPakPageBuilder m_pageBuilder; - - std::vector m_Assets; + std::vector m_assets; std::vector m_pagePointers; + CPakPageBuilder m_pageBuilder; + std::vector m_mandatoryStreamFilePaths; std::vector m_optionalStreamFilePaths;