Threading bitmap loads
pmprog

So, in OpenApoc, I was loading my menu GUI from XML, and rendering it to the screen. I got really confused why when loading from the XML it ran really slowly and jerky, but when I manually constructed the UI, it was smooth.

Anyway, long story short, it was because I threaded the load of the XML (which included the bitmap).

Now, when you try and draw with a bitmap loaded in a different thread, it takes a lot longer to render (I assume it's something to do with handing references between threads)

How can I go about threading my load, but without the overhead when it comes to rendering?

beoran

What probably happens is that the images got loaded in the wrong format. Normally, Allegro will use the display format to convert your images to display format for optimal performance. Likely the thread mis-loads the format and also loads the images as memory bitmaps, not video bitmaps.

Now I haven't done this before but I guess the way for you would be to open a display, inspect it's format with al_get_display_format, and then set that format with al_set_new_bitmap_format , then ensure that you will make video bitmap with al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP) and finally clone the loaded bitmap to the right format with al_clone_bitmap.

Thomas Fjellstrom

In some version of 5.1, you also get: al_convert_bitmap and al_convert_bitmaps which may or may not be faster and more efficient than al_clone_bitmap.

pmprog

Ah, I never really thought about display formats over threads, but that makes a lot of sense.

Thanks, I'll give it a try.

Edit: This didn't actually help me any. I'll just considering ditching the threaded loads

Max Savenkov

Did you try to actually profile the code to see what's causing slowdowns? It might be something unexpected.

pmprog

I remember thinking about it, but I couldn't find any tools in VS2013 for it... Having just opened VS2013 now, I think I was just going blind, will have a go tonight.

Though, I've actually modified my loading code, I only load images at first attempt to render them; otherwise, I would have been loading practically every reasource for the game straight off, and that could have been quite a chunk of memory. Still, I guess it'll be nice to know for future

Max Savenkov

You can use one of the 3rd party profiling tools. I myself quite liked Luke Stackwalker and VerySleepy. But I recently saw the new version of (free) AMD CodeXL tool and it was quite a step ahead of their old CodeAnalyst offering, so you can also use it.

Thread #614497. Printed from Allegro.cc