From 4154066c266ad49ea4ebfce2c626e06c24f69019 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Wed, 18 Aug 2021 10:59:50 -0400 Subject: [PATCH] Reduce memory footprint in FILESYSTEM_mountAssets --- desktop_version/src/FileSystemUtils.cpp | 69 +++++++++++++------------ 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index b35982f3..b114cb86 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -512,55 +512,38 @@ void FILESYSTEM_unmountAssets(void); bool FILESYSTEM_mountAssets(const char* path) { char filename[MAX_PATH]; - char zip_data[MAX_PATH]; - const char* zip_normal; + char virtual_path[MAX_PATH]; + const char* real_path; char dir[MAX_PATH]; VVV_between(path, "levels/", filename, ".vvvvvv"); + real_path = PHYSFS_getRealDir(path); + + /* Check for a zipped up level pack first */ SDL_snprintf( - zip_data, - sizeof(zip_data), + virtual_path, + sizeof(virtual_path), "levels/%s.data.zip", filename ); - - zip_normal = PHYSFS_getRealDir(path); - - SDL_snprintf( - dir, - sizeof(dir), - "levels/%s/", - filename - ); - - if (FILESYSTEM_exists(zip_data)) + if (FILESYSTEM_exists(virtual_path)) { - printf("Custom asset directory is .data.zip at %s\n", zip_data); + printf("Asset directory is .data.zip at %s\n", virtual_path); - if (!FILESYSTEM_mountAssetsFrom(zip_data)) + if (!FILESYSTEM_mountAssetsFrom(virtual_path)) { return false; } MAYBE_FAIL(graphics.reloadresources()); } - else if (zip_normal != NULL && endsWith(zip_normal, ".zip")) + else if (real_path != NULL && endsWith(real_path, ".zip")) { - printf("Custom asset directory is .zip at %s\n", zip_normal); + /* This is a base zip, probably the official data.zip */ + printf("Asset directory is .zip at %s\n", real_path); - if (!FILESYSTEM_mountAssetsFrom(zip_normal)) - { - return false; - } - - MAYBE_FAIL(graphics.reloadresources()); - } - else if (FILESYSTEM_exists(dir)) - { - printf("Custom asset directory exists at %s\n", dir); - - if (!FILESYSTEM_mountAssetsFrom(dir)) + if (!FILESYSTEM_mountAssetsFrom(real_path)) { return false; } @@ -569,7 +552,29 @@ bool FILESYSTEM_mountAssets(const char* path) } else { - puts("Custom asset directory does not exist"); + /* If it's not a level or base zip, look for a level folder */ + SDL_snprintf( + virtual_path, + sizeof(virtual_path), + "levels/%s/", + filename + ); + if (FILESYSTEM_exists(virtual_path)) + { + printf("Asset directory exists at %s\n", virtual_path); + + if (!FILESYSTEM_mountAssetsFrom(virtual_path)) + { + return false; + } + + MAYBE_FAIL(graphics.reloadresources()); + } + else + { + /* Wasn't a level zip, base zip, or folder! */ + puts("Asset directory does not exist"); + } } return true;