# [RTS]displaying explored area

This topic is 2893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, Im working on a tile-based game. Each field on the map may be either 'explored' or 'unexplored'.
Visibility is stored as an 2D array and explored[x][y]==0 means tile (x,y) is unexplored and explored[x][y]==1 means tile is explored.
In popurar games, unexplored areas are usually rendered as 'darker' versions of explored ones(darker texture or sth).
My question is, how to write a rendering code for my map, regarding what i've said before. I want it to have a good performance, and
I dont want something like: Move through all tiles(n^2 complexity) and decide whethrer to put darker or normal texture on that tile, regarding to
'explored' array.
regards

##### Share on other sites

Move through all tiles(n^2 complexity) and decide whethrer to put darker or normal texture on that tile, regarding to
'explored' array.

How would that be quadratic complexity? it's linear in the amount of tiles. And there is no way to do it in less, since you have to iterate over the tiles at some point anyway.
I suppose you have to do something like
 for each visible tile if explored(tile.x, tile.y) tile.draw_explored() else tile.draw_hidden() 

##### Share on other sites
Yea, that would be the simple solution, but I want my map to be big so I need something faster. When you double the map size, the number of tiles increases 4 times, so its quadratic.
Thus I dont want to draw each tile separately, for now I just render one big square covered with texture of drawn tiles. So I want to do something similar, but with recognition of explored/unexplored areas.
regards

##### Share on other sites
How are you drawing each tile currently? And are you using any shaders currently?

##### Share on other sites
I decided not to use shaders for this game but I can change it if i have to.
This is my simple rendering code
 glPushMatrix(); glBindTexture(GL_TEXTURE_2D,surfaceTex.texID); glBegin(GL_QUADS); glVertex2f(0,0); glTexCoord2d(0,0); glVertex2f(sizeX,0); glTexCoord2d(sizeY,0); glVertex2f(sizeX,sizeY); glTexCoord2d(sizeY,sizeX); glVertex2f(0,sizeY); glTexCoord2d(0,sizeX); glEnd(); glPopMatrix(); 
And the image I use for texture represents just one tile. I repeat it my multiplyng texture coordinates to make and impression of tiled suqare Edited by Mike_

##### Share on other sites
I do this by rendering the squares using the same texture, but use vertex colouring to give lighting effects. Yes you have to render one polygon per tile, rather than just one, but I don't see that this is a performance issue (you're using the same texture/shader, so it's just one rendering call - if it's slow, you shouldn't be using immediate mode). This has the advantage you can also using the lighting to make the light areas fade out gradually, rather than having a sudden transition from light to dark.

Another way might be to use two textures, one for explored, one for unexplored, and which gets drawn at each pixel depends on whether it's been explored or not. Again you could set it up to do gradual transitions. (Easily done in a shader - I've no idea what fixed function multitexturing offers.)

##### Share on other sites
you might be able to get away(performance wise) with iterating through every tile if you draw with vertex arrays instead of immediate mode, your program will be generally faster.

A quick Google search on "Vertex Arrays" will tell you how to use them.

##### Share on other sites

Yea, that would be the simple solution, but I want my map to be big so I need something faster. When you double the map size, the number of tiles increases 4 times, so its quadratic.

Think about this again, if i have a map 16x16, it will fit in an array of tiles[256]. if i double it it will be an array of tiles[512], not [1024], because I double the amount of tiles, not the size of EACH dimension. So again it is a linear time with respect to the number of tiles.

##### Share on other sites

[quote name='Mike_' timestamp='1321446836' post='4884546']
Yea, that would be the simple solution, but I want my map to be big so I need something faster. When you double the map size, the number of tiles increases 4 times, so its quadratic.

Think about this again, if i have a map 16x16, it will fit in an array of tiles[256]. if i double it it will be an array of tiles[512], not [1024], because I double the amount of tiles, not the size of EACH dimension. So again it is a linear time with respect to the number of tiles.
[/quote]
I think what he means is doubling the length of the edge not the area...
So I guess you "prebake" all the tiles into one big texture and render just that... but then you can also prebake the fog into another texture and just alpha blend them together. Also for this to be a real issue you'd have to draw absolutely absurd amounts of tiles which would all have to be on the screen at the same time.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 9
• 11
• 15
• 21