Lately I have been busy engaged on procedural era for ranges, which is one thing I did not initially plan for however began to look extra attainable as time went on. Very similar to the earlier work I did on path discoveringthere are some difficulties that include doing this sort of factor for a free-form atmosphere and never one which’s good and grid primarily based, which I am going to discuss extra beneath. Although I am nonetheless planning at hand design loads of the degrees, this may actually assist so as to add some additional alternative for gamers, and even open up the chance for an countless mode as soon as the principle sport is completed.
When you like what you see right here, please check out Deep Area Exploitation on Steam and maybe wishlist it!
Here’s a gif of random ranges you may count on for a scrap job.
Deciding on Proc-Gen
Initially I solely deliberate on utilizing procedural era for the textures of the asteroids and never the degrees themselves. My thought was that for the reason that sport is not going to be infinitely lengthy, and procedural era is difficult to truly make good and fascinating, I might hand design every degree as a substitute and reap the advantages of a human contact (like putting sources particularly to trick gamers or give them an enormous payoff). I had an enormous love of procedural era after I first began programming, and made plenty of little experiments but additionally wasted loads of time attempting to get the outcomes good after I might have been placing extra effort into different issues. So this was partly influenced by me not eager to get caught with a process I wasn’t certain I might truly pull off.
Now although, first rate procedural era began to appear extra attainable. After engaged on the sport all this time I felt I had a a lot better understanding of what labored and what did not for ranges, and the way I might have that pieced collectively randomly. That is partly confidence from having hand-built loads of ranges, and partly from having extra instruments out there to make use of for this (I say instruments, however I imply intelligent code for interacting with the bodily shapes of issues).
I made a decision to offer myself one week (which became one and a half after different commitments) to have a severe go at it, so what you are seeing right here is the results of that. I am fairly happy with the end result, and I feel it could solely get higher with tweaks and added options.
Step 0 – Parameterisation
The era is definitely fairly closely parameterised, with me specifying precisely what number of asteroids of every measurement and kind, what number of sources of every sort, what destruction to use, and at last what different entities to position. Due to this, I am just a little reluctant to name this “procedural era” because it’s extra simply intelligent placement of issues. Once I consider procedural era I consider the large worlds of video games like Dwarf Fortress. However this method works properly for me as a result of I do wish to actually specify what goes right into a degree for the aim of steadiness and a few type of predictability.
Step 1 – Asteroids
Step one is the location of asteroids, since they’re the most important objects on every degree and every thing revolves round them. There are 4 totally different sizes of asteroids (Massive, Medium, Small, and Tiny) and presently three differing kinds (Purple, Pink, and White), with parameterisation permitting to specify precisely what number of of every we would like. There are additionally asteroid presets, that are hand designed placements of asteroids, with every asteroid form having roughly 4 presets to select from.
Very roughly, that is the method for putting the asteroids:
1. Choose the most important asteroid measurement out there
2. Choose an out there asteroid sort for this measurement
3. Discover a random place for this asteroid with some further padding round it
4. Determine whether or not we are going to use a preset
4.1. Discover all presets which we’ve out there asteroids for
4.2. Place a preset which does not intersect with different asteroids
5. Determine the full variety of asteroids on this cluster
6. Place asteroids on this cluster till we attain the full quantity
6.1 Select a random asteroid on this cluster
6.2 Select a random measurement smaller than this asteroid that we nonetheless have availability for
6.3 Place a brand new asteroid of this measurement subsequent to the present asteroid
6.4 Repeat till we have positioned all asteroids on this cluster
7. Repeat till we have positioned all asteroids
I discover this strikes a good steadiness between being random, fascinating, enjoyable to fly round, and in addition semi-natural trying. I am pondering to experiment with broader guidelines, resembling making every thing extra scattered or condensed.
Step 2 – Destruction
Subsequent there’s the prospect for some destruction to be added, in order that the extent appears to be like like another person might need been right here earlier than and executed some mining. That is executed earlier than putting any sources or entities in order that we do not place something precisely the place we make the destruction and make it appear like somebody excavated some sources however then determined to not take them. The destruction can also be bodily simulated in order that asteroids appear like they’ve truly been moved by what’s been damaging them, and having sources/entities positioned whereas that’s taking place could make issues look just a little too random.
In the intervening time there are two sorts of destruction for randomisation; explosive prices, and bullet impacts. The destruction for explosive prices is positioned on the circumference of Massive or Medium asteroids, since putting them on smaller ones can utterly obliterate them, making it pointless to even place them. And the destruction for bullet impacts are positioned ranging from an empty level in house after which casting rays out in a fan to see the place bullets might impression, after which creating small destructions for these positions. After every destruction there is a random likelihood to position some particles related to it, resembling shrapnel from explosive prices, or un-detonated bullets from bullet impacts.
Step 3 – Entities
These are the totally different entities that we would need in a degree, just like the scrap processor or random items of scrap mendacity round. I plan so as to add particular person guidelines for every of those in order that I can have particular outcomes, as a substitute of attempting to give you one grasp rule for every thing. So if I need one degree to have a container that is at all times empty, I’d specify rule CONTAINER_EMPTY within the parameters, or if I need a later degree to have a container with some good loot in I’d specify rule CONTAINER_LOOT_3.
Step 4 – Sources
And eventually there are the sources, that are parameterised by sort (Blue, Inexperienced, or Pink), amount, and the vary of depths they are often positioned at. At present, there are guidelines stating which asteroid sorts a useful resource could be positioned on (Blue crystals solely on purple asteroids, for instance), and for every asteroid form I pre-compute the useful resource placement positions and their depths, so on the subject of putting sources we do the next:
1. Select a useful resource to position
2. Get all asteroids this useful resource could be positioned on
3. Get all placement positions for the given depth vary for these asteroids
4. Select a placement place out of those positions that does not overlap with an current useful resource
5. Place the useful resource there
6. Repeat till all sources are positioned
That is pretty easy however permits for good distribution of sources within the degree. I do wish to enhance this by forcing some clusters of sources, or giving a bigger weighted vary of depths, so you’ll be able to specify {that a} useful resource might be positioned at depth 1, nevertheless it’s more likely to be positioned at depths 4 to six.
This era is a little more busy and compact to point out extra of what it is doing.
Hacking these Gifs collectively
I needed to point out gifs of the era taking place in considerably sluggish movement, so you’ll be able to see what is going on on. Within the precise sport this era occurs in a short time (Underneath 100ms in debug, which makes me suppose I’ve much more room if I wish to use extra sophisticated logic) so I wanted to sluggish it down and in addition present it taking place in actual time whereas the extent is working.
First I attempted throwing it on a separate thread and locking between updates in order that the principle thread and the era thread weren’t combating for a similar sources, however even that did not work due to some restrictions to utilizing graphics parts off of the principle thread (I generate every asteroid’s texture because it’s created).
So what I ended up doing is popping every methodology within the degree era right into a C# Generator Methodology, which mainly signifies that execution can pause and return at particular factors. With this I can do every thing on a single thread and await a timer to elapse between every degree era step or placement. Enjoyable!
What’s Subsequent?
Now that I’ve this working I will very simply add extra “filler” ranges between the extra hand designed ranges. It additionally means I can hand design extra ranges as regardless of the procedural era outputs is totally editable utilizing my makeshift degree editor, so if I see it producing one thing that I do know might be higher, I can do a couple of handbook tweaks and voila.
This additionally units the sport up properly for a possible countless mode after launch. Although I will not go so far as to vow this, as a result of I do not know what the state of issues shall be as soon as I truly get there.
If you have to this level, thanks a lot for studying, and I hope you discovered this all even barely fascinating. When you did, make sure to try Deep Area Exploitation on Steam!