How do the maps work in Civilization?

Started by
8 comments, last by Semei 12 years, 10 months ago
In Civilization V there are no "sides" to the map (except for the top and bottom of course), so if you keep moving your camera, lets say to the left, you keep on circling around the map. How is this achieved? I was going to wrap my terrain around a cylinder, but I don't think that would produce the same effect, as the map in Civilization looks flat.
Advertisement

In Civilization V there are no "sides" to the map (except for the top and bottom of course), so if you keep moving your camera, lets say to the left, you keep on circling around the map. How is this achieved? I was going to wrap my terrain around a cylinder, but I don't think that would produce the same effect, as the map in Civilization looks flat.


Its called "wrapped" or "toroidal indexing". Basically just take the absolute xy coordinate of the tile you want to draw (can be any values, including outside the range of valid tile indexes), then you use the an unsigned mod operation with the max width and height to determine the "wrapped" index. e.g.:


x = -47
width = 20
wrappedx = x % width;
if(wrappedx < 0) wrappedx = width + x;
I don't know the exact technique Civ 5 used but you could achieve the same effect with having everything stored into a grid (tile map) and than write a rendering algorithm that when you are at 0 and keep trying to go to the left, the end of the array is rendered. It really is just rendering a tile map in respect to what tile you are looking at.

I am sure there are other ways to do this but that is the only way I have read about (thus far).

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca

Thanks guys. I wasn't going to use tiles, but I suppose if I sliced the terrain up into tiles it still work.

Thanks guys. I wasn't going to use tiles, but I suppose if I sliced the terrain up into tiles it still work.


Yep, your tiles don't have to be 1x1 though, in fact they could be the size of the entire map, so you are constantly drawing the whole map four times..

[quote name='beatlefan' timestamp='1309186439' post='4828264']
Thanks guys. I wasn't going to use tiles, but I suppose if I sliced the terrain up into tiles it still work.


Yep, your tiles don't have to be 1x1 though, in fact they could be the size of the entire map, so you are constantly drawing the whole map four times..
[/quote]

Wouldn't constantly drawing the whole map be a massive drain on the machine running it?

Wouldn't constantly drawing the whole map be a massive drain on the machine running it?



It depends on how costly it is to draw the map. Obviously it isn't optimal, but it would achieve what he originally wanted, while requiring barely any modifications to his code.

[quote name='Huwtrosky' timestamp='1309262676' post='4828622']
Wouldn't constantly drawing the whole map be a massive drain on the machine running it?



It depends on how costly it is to draw the map. Obviously it isn't optimal, but it would achieve what he originally wanted, while requiring barely any modifications to his code.
[/quote]

Good point
If you want to do it using a more traditional terrain renderer (rather than rendering code which knows about a wrapped world), one way is to simply duplicate the left hand side of the terrain - so if your engine draws at x = width+3, there's a valid entry there that's the same as at x = 3. The amount you need to duplicate is equal to what can be displayed on the screen. (This is the same trick that could be used for old-skool scrolling text messages that wrapped around.) This is the method that I'm using for my game, Conquests.

The same technique applies if you're just using a large image, rather than tiles - although it then basically becomes similar I think to what bluntman proposes. I don't think performance would be a problem - clipping will mean you only really spend time on the pixels that are visible on screen.

http://erebusrpg.sourceforge.net/ - Erebus, Open Source RPG for Windows/Linux/Android
http://conquests.sourceforge.net/ - Conquests, Open Source Civ-like Game for Windows/Linux

The same way you wold draw simple scrolling image.

Also thinking about how to get hexes to draw together without cracks and seamless is not needed - you can just splay your terrain height displacement on ground, and using that displacement in terrain vertex shader to displace regular triangle grid.

Also civilizations implementation is not-so-cool because there is still a crack visible ;p

This topic is closed to new replies.

Advertisement