Roads system in Raise Your Civilization
Road system ideas for Raise Your Civilization game
Roads in Raise Your Civilization will play big role in design of settlements and cities. Some city building games decided not to use road systems controlled by player. Instead it allows roads to be auto-placed on paths founds by AI. I love both kind of games with player controlled roads and where roads are marked on paths constructed by AI, but personally I enjoy to design city transport infrastructure. This is why I've made design decision to include player controlled roads in game. Raise Your Civilization should allow played to design all aspects of settlements, cities and finally whole civilization. Constructing road system in game is a big challenge. At start I thought that this would be the simplest part of game system, but with time I found it to be very complex to design. My First idea was to simply use decals. It was easy to handle and code. Idea was to create 3 tiles - start, mid and end. Start tile would be circle with line connecting to one side. Mid tile with connect two sides. End tile would be mirror image of start tile. When creating road I would spawn start and end time and if needed I will add additional mid tiles. Here is image showing how this design would work:
In theory this system should be working fine but sadly I've found many flaws in this approach. This system works almost good if you know size of your road. Raise Your Civilization will allow player to control how road will look and its size. This caused first issue - visual one. When you resized road you could see a jump when new mid tile has been added to reflect size selected by player. Second visual issue was that only sizes of road which was multiplication of tile size could be displayed. After first test I've scrapped this idea and started a design of upgraded version. This time I would need only two tiles types - connector tile and mid tile. It was upgrade to previous idea. Now on start I would create 3 tiles. Start/end and mid tile. Position of mid tile would be center of start tile. I would add new mid tile when road size would be change more then half of size of tile. This was working much better and any road size would be easy reflected. Schema of this idea can be found on this image:
For my initial development this system has been working perfectly. Sadly this one also has a flaws. Its very easy to spot gaps between last mid tile and end tile when road size is extended close to half of tile size. This one is minor issue compared to previous system but still easy to spot during game play. When I had all my basic systems ready I've started to think how to upgrade again road system. During my tests I've noticed that spawning a lot of decals and assigning material instance caused random crashes. I had no idea how to fix it but definitely it was caused by spawning a lot of mid elements with long roads. Next idea was why to have multiple mid elements - maybe one would be just enough. Then I realized it could be easy done by shader and modification of UV map on decal material. Now only 3 elements will be creating whole road. Schema for this idea is on image below:
This was it! This simple change was working amazing. I did a lot of test to spot any glitches in drawing on if previous crashes would occur. I could not find any previous issues I had. You can try to spot issue between old version and new shader version on images below:
Old Road System look
New Road System look
This all so far is great, works as expected, but still its not the system I would like to have. First of all Raise Your Civilization will have multiple road types. Each road type would be different - different sizes, different connections between road types. With decals I could not find any way to make nice junctions between different road types. There are two ideas left - mesh roads floating above terrain or roads baked into terrain texture. Mesh roads seems perfect for any tarmac roads as still I would need some extra mesh for side walks. For other road types I think that roads baked into terrain texture would be the best. Memory needs for this kind of roads are small - texture could be 256x256 or 512x512 if high level details would be selected. Here are two masks I could use to display road on single terrain tile:
Single Type Road Mask
Multi Type Road Mask
Current roads system now works, but still a lot of work will be ahead of me. As I will need to support multiple road types, probably rails too I think that I have underestimated amount of time need to complete roads systems for game. Hopefully current ideas when coded will be working perfect and I would not need to rewrite this system once again.