Preloader [b38]

Jon

  • *
  • Posts: 17526
For games with many scenes (> 25), you may find the initial load to be slow because we preload all scene data upfront.

What I'm going to do is add a new setting, with the default set to true. This setting will NOT preload scenes, and instead will load them on demand. This will add a very small delay the first time a scene's loaded. The benefit is that the initial startup of the game will be less.

To accompany this will be more calls (Obj-C for now, till this is tested further). One will load a single-scene. One will load every unloaded scene. The purpose of this is to basically let you decide if you want to load everything at a specific time, such as doing it in a preloader instead.

I hope that these options provide a way for the larger games to present a better user experience.

« Last Edit: September 03, 2011, 01:49:33 pm by Jon »

Jon

  • *
  • Posts: 17526
Would it be useful if I extended this not just to scenes but to make this all more automatic by showing an optional pre-game loading sequence before the game? It'll get the game starting practically as fast as it could possibly go, hit the preloader sequence than then start the game normally.

It'll follow the exact same parameters as what's in the "Loading Screen" page in the editor, the same that we use to make preloaders for Flash.

I'd probably need to buff up the options a little bit, but at least for a first cut, I can stick with what's there.

By loading "everything", this includes every resource, scene and asset in the game except for what the preloader uses.

Manuel

  • *
  • Posts: 764
That would be really useful, Angry Birds also has a small loading screen before going into a level, shortening the initial load. :)
Game developers are the deities of the virtual realm.
Game Development Blog
Personal Tumblr
Personal Twitter

Jon

  • *
  • Posts: 17526
If memory usage becomes a problem, we can allow a load/deload sequence to unload assets from memory and bring in a pre-level load sequence. I know some of the bigger games have to do this.

Jon

  • *
  • Posts: 17526
I'm working on this one tonight. Hope to have it ready for the next release. It should help a lot, user perception wise, for larger games.

As a general suggestion, though we won't mandate it, it's recommended that you use the same background image as what you used for the splash image. This makes the whole process look seamless.

Jon

  • *
  • Posts: 17526
In terms of how you configure this, we're going to start with making it identical to the Flash one you already specify in the Loading Screen page. No action is needed on your part.

Once the first cut is done, I'm going to add an option to use an image-based loading bar instead where you specify a single image, and it will display part of the image to indicate process. To make it look like a proper bar, you probably need to tune your background accordingly to do that, but you're all artists, and I don't need to tell you that. ;)

Jon

  • *
  • Posts: 17526
After a lot of work on this, I got it done. There was a *ton* of debugging involved because of the multi-threading this introduces, and the trickiest part was getting it to properly deal with loading OpenGL textures off a background thread.

Apparently, the textures all come up blank if you do. The solution was this:
http://developer.apple.com/library/ios/#qa/qa1612/_index.html

Creating a second OGL context with a shared space, loading the textures in there, all while making sure that it didn't conflict with the drawing I was doing of the preloader. I got some very, very funky errors in the process, and I hope you don't run into them. I've tested every demo in the simulator and device so far.

The end result is a much better initial launch experience for larger games. It'll hit the preloader very quickly and then begin loading right away, rather than getting "stuck" on the splash image for the equivalent time.

Combined with finer grained controls over atlas loading/deloading, this should help the larger games a lot.

fanstudio

  • Posts: 201
We really appreciate the work you put into this piece of software Jon!

I hope you will release soon the stable version so we can pay our subscriptions :)


Rhys

  • Posts: 1046
That's brilliant! How will you deal with iPad? (needs a different preloader with different positioning etc)

Jon

  • *
  • Posts: 17526
Probably a separate page with overrides for iPad.

In the first release of this, it'll just honor the Bar Style and Bar Color fields, just so we can stamp out any bugs first. I probably have to add a separate page for iPhone/iPad because of the different sizes and the off-case where the iPhone and Flash version's resolution's differ.

Jon

  • *
  • Posts: 17526
Discovered inconsistent behavior, probably due to multi-threading.

Then I ended up throwing away the implementation and trying a simpler one based on what I found on the Cocos2D forums. I reimplemented it in about 20 minutes, and it's working consistently well now.

The old approach used an NSOperationQueue with tasks allocated to every tiny sub-task, even down to the resource level. Apparently, due to concurrency or whatever where multiple things could be loading it simultaneously, this inconsistently bombed out on me. I went with the simpler approach of one task to cover everything instead, and it's not only simple but doesn't have a chance at running into those issues, which are pretty close to impossible to debug.

The only downside is that as the devices go multi-core, the multiple cores won't be used, but it's not a big deal right now since it's all loading really quickly to begin with.

Jon

  • *
  • Posts: 17526
I'm working on a fix to the landscape form of the preloader, which can have this weird effect of it starting in portrait for a blink and then rotating. I'll release a new version in place with this fixed later tonight.

Jon

  • *
  • Posts: 17526
It's been reuploaded with the fix.

Rhys

  • Posts: 1046
I'll just honor the Bar Style and Bar Color fields
Did you do this? The colour and style are incorrect.

Jon

  • *
  • Posts: 17526
Not yet. I decided to ship just to get it tested first.