Friday 30 September 2011

Asynchronous Resource Loading

After reading about Alex Okafor's difficulties with CGContextDrawImage on separate threads for loading graphical resources I decided to just load the textures on the main thread and save myself the hassle of changing my png lib.

The main bottle neck at the moment is the level geometry data and models so I've shifted that to load on a separate thread and permit me to add a loading animation. I decided to use posix threads for compatibility reasons rather than Apple's NSThreads api.

I thought I'd save texture space by using a single frame of animation and rotating it in code but this didn't work very well. The texture pixels were slightly off at different rotation values, so I opted for animation frames to keep a polished 'locked in' look to the animation.

The loading screen now has a loading bar for overall progress with an animation that gives the user some feedback whilst only stalling slightly initially for the texture loads, which are non-threaded. I feel this is polished enough and fully threading the loading screen is not worth the time investment at this stage.

Update 01/10/11:

I tried adding the OpenGL shared context stuff anyway and it all worked fine with my texture loading code, wasn't much of an effort to add either. All loading is now entirely done on a second worker thread. Shout out to BigMac for the sanity check!

No comments:

Post a Comment