I’ll explain a bit what I’m trying to achieve, and then I have some questions in case others have come across this and have some advice.
I have an application that contains multiple games that can be selected by the player. The applications has resources that are always loaded (common resources). Once the player clicks on one of the games, the resources for that game are loaded (along with initialization of the specific code to that game).
The player can then exit that game, and go back to the game selection screen (which is a separate scene object), and then can select another game to play.
More game resource bundles can be downloaded and added to the app, so they don’t actually exist within the initial bundle that is downloaded from the app stores. The code for the games already exists inside the application, so there is no dynamically loaded executable code or scripts (since they’re not allowed by app store policies).
The way I have it working at the moment is that the player can download the app (say from Google Play, the APK), and it installs. Once the player loads the application, it downloads several extra resource ZIP files from a host where the games exist. Those ZIP files are copied to a writable folder, and extracted. That path is then added to the search path in Cocos2d-x by FileUtils::getInstance()->addSearchPath(path).
Now, there doesn’t seem to be a way to remove that path from the list, so it’s always there, and I’m worried that resources for different games will clash because of this issue.
Also, there doesn’t seem to be a built in way to unload specific resources (since there is no concept of resource group etc). I think I’ve managed to find a way around this by manually tracking all the resources that are added, and then unloading them myself, but I’m not yet sure if it’s 100% effective (meaning resources still in memory when they shouldn’t be).
Now, my questions:
-
Is there a valid technical reason why a method does not exist for removing a path from the list of search paths? If there isn’t a reason, then I can add one myself without troubling the Cocos2d-x devs.
-
Is there any 100% effective way to unload only certain resources (like loading resources with some kind of ID or tag, be it integer or otherwise, and only unloading those with that tag).
-
Is there ANY way to use ZIP files directly without having to extract the contents? Basically the same way APKs are handled by Android, where the APK is accessed like a filesystem.
Any information or suggestions would be appreciated.
EDIT:
Possible solution to (1) is to use setSearchPaths instead of addSearchPath. setSearchPaths nukes the current file path cache along with all the set paths, and overwrites them with the new list. This will do the job fine for my app. One thing to note though, I just realised addSearchPath doesn’t check for duplicates, so you can end up with multiple of the same entry in the lists by using it.