Jump to content
  • Advertisement
Sign in to follow this  

Using C++ codebase

This topic is 1552 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

To start off, let me give you some perspective on my situation, so you can better understand my rather insignificant and trivial struggles. If you would like to skip some of this background to get to the actual question I have, feel free.
My programming experience is limited to a few community college classes, two classes in java, one class in C++. Unfortunately for me, the C++ class was rather poorly instructed, and I didn't learn anything that I couldn't have figured out by myself, with my prior knowledge from learning java.
My instructor teaching java was literally the best teacher I have ever had, anywhere, for any subject. He started out by explaining a lot of very primitive and basic things about how computers actually worked, things like the differences between the stack and the heap, how errors get tossed around and what order they get tossed around, and why errors show up in certain places when the actual error was somewhere else. He explained what the compiler actually did (in a nutshell) and showed us how to use the compiler using the command line, where the compiler was actually located on our machines, and a bunch of other awesome things that I've never had any other resource teach me. At the same time he kept the interest of almost the entire class the whole way through the introductory class, and helped us develop small command-line programs, and introduced us to some existing code (i think it was the ACM framework) to show us how to use code written by someone else.
I've done some work on my own in programming as well, but nothing beyond some simple command-line games with ASCII text representations, like that one Linux game with the guy running from the robots. I also am an enthusiastic 3d modeler (I've been doing it since I was 13 with good'ol Rhino) and have a small amount of experience with texturing, and a decent amount of experience using gimp (and Photoshop when I was in school).
Anyway, I feel like I have a really solid grasp on the fundamentals of programming, and I decided that I want to actually start making the game that I want to make.
Now one thing that you should understand about my thinking when it comes to programming, which was mentioned a lot of times by my teacher, is to try not to "re-invent the wheel." I am aware that there are PLENTY of very talented people working on building great game engines for people like me to use for my purposes, so I have 0 hesitation in deciding to use an already built game engine.
After a lot of comparisons in many different areas, I decided on using UE4 as my engine of choice, and was excited to get back into programming for a purpose other than demonstration of knowledge. After messing around in UE4 with the blueprint system, I fell in love with the engine, and I've been constantly making and refining plans for how my game logic and save system will work.
The largest influence to my game is going to be the procedurally generated nature of it. Because of this, I've done a lot of reasearch on different ways of doing procgen for games, and settled on using a noise function. In my implementation, I will be using the noise to generate values on a grid, which will then be used to place types of terrain, buildings, etc. I will be using the noise function in a lot of different ways, with a lot of different modifications on the parameters and the output to get the noise shaped how I want.
I settled on Kevin Perlin's simplex noise, because I really like how easy and fast it is, and the 'coherency' of it. The fact that it is also a gradiented noise, and just in general how it works (feed it x and y values, in my case 'coordinates,' and get a number between -1 and 1). Also the fact that it is 'tileable,' or rather, you can keep generating noise for whatever values you want, makes it perfect for the open-world type procedural game that I intend to make.
To my excitement I was able to use the noise function (which was released to public domain, the C++ variant i'm using is under GPL v3) in a simple console application to apply values between 1 and 10 to an array and display it on the console, while randomizing the z value for different 'slices' of noise, demonstrating to myself that I knew how to make use of it's functionality.
Here is my dilemma:
I want to use the actual noise class (not the separate one I wrote for the console) in my UE4 project and expose the noise function I want as a blueprint node, so I can feed values and get my float while blueprinting. I've done a lot of reading on how to do the 'exposing' part, but my largest problem, i think, is that the simplex noise class makes use of math.h. I'm not sure exactly where it uses this, but that brings me to my larger problem: I know very VERY little about how more complicated C++ programs are built.
Most of the programming I've done in the past was on a single file, because it was simple, and most of the time didn't make use of any codebase other than standard libraries and such, where you just needed one line to include it.
What I need is some sort of resource that explains in detail, how these large programs are set up. I don't need to know how UE4 does all of the things it does, but I do need to know how C++ works with all the header files, static libraries, source files, etc.
I feel like I can't find enough resources online, (other than books) and it's hard for me to google search things on these specific topics, because most of the keywords turn up all of these copy-pasted garbage tutorials on how to write "hello world". I know how to write a header file for my shitty little console programs, and why/how the header files are used. What i don't know is things like, do they have to be in the same folder? How do I make use of it in another program I'm building? How do I let my program know where to look for the header file? When would you use a static library and how? What kind of problems might I run into when building an application with these things?
I'm trying to find a good resource that teaches these types of things, because the only thing I've been able to do these past few days, is to do a very specific google search for every problem that I run into when trying to incorporate this noise function into my UE4 project.
How can I incorporate a function (which #includes math.h) into UE4 from a .cpp and .h file for use as a blueprint node? If there are multiple ways, what would be the way you would do it?
What is your recommended resource for learning C++ things like static/dynamic libraries, different ways to make use of existing codebases, and just the general structure of a larger C++ program?
I know that if I learned more about these things, a lot of the problems that I run into when trying to do something like this, I could figure out for myself. It would just be really nice if there was a resource that teaches this sort of structure of a C++ program, so when i run into future problems i'll at least have a vague/high level understanding of what I need to do.
To anybody that reads this whole thing, thank you very much for your time. I hope I didn't annoy anybody.

Share this post

Link to post
Share on other sites

Your questions are a bit vague, even though you're trying to be precise. I'll try to answer them though...


"What is the general structure of a larger C++ program?"

That really depends on what the program is trying to do and how it is architected. This is very hard to answer because it's similar to asking "What is the general structure of a building?"

So... for most C++ programs, you usually have tons of files broken down by classes. Usually you have a header file which defines all of the class headers, variables, functions, etc. Then the CPP file usually contains the implementations of the "stuff" described in the header file. I'm sure you already know that though, so I'm not sure what you're trying to answer. The second bit is how all of those classes interact with each other (aka, object oriented programming). When enough classes are used often enough and are general enough to be used all over the place, people create "libraries" which expose the commonly used data structures (such as lists/vectors, hash tables, sorting methods, etc). Usually you don't care about the implementation so long as it works as expected.


I think that if you're trying to incorporate the exposed functions from "math.h" into UE4, you'd probably want to create wrappers for each of the methods in math.h you'd like to use in UE4. But, as I recall, UE4 already comes with a robust math library so you're probably wasting your time and instead should be trying to figure out how to use their math library. I'm sure the differences in the implementation of Sine and Cosine yield the same results, right? Regardless, it doesn't sound right that you should be having trouble with including a header file into your program. Usually when you include a header file, you're giving the compiler a path to a distinct file which exists somewhere on the hard drive. When the compiler compiles the program, it takes all of the header files and cpp files and creates a single binary executable. If your project includes or references an external library (like a DLL), then the program it compiles will try to reference the DLL instead of adding its binary into your executable. For this reason, it is very important that the DLL on all computers which run your program are the same version or support backwards compatibility. Many games will bundle the dependent DLL's as a part of the installation process just to make sure that the right versions are being used.

If you're using Visual Studio, usually you can step through your code line by line, and step into functions to see where the implementation lives (or just highlight a method and press F12). This should tell you where any calls to math.h are being made. This also gives you a pretty good idea on how stuff is laid out in the framework you're using. For most programs/frameworks/libraries, the best way to get an understanding of their layout is to read the Application Programming Interface documentation. It's always specific to the API, so that's about all the help I can give you on program internals... Hope this helps!

Share this post

Link to post
Share on other sites

Maybe this would be a better thing to post on the unreal forums. What you mentioned about DLL's was helpful, it sounds like they have the behavior that I expected, I just find it frustrating that I have this piece of code that works on my machine so nicely all by itself, and there is such difficulty for me to figure out how to incorporate it into my UE4 project. I feel like there should be a way for me to just extend a class from a UE4 blueprint node and just #include it or something. I just don't know the rules, like what does it mean to #include something? how is that different than extending a class? You don't have to answer that, i'll end up googling it, but I just wish that the information about these types of things, like how all these files work together, would be accessible in one place, instead of me having to google search every single time I have a question like this. I.E.: if I search for information about header files, the places that I find information about header files doesn't mention any of the other types of files unless I do a lot of digging around. Heck I only found out about what libraries were very recently. Until a week or so ago, I didn't think DLL had anything to do with C++. I thought it was just some super low level operating system jargon or something.

Who knows, maybe I'm just too hopeful, It just feels like most of the teaching resources I've found jump from "hello world" to simple collections to advanced algorithms. How the heck is that useful if I don't even know how to re-use existing code? Maybe I'm just complaining too much.

Either way, thanks for your input, it was helpful.

Share this post

Link to post
Share on other sites
#include is to do with bringing in files; it is a pre-processor command which basically copies and pastes the code in the named file into the current .cpp being compiled.

In the case of 'math.h' this is a standard header file and #include will pull it into the file you are compiling.

DLLs have nothing to do with C or C++ directly, this is correct - they are an OS thing.

The UE4 blueprint stuff does largely work how you expect; you derive your new blueprint class or function from an existing base class and implement your code there. The docs on Blueprint development might help although I think you might need to improve your C++ knowledge a bit before getting into trying to code them.

Finally, a note on your noise lib of choice; the UE4 license specifically calls out the fact you are not allowed to use it with GPL code - while you keep it on your machine you are technically OK but you can never release your code, nor anything based on it, due to this restriction.

Share this post

Link to post
Share on other sites

Thanks phantom, that's really good to know. I'll be sure to try to dig up the original public domain version of the code then. I was worried this might be the case with the GPL v3, I wonder why they force my whole program to be open source when i could just release the source on the part under the GPL. That's some freedom for ya. Oh well, time to do some more digging i guess. I'm pretty sure Perlin has a C++ version of simplex when he released his algorithm to public domain, if not then hopefully it won't be too hard for me to grab the C# one that I know for sure is on public domain and rewrite it as C++.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!