From e12de45eaae99278d39cdef9b858f5aafef55a28 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:43:02 +0100 Subject: [PATCH] Light RTech code cleanup Use dedicated function for returning pak status as string instead of std::map. reduced compiled code size by 10kb. --- r5dev/rtech/rtech_utils.cpp | 26 ++++++++++++++++++++++++++ r5dev/rtech/rtech_utils.h | 24 +++--------------------- r5dev/vstdlib/callback.cpp | 12 ++++-------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/r5dev/rtech/rtech_utils.cpp b/r5dev/rtech/rtech_utils.cpp index f951cd6b..5d5e1610 100644 --- a/r5dev/rtech/rtech_utils.cpp +++ b/r5dev/rtech/rtech_utils.cpp @@ -708,6 +708,32 @@ RPakLoadedInfo_t* RTech::GetPakLoadedInfo(const char* szPakName) return nullptr; } +//----------------------------------------------------------------------------- +// Purpose: returns pak status as string +//----------------------------------------------------------------------------- +const char* RTech::PakStatusToString(RPakStatus_t status) +{ + switch (status) + { + case RPakStatus_t::PAK_STATUS_FREED: return "PAK_STATUS_FREED"; + case RPakStatus_t::PAK_STATUS_LOAD_PENDING: return "PAK_STATUS_LOAD_PENDING"; + case RPakStatus_t::PAK_STATUS_REPAK_RUNNING: return "PAK_STATUS_REPAK_RUNNING"; + case RPakStatus_t::PAK_STATUS_REPAK_DONE: return "PAK_STATUS_REPAK_DONE"; + case RPakStatus_t::PAK_STATUS_LOAD_STARTING: return "PAK_STATUS_LOAD_STARTING"; + case RPakStatus_t::PAK_STATUS_LOAD_PAKHDR: return "PAK_STATUS_LOAD_PAKHDR"; + case RPakStatus_t::PAK_STATUS_LOAD_PATCH_INIT: return "PAK_STATUS_LOAD_PATCH_INIT"; + case RPakStatus_t::PAK_STATUS_LOAD_PATCH_EDIT_STREAM: return "PAK_STATUS_LOAD_PATCH_EDIT_STREAM"; + case RPakStatus_t::PAK_STATUS_LOAD_ASSETS: return "PAK_STATUS_LOAD_ASSETS"; + case RPakStatus_t::PAK_STATUS_LOADED: return "PAK_STATUS_LOADED"; + case RPakStatus_t::PAK_STATUS_UNLOAD_PENDING: return "PAK_STATUS_UNLOAD_PENDING"; + case RPakStatus_t::PAK_STATUS_FREE_PENDING: return "PAK_STATUS_FREE_PENDING"; + case RPakStatus_t::PAK_STATUS_CANCELING: return "PAK_STATUS_CANCELING"; + case RPakStatus_t::PAK_STATUS_ERROR: return "PAK_STATUS_ERROR"; + case RPakStatus_t::PAK_STATUS_INVALID_PAKHANDLE: return "PAK_STATUS_INVALID_PAKHANDLE"; + case RPakStatus_t::PAK_STATUS_BUSY: return "PAK_STATUS_BUSY"; + default: return "PAK_STATUS_UNKNOWN"; + } +} //----------------------------------------------------------------------------- // Purpose: process guid relations for asset diff --git a/r5dev/rtech/rtech_utils.h b/r5dev/rtech/rtech_utils.h index 306b756b..65e16ffc 100644 --- a/r5dev/rtech/rtech_utils.h +++ b/r5dev/rtech/rtech_utils.h @@ -6,8 +6,8 @@ #include "public/rendersystem/schema/texture.g.h" #endif // !DEDICATED -#define PAK_PARAM_SIZE 0xB0 -#define DCMP_BUF_SIZE 0x400000 +#define PAK_MAX_TYPES 64 +#define PAK_PARAM_SIZE 0xB0 #define RPAKHEADER (('k'<<24)+('a'<<16)+('P'<<8)+'R') @@ -74,25 +74,6 @@ enum class RPakStatus_t : int32_t PAK_STATUS_BUSY = 15 }; -const static std::map g_PakStatusToString { - { RPakStatus_t::PAK_STATUS_FREED, "PAK_STATUS_FREED" }, - { RPakStatus_t::PAK_STATUS_LOAD_PENDING, "PAK_STATUS_LOAD_PENDING" }, - { RPakStatus_t::PAK_STATUS_REPAK_RUNNING, "PAK_STATUS_REPAK_RUNNING" }, - { RPakStatus_t::PAK_STATUS_REPAK_DONE, "PAK_STATUS_REPAK_DONE" }, - { RPakStatus_t::PAK_STATUS_LOAD_STARTING, "PAK_STATUS_LOAD_STARTING" }, - { RPakStatus_t::PAK_STATUS_LOAD_PAKHDR, "PAK_STATUS_LOAD_PAKHDR" }, - { RPakStatus_t::PAK_STATUS_LOAD_PATCH_INIT, "PAK_STATUS_LOAD_PATCH_INIT" }, - { RPakStatus_t::PAK_STATUS_LOAD_PATCH_EDIT_STREAM, "PAK_STATUS_LOAD_PATCH_EDIT_STREAM" }, - { RPakStatus_t::PAK_STATUS_LOAD_ASSETS, "PAK_STATUS_LOAD_ASSETS" }, - { RPakStatus_t::PAK_STATUS_LOADED, "PAK_STATUS_LOADED" }, - { RPakStatus_t::PAK_STATUS_UNLOAD_PENDING, "PAK_STATUS_UNLOAD_PENDING" }, - { RPakStatus_t::PAK_STATUS_FREE_PENDING, "PAK_STATUS_FREE_PENDING" }, - { RPakStatus_t::PAK_STATUS_CANCELING, "PAK_STATUS_CANCELING" }, - { RPakStatus_t::PAK_STATUS_ERROR, "PAK_STATUS_ERROR" }, - { RPakStatus_t::PAK_STATUS_INVALID_PAKHANDLE, "PAK_STATUS_INVALID_PAKHANDLE" }, - { RPakStatus_t::PAK_STATUS_BUSY, "PAK_STATUS_BUSY" }, -}; - struct RPakAssetBinding_t { uint32_t m_nExtension; // For example '0x6C74616D' for the material asset. @@ -353,6 +334,7 @@ public: uint64_t __fastcall DecompressPakFileInit(RPakDecompState_t* state, uint8_t* fileBuffer, uint64_t fileSize, uint64_t offNoHeader, uint64_t headerSize); RPakLoadedInfo_t* GetPakLoadedInfo(RPakHandle_t nPakId); RPakLoadedInfo_t* GetPakLoadedInfo(const char* szPakName); + const char* PakStatusToString(RPakStatus_t status); static int32_t OpenFile(const CHAR* szFilePath, void* unused, LONGLONG* fileSizeOut); diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index 5c6291b3..16f329b6 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -258,21 +258,17 @@ void Pak_ListPaks_f(const CCommand& args) uint32_t nTotalLoaded = 0; - for (int16_t i = 0; i < *g_pLoadedPakCount; ++i) + for (int16_t i = 0, n = *g_pLoadedPakCount; i < n; ++i) { const RPakLoadedInfo_t& info = g_pLoadedPakInfo[i]; if (info.m_nStatus == RPakStatus_t::PAK_STATUS_FREED) continue; - string rpakStatus = "RPAK_CREATED_A_NEW_STATUS_SOMEHOW"; - - auto it = g_PakStatusToString.find(info.m_nStatus); - if (it != g_PakStatusToString.end()) - rpakStatus = it->second; + const char* szRpakStatus = g_pRTech->PakStatusToString(info.m_nStatus); // todo: make status into a string from an array/vector - DevMsg(eDLL_T::RTECH, "| %04i | %-50s | %-36s | %11i |\n", info.m_nHandle, info.m_pszFileName, rpakStatus.c_str(), info.m_nAssetCount); + DevMsg(eDLL_T::RTECH, "| %04i | %-50s | %-36s | %11i |\n", info.m_nHandle, info.m_pszFileName, szRpakStatus, info.m_nAssetCount); nTotalLoaded++; } DevMsg(eDLL_T::RTECH, "|------|----------------------------------------------------|--------------------------------------|-------------|\n"); @@ -292,7 +288,7 @@ void Pak_ListTypes_f(const CCommand& args) uint32_t nRegistered = 0; - for (int8_t i = 0; i < 64; ++i) + for (int8_t i = 0; i < PAK_MAX_TYPES; ++i) { RPakAssetBinding_t* type = &g_pPakGlobals->m_nAssetBindings[i];