Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 7:19 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed May 02, 2012 3:47 pm 
Offline

Joined: Sun Jul 10, 2011 8:27 am
Posts: 25
Hi all,

Are there any commonly-used patterns for loading assets in background threads? Before going and re-inventing the wheel, I thought I'd check to see if the problem has already been solved.

In particular I need to load TiledMaps and images from a webserver. The actual loading is straightforward enough, but I'm wondering about loading these in a background thread whilst having a different gamestate display a loading animation. In XNA-land it was a performance problem to draw at the same time as loading textures because of some lock on the GraphicsDevice... Are there any such gotchas in Slick2D/LWJGL?

_________________
Deejay
BinaryTweed.com - New games that are like old games, but better
IndieCity.com - Playing a different game


Top
 Profile  
 
PostPosted: Wed May 02, 2012 6:17 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
It's been done before, but it takes a bit of work. You can't call GL from a different thread, so you'll need to load the image separately data using LoadableImageData. Then, with the ByteBuffer and ImageData, you will pass that to GL via InternalTextureLoader to actually create the texture. I'd recommend using the latest dev branch version of Slick.

I'm not sure how this would be implemented using TiledMap as I've never used that class myself.


Top
 Profile  
 
PostPosted: Wed May 02, 2012 6:31 pm 
Offline

Joined: Sun Jul 10, 2011 8:27 am
Posts: 25
Hi Davedes,

Thanks for the reply! That doesn't sound as straightforward as I was naively hoping for.

Apologies for my ignorance, but is that GL as in OpenGL, or something else? Are you aware of any code samples implementing the technique you described?

Thanks again for your help.

_________________
Deejay
BinaryTweed.com - New games that are like old games, but better
IndieCity.com - Playing a different game


Top
 Profile  
 
PostPosted: Wed May 02, 2012 6:46 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
I wrote a library which does async/background texture loading: http://twl.l33tlabs.org/textureloader/ (still needs a website).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed May 02, 2012 6:51 pm 
Offline

Joined: Sun Jul 10, 2011 8:27 am
Posts: 25
Ooh, thanks Matthias! When I get around to implementing this bit, I'll certainly give it a try and let you know how I get on.

Is there any documentation for how it should be used?

_________________
Deejay
BinaryTweed.com - New games that are like old games, but better
IndieCity.com - Playing a different game


Top
 Profile  
 
PostPosted: Wed May 02, 2012 8:17 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
In the javadoc - but it's not really compatible with Slick at all.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed May 02, 2012 8:54 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Shouldn't be hard to make it work with slick. Load the textures with TextureLoader, and once they loaded successfully, wrap them as Slick textures. Then just create a new Slick Image based on the wrapped texture.

http://pastebin.com/Wv28XsL3


Top
 Profile  
 
PostPosted: Wed May 02, 2012 11:02 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Don't forget to call
Code:
async.executeQueuedJobs();
textureManager.nextFrame();
from the main loop - see the javadoc of the TextureManager for details. Otherwise nothing will work.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed Oct 03, 2012 1:24 pm 
Offline
Regular

Joined: Wed Dec 09, 2009 6:56 pm
Posts: 132
Is there a way to load audio files asynchronously?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group