November 5, 2015 By: David Tse
Over the last few weeks I’ve got quite a lot done on road generation and streaming. I’ve also decided to move from a development update every week to less frequent, but more substantial updates every 2-3 weeks. This way I can give you guys better updates and have more time spend working on the actual game.
I’ll still be doing daily updates about the stuff I’ve been working on over on my twitter if you want more frequent news about development. This update will be larger than future updates because it’s been a month since the last update and there has been a ton of progress. So strap in because there is a lot to talk about.
While my focus is still on getting the generation pipeline completely flowing from start to end before working more on the generation algorithms, I did have to go back to generation and make some changes. These changes where necessary for streaming the roads and creating correct meshes for them.
The first thing I had to do was convert the road generation system from creating and saving individual road segments to creating and saving out continuous splines. Having the spline data makes creating the interstates and the actual road meshes much easier. This is also needed to handle different types of roads and their intersections.
High level view of the interstate generation. It's a little hard to tell whats going on, but each Color is a different interstate. You can follow a color to see all the cities it connects.
This is before the noise pass so there are just straight lines connecting interstates and it doesn't look that great.
Since we are generating splines now, I also had to change the export of the road data to split up splines along chunk bounds. I then had to add extended point data at the end so splines are still smooth along chunk boundaries. After that it’s just about saving the splines instead of a list of chunks to the custom streaming format I talked about before.
After those generation changes I then moved on to doing some improvements to the interstate generation. The Primary problem was all the interstates connected at one point at the city center which made handling of intersections pretty much impossible. So to test the intersection mesh creation I had to split up the interstates into real interstates that are continuous and connect multiple cities.These interstates now pass through cities sort of randomly and intersect other interstates at random points in the city just like they do in real life.
Zoomed in view of a few cities and their interstates. Notice how they flow through cities instead of meeting at one point.
I also gave each city a random size which you can see in the screenshot.
To make this happen I had to do a decent amount of work randomly connecting interstate segments inside cities and then creating a doubly linked-list to grow interstates from connecting just two cities to connecting 10s or 100s of cities. It is fairly complicated, but the end result is a list of large continuous interstates that connect many cities. This improvement also has the added benefit of being able to name interstates that you can follow as you explore the world (for example I-10, I-95, etc.).
Screenshot of debug lines from when I was working on mesh creation testing up, right, and look vectors for road segments.
Once the interstates where created and connecting cities I did a quick pass on making them look good. For now I simply took the straight lines that made up the interstates and did a 2D noise similar to what I do for terrain to give each segment both high and low level movement. So interstates do large and small scale deviation from their straight connecting path.
Top down view of a bunch of chunks loaded with their roads. Red chunks actually have data.
This creates pretty realistic looking interstates, but there are still some problems with interstates intersecting outside of cities, intersecting too many times in a close area when they should be combined, and only passing through the outside of some coastal cities. These will be fixed in the future, but for now they get the job done. They connect cities and pass through them in a realistic way allowing me to test intersection mesh creation.
Streaming and Mesh Creation
Once those changes were made I was back in the game to stream all this data. The first step was designing a new data driven entity system. I briefly mentioned it in the last blog post, but I did a good amount of work on it after that post. You can see the details of the new system in the picture of my whiteboard below.
Detailed plan for the new entity system that I did on my whiteboard.
The system is designed to handle streaming large quantities of data in chunks and is the backbone of the streaming system. This system is also designed for maximum speed after stuff is streamed in. Once this entity system was in place I updated the chunk streaming to load data into this and created a chunk prioritization system. As you move through the world new chunks encountered are loaded and chunks in the distance are unloaded to make room.
Actual road mesh loaded into world on test terrain. If you look close you can see if climbing over a hill in the distance.
After the raw spline data was being streamed in I started work on the actual road meshes. For every chunk we go through each spline and create one mesh. So it’s one draw call per spline per chunk. The actual creation of the mesh is done by extending an arbitrary road mesh along the spline.
This lets us create any type of road like country interstates, city highways, city streets, neighborhoods with sidewalks, etc. The system can extend any mesh so there are no limits to the types of roads or even other things like rivers the system can render.
That’s everything I’ve been working on over the last few weeks. There is still work to be done on mesh creation, primarily the placement of intersection meshes. To do this I’ll have to save out the intersection points and push back the splines to the intersection mesh start points and some other complicated stuff. There are also some issues with world shifting when streaming the chunk data that need to be addressed.
So that’s the stuff I’m off to work on right now, let me know what you guys think about the new update schedule or if you have any questions. Don’t forget to checkout my twitter if you want updates more frequently than the blog update every 2-3 weeks.