TOON: Cache recently used resources, rather than preloading
|Reported by:||eriktorbjorn||Owned by:||sylvaintv|
Some time ago, I mentioned to SylvainTV that the Toonstruck engine uses a lot of memory for preloading entire PAK files, DREW.PAK probably being the worst offender since it's 20 MB that remains in memory for the duration of the game. This patch is an attempt at keeping the memory usage down by caching resources as they are used. I haven't tested it much, but it seems to work for me.
It's built on the assumption that Resources::getFileData() is for short-lived data (typically read from file and immediately copied to another data structure), so it doesn't matter if the actual data is removed from the cache, while Resources::openFile() is for long-lived data which the engine itself is responsible for handling so it doesn't go through the cache at all.
I'm sure there's room for improvements, but at least this demonstrates that the concept could work.
Ticket imported from: #3194044. Ticket imported from: patches/1389.