Sign in to follow this  
KazenoZ

Unity How do game engines compile?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You can't compile C++ at runtime.

That being said, I have seen the Tiny C Compiler (found [url="http://bellard.org/tcc/"]here[/url]) 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 [url="http://www.unity3d.com"]Unity[/url] and the [url="http://udk.com/"]UDK[/url] 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

[list][*]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)[/list]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='WavyVirus' timestamp='1298490388' post='4778096']
[list][*]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)[/list][/quote]
[url="http://llvm.org/"]LLVM[/url] is a good option for both ahead of time compilation and JIT compiling as part of a VM and it is distributed under an [url="http://llvm.org/svn/llvm-project/llvm/trunk/LICENSE.TXT"]unrestrictive license[/url]. 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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
First off I should point out that I agree with dublindan that, if you are more interested in getting results than experimenting with programming languages, generating code in an existing scripting language is probably the most practical approach

[quote name='KazenoZ' timestamp='1298718694' post='4779274']Ok, I'm getting a little lost here, could you guys sharpen my terminology here?


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?[/quote]


The definition of "game engine" isn't unanimously agreed upon, but the following is my attempt to define it:

[i]A game engine is a collection of software components used in the production of games, which is separate from the content, game-world and gameplay rules that define a particular game. It is reusable, sufficiently generic code which aids in the creation of many different games by exposing an interface to common, often lower-level functionality such as rendering, audio or physics systems.[/i]

The line between game and engine is often blurry - an engine could be extremely generic, or targeted at a more specific type of game (it might, for example, include the concept of a "ragdoll", a "weapon" or a "quest" - a more generic game engine might only deal with things as specific as a "sprite", "sound" or "mesh"). A game engine might come with a set of tools designed around it, or might be simply a collection of code.[i]
[/i]

I would call RPG Maker a "game development tool" or something similar. again, I don't know if there are black and white definitions here.




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


A "machine", in this context, can be thought of as a system for processing a sequence instructions encoded in some specific format. Your PC is a machine, with a CPU processing a list low-level instructions from a well-defined set of possible instructions (e.g. "read a byte from location X, storing it in Y", "add value X to the value in location Y"). A "virtual machine" is a machine running on top of a second machine, e.g. a "simulated" machine running on top of a physical machine. A virtual machine is usually a natively-compiled "host" program which interprets and executes a second program made up of instructions defined by the creator of the VM.

