From 39244b11aac3c4c8002c710bbb3ab11ae9a41a8b Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 7 May 2022 15:54:27 -0700 Subject: [PATCH] Fix various checks for whether or not we should generate tex files --- data/dynos.cpp.h | 2 +- data/dynos_bin_tex.cpp | 22 +++++++++++++++------- data/dynos_gfx_init.cpp | 4 ++-- data/dynos_mgr_tex.cpp | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index b889aa1f..7d78d299 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -885,7 +885,7 @@ void DynOS_Tex_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); DataNode* DynOS_Tex_Load(FILE *aFile, GfxData *aGfxData); DataNode* DynOS_Tex_LoadFromBinary(const SysPath &aPackFolder, const SysPath &aFilename, const char *aTexName, bool aAddToPack); void DynOS_Tex_ConvertTextureDataToPng(GfxData *aGfxData, TexData* aTexture); -void DynOS_Tex_GeneratePack(const SysPath &aPackFolder, SysPath &aOutputFolder); +void DynOS_Tex_GeneratePack(const SysPath &aPackFolder, SysPath &aOutputFolder, bool aAllowCustomTextures); DataNode* DynOS_TexList_Parse(GfxData* aGfxData, DataNode* aNode); void DynOS_TexList_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode); diff --git a/data/dynos_bin_tex.cpp b/data/dynos_bin_tex.cpp index 3a3680c8..c9d548a0 100644 --- a/data/dynos_bin_tex.cpp +++ b/data/dynos_bin_tex.cpp @@ -304,13 +304,14 @@ DataNode* DynOS_Tex_LoadFromBinary(const SysPath &aPackFolder, const Sy // Generate // ////////////// -static void DynOS_Tex_GeneratePack_Recursive(const SysPath &aPackFolder, SysPath &aOutputFolder, SysPath& aRelativePath, SysPath& aPrefix, GfxData *aGfxData) { - // skip generation if any .c files exist - if (FileTypeExists(aOutputFolder, ".c")) { +static void DynOS_Tex_GeneratePack_Recursive(const SysPath &aPackFolder, SysPath &aOutputFolder, SysPath& aRelativePath, SysPath& aPrefix, GfxData *aGfxData, bool aAllowCustomTextures) { + SysPath _DirPath = fstring("%s/%s", aPackFolder.c_str(), aRelativePath.c_str()); + + // skip generation if any .c files exist + if (FileTypeExists(_DirPath, ".c")) { return; } - SysPath _DirPath = fstring("%s/%s", aPackFolder.c_str(), aRelativePath.c_str()); DIR *_PackDir = opendir(_DirPath.c_str()); if (!_PackDir) { return; } @@ -327,7 +328,7 @@ static void DynOS_Tex_GeneratePack_Recursive(const SysPath &aPackFolder, SysPath if (fs_sys_dir_exists(_Path.c_str())) { SysPath _NextPath = fstring("%s%s/", aRelativePath.c_str(), _PackEnt->d_name); SysPath _Prefix = fstring("%s.", _PackEnt->d_name); - DynOS_Tex_GeneratePack_Recursive(aPackFolder, aOutputFolder, _NextPath, _Prefix, aGfxData); + DynOS_Tex_GeneratePack_Recursive(aPackFolder, aOutputFolder, _NextPath, _Prefix, aGfxData, aAllowCustomTextures); continue; } @@ -356,6 +357,13 @@ static void DynOS_Tex_GeneratePack_Recursive(const SysPath &aPackFolder, SysPath _BaseName = _PackEnt->d_name; _BaseName = _BaseName.SubString(0, nameLen - 4); } + + // if we aren't overriding a texture, only generate textures in the output directory + SysPath _OutputFolder = fstring("%s/", aOutputFolder.c_str()); + if (_OverrideName == NULL && (!aAllowCustomTextures || strcmp(_DirPath.c_str(), _OutputFolder.c_str()))) { + continue; + } + SysPath _OutputPath = fstring("%s/%s.tex", aOutputFolder.c_str(), _BaseName.begin()); // create output dir if it doesn't exist @@ -369,7 +377,7 @@ static void DynOS_Tex_GeneratePack_Recursive(const SysPath &aPackFolder, SysPath closedir(_PackDir); } -void DynOS_Tex_GeneratePack(const SysPath &aPackFolder, SysPath &aOutputFolder) { +void DynOS_Tex_GeneratePack(const SysPath &aPackFolder, SysPath &aOutputFolder, bool aAllowCustomTextures) { Print("---------- Texture pack folder: \"%s\" ----------", aPackFolder.c_str()); // skip generation if any .tex files exist @@ -380,6 +388,6 @@ void DynOS_Tex_GeneratePack(const SysPath &aPackFolder, SysPath &aOutputFolder) GfxData *_GfxData = New(); _GfxData->mModelIdentifier = 0; SysPath _Empty = ""; - DynOS_Tex_GeneratePack_Recursive(aPackFolder, aOutputFolder, _Empty, _Empty, _GfxData); + DynOS_Tex_GeneratePack_Recursive(aPackFolder, aOutputFolder, _Empty, _Empty, _GfxData, aAllowCustomTextures); DynOS_Gfx_Free(_GfxData); } diff --git a/data/dynos_gfx_init.cpp b/data/dynos_gfx_init.cpp index edb73d93..54fd8c8f 100644 --- a/data/dynos_gfx_init.cpp +++ b/data/dynos_gfx_init.cpp @@ -22,7 +22,7 @@ void DynOS_Gfx_GeneratePacks(const char* directory) { SysPath _TexturePackFolder = fstring("%s/%s", directory, dir->d_name); SysPath _TexturePackOutputFolder = fstring("%s/%s/textures", directory, dir->d_name); if (fs_sys_dir_exists(_TexturePackFolder.c_str())) { - DynOS_Tex_GeneratePack(_TexturePackFolder, _TexturePackOutputFolder); + DynOS_Tex_GeneratePack(_TexturePackFolder, _TexturePackOutputFolder, true); } } @@ -73,7 +73,7 @@ static void ScanPacksFolder(SysPath _DynosPacksFolder) { if (fs_sys_dir_exists(_PackFolder.c_str())) { struct PackData* _Pack = DynOS_Pack_Add(_PackFolder); DynOS_Actor_GeneratePack(_PackFolder); - DynOS_Tex_GeneratePack(_PackFolder, _PackFolder); + DynOS_Tex_GeneratePack(_PackFolder, _PackFolder, false); ScanPackBins(_PackFolder); } } diff --git a/data/dynos_mgr_tex.cpp b/data/dynos_mgr_tex.cpp index 89770b46..59ce38a4 100644 --- a/data/dynos_mgr_tex.cpp +++ b/data/dynos_mgr_tex.cpp @@ -435,7 +435,7 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) { if (!strcmp(_DynosCustomTexs[i].first, aTexName)) { auto& _Data = _DynosCustomTexs[i].second->mData; - // load the texture if it hasn't been yet + // load the texture if it hasn't been yet if (_Data->mRawData.begin() == NULL) { u8 *_RawData = stbi_load_from_memory(_Data->mPngData.begin(), _Data->mPngData.Count(), &_Data->mRawWidth, &_Data->mRawHeight, NULL, 4); _Data->mRawFormat = G_IM_FMT_RGBA;