10 Replies - 2193 Views - Last Post: 08 August 2013 - 07:28 AM

Large Tilemap Optimizations

Posted 03 August 2013 - 05:04 PM

So, I've been working on a tilemap for some time now, and I've never really been satisfied with the draw performance. I need to render about 8k tiles to fill a screen at 1080p, and the Spritebatch seems to be limiting me, here.

I've tried all sorts of things, and can't quite figure out how everyone else did it. I tend to get a fairly good framerate, but I need a whole lot of room for other things to come.

Without going too far into detail, what's the best way to call the spritebatch thousands of times per frame with as little lag as possible for a large tilemap?

Replies To: Large Tilemap Optimizations

Re: Large Tilemap Optimizations

Posted 03 August 2013 - 06:10 PM

I don't know if you're aware of this, but SpriteBatch is intended to be called once per frame. That's why its a batch. There's huge overhead every time it's called. So, you want to call it once per frame. If you have a million sprites, you want to put them in one SpriteBatch.

Re: Large Tilemap Optimizations

Posted 03 August 2013 - 07:00 PM

BBeck, on 03 August 2013 - 06:10 PM, said:

I don't know if you're aware of this, but SpriteBatch is intended to be called once per frame. That's why its a batch. There's huge overhead every time it's called. So, you want to call it once per frame. If you have a million sprites, you want to put them in one SpriteBatch.

Of course I'm aware. I'm talking about the Spritebatch.Draw. How am I meant to draw other than with that?

Re: Large Tilemap Optimizations

Posted 04 August 2013 - 04:15 AM

Still, drawing 8000 is not a lot of tiles. There must be something in your code that is causing an issue. Can you post the rendering code?

You don't optimize your calls to Draw, you limit what you draw. If you've got an extremely large map you only draw what is visible on the screen plus or minus 1 tile. Same goes with other objects on the map. If they're not visible, don't draw them.

Re: Large Tilemap Optimizations

Posted 04 August 2013 - 02:59 PM

Here's my performance, as of yet. I've actually increased the size of the tiles to 32x32 to try to reduce the draw calls, but I'm very unsatisfied with the look. In this image in particular, I've forced it to draw as if the tiles were 16x16 to show how little room I have for the rest of my game. Sure, 170 fps will do, but I'm not sure I'm happy with so much of my loop being unavailable so early.

Am I being unrealistic with my performance desires, or am I missing something vital?

Re: Large Tilemap Optimizations

Posted 07 August 2013 - 08:54 AM

I don't understand where the problem is. Your current FPS is 174 in the screenshot. You're obviously not taking much of a performance hit by this tilemap, as a framerate that high is still way beyond the point at which humans can no longer distinguish between differences in framerate. I wouldn't be so concerned with it unless it becomes a major issue later. I don't think 8k 16x16 tiles are going to be as much of a problem as you seem to think they will be.

Re: Large Tilemap Optimizations

Posted 07 August 2013 - 11:04 AM

Kilorn, on 07 August 2013 - 08:54 AM, said:

I don't understand where the problem is. Your current FPS is 174 in the screenshot. You're obviously not taking much of a performance hit by this tilemap, as a framerate that high is still way beyond the point at which humans can no longer distinguish between differences in framerate.

Yes, however, I'm on a $1600 machine. I don't trust that the everyday desktop will run this fast enough. Also, I'm trying to keep in consideration the fact that I'm left with only about 10ms to do EVERY other operation necessary for a large RPG.

Re: Large Tilemap Optimizations

Posted 07 August 2013 - 11:18 AM

I'd suggest finding a computer that you could test it on that is a couple of years old. I'm sure a friend of yours wouldn't mind letting you test it out. I'm also not sure where you're getting the math that tells you that you will only have 10ms to do every other operation necessary for a large RPG. How are you calculating how much time it takes to render this tilemap?

Re: Large Tilemap Optimizations

Posted 07 August 2013 - 02:36 PM

Kilorn, on 07 August 2013 - 11:18 AM, said:

How are you calculating how much time it takes to render this tilemap?

Rendering at 170 fps means I'm using 5.8ms per update loop just for my tilemap. I have to maintain a 16.66ms or lower loop to keep the game from dropping under 60fps. That leaves me with just 10.8ms for everything else - shaders, logic, etc.

Re: Large Tilemap Optimizations

Posted 08 August 2013 - 07:28 AM

So according to your math, you're using about 1/3rd of your time to load, analyze, and render your tilemap, which is going to take up at least half of your screen. Considering that roughly 8000 tiles make up the viewable area of your tilemap, that means you could theoretically render another 16,000 sprites in the time remaining before you notice any frame drop. Do you really think you're going to have more than 16,000 sprites that need to be rendered beyond the tilemap? If so, I'd dare to say that your game is going to be incredibly busy on screen and completely chaotic with that many sprites/images/tiles/whatever to deal with on screen at the same time.