daniele-rapagnani / alephone-android

Port of the AlephOne engine on Android
GNU General Public License v3.0
40 stars 3 forks source link

Assets take a huge amount of time to load #13

Closed daniele-rapagnani closed 3 years ago

daniele-rapagnani commented 3 years ago

When the game is started it takes a huge amount of time to load. This seems especially the case for Marathon 2 / Marathon Infinity. I suspect the issue may be related to random file access and the fact that the assets are not physical files but are located inside the APK file (which is just a zip). If I remember correctly this problem didn't occur when loading assets from the SD card.

daniele-rapagnani commented 3 years ago

I finally had some time to work on this issue and I think I've tracked it down. As I suspected in #15 the issue seems to be with seeking into the assets when loading sounds. Seeking is probably slow in general, but the seeking done at SoundFile.cpp:126 to guess the sample encoding is the one causing the slowdown when the app starts.

Edit: The above wasn't true, simply messing with the encoding caused the sounds to not be loaded in the first place giving the impression that it was the main problem. The issue was caused by two different causes. The first was that the SDL2 version I was using read files directly to seek into them rather than using Android's built-in function to seek into assets. This was fixed in the master branch of SDL2. The other one was that the assets couldn't be seeked in constant time because they were compressed and AlephOne does seeking all over the place to load sounds. Simply disabling compression for the assets reduced the loading time to less than one second.