A natively-compiled program is a chunk of low-level code generated (from source code in some language) to run on a specific architecture, made from a specific set of instructions which the architecture supports. This is why different c++ compilers are required for different operating systems/CPUs. A program compiled to run on a VM usually takes the form of "bytecode" (also compiled from source code in some language), which doesnt care about the specific physical architecture it is running on - the VM itself is compiled for various architectures, and executes the correct architecture-specific code "on behalf" of the program running within the VM. The bytecode instructions which the VM recognises are often more high-level, for example "Add X days to date Y" or even something like "Draw image X at location Y" (how high level these instructions are depends on how general-purpose the language supported by the VM is designed to be.

So a VM is effectively a program which "runs" another program inside of itself, by reading an interpreting instructions/commands made up by the developer of the VM.

This could be applied to your project in a couple of ways -

[list][*]You can embed the VM for an existing language like Lua, generating Lua code and handing it off to the Lua VM to execute for you - you provide Lua with "hooks" into your own code to allow it to call functions to draw stuff etc.[*]You dream up your own set of instructions which you think are flexible enough to allow a game to be expressed in terms of. Your front-end tool ultimately generates a set of instructions in the instruction set you have defined - often intermediate representations of the program (or game in your case) are used before it is "compiled" into the final instruction set. You then implement a "back-end" VM which allows such a game to actually be executed by interpreting the instructions and doing whatever is necessary to "execute" each one[/list]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627708
    • Total Posts
      2978730
  • Similar Content

    • By Canislupus54
       
      I'm looking for a team to help me out with a 3D platformer. Basically, you jump between platforms with parkour elements and you fight enemies with a mix of melee and ranged attacks. This is purely a hobby project. I'm not promising any payment, ever. You can do it for experience, to learn, for fun, whatever, as long as you don't expect to get paid. Right now I need a 3D modeler and animator. Reply or email me at jordestoj@yahoo.com if you're interested. Thanks.
    • By Pixelated_Nate
      Hi all!
      We are looking for a C# programmer for our 2D Action RPG titled Adavia, made in Unity.
      The game itself is akin to Legend of Zelda: Link to the Past, though we're also adding in traditional RPG elements such as Character Creation.
      This is more of a hobby than anything commercial, if it somehow does manage to go commercially, all revenue will be split equally among the team.
      If you're interested, we ask that you be comfortable with:
      Unity Coding A.I's for enemies and NPCs. Working with GUI's. Communicating regularly with the team via Skype (text only). If you have any questions or would like to apply, please contact me at nathan.jenkins1012@gmail.com
       
    • By MrGiratinaORIGINAL

      I'm the co-director of LM Team, a 7-member team currently constructing a fangame based upon the Mega Man series. We've been working for about 2 years now, and both of our current programmers are busy for the next 6 months or so. Because of this, we're currently looking for a programmer (or more) to take care of gameplay and animation programming. We already have a base system in place that may optionally be built upon. This will be a hobby project to invest your free time in, not a gamedev gig.
      We're currently about 67% done with the OST, 75% done with the design work, and 33% done with the graphical work. As such, the specifications of what we need should remain pretty stagnant from now on.
      Here's some links of our team's work, to give you an idea of what we're currently capable of achieving:
      Actual Y+1 Stuff:
      - Current public playlist of music
      - Old footage of the first boss of the game, since been altered slightly based on feedback
      - Mockups
      m9m (director, composer):
       
      - Grand Dad Reboot - Ominous Cavern
      - Lands of Onlup
      - Mega Man Revolution Remix - Wily 2
      MrKyurem (co-director, main designer, me):
      - Boil Man - 10th place in Make a Good Mega Man Level 2 Contest
      NaOH (programmer [not programmer who is currently working on the engine]):
      - Programmer for Make a Good Mega Man Level 2 Contest's release game (did co-op mode and leaderboard functionality)
      - 15 years of programming experience
      - Castlevania 3 controls romhack
      - GML code beautifier
      - Beat-Em-Up engine
      Alm (artist):
      - Cutscene for a personal project
      - Tileset for Boil Man's stage in MaGMML2
      - Concept sprite
      Valo (artist):
      - Jungle Man tileset in Mega Man SD
      - Boxart for Mega Man SD
      - Wily sprite
      Karakato (artist):
      - Robot Masters in BCA
      - Idol Woman
      - Stage Select for separate project
      Deathro (composer):
      - Through the Eye of a Prism - 2nd place in Famicompo 2015's Original category
      - Mega Man SFR - Wily 2
      - Geno Force - Silent Breeze
      Contact
      If you're interested in joining, I'd recommend signing up to Discord, as we almost exclusively communicate through this.
      Discord Tags:
      MrKyurem#8741
      m9m#1104
      Email:
      LMTeam.Y1@gmail.com
    • By ilovegames
      You are the commander of a special forces squadron. You were given a task that appeared simple at first glance - to check for suspicious activity in the building of an abandoned psychiatric hospital. But you could not even imagine what you will actually have to face.
      Download https://falcoware.com/HospitalSurvival.php



    • By ilovegames
      You find yourself in an abandoned place full of mutants in the dead of night, and have to kill waves of monsters with a different kind of weapon. The main goal is to survive through the night.
      Controls:
      WASD – Walk
      Shift – Run
      Mouse1 - Attack
      Space - Jump
      Scroll Down – Change weapon
      Esc - Exit, pause
      Download https://falcoware.com/NightSurvival.php



  • Popular Now