How do game engines compile?

Started by
9 comments, last by WavyVirus 13 years, 1 month ago
Hello,

I've been trying to deal with this problem for a while now, I'm currently working on a game engine I could use to help myself later on, the thing is made in .NET C++, and is similiar in design plan to RPG Maker, and GameMaker and the such in the way that it handles the creation and handling of maps and events in the UI from .NET.

After the project is done, it is exported to code files in the format of native C++ using SDL.

Now, my problem is this part, I have the code generator mostly ready, it creates all the neccassery files for compilement and works well, now my problem is with actually compiling it automatically from within the GUI in .NET, I was thinking of using the CMD and vcvarsall.bat, but that didn't work, and thought about using makefiles, but that doesn't work on Windows, and I don't want the program to depend on too much external software by using NMake or something.

So, I guess, what I've come here to ask would be what are common methods for this type of thing? How do the popular engines, like the aformentioned ones, or Unity, or UDK, or any of the handful out there, work? How do they compile the work on them into and executable?
Advertisement
Unity has an embedded Mono runtime, which JIT-compiles .NET bytecode. The UDK uses UnrealScript, which is compiled to bytecode, and interpreted by Unreal's virtual machine. I'm not really understanding what exactly you have made. A code generator? Please elaborate.
Will Miller | Game Designer | Big Huge Games
Yes, it's a code generator, it takes all the data you input to it when you make the maps, events, and various other data and puts it in C++ format code through the algorithms of the program, is there any way to compile such a thing at run time?

And could I ask for some more information about those 2 methods you mentioned? Are they plausible for hobbyist use? How do you use them? Where can I read more, tutorials peraphs?

Thanks for replying.
You can't compile C++ at runtime.

That being said, I have seen the Tiny C Compiler (found here) used to compile C code at runtime and execute it. It's reasonably fast, but still not a popular solution when programming games. I'm still not quite understanding this code generator you have made. Did you write it yourself, or are you referring to the "designer view" in Visual Studio .NET (or something similar)?

Both Unity and the UDK are free to use. You will not be able to take whatever C++ code you're generating and run it in either of these engines. Unity is programmed using C#, JavaScript, or Boo. The UDK is programmed using UnrealScript and Kismet. I would advise you to check these engines out and learn how to use them before you try to write your own engine (if you write an engine at all - you should be writing games instead). Both of these engines have large communities and great resources to help you learn. They are both suitable for commercial and small-scale projects.
Will Miller | Game Designer | Big Huge Games
I'm writing the engine myself, it's using the .NET form project as a GUI, but implements algorithms for outputting .cpp and .h files for every map and event on the map, as well as graphics management and the such, I'm sorry if I haven't made that clear, and it has nothing to do with neigther UDK nor Unity, I was just giving examples as to what I mean in the way I want to compile.

As for TCC, it's nice, but I need a way to compile C++ code, not C, searching around about it suggest that it doesn't support that.
You could compile the C++ as a DLL using Visual C++, GCC, or something similar, then link it at runtime. Just know that there are much better and more practical approaches to this. Consider a scripting language like Lua or Python. Or have your engine generate XML or JSON when storing level data - these are much easier to load up and use.
Will Miller | Game Designer | Big Huge Games
Hi KazenoZ,

I'm not sure what you'd call an application which generates the c++ code for a game, but I don't think that "game engine" is entirely fitting - it's more like a "game generator" (although the common code this generated source code relies upon might be called a game engine). I'm also not familiar with any similar products - AFAIK this isn't such a common approach to a game-creation tool.

That said, you have a few options:

  • Write your own c++ compiler
  • Bundle an existing compiler with your product (ensuring licensing and such as all above-board)
  • Require the user to have a compiler already available
  • Scrap the c++ code generation/compilation model - you might generate code in a proprietary domain-specific language and write a VM. You could take an entirely data-driven approach (where a specific game consists entirely of "configuration"/content, and the same "host" application is always used to run the game - if you allow lots of complicated and varied options then this might become practically indistinguishable from creating a language/VM)
Thanks alot for the comments guys, especially you, Virus, I've taken fancy to the 4th approach and already started work on it and it seems great so far, perfect for my cause, thanks much for the tip.

  • Write your own c++ compiler
  • Bundle an existing compiler with your product (ensuring licensing and such as all above-board)
  • Require the user to have a compiler already available
  • Scrap the c++ code generation/compilation model - you might generate code in a proprietary domain-specific language and write a VM. You could take an entirely data-driven approach (where a specific game consists entirely of "configuration"/content, and the same "host" application is always used to run the game - if you allow lots of complicated and varied options then this might become practically indistinguishable from creating a language/VM)

LLVM is a good option for both ahead of time compilation and JIT compiling as part of a VM and it is distributed under an unrestrictive license. Clang is distributed under the GPL because the frontend uses GCC, but you may be able to bundle it anyway as long as you comply with the GPL (afaik since your code is separate from the GCC bianries you can release your code however you like, but you will want to check this yourself).

Of course, if you are embedding a full blown language (rather than data-driven configuration), unless you want something very specific to your engine, it would usually be better (easier and less buggy) to not write your own language and use an existing embeddable language like Lua (and LuaJIT if you want super fast), AngelScript, Squirrel or even Python. Actually, since you said you are using .NET you have a bunch of options there too. You could embed C# or F# or some other .NET language. Of course, then, as you said, you will need to bundle the compiler and will have to check the terms for the specific language. The engine wouldn't need to bundle these tools to the gamer, but the editor/tools would.
Ok, I'm getting a little lost here, could you guys sharpen my terminology?

So, a game ENGINE, is actually not a program you build the game through, but rather a set of functions that are externally linked to your program to make it easier to still WRITE in a regular compiler?

What IS such a program called then? How would you define RPG Maker for example?

And exactly is a VM? A virtual machine, I think? What does it even mean?


I'm sorry, it's just the first time I'm dealing with such a project, I'm not quite keen on the terms...

This topic is closed to new replies.

Advertisement