Jump to content
  • Advertisement
Sign in to follow this  
archev1

[RTS]displaying explored area

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!