Hilbert Curve Procedural Project

Click for better view

Problem

The last project for Tech Art class was to do anything with the only requirements being weekly updates. I’ve always liked the idea of procedural content especially when it comes to dungeon/level layouts. Oddly enough, I felt like I had more experience C++ coding in Unreal Engine 4 than working with Houdini and I felt that any time I spent learning more Houdini would take away from my research time. So for the project I needed to make a procedural dungeon maker in UE4.

Solution

At the end of the day the project goal wasn’t to make a dungeon maker but something that could make the golden path for a level and add dead ends to that path to make it interesting. There are many ways to do this and the solution really depends on the game. However, I was doing this as a fun way to learn about procedural content generation and not to for a game. So I picked a pre existing solution that really intrigued me. I would make the golden path based off of a Hilbert Curve algorithm much like what was used in Galak-Z.

hilbert-1-to-4-600px.png

Process

The beginning of the project was focused heavily on collecting and examining resources on the subject. After settling on approaching the problem the same way as Galak-Z I began making prototypes just for producing a Hilbert Curve. I will note I looked into other methods such as using 2d physics to blaw the rooms into place or cell automata. Once I could successfully produce a Hilbert Curve of varying dimensions I looked into how I could walk along that path to make the golden path.

Hilbert.png

The approach is probably the same as Galak-Z minus specific rules for picking points along the Hilbert Curve. That is we walk along the hilbert curve and only mark points that fall within a specific area on the curve. Say the Hilbert Curve is a size of 16x16 then we would use an area, a sample size, of 8x8. So we have a curve path we walk and a path specific to the sample size that we will use for the golden path. When the curve path we are walking exits the sample size we just continue the golden path when the curve path re enters the sample size. Sometimes a point on the curve path will never lead back into the sample size. These points are marked for later and can be used as dead ends to add variety to the golden path.

Once I got the golden path running with dead ends I was happy. However, I still needed a visually appealing way to show this in engine. I tried approaching this as if I had to take everything I did for this project and hand it off to a level designer or environment artist to use. In engine the algorithm would randomly pick from premade rooms to place along the path. The question then was would you use level streaming or blueprints to make these premade rooms. I used blueprints for testing and level streaming for the actual rooms themselves. I think from a user perspective it’s more time consuming to make edits in a blueprint and compile than it is to make changes to a sub level especially when lighting is involved. The only issue I ran into was getting level streaming to work in C++. Eventually I had scrap it and have all the streaming code in a blueprint that would talk to containers or functions I made in C++.

Test Path

Test Path with premade rooms

Code

Github link to view the code.

The main class in the code is the LayoutGenerator. It talks to or knows about the Cell, Grid, and Hilbert. The LayoutGenerator contains a Layout which is a Grid and a Grid contains a couple collections of Cells. The Cells know a few things like what Cell came before them, what type of Cell, the direction of the Cell, etc.