Sign in to follow this  
wespaugh

Tiled Minimap

Recommended Posts

I'm working on roguelike, and we're hopefully about 3 weeks from releasing it. The programmer I took over for wrote a minimap implementation that I've discovered is horribly inefficient; framerate drops from a smooth 30 to a shaky 17 in the worst case when it's active. The algorithm in use now basically does this: // iterate over each tile for( map.width ){ for( map.height ){ // set line width glLineWidth(LINE_WIDTH); // if the tile's been explored, set color to whatever the tile's map color is if(currentTile.explored) glColor4ub(currentTile.minimapR, currentTile.minimapG, currentTile.minimapB, currentTile.minimapA); // if the tile hasn't been explored, set color to black else glColor4ub(0, 0, 0, 255); // draw a line as long as it is thick, making a square tile drawLine( CGPointMake(x, y), CGPointMake(x, y+LINE_WIDTH)); } } which gets called every frame. Even when only drawing a 30x30 subset of the tilemap, this is killing the framerate. It was suggested to me that I create one texture for the entire map in advance, and just draw that static texture, which makes sense. However, that approach might not fully meet the requirements I've got to implement and it would take me a day or so learning how to do, so I want to make sure that's what I should be doing. The snag is that the map needs to reveal itself as the player explores it, so building one texture upfront for the entire map would require some way to mask parts of it. Can that be done somehow? The current implementation was probably designed with this feature in mind. The alternative would be remaking the texture each time more of the map has been revealed, which is almost constantly. I have to assume that would be a lot worse than our current algorithm. Is that a reasonable assumption to make?

Share this post


Link to post
Share on other sites
I may be thinking about your suggestion the wrong way, but it seems like that would incur the same performance overhead as the approach I'm currently using.

Whereas now, framerate starts at roughly 30 FPS and dips to 17-20 when the map is explored more fully, wouldn't covering a static texture with drawn squares as you suggest worsen the framerate by the same amount until those tiles are explored and no longer need to be masked?

Share this post


Link to post
Share on other sites
Hey wespaugh.

First, if you consider the texture approach, use two textures. Draw both on the same geometry. the first should be a texture of the zoomed out level, the second a picture resemblimg a lightmap or, if you wish, a black/white pattern. This is your exploration image.

Second, use vbo's. or just displaylists rebuilt.when explored tiles change. they are quite efficient, even with 30^2*2 primitives.

Share this post


Link to post
Share on other sites
Another idea would be to create a "minimap texture" as you were talking about which is the entire minimap.

It would be just a single quad to display it, and you'd only need to regenerate the texture when a new area has been explored. Your looping would go from every frame, to just the comparatively rare event of the player exploring a new area.

like dragonsoulj said though, vbos may make it fast enough and that seems like the simpler solution since you already have some working code (:

Share this post


Link to post
Share on other sites
@SuperVGA Wow. "Quite efficient" sounds like what I want, but I am entirely new to the rest of those concepts. I found a few overviews of what blitter, VBOs and displaylists are, but I'm having trouble wrapping my head around how exactly to apply them to the current problem.

Do you know of any books or websites that might have more hands-on or practical information on the concepts?

Share this post


Link to post
Share on other sites
Quote:
Original post by Atrix256
It would be just a single quad to display it, and you'd only need to regenerate the texture when a new area has been explored. Your looping would go from every frame, to just the comparatively rare event of the player exploring a new area.


The game is a roguelike, so exploration would be happening every turn as the player walks from one tile to the next and sees the area that was just offscree, so it would be need to be updated pretty frequently. Would this approach still be feasible?

Share this post


Link to post
Share on other sites
Sure, you can do it as fast as every turn. You could do it realtime if you did it properly.

There are many VBO examples out there.
Check NeHe's Lesson 45

I think i'd go with the texture solution though. Textures are easy to access and fast to draw. The VBO's will probably need to be re-generated every turn.
Furthermore, the extension of light in the minimap would be a neat feature,
and every RL should have some sort of Fog of war, darkened areas of the map.

Doable with the texture solution.

[Edited by - SuperVGA on March 4, 2010 8:00:25 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this