(Slick2D) TiledMap resource efficiency

I’m really loving the tools that come out of the box of Slick2D! I’m building a platformer game in which I control the transitions from area to area.

I’m only slightly concerned with loading’s effects on the background music playing. When transitioning from one level to another, there is a slight hiccup in the background music that is playing. I’ve narrowed the problem down to the TiledMap that is used in each level. I use a resource manager to dynamically cache and access resources.

Is there a way when creating a new TiledMap to re-use the resources used in previous TiledMaps? If that’s not possible, is there a way to prevent the TiledMap’s loading from interfering with music playing in the background? I also have considered preloading a TiledMap into the resource manager so that it may be used later without reading from a .tmx file. I’d just like to know all of my options.

Thanks a bunch!

Doesn’t music play in its own thread? If so, then this seems like thread fighting really.

It was my understanding that music played in it’s own thread just like you said. For some reason, though, the music skips a little when making transitions… I actually tried what I mentioned above and preloaded TiledMaps, but the music always skips a tad when making transitions. Strange… The game’s performance is generally buttery smooth in every other aspect.

How many cores does your CPU have? I wouldn’t worry too much about this anyway.

I’m pretty sure it’s four. Not that my laptop is particularly fast, though. It get’s its job done, but I usually get a better performance on other computers. Anyway, yeah, I wasn’t TOO concerned about this issue, but I’ll post if I find a solution.

Ah Ha! I figured it out! I use a bunch of HashMaps to store previously used data in my Resources class. I was an idiot and forgot to put the resources used for font into its designated HashMap after being loaded the first time… Derp… Doesn’t COMPLETELY fix the problem with the music, but as long as I’m careful with my resources, the split second skippyness in the music shouldn’t happen.

Slick’s music is streamed in the same thread as rendering/logic/etc which is most likely causing your issues.

Map loading should be pretty fast since it’s just parsing XML text – if it’s slow, I’d imagine it’s because the tiled loader is decoding/uploading texture data for a tilesheet. Instead, you should be loading the tilesheet image once, and reusing it with multiple maps. (If this isn’t currently possible with the TiledMap API, you should file a RFE.)

Another solution would be to use a different audio library which supports threading, like Paul’s SoundSystem or TinySound.

Slick doesn’t create a new thread just for audio?! That’s not a good idea :S

TinySound uses JavaSound, which is completely unreliable. Just use OpenAL entire directly or through Paul’s SoundSystem.