cocos2d/cocos2d-x — pull request #2919 by j4m3z0r (2013-06-18 23:21:14+00:00)
Title: Asynchronous Image loading for Emscripten

Added async image loading for Emscripten builds. Async loaded images are fetched via a normal HTTP request for the image, so when this is used, it allows for a much smaller initial download since images can just be fetched on demand.

This is done by adding a new CCTextureCache subclass rather than a nest of #ifdefs. I think this is a cleaner design. Note also that a .js file was added in order to implement the actual async image loader -- this requires slightly different flags to Emscripten (--js-library).

The async image loader will divide up images into multiple sub-rectangles, and pixel data is alpha pre-multiplied and copied into the texture buffer over multiple frames. This approach helps to minimize UI stalls when textures are loading.

Firefox load times are greatly improved by this change (~3X), but Chrome is actually a little bit slower. I'm yet to look into why, but believe something like this is the right long-term solution, so pushing this up now.