Summer Work (Day 14)

Procedural Terrain Generation pt.3

    Little progress has been made in actually fixing any of the things that I have meant to, but on the bright side I have managed to get different types of noise to work together.
    
    First off, the layered noise/detail problem from last blog. Turns out it was me being stupid and the generation was working exactly as it was supposed to. The "problem" was that I was looking at a relatively low resolution gen of the planet, so no matter what I did it would always have a maximum level of detail that it could render. I had the resolution at 16x16 per side so that the planet would respond quickly to updated to the settings. If I upped that to 128x128 or even 256x256 it would take considerably longer to update but would be more detailed.
    Once I figured that out I went no to creating different types of noise. The idea was to make ridge-like features on top of the rough and bumpy default generation. It ended up working, but only after frustration with VS. This was because I wanted a tree of inheritance in the noise generation classes to make iterating and creating new ones easier. I settled on an interface that would have the one required Evaluate() function for all noise types. Everything was fine until it came to creating the generator from the given generation type.
    I wanted to have a switch that would return a generator from the given generation type. The catch was that it had to return the parent class so that all the places that were using it could accept any variation in the type. I thought, since all of the generation classes were derived from this one parent, that there would be no problem... and I was right. Only VS was having a bad day or something and refused to compile. The first thing I tried was: "return new SimpleNoiseFilter(NoiseSettings);". VS didn't like it, saying there was no way to convert from SimpleNoiseFilter to INoiseFilter (the parent class). I then thought that I might have to cast, and that would be no problem because of the inheritance I described before.
    But using Unreal's Cast<T>() wouldn't work either, this time saying that it wouldn't take the argument list. I then turned to basic C++ casting and that gave me no red squiggles. I did: "dynamic_cast<INoiseFilter*>(SimpleNoiseFilter(NoiseSettings));". I compiled and then it gave errors. At that point I gave up for the day and left it to future me to solve.
    I came back today and "return new SimpleNoiseFilter(NoiseSettings);" worked. Just like that I had ridged mountains and hilly continents.

    Other than that, I have put some time into making the project cleaner. I realized that you can put UENUMs above a UCLASS in the same file so that's cool, and as a bonus also means I have less files to deal with. I then went on to tackle making the noise settings variables cleaner. My first thought was to make them into structs. Then by using a USTRUCT I could still see and edit them in editor but I could also use extra things that are special to structs. 
    I tried this out and the problem that I have run into is actually accessing these variables. Now that they are now technically UNoiseSettings.... nevermind. While writing this I went back to the code to see if I could grab the error message to put here, but instead I managed to fix it. The downside is that it requires that I move the UENUM back to its own separate file so that it can have a specialized .generated.h.
    So it turns out the problem was I was just using the wrong syntax to try to access the struct. I was trying to do UNoiseSettings::FSimpleNoiseSettings where I should have just been using FSimpleNoiseSettings. Makes sense now but I'm really glad that works. The only remaining problem is that the noise variables don't show up in the editor anymore because they are part of the struct... hmmm.
    Another win! All that took was the struct specifier "BlueprintType". Now I'll stop. The real last problem is that all settings show up when you have one selected. This was also an issue in the Unity project and to fix that it took editor scripting. I assume Unreal will have something similar, or maybe it's just more specifiers. ;)

Comments

Popular posts from this blog

Polishing the Foundation

Progress Update #13

A New Chapter