diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index 7d78d299..d0cec21a 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -459,6 +459,7 @@ struct PackData { String mDisplayName; Array> mGfxData; Array*> mTextures; + bool mLoaded; }; typedef Pair Label; diff --git a/data/dynos_gfx_init.cpp b/data/dynos_gfx_init.cpp index 54fd8c8f..726dce21 100644 --- a/data/dynos_gfx_init.cpp +++ b/data/dynos_gfx_init.cpp @@ -29,35 +29,6 @@ void DynOS_Gfx_GeneratePacks(const char* directory) { closedir(modsDir); } -static void ScanPackBins(SysPath aPackFolder) { - DIR *_PackDir = opendir(aPackFolder.c_str()); - if (!_PackDir) { return; } - - struct dirent *_PackEnt = NULL; - while ((_PackEnt = readdir(_PackDir)) != NULL) { - // Skip . and .. - if (SysPath(_PackEnt->d_name) == ".") continue; - if (SysPath(_PackEnt->d_name) == "..") continue; - - SysPath _FileName = fstring("%s/%s", aPackFolder.begin(), _PackEnt->d_name); - s32 length = strlen(_PackEnt->d_name); - - // check for actors - if (length > 4 && !strncmp(&_PackEnt->d_name[length - 4], ".bin", 4)) { - String _ActorName = _PackEnt->d_name; - _ActorName[length - 4] = '\0'; - DynOS_Actor_LoadFromBinary(aPackFolder, strdup(_ActorName.begin()), _FileName, true); - } - - // check for textures - if (length > 4 && !strncmp(&_PackEnt->d_name[length - 4], ".tex", 4)) { - String _TexName = _PackEnt->d_name; - _TexName[length - 4] = '\0'; - DynOS_Tex_LoadFromBinary(aPackFolder, _FileName, _TexName.begin(), true); - } - } -} - static void ScanPacksFolder(SysPath _DynosPacksFolder) { DIR *_DynosPacksDir = opendir(_DynosPacksFolder.c_str()); if (_DynosPacksDir) { @@ -74,7 +45,6 @@ static void ScanPacksFolder(SysPath _DynosPacksFolder) { struct PackData* _Pack = DynOS_Pack_Add(_PackFolder); DynOS_Actor_GeneratePack(_PackFolder); DynOS_Tex_GeneratePack(_PackFolder, _PackFolder, false); - ScanPackBins(_PackFolder); } } closedir(_DynosPacksDir); diff --git a/data/dynos_mgr_pack.cpp b/data/dynos_mgr_pack.cpp index 3267b510..5dadf919 100644 --- a/data/dynos_mgr_pack.cpp +++ b/data/dynos_mgr_pack.cpp @@ -8,6 +8,35 @@ static Array& DynosPacks() { return sDynosPacks; } +static void ScanPackBins(struct PackData* aPack) { + DIR *_PackDir = opendir(aPack->mPath.c_str()); + if (!_PackDir) { return; } + + struct dirent *_PackEnt = NULL; + while ((_PackEnt = readdir(_PackDir)) != NULL) { + // Skip . and .. + if (SysPath(_PackEnt->d_name) == ".") continue; + if (SysPath(_PackEnt->d_name) == "..") continue; + + SysPath _FileName = fstring("%s/%s", aPack->mPath.c_str(), _PackEnt->d_name); + s32 length = strlen(_PackEnt->d_name); + + // check for actors + if (length > 4 && !strncmp(&_PackEnt->d_name[length - 4], ".bin", 4)) { + String _ActorName = _PackEnt->d_name; + _ActorName[length - 4] = '\0'; + DynOS_Actor_LoadFromBinary(aPack->mPath, strdup(_ActorName.begin()), _FileName, true); + } + + // check for textures + if (length > 4 && !strncmp(&_PackEnt->d_name[length - 4], ".tex", 4)) { + String _TexName = _PackEnt->d_name; + _TexName[length - 4] = '\0'; + DynOS_Tex_LoadFromBinary(aPack->mPath, _FileName, _TexName.begin(), true); + } + } +} + static void DynOS_Pack_ActivateActor(s32 aPackIndex, Pair& pair) { const char* aActorName = pair.first; GfxData* aGfxData = pair.second; @@ -61,6 +90,11 @@ void DynOS_Pack_SetEnabled(PackData* aPack, bool aEnabled) { aPack->mEnabled = aEnabled; aPack->mEnabledSet = true; + if (aEnabled && !aPack->mLoaded) { + ScanPackBins(aPack); + aPack->mLoaded = true; + } + if (aEnabled) { for (auto& pair : aPack->mGfxData) { DynOS_Pack_ActivateActor(aPack->mIndex, pair); @@ -106,6 +140,8 @@ PackData* DynOS_Pack_Add(const SysPath& aPath) { .mIndex = index, .mPath = aPath, .mGfxData = {}, + .mTextures = {}, + .mLoaded = false, }); PackData* _Pack = &_DynosPacks[index];